Release version 1.13.7
[sdc.git] / catalog-ui / src / app / ng2 / pages / workspace / workspace.service.ts
1 /**
2  * Created by ob0695 on 6/5/2018.
3  */
4 /*-
5  * ============LICENSE_START=======================================================
6  * SDC
7  * ================================================================================
8  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  */
23
24 /**
25  * Created by rc2122 on 5/23/2017.
26  */
27 import { Injectable } from '@angular/core';
28 import {WorkspaceMode, ComponentState, Role} from "../../../utils/constants";
29 import {Component as TopologyTemplate, ComponentMetadata} from "app/models";
30 import {CacheService} from "../../services/cache.service";
31 import {IComponentMetadata} from "../../../models/component-metadata";
32 import {ComponentType} from "../../../utils";
33
34 @Injectable()
35 export class WorkspaceService {
36
37     public metadata:ComponentMetadata;
38
39     constructor(private cacheService:CacheService) {
40
41     }
42
43     public setComponentMetadata = (metadata: ComponentMetadata) => {
44         this.metadata = metadata;
45     }
46
47     public getMetadataType(): string {
48         switch (this.metadata.componentType) {
49             case ComponentType.SERVICE:
50                 return ComponentType.SERVICE;
51             default:
52                 return this.metadata.resourceType;
53         }
54     }
55
56     public getComponentMode = (component:TopologyTemplate):WorkspaceMode => {//return if is edit or view for resource or service
57         let mode = WorkspaceMode.VIEW;
58
59         let user = this.cacheService.get("user");
60         if (component.lifecycleState === ComponentState.NOT_CERTIFIED_CHECKOUT &&
61             component.lastUpdaterUserId === user.userId) {
62             if ((component.isService() || component.isResource()) && user.role == Role.DESIGNER) {
63                 mode = WorkspaceMode.EDIT;
64             }
65         }
66         return mode;
67     }
68 }
69
70