File

src/app/models/kidaia-org.ts

Properties

active
active: boolean
Type : boolean
code
code: string
Type : string
isDemo
isDemo: boolean
Type : boolean
name
name: string
Type : string
import { AppUtils } from '../app-utils';
import { OseMap, TerritoireMap } from './ose-maps';
import { POI } from './poi';
import { KidaiaSso } from './user';
export interface OrganizationConfig {
  name: string;
  active: boolean;
  code?: string;
  isDemo?: boolean;
}

export class KidaiaOrg {
  private organizations: Map<string, OrganizationConfig> = new Map();
  private url: string[];
  constructor(territoireMaps: TerritoireMap[]) {
    this.url = window.location.pathname.split('/').filter(part => part !== '');
    territoireMaps.forEach((territoireMap) => {
      if(territoireMap.url){
        this.registerOrganization(territoireMap.url, {
          name: territoireMap.url,
          active: false,
          code: territoireMap.code,
          isDemo: false
        });
      }
    });
  }

  registerOrganization(orgId: string, config: OrganizationConfig) {
    this.organizations.set(orgId, config);
  }

  isOrganizationActive(orgId: string): boolean {
    return this.organizations.get(orgId)?.active || false;
  }

  activateOrganization(orgId: string,isDemo: boolean = false) {
    const org = this.organizations.get(orgId);
    if (org) {
      org.active = true;
      org.isDemo = isDemo;
    }
  }

  getOrganizationConfig(orgId: string): OrganizationConfig | undefined {
    return this.organizations.get(orgId);
  }

  getTerrioirePath(orgId: string): string | undefined {
    if(this.organizations.has(orgId)){
      let currentRoute = `/territoire/${orgId}`;
      if (this.url[2]) {
        currentRoute += `/${this.url[2]}`;
      }
      return currentRoute;
    }
    return null;
  }

  getActiveOrganization(): OrganizationConfig | undefined {
    return Array.from(this.organizations.values()).find((org) => org.active);
  }

  removeActiveOrganization() {
    const org = this.getActiveOrganization();
    if (org) {
      org.active = false;
    }
  }

  getOrganizationsCodeClasse(): string[] {
    return Array.from(this.organizations.values()).map((org) => org.code);
  }
// "bellevilleenbeaujolais"
  checkIntegration(orgParam: string): boolean {
    if (orgParam) {
      if (this.organizations.has(orgParam)) {
        this.activateOrganization(orgParam);
        return true;
      }
    }
    const hasOrg = this.url.some((part) => {
      if (this.organizations.has(part)) {
        this.activateOrganization(part);
        return true;
      }
    })

    return hasOrg;
  }

  needActivateDemoAccount(codeClasse: string): boolean {
    if(codeClasse === "5agp4"){
      this.activateOrganization("bellevilleenbeaujolais",true);
      return true;
    }
    return false;
  }




  getPoi(listPOI: POI[], poiCurrentId: number): number {
    if (this.getActiveOrganization()) {
      const poiTag = AppUtils.getUrlParams()?.poi
      if (poiTag) {
        const poi = listPOI.find((element) => {
          if (element.id === poiCurrentId) {
            return element.maps.some((map) => {
              return map.tag === poiTag
            })
          }
        })
        if (poi) {
          return poi.id
        }
      }
    }
    return null;
  }

}


results matching ""

    No results matching ""