2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 import * as _ from "lodash";
22 import {ArtifactModel} from "../models/artifacts";
23 import {IArtifactResourceFormViewModelScope} from "../view-models/forms/artifact-form/artifact-form-view-model";
24 import {Component} from "../models/components/component";
25 import {ArtifactGroupType, ArtifactType} from "./constants";
27 export class ArtifactsUtils {
33 constructor(private $filter:ng.IFilterService) {
37 public getArtifactTypeByState(currentState:string):string {
38 switch (currentState) {
39 case "workspace.composition.lifecycle":
41 case "workspace.composition.api":
43 case "workspace.deployment_artifacts":
44 case "workspace.composition.deployment":
46 case "workspace.composition.artifacts":
47 return "informational";
49 return "informational";
53 public getTitle(artifactType:string, selectedComponent:Component):string {
54 switch (artifactType) {
56 return "Lifecycle Management";
58 return "API Artifacts";
60 return "Deployment Artifacts";
62 return "Informational Artifacts";
64 if (!selectedComponent) {
67 return this.$filter("resourceName")(selectedComponent.name) + ' Artifacts';
72 public setArtifactType = (artifact:ArtifactModel, artifactType:string):void => {
73 switch (artifactType) {
75 artifact.artifactGroupType = ArtifactGroupType.SERVICE_API;
78 artifact.artifactGroupType = ArtifactGroupType.DEPLOYMENT;
81 artifact.artifactGroupType = ArtifactGroupType.INFORMATION;
86 public isLicenseType = (artifactType:string):boolean => {
87 let isLicense:boolean = false;
89 if (ArtifactType.VENDOR_LICENSE === artifactType || ArtifactType.VF_LICENSE === artifactType) {
96 public removeArtifact = (artifact:ArtifactModel, artifactsArr:Array<ArtifactModel>):void => {
98 if (!artifact.mandatory && (ArtifactGroupType.INFORMATION == artifact.artifactGroupType ||
99 ArtifactGroupType.DEPLOYMENT == artifact.artifactGroupType)) {
100 _.remove(artifactsArr, {uniqueId: artifact.uniqueId});
103 let artifactToDelete = _.find(artifactsArr, {uniqueId: artifact.uniqueId});
105 delete artifactToDelete.esId;
106 delete artifactToDelete.description;
107 delete artifactToDelete.artifactName;
108 delete artifactToDelete.apiUrl;
112 public addAnotherAfterSave(scope:IArtifactResourceFormViewModelScope) {
113 let newArtifact = new ArtifactModel();
114 this.setArtifactType(newArtifact, scope.artifactType);
115 scope.editArtifactResourceModel.artifactResource = newArtifact;
117 scope.forms.editForm['description'].$setPristine();
118 if (scope.forms.editForm['artifactLabel']) {
119 scope.forms.editForm['artifactLabel'].$setPristine();
121 if (scope.forms.editForm['type']) {
122 scope.forms.editForm['type'].$setPristine();