From 46f9fd57f24428f6a6fd0d290b0463e188975231 Mon Sep 17 00:00:00 2001 From: Michael Lando Date: Thu, 10 Aug 2017 12:08:45 +0300 Subject: [SDC] code sync Change-Id: Ia33a7874802b8ac2f49aed9199e109ea509e950e Signed-off-by: Michael Lando --- .../workspace/tabs/general/general-view-model.ts | 56 ++++++++++++++++------ 1 file changed, 42 insertions(+), 14 deletions(-) (limited to 'catalog-ui/src/app/view-models/workspace') diff --git a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts index 98539d6a3b..48fc9dbb42 100644 --- a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts +++ b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts @@ -21,9 +21,10 @@ 'use strict'; import {ModalsHandler, ValidationUtils, EVENTS, CHANGE_COMPONENT_CSAR_VERSION_FLAG, ComponentType, DEFAULT_ICON, ResourceType} from "app/utils"; -import {CacheService, EventListenerService, ProgressService} from "app/services"; -import {IAppConfigurtaion, IValidate, IMainCategory, Resource, ISubCategory,Service} from "app/models"; +import {CacheService, EventListenerService, ProgressService, OnboardingService} from "app/services"; +import {IAppConfigurtaion, IValidate, IMainCategory, Resource, ISubCategory,Service, ICsarComponent} from "app/models"; import {IWorkspaceViewModelScope} from "app/view-models/workspace/workspace-view-model"; +import {Dictionary} from "lodash"; export class Validation { componentNameValidationPattern:RegExp; @@ -91,7 +92,8 @@ export class GeneralViewModel { 'Sdc.Services.ProgressService', '$interval', '$filter', - '$timeout' + '$timeout', + 'Sdc.Services.OnboardingService' ]; constructor(private $scope:IGeneralScope, @@ -113,7 +115,8 @@ export class GeneralViewModel { private progressService:ProgressService, protected $interval:any, private $filter:ng.IFilterService, - private $timeout:ng.ITimeoutService) { + private $timeout:ng.ITimeoutService, + private onBoardingService:OnboardingService) { this.initScopeValidation(); this.initScopeMethods(); @@ -135,6 +138,40 @@ export class GeneralViewModel { this.$scope.validation.projectCodeValidationPattern = this.ProjectCodeValidationPattern; }; + private initImportedToscaBrowseFile = ():void =>{ + // Init the decision if to show onboarding + this.$scope.isShowOnboardingSelectionBrowse = false; + if (this.$scope.component.isResource() && + this.$scope.isEditMode() && + (this.$scope.component).resourceType == ResourceType.VF && + (this.$scope.component).csarUUID) { + this.$scope.isShowOnboardingSelectionBrowse = true; + let onboardCsarFilesMap:Dictionary = this.cacheService.get('onboardCsarFilesMap'); + // The onboardCsarFilesMap in cache contains map of [packageId]:[vsp display name for brows] + // if the map is empty - Do request to BE + if(onboardCsarFilesMap) { + this.$scope.importedToscaBrowseFileText = onboardCsarFilesMap[(this.$scope.component).csarUUID]; + } + if(!onboardCsarFilesMap || !this.$scope.importedToscaBrowseFileText){ + + let onSuccess = (vsps:Array): void =>{ + onboardCsarFilesMap = {}; + _.each(vsps, (vsp:ICsarComponent)=>{ + onboardCsarFilesMap[vsp.packageId] = vsp.vspName + " (" + vsp.version + ")"; + }); + this.cacheService.set('onboardCsarFilesMap', onboardCsarFilesMap); + this.$scope.importedToscaBrowseFileText = onboardCsarFilesMap[(this.$scope.component).csarUUID]; + }; + + let onError = (): void =>{ + console.log("Error getting onboarding list"); + }; + + this.onBoardingService.getOnboardingVSPs().then(onSuccess, onError); + } + } + }; + private initScope = ():void => { // Work around to change the csar version @@ -142,7 +179,6 @@ export class GeneralViewModel { (this.$scope.component).csarVersion = this.cacheService.get(CHANGE_COMPONENT_CSAR_VERSION_FLAG); } - this.$scope.importedToscaBrowseFileText = this.$scope.component.name + " (" + (this.$scope.component).csarVersion + ")"; this.$scope.importCsarProgressKey = "importCsarProgressKey"; this.$scope.browseFileLabel = this.$scope.component.isResource() && (this.$scope.component).resourceType === ResourceType.VF ? "Upload file" : "Upload VFC"; this.$scope.progressService = this.progressService; @@ -167,16 +203,8 @@ export class GeneralViewModel { this.$scope.isShowFileBrowse = true; } } - ; - // Init the decision if to show onboarding - this.$scope.isShowOnboardingSelectionBrowse = false; - if (this.$scope.component.isResource() && - this.$scope.isEditMode() && - (this.$scope.component).resourceType == ResourceType.VF && - (this.$scope.component).csarUUID) { - this.$scope.isShowOnboardingSelectionBrowse = true; - } + this.initImportedToscaBrowseFile(); //init file extensions based on the file that was imported. if (this.$scope.component.isResource() && (this.$scope.component).importedFile) { -- cgit 1.2.3-korg