Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 1 | import {ArtifactModel} from "../models/artifacts"; |
| 2 | import {IArtifactResourceFormViewModelScope} from "../view-models/forms/artifact-form/artifact-form-view-model"; |
| 3 | import {Component} from "../models/components/component"; |
| 4 | import {ArtifactGroupType, ArtifactType} from "./constants"; |
| 5 | export class ArtifactsUtils { |
| 6 | |
| 7 | static '$inject' = [ |
| 8 | '$filter' |
| 9 | ]; |
| 10 | |
| 11 | constructor(private $filter:ng.IFilterService) { |
| 12 | |
| 13 | } |
| 14 | |
| 15 | public getArtifactTypeByState(currentState:string):string { |
| 16 | switch (currentState) { |
| 17 | case "workspace.composition.lifecycle": |
| 18 | return "interface"; |
| 19 | case "workspace.composition.api": |
| 20 | return "api"; |
| 21 | case "workspace.deployment_artifacts": |
| 22 | case "workspace.composition.deployment": |
| 23 | return "deployment"; |
| 24 | case "workspace.composition.artifacts": |
| 25 | return "informational"; |
| 26 | default: |
| 27 | return "informational"; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | public getTitle(artifactType:string, selectedComponent:Component):string { |
| 32 | switch (artifactType) { |
| 33 | case "interface": |
| 34 | return "Lifecycle Management"; |
| 35 | case "api": |
| 36 | return "API Artifacts"; |
| 37 | case "deployment": |
| 38 | return "Deployment Artifacts"; |
| 39 | case "informational": |
| 40 | return "Informational Artifacts"; |
| 41 | default: |
| 42 | if (!selectedComponent) { |
| 43 | return ""; |
| 44 | } else { |
| 45 | return this.$filter("resourceName")(selectedComponent.name) + ' Artifacts'; |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | public setArtifactType = (artifact:ArtifactModel, artifactType:string):void => { |
| 51 | switch (artifactType) { |
| 52 | case "api": |
| 53 | artifact.artifactGroupType = ArtifactGroupType.SERVICE_API; |
| 54 | break; |
| 55 | case "deployment": |
| 56 | artifact.artifactGroupType = ArtifactGroupType.DEPLOYMENT; |
| 57 | break; |
| 58 | default: |
| 59 | artifact.artifactGroupType = ArtifactGroupType.INFORMATION; |
| 60 | break; |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | public isLicenseType = (artifactType:string):boolean => { |
| 65 | let isLicense:boolean = false; |
| 66 | |
| 67 | if (ArtifactType.VENDOR_LICENSE === artifactType || ArtifactType.VF_LICENSE === artifactType) { |
| 68 | isLicense = true; |
| 69 | } |
| 70 | |
| 71 | return isLicense; |
| 72 | }; |
| 73 | |
| 74 | public removeArtifact = (artifact:ArtifactModel, artifactsArr:Array<ArtifactModel>):void => { |
| 75 | |
| 76 | if (!artifact.mandatory && (ArtifactGroupType.INFORMATION == artifact.artifactGroupType || |
| 77 | ArtifactGroupType.DEPLOYMENT == artifact.artifactGroupType)) { |
| 78 | _.remove(artifactsArr, {uniqueId: artifact.uniqueId}); |
| 79 | } |
| 80 | else { |
| 81 | let artifactToDelete = _.find(artifactsArr, {uniqueId: artifact.uniqueId}); |
| 82 | |
| 83 | delete artifactToDelete.esId; |
| 84 | delete artifactToDelete.description; |
| 85 | delete artifactToDelete.artifactName; |
| 86 | delete artifactToDelete.apiUrl; |
| 87 | } |
| 88 | }; |
| 89 | |
| 90 | public addAnotherAfterSave(scope:IArtifactResourceFormViewModelScope) { |
| 91 | let newArtifact = new ArtifactModel(); |
| 92 | this.setArtifactType(newArtifact, scope.artifactType); |
| 93 | scope.editArtifactResourceModel.artifactResource = newArtifact; |
| 94 | |
| 95 | scope.forms.editForm['description'].$setPristine(); |
| 96 | if (scope.forms.editForm['artifactLabel']) { |
| 97 | scope.forms.editForm['artifactLabel'].$setPristine(); |
| 98 | } |
| 99 | if (scope.forms.editForm['type']) { |
| 100 | scope.forms.editForm['type'].$setPristine(); |
| 101 | } |
| 102 | |
| 103 | } |
| 104 | } |