diff options
author | 2022-11-24 10:29:04 +0000 | |
---|---|---|
committer | 2023-01-26 23:32:10 +0000 | |
commit | 701e441228724c5b701d94cc3f1e520ce656398a (patch) | |
tree | 5900482086d86f8b8e465e6d4b57db4bd7a94184 /catalog-ui/src/app/ng2/pages/type-workspace/type-workspace.component.ts | |
parent | 1bbecd7edbdd907a53812d303d378236d23d071e (diff) |
Import data type in UI
Develop all necessary changes in the UI to allow importing a data type from a yaml file
Issue-ID: SDC-4279
Signed-off-by: franciscovila <javier.paradela.vila@est.tech>
Change-Id: Id413386fad8b362e8c4a1d25c859a22178189074
Diffstat (limited to 'catalog-ui/src/app/ng2/pages/type-workspace/type-workspace.component.ts')
-rw-r--r-- | catalog-ui/src/app/ng2/pages/type-workspace/type-workspace.component.ts | 66 |
1 files changed, 60 insertions, 6 deletions
diff --git a/catalog-ui/src/app/ng2/pages/type-workspace/type-workspace.component.ts b/catalog-ui/src/app/ng2/pages/type-workspace/type-workspace.component.ts index d0d5ae8c69..e0f7ac77a0 100644 --- a/catalog-ui/src/app/ng2/pages/type-workspace/type-workspace.component.ts +++ b/catalog-ui/src/app/ng2/pages/type-workspace/type-workspace.component.ts @@ -19,11 +19,17 @@ * ============LICENSE_END========================================================= */ -import {Component, Inject, OnInit} from '@angular/core'; +import {Component, Inject, Injector, OnInit} from '@angular/core'; import {MenuItem, MenuItemGroup} from "../../../utils/menu-handler"; import {CacheService} from "../../services/cache.service"; import {DataTypeModel} from "../../../models/data-types"; import {DataTypeService} from "../../services/data-type.service"; +import {IWorkspaceViewModelScope} from "../../../view-models/workspace/workspace-view-model"; +import {TranslateService} from "../../shared/translator/translate.service"; +import {HttpErrorResponse} from "@angular/common/http"; +import {ServerErrorResponse} from "../../../models/server-error-response"; +import {Observable} from "rxjs/Observable"; +import {SdcUiServices} from "onap-ui-angular/dist"; @Component({ selector: 'app-type-workspace', @@ -33,27 +39,32 @@ import {DataTypeService} from "../../services/data-type.service"; export class TypeWorkspaceComponent implements OnInit { private typeMenuItemGroup: MenuItemGroup; - isLoading: boolean; disabled: boolean; isViewOnly: boolean = true; sdcVersion: string; breadcrumbsModel: Array<MenuItemGroup> = []; dataType: DataTypeModel = new DataTypeModel(); + importedDataType: DataTypeModel = new DataTypeModel(); currentMenu: MenuItem; - constructor(private dataTypeService: DataTypeService, private cacheService: CacheService, + constructor(@Inject('$scope') private $scope: IWorkspaceViewModelScope, + private dataTypeService: DataTypeService, private cacheService: CacheService, + @Inject('Notification') private Notification: any, + private translateService: TranslateService, @Inject('$state') private $state: ng.ui.IStateService, - @Inject('$stateParams') private stateParams) { } + @Inject('$stateParams') private stateParams, + private injector: Injector) { } ngOnInit(): void { this.sdcVersion = this.cacheService.get('version'); this.typeMenuItemGroup = this.createTypeBreadcrumb(); + this.loadDataType(); } private loadDataType(): void { - if (this.stateParams.id) { + if (this.stateParams.id && this.stateParams.id != "import") { this.dataTypeService.findById(this.stateParams.id).subscribe(dataType => { this.dataType = dataType; this.updateTypeBreadcrumb(); @@ -61,11 +72,49 @@ export class TypeWorkspaceComponent implements OnInit { console.debug('Could not find data type %s', this.stateParams.id, error); this.goToBreadcrumbHome(); }); + this.isViewOnly = true; } else { + + this.isViewOnly = false; this.dataType = new DataTypeModel(); } } + onImportedType(dataType) { + this.typeMenuItemGroup.updateSelectedMenuItemText(`Data Type: ${dataType.name}`); + } + + private createImportType() { + if (this.$scope.dataType.derivedFromName != undefined && this.$scope.dataType.model != undefined) { + this.dataTypeService.createImportedType(this.$scope.dataType.model.name, this.$scope.importFile) + .subscribe(response => { + this.importedDataType = new DataTypeModel(response); + this.Notification.success({ + message: this.$scope.dataType.name + ' ' + this.translateService.translate('IMPORT_DATA_TYPE_SUCCESS_MESSAGE_TEXT'), + title: this.translateService.translate('IMPORT_DATA_TYPE_TITLE_TEXT') + }); + this.$state.go(this.$state.current.name, {importedFile: null, id: this.$scope.dataType.uniqueId, isViewOnly: true}, {reload: true}); + }, error => {//because overriding http interceptor + if (error instanceof HttpErrorResponse) { + const errorResponse: ServerErrorResponse = new ServerErrorResponse(error); + const modalService = this.injector.get(SdcUiServices.ModalService); + const errorDetails = { + 'Error Code': errorResponse.status != 409 ? errorResponse.messageId : "Data Type already exists", + 'Status Code': errorResponse.status + }; + modalService.openErrorDetailModal('Error', errorResponse.status != 409 ? errorResponse.message : "Data Type already exists", 'error-modal', errorDetails); + return Observable.throwError(error); + } + }); + } + else { + this.Notification.error({ + message: this.$scope.dataType.name + ' ' + "Derived from is invalid in file", + title: this.translateService.translate('IMPORT_DATA_TYPE_TITLE_TEXT') + }); + } + } + private updateTypeBreadcrumb(): void { this.typeMenuItemGroup.updateSelectedMenuItemText(`Data Type: ${this.dataType.name}`); } @@ -82,10 +131,15 @@ export class TypeWorkspaceComponent implements OnInit { onMenuUpdate(menuItemGroup: MenuItemGroup): void { this.breadcrumbsModel.push(...[this.typeMenuItemGroup, menuItemGroup]); + if (!this.isViewOnly) { + this.$scope.leftBarTabs.menuItems.forEach((item: MenuItem) => { + item.isDisabled = ('general' !== item.state); + item.disabledCategory = ('general' !== item.state); + }); + } } onMenuClick(menuItem: MenuItem): void { this.currentMenu = menuItem; } - } |