import { Component, OnInit } from '@angular/core'; import { PublicService } from '../../../PublicService'; import {JwtHelperService} from '@auth0/angular-jwt'; import {Constants} from '../../../Constant'; import {NavController} from '@ionic/angular'; @Component({ selector: 'app-message-setting', templateUrl: './message-setting.page.html', styleUrls: ['./message-setting.page.scss'], }) export class MessageSettingPage implements OnInit { private user = this.publicService.getCurrentUser(); private userConfig = this.user.userConfig; private messageWarn = {isMsgUpdate: true, isMsgNew: true, isMsgDelete: true}; constructor(private readonly navController: NavController, private readonly publicService: PublicService ) { } ngOnInit() { const isMsgUpdate = this.user.userConfig.isMsgUpdate; const isMsgNew = this.user.userConfig.isMsgNew; const isMsgDelete = this.user.userConfig.isMsgDelete; if (isMsgUpdate === '0'){ this.messageWarn.isMsgUpdate = false; }else{ this.messageWarn.isMsgUpdate = true; } if (isMsgNew === '0'){ this.messageWarn.isMsgNew = false; }else{ this.messageWarn.isMsgNew = true; } if (isMsgDelete === '0'){ this.messageWarn.isMsgDelete = false; }else{ this.messageWarn.isMsgDelete = true; } } toggleChange(){ if (this.messageWarn.isMsgUpdate){ this.userConfig.isMsgUpdate = '1'; }else{ this.userConfig.isMsgUpdate = '0'; } if (this.messageWarn.isMsgNew){ this.userConfig.isMsgNew = '1'; }else{ this.userConfig.isMsgNew = '0'; } if (this.messageWarn.isMsgDelete){ this.userConfig.isMsgDelete = '1'; }else{ this.userConfig.isMsgDelete = '0'; } this.publicService.updateUserConfig(this.userConfig).then(res => { if (res.code === Constants.SUCCESS){ this.publicService.setCurrentUser(this.user); }else{ this.publicService.presentToast(res.msg); } }, err => { this.publicService.checkNetworkToast(err); }); } back(){ this.navController.back(); } }