From f7c23eb8d44f0f59ca6f41c29805ca511ea5db9a Mon Sep 17 00:00:00 2001 From: enadhilal Date: Wed, 8 Dec 2021 15:58:09 +0300 Subject: [PATCH] added notification service for worklist --- .../models/userItemTypeRequest.ts | 6 ++ .../service/work-list.main.service.ts | 8 +-- .../worklist-setting.component.html | 14 +++- .../worklist-setting.component.ts | 68 +++++++++++++++---- Mohem/src/assets/localization/i18n.json | 8 +++ 5 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 Mohem/src/app/notification/models/userItemTypeRequest.ts diff --git a/Mohem/src/app/notification/models/userItemTypeRequest.ts b/Mohem/src/app/notification/models/userItemTypeRequest.ts new file mode 100644 index 00000000..d6c934a2 --- /dev/null +++ b/Mohem/src/app/notification/models/userItemTypeRequest.ts @@ -0,0 +1,6 @@ +export class UserItemTypes extends Request { + public P_ITEM_TYPE: string; + public P_FYA_ENABLED_FALG: string; + public P_FYI_ENABLED_FLAG: string; + public ItemID: number; +} \ No newline at end of file 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 a179e13d..c3badf4c 100644 --- a/Mohem/src/app/notification/service/work-list.main.service.ts +++ b/Mohem/src/app/notification/service/work-list.main.service.ts @@ -20,6 +20,7 @@ import { QuotationAnalysisResponse } from '../models/quotationAnalysisRes'; import { Request } from 'src/app/hmg-common/services/models/request'; import { LoginModel } from '../../authentication/models/LoginModel'; import { itgRequest } from '../models/itgFormDetailsRequest'; +import { UserItemTypes } from "../models/userItemTypeRequest"; @Injectable() export class WorklistMainService { @@ -395,18 +396,17 @@ export class WorklistMainService { } public updateWorklistNotifications( + requestData: any, onError?: any, errorLabel?: string ): Observable { - const request = new Request(); - this.authService.authenticateRequest(request); + this.authService.authenticateRequest(requestData); return this.api.post( WorklistMainService.updateWorklistNotificationURL, - request, + requestData, onError, errorLabel ); } - } diff --git a/Mohem/src/app/notification/worklist-setting/worklist-setting.component.html b/Mohem/src/app/notification/worklist-setting/worklist-setting.component.html index f7faf500..9f1ef3f6 100644 --- a/Mohem/src/app/notification/worklist-setting/worklist-setting.component.html +++ b/Mohem/src/app/notification/worklist-setting/worklist-setting.component.html @@ -16,18 +16,26 @@
+ + +

item type

+
+

FYA

+          +

FYI

+

{{data.ITEM_TYPE}}

- +     - +

- {{ 'worklist, save-changes' | translate}} + {{ 'worklist, save-changes' | translate}} \ No newline at end of file diff --git a/Mohem/src/app/notification/worklist-setting/worklist-setting.component.ts b/Mohem/src/app/notification/worklist-setting/worklist-setting.component.ts index 07357490..bd9c607e 100644 --- a/Mohem/src/app/notification/worklist-setting/worklist-setting.component.ts +++ b/Mohem/src/app/notification/worklist-setting/worklist-setting.component.ts @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { ModalController } from '@ionic/angular'; import { CommonService } from 'src/app/hmg-common/services/common/common.service'; import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service'; +import { UserItemTypes } from '../models/userItemTypeRequest'; import { WorklistMainService } from '../service/work-list.main.service'; @Component({ @@ -12,6 +13,8 @@ import { WorklistMainService } from '../service/work-list.main.service'; export class WorklistSettingComponent implements OnInit { notificationList = []; + request = []; + isChange = false; public direction: string; @@ -19,30 +22,67 @@ export class WorklistSettingComponent implements OnInit { public modalController: ModalController, public ts: TranslatorService, public common: CommonService, - public workListService: WorklistMainService,) { } + public workListService: WorklistMainService) {} - ionViewWillEnter() { + + ngOnInit() { + this.direction = TranslatorService.getCurrentDirection(); this.workListService.getWorklistNotifications() .subscribe((result: any) => { - result.GetUserItemTypesList.forEach(element => { - this.notificationList.push(element); - }); + this.notificationList = result.GetUserItemTypesList; + for (let i = 0; i < this.notificationList.length; i++) { + this.request[i] = { + P_FYA_ENABLED_FALG: this.notificationList[i].FYA_ENABLED_FALG, + P_FYI_ENABLED_FLAG: this.notificationList[i].FYI_ENABLED_FLAG, + P_ITEM_TYPE: this.notificationList[i].ITEM_TYPE, + ItemID: i + }; + } }); } - ngOnInit() { - this.direction = TranslatorService.getCurrentDirection(); - // list.forEach(element => { - // this.notificationList.push(element); - // }); - // console.log(this.notificationList); + dismiss() { + this.modalController.dismiss({ + dismissed: true + }); } + chnageToggle(toggleValue, type, val) { + if ( val === 'Y') { + val = 'N'; + } else if ( val === 'N') { + val = 'Y'; + } + this.notificationList.forEach((el, index) => { + if ( el.ITEM_TYPE === toggleValue.ITEM_TYPE) { + if (type === 'FYI') { + this.request[index].P_FYI_ENABLED_FLAG = val; + } else if (type === 'FYA') { + this.request[index].P_FYA_ENABLED_FALG = val; + } + this.request[index].ItemID = index; + } + this.request[index].P_ITEM_TYPE = el.ITEM_TYPE; + }); + } - dismiss() { - this.modalController.dismiss({ - 'dismissed': true + saveChanges() { + const body = { + UpdateItemTypeList: this.request + }; + this.workListService.updateWorklistNotifications(body) + .subscribe((result: any) => { + if (result.UpdateItemTypeSuccessList) { + if (result.UpdateUserItemTypesList) { + this.common.greenToastPK('worklist', 'save-successfully'); + this.dismiss(); + } else { + this.common.redToastPK('worklist', 'save-error'); + } + } else { + this.common.redToastPK('worklist', 'save-error'); + } }); } diff --git a/Mohem/src/assets/localization/i18n.json b/Mohem/src/assets/localization/i18n.json index f53543be..c188decf 100644 --- a/Mohem/src/assets/localization/i18n.json +++ b/Mohem/src/assets/localization/i18n.json @@ -2551,6 +2551,14 @@ "loading":{ "en":"Loading", "ar":"يتم التحميل" + }, + "save-successfully":{ + "ar":"تم حفظ التغيير بنجاح", + "en":"Your change has been saved successfully" + }, + "save-error":{ + "ar":"هناك شئ خاطئ، يرجى المحاولة فى وقت لاحق", + "en":"Something went wrong please try again later" } }, "worklistMain": {