2 * Created by ob0695 on 6/5/2018.
5 * ============LICENSE_START=======================================================
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
25 * Created by rc2122 on 5/23/2017.
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";
35 export class WorkspaceService {
37 public metadata:ComponentMetadata;
39 constructor(private cacheService:CacheService) {
43 public setComponentMetadata = (metadata: ComponentMetadata) => {
44 this.metadata = metadata;
47 public getMetadataType(): string {
48 switch (this.metadata.componentType) {
49 case ComponentType.SERVICE:
50 return ComponentType.SERVICE;
52 return this.metadata.resourceType;
56 public getComponentMode = (component:TopologyTemplate):WorkspaceMode => {//return if is edit or view for resource or service
57 let mode = WorkspaceMode.VIEW;
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;