UI support for deleting services 17/128417/8
authorJvD_Ericsson <jeff.van.dam@est.tech>
Thu, 14 Apr 2022 10:41:46 +0000 (11:41 +0100)
committerMichael Morris <michael.morris@est.tech>
Tue, 26 Apr 2022 12:07:50 +0000 (12:07 +0000)
Issue-ID: SDC-3962
Change-Id: Ib72a0c43b067cff31609bb47759497802a420511
Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
catalog-ui/src/app/ng2/services/component-services/component.service.ts
catalog-ui/src/app/view-models/workspace/workspace-view-model.ts
catalog-ui/src/app/view-models/workspace/workspace-view.html
catalog-ui/src/assets/languages/en_US.json

index 3889b73..c9bb4d5 100644 (file)
@@ -418,6 +418,10 @@ export class ComponentServiceNg2 {
         return this.http.get<InstanceBePropertiesMap>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/filteredproperties/' + filterData.propertyName, {params: params});
     }
 
+    deleteComponent(componentType: string, componentId: string) {
+        return this.http.delete(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + "?deleteAction=DELETE", {});
+    }
+
     createServiceProperty(component: Component, propertyModel: PropertyBEModel): Observable<PropertyBEModel> {
         let serverObject = {};
         serverObject[propertyModel.name] = propertyModel;
index dad7b13..532df0e 100644 (file)
@@ -45,6 +45,7 @@ import {
 import {
     CacheService
 } from 'app/services-ng2';
+import { SdcUiCommon, SdcUiComponents, SdcUiServices } from 'onap-ui-angular';
 import { AutomatedUpgradeService } from '../../ng2/pages/automated-upgrade/automated-upgrade.service';
 import { CatalogService } from '../../ng2/services/catalog.service';
 import { ComponentServiceNg2 } from '../../ng2/services/component-services/component.service';
@@ -151,6 +152,7 @@ export class WorkspaceViewModel {
         'ComponentServiceNg2',
         'AutomatedUpgradeService',
         'EventBusService',
+        'ModalServiceSdcUI',
         'PluginsService',
         'WorkspaceNg1BridgeService',
         'workspaceService'
@@ -176,6 +178,7 @@ export class WorkspaceViewModel {
                 private ComponentServiceNg2: ComponentServiceNg2,
                 private AutomatedUpgradeService: AutomatedUpgradeService,
                 private eventBusService: EventBusService,
+                private modalServiceSdcUI: SdcUiServices.ModalService,
                 private pluginsService: PluginsService,
                 private workspaceNg1BridgeService: WorkspaceNg1BridgeService,
                 private workspaceService: WorkspaceService) {
@@ -613,7 +616,48 @@ export class WorkspaceViewModel {
             this.ChangeLifecycleStateHandler.changeLifecycleState(this.$scope.component, data, this.$scope, onSuccess);
         };
 
+        this.$scope.deleteArchivedComponent = (): void => {
+            const modalTitle: string = this.$filter('translate')("COMPONENT_VIEW_DELETE_MODAL_TITLE");
+            const modalMessage: string = this.$filter('translate')("COMPONENT_VIEW_DELETE_MODAL_TEXT");
+            const modalButton = {
+                testId: 'ok-button',
+                text: this.sdcMenu.alertMessages.okButton,
+                type: SdcUiCommon.ButtonType.warning,
+                callback: this.$scope.handleDeleteArchivedComponent,
+                closeModal: true
+            } as SdcUiComponents.ModalButtonComponent;
+            this.modalServiceSdcUI.openWarningModal(modalTitle, modalMessage, 'alert-modal', [modalButton]);
+        };
 
+        this.$scope.handleDeleteArchivedComponent = (): void => {
+            this.$scope.isLoading = true;
+            const typeComponent = this.$scope.component.componentType;
+            this.ComponentServiceNg2.deleteComponent(typeComponent, this.$scope.component.uniqueId).subscribe(()=> {
+                this.deleteArchiveCache();
+                this.Notification.success({
+                    message: this.$scope.component.name + ' ' + this.$filter('translate')("DELETE_SUCCESS_MESSAGE_TEXT"),
+                    title: this.$filter('translate')("DELETE_SUCCESS_MESSAGE_TITLE")
+                });
+                if (this.$state.params.previousState) {
+                    switch (this.$state.params.previousState) {
+                        case 'catalog':
+                        case 'dashboard':
+                            this.$state.go(this.$state.params.previousState);
+                            break;
+                        default:
+                            this.$state.go('dashboard');
+                            break;
+                    }
+                }
+                this.$scope.isLoading = false;
+            }, () => {
+                this.Notification.error({
+                    message: this.$scope.component.name + ' ' + this.$filter('translate')('DELETE_FAILURE_MESSAGE_TEXT'),
+                    title: this.$filter('translate')('DELETE_FAILURE_MESSAGE_TITLE')
+                });
+                this.$scope.isLoading = false;
+            });
+        };
 
         this.$scope.isViewMode = ():boolean => {
             return this.$scope.mode === WorkspaceMode.VIEW;
index 2d5b234..21cebeb 100644 (file)
                         data-ng-class="{'disabled' : !isValidForm || isDisableMode() || isViewMode() || unsavedChanges}" ng-click="changeLifecycleState('deleteVersion')"
                         class="sprite-new delete-btn" data-tests-id="delete_version" sdc-smart-tooltip="Delete" prevent-double-click>Delete</span>
 
+                    <span ng-if="!isCreateMode() && component.isArchived"
+                          ng-click="deleteArchivedComponent()"
+                          class="sprite-new delete-btn"
+                          data-tests-id="delete_archive_version"
+                          sdc-smart-tooltip="Delete Service"
+                          prevent-double-click>Delete</span>
+
                     <span data-ng-click = "archiveComponent()"
                         ng-model-options="{ debounce: 300 }"
                         data-ng-class="{'disabled' : !component.isLatestVersion()}"
index 88bd407..aa5e368 100644 (file)
   "=========== ARTIFACT VIEW ===========": "",
   "ARTIFACT_VIEW_DELETE_MODAL_TITLE": "Delete Artifact Confirmation",
   "ARTIFACT_VIEW_DELETE_MODAL_TEXT": "Are you sure you want to delete '{{name}}'?",
+  "========== COMPONENT VIEW ===========": "",
+  "COMPONENT_VIEW_DELETE_MODAL_TITLE": "Delete Component Confirmation",
+  "COMPONENT_VIEW_DELETE_MODAL_TEXT": "All versions of this component will be permanently deleted. This action cannot be undone. Are you sure you want to proceed?",
   "=========== PROPERTY VIEW ===========": "",
   "PROPERTY_VIEW_DELETE_MODAL_TITLE": "Delete Property Confirmation",
   "PROPERTY_VIEW_DELETE_MODAL_TEXT": "Are you sure you want to delete '{{name}}'?",
   "RESTORE_SUCCESS_MESSAGE_TEXT": "successfully restored",
   "ARCHIVE_SUCCESS_MESSAGE_TITLE": "Archive",
   "ARCHIVE_SUCCESS_MESSAGE_TEXT": "successfully archived",
+  "=========== FAILURE MESSAGES ===========": "",
+  "DELETE_FAILURE_MESSAGE_TEXT": "Deletion Failed",
+  "DELETE_FAILURE_MESSAGE_TITLE": "Delete",
   "=========== ON BOARDING MODAL ===========": "",
   "ON_BOARDING_MODAL_SUB_TITLE": "Select one of the software product component below:",
   "ON_BOARDING_GENERAL_INFO": "Displays a table of VSPs created using Onboarding.\nEach row displays details for a single VSP.\nWhen expanded you can either import CSAR files that are yet to  be imported or update CSAR files that were previously imported.",