blob: d6ea616c1e8aedf0e8b765be2df6723af08a30fd [file] [log] [blame]
Michael Landodd603392017-07-12 00:54:52 +03001/*-
2 * ============LICENSE_START=======================================================
3 * SDC
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20
Michael Landoed64b5e2017-06-09 03:19:04 +030021import {ArtifactModel} from "../models/artifacts";
22import {IArtifactResourceFormViewModelScope} from "../view-models/forms/artifact-form/artifact-form-view-model";
23import {Component} from "../models/components/component";
24import {ArtifactGroupType, ArtifactType} from "./constants";
25export class ArtifactsUtils {
26
27 static '$inject' = [
28 '$filter'
29 ];
30
31 constructor(private $filter:ng.IFilterService) {
32
33 }
34
35 public getArtifactTypeByState(currentState:string):string {
36 switch (currentState) {
37 case "workspace.composition.lifecycle":
38 return "interface";
39 case "workspace.composition.api":
40 return "api";
41 case "workspace.deployment_artifacts":
42 case "workspace.composition.deployment":
43 return "deployment";
44 case "workspace.composition.artifacts":
45 return "informational";
46 default:
47 return "informational";
48 }
49 }
50
51 public getTitle(artifactType:string, selectedComponent:Component):string {
52 switch (artifactType) {
53 case "interface":
54 return "Lifecycle Management";
55 case "api":
56 return "API Artifacts";
57 case "deployment":
58 return "Deployment Artifacts";
59 case "informational":
60 return "Informational Artifacts";
61 default:
62 if (!selectedComponent) {
63 return "";
64 } else {
65 return this.$filter("resourceName")(selectedComponent.name) + ' Artifacts';
66 }
67 }
68 }
69
70 public setArtifactType = (artifact:ArtifactModel, artifactType:string):void => {
71 switch (artifactType) {
72 case "api":
73 artifact.artifactGroupType = ArtifactGroupType.SERVICE_API;
74 break;
75 case "deployment":
76 artifact.artifactGroupType = ArtifactGroupType.DEPLOYMENT;
77 break;
78 default:
79 artifact.artifactGroupType = ArtifactGroupType.INFORMATION;
80 break;
81 }
82 };
83
84 public isLicenseType = (artifactType:string):boolean => {
85 let isLicense:boolean = false;
86
87 if (ArtifactType.VENDOR_LICENSE === artifactType || ArtifactType.VF_LICENSE === artifactType) {
88 isLicense = true;
89 }
90
91 return isLicense;
92 };
93
94 public removeArtifact = (artifact:ArtifactModel, artifactsArr:Array<ArtifactModel>):void => {
95
96 if (!artifact.mandatory && (ArtifactGroupType.INFORMATION == artifact.artifactGroupType ||
97 ArtifactGroupType.DEPLOYMENT == artifact.artifactGroupType)) {
98 _.remove(artifactsArr, {uniqueId: artifact.uniqueId});
99 }
100 else {
101 let artifactToDelete = _.find(artifactsArr, {uniqueId: artifact.uniqueId});
102
103 delete artifactToDelete.esId;
104 delete artifactToDelete.description;
105 delete artifactToDelete.artifactName;
106 delete artifactToDelete.apiUrl;
107 }
108 };
109
110 public addAnotherAfterSave(scope:IArtifactResourceFormViewModelScope) {
111 let newArtifact = new ArtifactModel();
112 this.setArtifactType(newArtifact, scope.artifactType);
113 scope.editArtifactResourceModel.artifactResource = newArtifact;
114
115 scope.forms.editForm['description'].$setPristine();
116 if (scope.forms.editForm['artifactLabel']) {
117 scope.forms.editForm['artifactLabel'].$setPristine();
118 }
119 if (scope.forms.editForm['type']) {
120 scope.forms.editForm['type'].$setPristine();
121 }
122
123 }
124}