summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/utils/change-lifecycle-state-handler.ts
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-06-09 03:19:04 +0300
committerMichael Lando <ml636r@att.com>2017-06-09 03:19:04 +0300
commited64b5edff15e702493df21aa3230b81593e6133 (patch)
treea4cb01fdaccc34930a8db403a3097c0d1e40914b /catalog-ui/src/app/utils/change-lifecycle-state-handler.ts
parent280f8015d06af1f41a3ef12e8300801c7a5e0d54 (diff)
[SDC-29] catalog 1707 rebase commit.
Change-Id: I43c3dc5cf44abf5da817649bc738938a3e8388c1 Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-ui/src/app/utils/change-lifecycle-state-handler.ts')
-rw-r--r--catalog-ui/src/app/utils/change-lifecycle-state-handler.ts163
1 files changed, 163 insertions, 0 deletions
diff --git a/catalog-ui/src/app/utils/change-lifecycle-state-handler.ts b/catalog-ui/src/app/utils/change-lifecycle-state-handler.ts
new file mode 100644
index 0000000000..dc59e3bb98
--- /dev/null
+++ b/catalog-ui/src/app/utils/change-lifecycle-state-handler.ts
@@ -0,0 +1,163 @@
+import {ComponentFactory} from "./component-factory";
+import {Component, Service,IAppMenu, IAppConfigurtaion} from "../models";
+import {IEmailModalModel, IEmailModalModel_Email, IEmailModalModel_Data} from "../view-models/modals/email-modal/email-modal-view-model";
+import {AsdcComment} from "../models/comments";
+import {ModalsHandler} from "./modals-handler";
+import {ServiceServiceNg2} from "../ng2/services/component-services/service.service";
+
+/**
+ * Created by obarda on 2/11/2016.
+ */
+
+export class ChangeLifecycleStateHandler {
+
+ static '$inject' = [
+ 'sdcConfig',
+ 'sdcMenu',
+ 'ComponentFactory',
+ '$filter',
+ 'ModalsHandler',
+ 'ServiceServiceNg2'
+ ];
+
+ constructor(private sdcConfig:IAppConfigurtaion,
+ private sdcMenu:IAppMenu,
+ private ComponentFactory:ComponentFactory,
+ private $filter:ng.IFilterService,
+ private ModalsHandler:ModalsHandler,
+ private ServiceServiceNg2:ServiceServiceNg2) {
+
+ }
+
+ private actualChangeLifecycleState = (component:Component, data:any, scope:any, onSuccessCallback?:Function, onErrorCallback?:Function):void => {
+
+ let self = this;
+
+ let getContacts = (component:Component):string => {
+ let testers = this.sdcConfig.testers;
+ let result:string = testers[component.componentType][component.categories[0].name] ?
+ testers[component.componentType][component.categories[0].name] :
+ testers[component.componentType]['default'];
+ return result;
+ };
+
+ let onSuccess = (newComponent:Component):void => {
+ //scope.isLoading = false;
+ console.info(component.componentType.toLowerCase + ' change state ', newComponent);
+ if (onSuccessCallback) {
+ onSuccessCallback(self.ComponentFactory.createComponent(newComponent), data.url);
+ }
+ };
+
+ let onError = (error):void => {
+ scope.isLoading = false;
+ console.info('Failed to changeLifecycleState to ', data.url);
+ if (onErrorCallback) {
+ onErrorCallback(error);
+ }
+ };
+
+ let comment:AsdcComment = new AsdcComment();
+ if (data.alertModal) {
+ // Show alert dialog if defined in menu.json
+ //-------------------------------------------------
+ let onOk = (confirmationText):void => {
+ comment.userRemarks = confirmationText;
+ scope.isLoading = true;
+ component.changeLifecycleState(data.url, comment).then(onSuccess, onError);
+ };
+
+ let onCancel = ():void => {
+ console.info('Cancel pressed');
+ scope.isLoading = false;
+ };
+
+ let modalTitle = this.sdcMenu.alertMessages[data.alertModal].title;
+ let modalMessage = this.sdcMenu.alertMessages[data.alertModal].message.format([component.componentType.toLowerCase()]);
+ this.ModalsHandler.openAlertModal(modalTitle, modalMessage).then(onOk, onCancel);
+ } else if (data.confirmationModal) {
+ // Show confirmation dialog if defined in menu.json
+ //-------------------------------------------------
+ let onOk = (confirmationText):void => {
+ comment.userRemarks = confirmationText;
+ scope.isLoading = true;
+ component.changeLifecycleState(data.url, comment).then(onSuccess, onError);
+ };
+
+ let onCancel = ():void => {
+ console.info('Cancel pressed');
+ scope.isLoading = false;
+ };
+
+ let modalTitle = this.sdcMenu.confirmationMessages[data.confirmationModal].title;
+ let modalMessage = this.sdcMenu.confirmationMessages[data.confirmationModal].message.format([component.componentType.toLowerCase()]);
+ let modalShowComment = this.sdcMenu.confirmationMessages[data.confirmationModal].showComment;
+ this.ModalsHandler.openConfirmationModal(modalTitle, modalMessage, modalShowComment).then(onOk, onCancel);
+
+ } else if (data.emailModal) {
+ // Show email dialog if defined in menu.json
+ //-------------------------------------------------
+ let onOk = (resource):void => {
+ if (resource) {
+ onSuccess(resource);
+ } else {
+ onError("Error changing life cycle state");
+ }
+ };
+
+ let onCancel = ():void => {
+ scope.isLoading = false;
+ };
+
+ let emailModel:IEmailModalModel = <IEmailModalModel>{};
+ emailModel.email = <IEmailModalModel_Email>{};
+ emailModel.data = <IEmailModalModel_Data>{};
+ emailModel.title = this.$filter('translate')("EMAIL_MODAL_TITLE");
+ emailModel.email.to = getContacts(component);
+ emailModel.email.subject = this.$filter('translate')("EMAIL_MODAL_SUBJECT", "{'entityName': '" + this.$filter('resourceName')(component.name) + "','entityVersion': '" + component.version + "'}");
+ emailModel.email.message = '';
+ emailModel.data.component = component;
+ emailModel.data.stateUrl = data.url;
+
+ this.ModalsHandler.openEmailModal(emailModel).then(onOk, onCancel);
+
+ } else {
+ // Submit to server only (no modal is shown).
+ scope.isLoading = true;
+ component.changeLifecycleState(data.url, comment).then(onSuccess, onError);
+ }
+
+ }
+
+ public changeLifecycleState = (component:Component, data:any, scope:any, onSuccessCallback?:Function, onErrorCallback?:Function):void => {
+
+ if (data.conformanceLevelModal) {
+ this.validateConformanceLevel(component, data, scope, onSuccessCallback, onErrorCallback);
+ } else {
+ this.actualChangeLifecycleState(component, data, scope, onSuccessCallback, onErrorCallback);
+ }
+ }
+
+ private validateConformanceLevel = (component:Component, data:any, scope:any, onSuccessCallback?:Function, onErrorCallback?:Function):void => {
+ // Validate conformance level if defined in menu.json
+ //-------------------------------------------------
+ this.ServiceServiceNg2.validateConformanceLevel(<Service>component).subscribe((res:boolean) => {
+ if (res === true) {
+ //conformance level is ok - continue
+ this.actualChangeLifecycleState(component, data, scope, onSuccessCallback, onErrorCallback);
+
+ } else {
+ //show warning modal
+ this.ModalsHandler.openConformanceLevelModal()
+ .then(() => {
+ //continue distribute
+ this.actualChangeLifecycleState(component, data, scope, onSuccessCallback, onErrorCallback);
+
+ }).catch(() => {
+ //reject distribution
+ this.actualChangeLifecycleState(component, data.conformanceLevelModal, scope, onSuccessCallback, onErrorCallback);
+ });
+ }
+ });
+ }
+}