summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/view-models/designers/designers-view-model.ts
blob: 42c119425827e6c913f9dd0db1773bdf80701acc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import {Designer, IUserProperties, DesignersConfiguration} from "app/models";
import {CacheService} from "app/services";
import {MenuItemGroup} from "app/utils";


interface IDesignerViewModelScope extends ng.IScope {
    designer: Designer
    topNavMenuModel:Array<MenuItemGroup>;
    user:IUserProperties;
    version:string;
}

export class DesignersViewModel {
    static '$inject' = [
        '$scope',
        '$stateParams',
        '$sce',
        'Sdc.Services.CacheService'
    ];

    constructor(private $scope:IDesignerViewModelScope,
                private $stateParams:any,
                private $sce:any,
                private cacheService:CacheService) {

        this.initScope();
    }

    private initScope = ():void => {
        // get the designer object by using the path parameter
        let designerKey: any = _.findKey(DesignersConfiguration.designers, (designerConfig: Designer) =>{
            return designerConfig.designerStateUrl ===  this.$stateParams.path;
        });

        this.$scope.designer = DesignersConfiguration.designers[designerKey];

        this.$scope.version = this.cacheService.get('version');
        this.$scope.topNavMenuModel = [];

        this.$scope.user = this.cacheService.get('user');
    }
}