From 098f81b3c8a39fbdf98753c44ff10a83518c0e53 Mon Sep 17 00:00:00 2001 From: ashwaq Date: Thu, 9 Apr 2020 15:37:13 +0300 Subject: [PATCH] itg error text --- .../services/connector/connector.service.ts | 66 +++++++++++++++++++ .../hmg-common/services/models/response.ts | 1 + .../service/work-list.main.service.ts | 2 +- .../work-list-main-itg.component.ts | 49 +++++++++++++- Mohem/src/assets/localization/i18n.json | 5 ++ 5 files changed, 121 insertions(+), 2 deletions(-) diff --git a/Mohem/src/app/hmg-common/services/connector/connector.service.ts b/Mohem/src/app/hmg-common/services/connector/connector.service.ts index e1ce2293..38a135ac 100644 --- a/Mohem/src/app/hmg-common/services/connector/connector.service.ts +++ b/Mohem/src/app/hmg-common/services/connector/connector.service.ts @@ -64,6 +64,31 @@ public static host = 'https://uat.hmgwebservices.com/'; ); } + public postItg( + service: string, + data: any, + onError: any, + errorLabel?: string + ): Observable { + this.cs.startLoading(); + return this.httpClient + .post( + ConnectorService.host + service, + data, + ConnectorService.httpOptions + ) + .pipe( + timeout(ConnectorService.timeOut), + retry(ConnectorService.retryTimes), + tap( + res => this.handleResponseItg(res, onError, errorLabel), + error => this.handleError(error, onError, errorLabel) + ) + ); + } + + + // public postNoLoad(service: string, data: any, onError: any): Observable { // return this.httpClient // .post( @@ -170,7 +195,10 @@ public static host = 'https://uat.hmgwebservices.com/'; this.cs.stopLoading(); this.cs.presentAcceptDialog(result.ErrorEndUserMessage, () => { this.cs.sharedService.clearAll(); + // this.cs.setIsTimeSessionOut(result.IsAuthenticated); + this.cs.openLogin(); + }); return false; } else if (result.ErrorType === 2 || result.ErrorType === 4) { @@ -183,10 +211,48 @@ public static host = 'https://uat.hmgwebservices.com/'; errorLabel, result.ErrorEndUserMessage ); + //add flag if user not auth + } } } + public handleResponseItg(result: Response, onError: any, errorLabel: string, isPostNoLoad = false) { + console.log("handleResponseItg"); + if (!isPostNoLoad) { + this.cs.stopLoading(); + } + if (!this.cs.validResponse(result)) { + if (result.IsAuthenticated === false) { + this.cs.stopLoading(); + this.cs.presentAcceptDialog(result.ErrorEndUserMessage, () => { + console.log("presentAcceptDialog"); + this.cs.sharedService.clearAll(); + // this.cs.setIsTimeSessionOut(result.IsAuthenticated); + + this.cs.openLogin(); + + }); + return false; + } else if (result.ErrorType === 2 || result.ErrorType === 4) { + console.log("ErrorType if"); + + // console.log("error expired"); + this.cs.stopLoading(); + } else { + console.log("ErrorType else"); + + this.cs.stopLoading(); + // this.cs.showErrorMessageDialog( + // onError, + // errorLabel, + // result.Message + // ); + //add flag if user not auth + + } + } + } public getURLText( url: string, onError: any, diff --git a/Mohem/src/app/hmg-common/services/models/response.ts b/Mohem/src/app/hmg-common/services/models/response.ts index cd054b8f..56ff9657 100644 --- a/Mohem/src/app/hmg-common/services/models/response.ts +++ b/Mohem/src/app/hmg-common/services/models/response.ts @@ -13,5 +13,6 @@ export class Response { */ public MessageStatus: number; public SuccessMsg; + public Message; } diff --git a/Mohem/src/app/notification/service/work-list.main.service.ts b/Mohem/src/app/notification/service/work-list.main.service.ts index 2876fe15..b4d19488 100644 --- a/Mohem/src/app/notification/service/work-list.main.service.ts +++ b/Mohem/src/app/notification/service/work-list.main.service.ts @@ -301,7 +301,7 @@ export class WorklistMainService { itgrequest.EmployeeNumber = itgrequest.P_USER_NAME; console.log(itgrequest); console.log(actionURL); - return this.api.post( + return this.api.postItg( actionURL, itgrequest, onError, diff --git a/Mohem/src/app/notification/work-list-main-itg/work-list-main-itg.component.ts b/Mohem/src/app/notification/work-list-main-itg/work-list-main-itg.component.ts index eeb5f349..aa4906f5 100644 --- a/Mohem/src/app/notification/work-list-main-itg/work-list-main-itg.component.ts +++ b/Mohem/src/app/notification/work-list-main-itg/work-list-main-itg.component.ts @@ -208,6 +208,8 @@ export class WorkListMainItgComponent implements OnInit { actionService(action, comments?, grantRequests?) { + console.log("hello actionService"); + let url: string; let request = new itgRequest(); request.RequestType = this.request_name; @@ -223,17 +225,32 @@ export class WorkListMainItgComponent implements OnInit { url = WorkListMainItgComponent.APPROVAL; this.workListService.getITGActionRequest(request, url) .subscribe((result: any) => { + if (result.MessageStatus != 1) { + this.common.presentAlert(result.Message); + + } else if (result.MessageStatus == 1) { + console.log("hello action 1"); + + this.confirmMsg(1) // this.common.openNotificationPage(); this.skip(); + } }); } else if (action == 2) {//reject url = WorkListMainItgComponent.REJECT; this.workListService.getITGActionRequest(request, url) .subscribe((result: any) => { + console.log("hello action 2"); + + if (result.MessageStatus != 1) { + this.common.presentAlert(result.Message); + + } else if (result.MessageStatus == 1) { this.confirmMsg(2) // this.common.openNotificationPage(); this.skip(); + } }); } else if (action == 3) {//request more info request.NewUserEMPId = this.replcamentID; @@ -244,9 +261,18 @@ export class WorkListMainItgComponent implements OnInit { request.Comments = comments; this.workListService.getITGActionRequest(request, url) .subscribe((result: any) => { - this.confirmMsg(3) + console.log("hello action 3"); + + if (result.MessageStatus != 1) { + //this.common.presentAlert(result.Message); + this.common.presentAlert(this.ts.trPK('general', 'error-itg')); + } + + if (result.MessageStatus == 1) { + this.confirmMsg(3) // this.common.openNotificationPage(); this.skip(); + } }); } } else if (action == 4) {//delegate @@ -254,9 +280,16 @@ export class WorkListMainItgComponent implements OnInit { url = WorkListMainItgComponent.DELEGATE; this.workListService.getITGActionRequest(request, url) .subscribe((result: any) => { + console.log("hello action 4"); + + if (result.MessageStatus != 1) { + this.common.presentAlert(this.ts.trPK('general', 'error-itg')); + + } else if (result.MessageStatus == 1) { this.confirmMsg(4) // this.common.openNotificationPage(); this.skip(); + } }); } else if (action == 5) { //answer url = WorkListMainItgComponent.ANSWER; @@ -265,9 +298,16 @@ export class WorkListMainItgComponent implements OnInit { } else { this.workListService.getITGActionRequest(request, url) .subscribe((result: any) => { + console.log("hello action 5"); + + if (result.MessageStatus != 1) { + this.common.presentAlert(this.ts.trPK('general', 'error-itg')); + + } else if (result.MessageStatus == 1) { this.confirmMsg(5) // this.common.openNotificationPage(); this.skip(); + } }); } } else if (action == 6) { //grant @@ -280,9 +320,15 @@ export class WorkListMainItgComponent implements OnInit { request.AdditionalFields = this.grantRequest; this.workListService.getITGActionRequest(request, url) .subscribe((result: any) => { + console.log("hello action 6"); + if (result.MessageStatus != 1) { + this.common.presentAlert(result.Message); + + } else if (result.MessageStatus == 1) { this.confirmMsg(6) // this.common.openNotificationPage(); this.skip(); + } }); } else { this.common.presentAlert(this.ts.trPK('worklist', 'empty-comment')); @@ -299,6 +345,7 @@ export class WorkListMainItgComponent implements OnInit { } confirmMsg(action) { + console.log("confirmMsg"); if (action === 1) { return this.ts.trPK('worklist', 'approveMsg'); } diff --git a/Mohem/src/assets/localization/i18n.json b/Mohem/src/assets/localization/i18n.json index 747776fa..d7d8cdf1 100644 --- a/Mohem/src/assets/localization/i18n.json +++ b/Mohem/src/assets/localization/i18n.json @@ -225,6 +225,11 @@ "en": " The connection timeout expired due to an error in the network or servers may be busy!", "ar": " انتهت مهلة الاتصال بسبب خطأ في الشبكة أو الخوادم قد تكون مشغولة!" }, + "error-itg": { + "en": "Dear, this service is not available now, please try again later", + "ar": " هذه الخدمة غير متاحة الآن ، يرجى المحاولة مرة أخرى في وقت لاحق" + }, + "details": { "en": "Details", "ar": "التفاصيل"