diff options
Diffstat (limited to 'catalog-ui/src/app')
8 files changed, 134 insertions, 12 deletions
diff --git a/catalog-ui/src/app/models/components/component.ts b/catalog-ui/src/app/models/components/component.ts index b76d29c8c6..a0706b4157 100644 --- a/catalog-ui/src/app/models/components/component.ts +++ b/catalog-ui/src/app/models/components/component.ts @@ -233,6 +233,11 @@ export abstract class Component implements IComponent { this.handleTags(); return this.componentService.createComponent(this); }; + + public importComponentOnServer = (): ng.IPromise<Component> => { + this.handleTags(); + return this.componentService.importComponent(this); + }; public updateComponent = ():ng.IPromise<Component> => { this.handleTags(); @@ -243,8 +248,12 @@ export abstract class Component implements IComponent { return this.componentService.validateName(newName, subtype); }; - public downloadArtifact = (artifactId:string):ng.IPromise<IFileDownload> => { - return this.componentService.downloadArtifact(this.uniqueId, artifactId); + public downloadArtifact = (artifactId: string): ng.IPromise<IFileDownload> => { + if(this.vendorName === 'IsService'){ + return this.componentService.downloadArtifact(this.uniqueId, artifactId, this.vendorName); + }else{ + return this.componentService.downloadArtifact(this.uniqueId, artifactId); + } }; public addOrUpdateArtifact = (artifact:ArtifactModel):ng.IPromise<ArtifactModel> => { diff --git a/catalog-ui/src/app/models/components/service.ts b/catalog-ui/src/app/models/components/service.ts index 911a43204f..d11a06abdf 100644 --- a/catalog-ui/src/app/models/components/service.ts +++ b/catalog-ui/src/app/models/components/service.ts @@ -27,6 +27,7 @@ import {IServiceService} from "../../services/components/service-service"; import {Component, PropertyModel, DisplayModule, InputsAndProperties, InputModel, InstancesInputsOrPropertiesMapData, InstancesInputsPropertiesMap, Distribution, DistributionComponent, ArtifactGroupModel} from "../../models"; import {ArtifactGroupType} from "../../utils/constants"; +import {FileUploadModel} from "../../directives/file-upload/file-upload"; import {ComponentMetadata} from "../component-metadata"; import {ForwardingPath} from "app/models/forwarding-path"; @@ -42,6 +43,15 @@ export class Service extends Component { public environmentContext:string; public instantiationType:string; public forwardingPaths:{ [key:string]:ForwardingPath } = {}; + public payloadData: string; + public payloadName: string; + public importedFile: FileUploadModel; + + // Onboarding parameters + public csarUUID: string; + public csarVersion: string; + public csarPackageType: string; + public packageId: string; constructor(componentService:IServiceService, $q:ng.IQService, component?:Service) { super(componentService, $q, component); @@ -56,15 +66,40 @@ export class Service extends Component { this.serviceFunction = component.serviceFunction; this.instantiationType = component.instantiationType; this.environmentContext = component.environmentContext; + this.payloadData = component.payloadData ? component.payloadData : undefined; + this.payloadName = component.payloadName ? component.payloadName : undefined; + this.csarUUID = component.csarUUID; + this.csarVersion = component.csarVersion; if (component.categories && component.categories[0]) { this.mainCategory = component.categories[0].name; this.selectedCategory = this.mainCategory; + this.importedFile = component.importedFile; } } this.componentService = componentService; this.iconSprite = "sprite-services-icons"; } + public importComponentOnServer = (): ng.IPromise<Component> => { + let deferred = this.$q.defer<Component>(); + let onSuccess = (component: Service): void => { + this.payloadData = undefined; + this.payloadName = undefined; + deferred.resolve(component); + }; + let onError = (error: any): void => { + deferred.reject(error); + }; + + this.handleTags(); + if (this.importedFile) { + this.payloadData = this.importedFile.base64; + this.payloadName = this.importedFile.filename; + } + this.componentService.importComponent(this).then(onSuccess, onError); + return deferred.promise; + }; + public getDistributionsList = ():ng.IPromise<Array<Distribution>> => { return this.componentService.getDistributionsList(this.uuid); }; diff --git a/catalog-ui/src/app/ng2/pages/home/home.component.html b/catalog-ui/src/app/ng2/pages/home/home.component.html index 1c8c2b4373..3bdf54e694 100644 --- a/catalog-ui/src/app/ng2/pages/home/home.component.html +++ b/catalog-ui/src/app/ng2/pages/home/home.component.html @@ -48,6 +48,16 @@ (fileUpload)="onImportVf($event)" [convertToBase64]="true" ></sdc-button-file-opener> + <sdc-button-file-opener + *ngIf="roles[user.role].dashboard.showCreateNew" + size="medium" + type="secondary" + text="Import Service Csar" + testId="importServicebutton" + [extensions]="sdcConfig.csarFileExtension" + (fileUpload)="onImportService($event)" + [convertToBase64]="true" + ></sdc-button-file-opener> </div> </div> </div> diff --git a/catalog-ui/src/app/ng2/pages/home/home.component.ts b/catalog-ui/src/app/ng2/pages/home/home.component.ts index 1b69eba929..77fd3b5ae4 100644 --- a/catalog-ui/src/app/ng2/pages/home/home.component.ts +++ b/catalog-ui/src/app/ng2/pages/home/home.component.ts @@ -138,6 +138,24 @@ export class HomeComponent implements OnInit { } } + public onImportService(file: any): void { + if (file && file.filename) { + // Check that the file has valid extension. + const fileExtension: string = file.filename.split(".").pop(); + if (this.sdcConfig.csarFileExtension.indexOf(fileExtension.toLowerCase()) !== -1) { + this.$state.go('workspace.general', { + type: ComponentType.SERVICE.toLowerCase(), + importedFile: file, + serviceType: 'Service' + }); + } else { + const title: string = this.translateService.translate('NEW_SERVICE_RESOURCE_ERROR_VALID_CSAR_EXTENSIONS_TITLE'); + const message: string = this.translateService.translate('NEW_SERVICE_RESOURCE_ERROR_VALID_CSAR_EXTENSIONS', {extensions: this.sdcConfig.csarFileExtension}); + this.modalService.openWarningModal(title, message, 'error-invalid-csar-ext'); + } + } + }; + public openCreateModal(componentType: string, importedFile: any): void { if (importedFile) { this.initEntities(true); // Return from import diff --git a/catalog-ui/src/app/services/components/component-service.ts b/catalog-ui/src/app/services/components/component-service.ts index c7ab975e6e..bece12d4f0 100644 --- a/catalog-ui/src/app/services/components/component-service.ts +++ b/catalog-ui/src/app/services/components/component-service.ts @@ -32,6 +32,8 @@ export interface IComponentService { changeLifecycleState(component:Component, state:string, userRemarks:any):ng.IPromise<ComponentMetadata> ; validateName(newName:string, subtype?:string):ng.IPromise<IValidate>; createComponent(component:Component):ng.IPromise<Component>; + //importComponent + importComponent(component: Component): ng.IPromise<Component>; addOrUpdateArtifact(componentId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel>; deleteArtifact(componentId:string, artifact:string, artifactLabel):ng.IPromise<ArtifactModel>; addProperty(componentId:string, property:PropertyModel):ng.IPromise<PropertyModel>; @@ -48,7 +50,7 @@ export interface IComponentService { createComponentInstance(componentId:string, componentInstance:ComponentInstance):ng.IPromise<ComponentInstance>; updateComponentInstance(componentId:string, componentInstance:ComponentInstance):ng.IPromise<ComponentInstance>; updateMultipleComponentInstances(componentId:string, instances:Array<ComponentInstance>):ng.IPromise< Array<ComponentInstance>>; - downloadArtifact(componentId:string, artifactId:string):ng.IPromise<IFileDownload>; + downloadArtifact(componentId: string, artifactId: string, vendorName?: string): ng.IPromise<IFileDownload>; uploadInstanceEnvFile(componentId:string, instanceId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel>; downloadInstanceArtifact(componentId:string, instanceId:string, artifactId:string):ng.IPromise<IFileDownload>; deleteComponentInstance(componentId:string, componentInstanceId:string):ng.IPromise<ComponentInstance>; @@ -206,6 +208,20 @@ export class ComponentService implements IComponentService { }); return deferred.promise; }; + + public importComponent = (component: Component): ng.IPromise<Component> => { + component.vendorName = "xfr"; + component.vendorRelease = "xfr"; + let deferred = this.$q.defer<Component>(); + let headerObj = this.getHeaderMd5(component); + this.restangular.customPOST(JSON.stringify(component), 'importService', {}, headerObj).then((response: Component) => { + let component: Component = this.createComponentObject(response); + deferred.resolve(component); + }, (err) => { + deferred.reject(err); + }); + return deferred.promise; + }; public validateName = (newName:string, subtype?:string):ng.IPromise<IValidate> => { let deferred = this.$q.defer<IValidate>(); @@ -244,13 +260,21 @@ export class ComponentService implements IComponentService { return deferred.promise; }; - public downloadArtifact = (componentId:string, artifactId:string):ng.IPromise<IFileDownload> => { + public downloadArtifact = (componentId: string, artifactId: string, vendorName?: string): ng.IPromise<IFileDownload> => { let deferred = this.$q.defer<IFileDownload>(); - this.restangular.one(componentId).one("artifacts").one(artifactId).get().then((response:any) => { - deferred.resolve(response.plain()); - }, (err)=> { - deferred.reject(err); - }); + if(vendorName === 'IsService'){ + this.restangular.one('importService').one(componentId).one("artifacts").one(artifactId).get().then((response: any) => { + deferred.resolve(response.plain()); + }, (err) => { + deferred.reject(err); + }); + }else{ + this.restangular.one(componentId).one("artifacts").one(artifactId).get().then((response: any) => { + deferred.resolve(response.plain()); + }, (err) => { + deferred.reject(err); + }); + } return deferred.promise; }; diff --git a/catalog-ui/src/app/utils/component-factory.ts b/catalog-ui/src/app/utils/component-factory.ts index 5fda9c8db2..fd82c27dd8 100644 --- a/catalog-ui/src/app/utils/component-factory.ts +++ b/catalog-ui/src/app/utils/component-factory.ts @@ -185,6 +185,12 @@ export class ComponentFactory { }; + public importComponentOnServer = (componentObject: Component): ng.IPromise<Component> => { + let component: Component = this.createComponent(componentObject); + return component.importComponentOnServer(); + + }; + public getComponentWithMetadataFromServer = (componentType:string, componentId:string):ng.IPromise<Component> => { let deferred = this.$q.defer<Component>(); let component = this.createEmptyComponent(componentType); 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 87937dd761..e10dc98fac 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 @@ -219,7 +219,7 @@ export class GeneralViewModel { this.$scope.importCsarProgressKey = "importCsarProgressKey"; - this.$scope.browseFileLabel = this.$scope.component.isResource() && (<Resource>this.$scope.component).resourceType === ResourceType.VF ? 'Upload File:' : 'Upload VFC:'; + this.$scope.browseFileLabel = (this.$scope.component.isResource() && ((<Resource>this.$scope.component).resourceType === ResourceType.VF || (<Resource>this.$scope.component).resourceType === 'SRVC')) || this.$scope.component.isService() ? 'Upload File:' : 'Upload VFC:'; this.$scope.progressService = this.progressService; this.$scope.componentCategories = new componentCategories(); this.$scope.componentCategories.selectedCategory = this.$scope.component.selectedCategory; @@ -245,6 +245,15 @@ export class GeneralViewModel { this.$scope.isShowFileBrowse = true; } } else if(this.$scope.component.isService()){ + let service: Service = <Service>this.$scope.component; + console.log(service.name + ": " + service.csarUUID); + if (service.importedFile) { // Component has imported file. + this.$scope.isShowFileBrowse = true; + (<Service>this.$scope.component).serviceType = 'Service'; + } + if (this.$scope.isEditMode() && service.serviceType == 'Service' && !service.csarUUID) { + this.$scope.isShowFileBrowse = true; + } // Init Instantiation types this.$scope.initInstantiationTypes(); } @@ -497,7 +506,11 @@ export class GeneralViewModel { return; } - const subtype:string = ComponentType.RESOURCE == this.$scope.componentType ? this.$scope.component.getComponentSubType() : undefined; + + let subtype:string = ComponentType.RESOURCE == this.$scope.componentType ? this.$scope.component.getComponentSubType() : undefined; + if (subtype == "SRVC") { + subtype = "VF" + } const onFailed = (response) => { // console.info('onFaild', response); diff --git a/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts b/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts index 11667283b2..e132d53eaf 100644 --- a/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts +++ b/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts @@ -27,6 +27,7 @@ import { IUserProperties, IAppMenu, Resource, + Service, Component, Plugin, PluginsConfiguration, @@ -431,8 +432,14 @@ export class WorkspaceViewModel { components: this.components }, {inherit: false}); }; + + console.log(this.$scope.component, "this.$scope.component") + if ((<Service>this.$scope.component).serviceType == "Service") { + this.ComponentFactory.importComponentOnServer(this.$scope.component).then(onSuccessCreate, onFailed); + } else { + this.ComponentFactory.createComponentOnServer(this.$scope.component).then(onSuccessCreate, onFailed); + } - this.ComponentFactory.createComponentOnServer(this.$scope.component).then(onSuccessCreate, onFailed); }; |