You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mohemmionic5/Mohem/src/app/hmg-common/services/common/common.service.ts

1733 lines
43 KiB
TypeScript

import { Injectable } from '@angular/core';
import {
NavController,
ToastController,
LoadingController,
AlertController,
Platform,
MenuController
} from '@ionic/angular';
import { Router, NavigationExtras } from '@angular/router';
import { TranslatorService } from '../translator/translator.service';
import { AlertControllerService } from '../../ui/alert/alert-controller.service';
//import { Response } from "../models/response";
import { Response } from 'src/app/hmg-common/services/models/response';
import { Location, DatePipe } from '@angular/common';
import { ThemeableBrowser } from '@ionic-native/themeable-browser/ngx';
import { BrowserConfig } from './models/browser-config';
import {
LaunchNavigator,
LaunchNavigatorOptions
} from '@ionic-native/launch-navigator/ngx';
import { Device } from '@ionic-native/device/ngx';
import { ProgressLoadingService } from '../../ui/progressLoading/progress-loading.service';
import { Observable, throwError } from 'rxjs';
import { SharedDataService } from '../shared-data-service/shared-data.service';
import { Badge } from '@ionic-native/badge/ngx';
import { LifeCycleService } from '../life-cycle/life-cycle.service';
import { Diagnostic } from '@ionic-native/diagnostic/ngx';
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
@Injectable({
providedIn: 'root'
})
export class CommonService {
public static MOHEMM_WIFI_SSID = "";
public static MOHEMM_WIFI_PASSWORD = "";
public static SKIP = false;
public static months_en_long = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
public static months_en = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
];
public static months_ar = [
'يناير',
'فبراير',
'مارس',
'أبريل',
'مايو',
'يونيو',
'يوليو',
'أغسطس',
'سبتمبر',
'أكتوبر',
'نوفمبر',
'ديسمبر'
];
public filterKeys = {
'HRSSA': 0,
'INVMOA': 0,
'REQAPPRV': 0,
'POAPPRV': 0,
'INVITEM': 0,
"STAMP": 0,
'ITG': 0,
'COC': 0
}
private progressLoaders: any[] = [];
private loadingProgress: any;
public updateImage: boolean = false;
public setUpdateImg: any;
DT: any;
activeType: any;
constructor(
public nav: NavController,
public router: Router,
public location: Location,
public ts: TranslatorService,
public loadingController: LoadingController,
public progressLoadingService: ProgressLoadingService,
public toastController: ToastController,
public alertController: AlertControllerService,
public alertControllerIonic: AlertController,
public themeableBrowser: ThemeableBrowser,
public launchNavigation: LaunchNavigator,
public platform: Platform,
public device: Device,
public sharedService: SharedDataService,
public badge: Badge,
public lifeCycle: LifeCycleService,
public diagnostic: Diagnostic,
public iab: InAppBrowser,
private menu: MenuController,
) { }
public back() {
// this.nav.pop();
// this.nav.back({
// animated: true,
// animationDirection: "back"
// });
this.nav.pop();
}
public getMonthName(value: number): string {
switch (value) {
case 1:
return 'January';
case 2:
return 'February';
case 3:
return 'March';
case 4:
return 'April';
case 5:
return 'May';
case 6:
return 'June';
case 7:
return 'July';
case 8:
return 'August';
case 9:
return 'September';
case 10:
return 'October';
case 11:
return 'November';
case 12:
return 'December';
}
}
public getMonthNameAr(value: number): string {
switch (value) {
case 1:
return 'يناير';
case 2:
return ' فبراير';
case 3:
return 'مارس';
case 4:
return 'أبريل';
case 5:
return 'مايو';
case 6:
return 'يونيو';
case 7:
return 'يوليو';
case 8:
return 'أغسطس';
case 9:
return 'سبتمبر';
case 10:
return ' اكتوبر';
case 11:
return ' نوفمبر';
case 12:
return 'ديسمبر';
}
}
public round(value: number, decimal: number): string {
const valueStr = value.toString();
const dotIndex = valueStr.indexOf('.');
if (dotIndex >= 0) {
return valueStr.toString().substr(0, dotIndex + decimal);
} else {
return value.toString();
}
}
getSecondsAsDigitalClock(inputSeconds: number) {
var sec_num = parseInt(inputSeconds.toString(), 10); // don't forget the second param
var hours = Math.floor(sec_num / 3600);
var minutes = Math.floor((sec_num - hours * 3600) / 60);
var seconds = sec_num - hours * 3600 - minutes * 60;
var hoursString = '';
var minutesString = '';
var secondsString = '';
hoursString = hours < 10 ? '0' + hours : hours.toString();
minutesString = minutes < 10 ? '0' + minutes : minutes.toString();
secondsString = seconds < 10 ? '0' + seconds : seconds.toString();
return minutesString + ':' + secondsString;
}
public toastPK(page: string, key: string) {
this.toast(this.ts.trPK(page, key));
}
async toast(message: string) {
const toast = await this.toastController.create({
message: message,
showCloseButton: true,
position: 'top',
duration: 2000,
closeButtonText: this.ts.trPK('general', 'close')
});
toast.present();
}
public redToastPK(page: string, key: string) {
this.redToast(this.ts.trPK(page, key));
}
public greenToastPK(page: string, key: string) {
this.greenToast(this.ts.trPK(page, key));
}
async redToast(message: string) {
const toast = await this.toastController.create({
message: message,
showCloseButton: true,
position: 'top',
duration: 2000,
color: 'danger',
closeButtonText: this.ts.trPK('general', 'close')
});
toast.present();
}
async greenToast(message: string) {
const toast = await this.toastController.create({
message: message,
showCloseButton: true,
position: 'top',
duration: 2000,
color: 'success',
closeButtonText: this.ts.trPK('general', 'close')
});
toast.present();
}
private loaderIsActive = false;
async startLoadingOld() {
this.stopLoading();
const loader = await this.loadingController.create({
spinner: 'bubbles',
duration: 30000,
message: this.ts.trPK('error', 'wait'),
translucent: true
});
this.progressLoaders.push(loader);
return await loader.present();
}
public startLoading() {
/*this.stopLoading(small);
this.progressLoadingService.presentLoading( this.ts.trPK("general", "loading") , small );
*/
this.stopLoading();
this.progressLoadingService.presentLoading(
this.ts.trPK('general', 'loading')
);
}
public mobileNumber(number: string) {
return number.substr(1, number.length - 1);
}
public stopLoading() {
this.progressLoadingService.dismiss();
}
public presentAlert(message: string, onAccept?: any) {
this.alertDialog(
() => {
if (onAccept) {
onAccept();
}
},
this.ts.trPK('general', 'ok'),
this.ts.trPK('general', 'alert'),
message
);
}
public presentConfirmDialog(message: string, onAccept: any, onCancel?: any) {
this.confirmAlertDialog(
onAccept,
this.ts.trPK('general', 'ok'),
onCancel,
this.ts.trPK('general', 'cancel'),
this.ts.trPK('general', 'confirm'),
message
);
}
public presentAcceptDialog(message: string, onAccept: any) {
this.alertDialog(
onAccept,
this.ts.trPK('general', 'ok'),
this.ts.trPK('general', 'confirm'),
message
);
}
public confirmBackDialog(message: string) {
this.alertDialog(
() => {
this.back();
},
this.ts.trPK('general', 'ok'),
this.ts.trPK('general', 'info'),
message
);
}
public confirmNotAllowedDialog() {
this.openHome();
this.alertDialog(
() => { },
this.ts.trPK('general', 'ok'),
this.ts.trPK('general', 'info'),
this.ts.trPK('general', 'not-allowed')
);
}
public showErrorMessageDialog(
onClick: any,
okLabel: string,
message: string
) {
this.alertDialog(
onClick,
this.ts.trPK('general', 'ok'),
this.ts.trPK('general', 'alert'),
message
);
}
public userNeedToReLogin() {
this.presentAcceptDialog(this.ts.trPK('general', 'relogin'), () => {
this.sharedService.clearAll();
this.openLogin();
});
}
public showConnectionErrorDialog(onClick: any, okLabel: string) {
this.alertDialog(
onClick,
this.ts.trPK('general', 'ok'),
this.ts.trPK('general', 'alert'),
this.ts.trPK('general', 'connError')
);
}
public showConnectionTimeout(onClick: any, okLabel: string) {
this.alertDialog(
onClick,
okLabel,
this.ts.trPK('general', 'alert'),
this.ts.trPK('general', 'timeout')
);
}
async JustAlertDialog(acceptLabel: string, message: string) {
this.clearAllAlerts();
const alert = await this.alertControllerIonic.create({
header: this.ts.trPK('general', 'info'),
message: message,
buttons: [
{
text: acceptLabel,
handler: () => {
this.alertControllerIonic.dismiss();
}
}
]
});
// this.alerts.push(alert);
await alert.present();
}
async confirmAlertDialog(
onAccept: any,
acceptLabel: string,
onCancel: any,
cancelLabel: string,
title: string,
message: string
) {
this.clearAllAlerts();
const alert = await this.alertControllerIonic.create({
header: this.ts.trPK('general', 'confirm'),
message: message,
buttons: [
{
text: cancelLabel,
role: 'cancel',
cssClass: 'cancel-button',
handler: () => {
if (onCancel) {
onCancel();
}
this.alertControllerIonic.dismiss();
}
},
{
text: acceptLabel,
handler: () => {
if (onAccept) {
onAccept();
}
this.alertControllerIonic.dismiss();
}
}
]
});
// this.alerts.push(alert);
await alert.present();
}
async confirmAlertDialogPrimarySecondary(
onPrimary: any,
primaryLabel: string,
onSecondary: any,
secondaryLabel: string,
title: string,
message: string
) {
this.clearAllAlerts();
const alert = await this.alertControllerIonic.create({
header: this.ts.trPK('general', 'confirm'),
message: message,
buttons: [
{
text: primaryLabel,
handler: () => {
onPrimary();
this.alertControllerIonic.dismiss();
}
},
{
text: secondaryLabel,
handler: () => {
onSecondary();
this.alertControllerIonic.dismiss();
}
}
]
});
await alert.present();
}
async alertDialog(
onAccept: any,
acceptLabel: string,
title: string,
message: string
) {
this.clearAllAlerts();
const alert = await this.alertControllerIonic.create({
header: title,
message: message,
buttons: [
{
text: this.ts.trPK('general', 'ok'),
handler: () => {
if (onAccept) {
onAccept();
}
this.alertControllerIonic.dismiss();
}
}
]
});
// this.alerts.push(alert);
await alert.present();
}
async loginAlertDialog(acceptLabel: string, title: string, message: string) {
this.clearAllAlerts();
const alert = await this.alertControllerIonic.create({
header: title,
message: message,
backdropDismiss: false,
buttons: [
{
text: acceptLabel,
handler: () => {
// this.openUserLogin();
this.alertControllerIonic.dismiss();
}
}
]
});
// this.alerts.push(alert);
await alert.present();
}
async confirmAlertDialogAction(
onAccept: any,
acceptLabel: string,
onCancel: any,
cancelLabel: string,
title: string,
message: string
) {
this.clearAllAlerts();
const alert = await this.alertControllerIonic.create({
header: this.ts.trPK('general', 'confirm'),
message: message,
buttons: [
{
text: cancelLabel,
role: 'cancel',
cssClass: 'checkOutCancelBtn',
handler: () => {
if (onCancel) {
onCancel();
}
this.alertControllerIonic.dismiss();
}
},
{
text: acceptLabel,
role: 'Confirm',
cssClass: 'checkOutOkBtn',
handler: () => {
if (onAccept) {
onAccept();
}
this.alertControllerIonic.dismiss();
}
}
]
});
// this.alerts.push(alert);
await alert.present();
}
async confirmAlertDialogAttendance(
onAccept: any,
acceptLabel: string,
onCancel: any,
cancelLabel: string,
title: string,
message: string
) {
this.clearAllAlerts();
const alert = await this.alertControllerIonic.create({
header: this.ts.trPK('general', 'confirm'),
message: message,
buttons: [
{
text: cancelLabel,
role: 'cancel',
cssClass: 'checkOutCancelBtn',
handler: () => {
if (onCancel) {
onCancel();
}
this.alertControllerIonic.dismiss();
}
},
{
text: acceptLabel,
role: 'Confirm',
cssClass: 'checkOutOkBtn',
handler: () => {
if (onAccept) {
onAccept();
}
this.alertControllerIonic.dismiss();
}
}
]
});
// this.alerts.push(alert);
await alert.present();
}
public clearAllAlerts() {
// custom solutions because of async issue
const alerts = document.getElementsByTagName('ion-alert');
for (let i = 0; i < alerts.length; i++) {
const alert = alerts[i];
alert.parentNode.removeChild(alert);
}
}
public getDeviceInfo(): string {
if (this.platform.is('mobile')) {
const os = this.platform.is('ios') ? 'Iphone' : 'android';
return (
os +
' - ' +
this.device.platform +
' - ' +
this.device.version +
' , ' +
this.device.manufacturer
);
} else {
return navigator.userAgent;
}
}
public getDeviceType(): string {
if (this.platform.is('mobile')) {
// return "Mobile " + (this.platform.is("ios") ? "Iphone" : "android");
return (this.platform.is('ios') ? 'Iphone' : 'android');
} else {
return 'Desktop';
}
}
public validResponse(result: Response): boolean {
if (result.MessageStatus === 1) {
return true;
} else if (result.MessageStatus === 2) {
return false;
}
return false;
}
public openBrowser(
url: string,
onExit?,
onFaild?,
onSuccess?,
successURLS?: string[]
) {
console.log(url);
if (this.isCordova()) {
this.openBrowserInApp(url, onExit, onFaild, onSuccess, successURLS);
} else {
this.openBrowserHtml(url, onExit, onFaild, onSuccess);
}
}
private openBrowserHtml(url, onExit?, onFaild?, onSuccess?) {
const browser = window.open(url, '_blank', 'location=no');
browser.addEventListener('loadstart', () => { });
browser.addEventListener('loaderror', () => {
if (onFaild) {
onFaild();
}
});
browser.addEventListener('loadstop', () => {
if (onSuccess) {
onSuccess();
}
});
}
private openBrowserInApp(
url: string,
onExit?,
onFaild?,
onSuccess?,
successURLS?: string[]
) {
this.platform.ready().then(() => {
const browser = this.iab.create(
url,
'_blank',
'closebuttoncolor=#60686b,hidenavigationbuttons=yes,hideurlbar=yes,zoom=no'
);
// browser.executeScript(...);
// browser.insertCSS(...);
browser.on('loaderror').subscribe(event => {
if (onFaild) {
onFaild();
}
browser.close();
});
/*
browser.on('loadstop').subscribe(event => {
// browser.insertCSS({ code: 'body{color: white;}' });
if (onSuccess) {
onSuccess();
}
});
*/
browser.on('exit').subscribe(event => {
if (onExit) {
onExit();
}
});
browser.on('loadstart').subscribe(event => {
if (successURLS) {
successURLS.forEach((successURL, index) => {
if (event.url && event.url.indexOf(successURL) >= 0) {
// alert('load start found success url');
browser.close();
if (onSuccess) {
onSuccess();
}
}
});
}
});
});
}
public imageFromBase64(base64: string) {
return 'data:image/jpeg;base64,' + base64;
}
public openLocation(lat: number, lng: number) {
this.platform.ready().then(() => {
this.launchNavigation.navigate([lat, lng]).then(
() => { },
err => {
// this.failedToOpenMap();
window.open('https://maps.google.com/?q=' + lat + ',' + lng);
}
);
});
}
private failedToOpenMap() {
this.presentAlert(this.ts.trPK('error', 'map'));
}
public localizeTime(date: Date) {
if (!(date.getHours() == 0 && date.getMinutes() == 0)) {
let h = date.getHours() % 12 || 12;
let hStr = h < 10 ? '0' + h : h; // leading 0 at the left for 1 digit hours
const m = date.getMinutes();
let mStr = m < 10 ? '0' + m : m;
return hStr + ':' + mStr + (date.getHours() < 12 ? ' AM' : ' PM');
}
return '';
}
public localizeDate(date: Date, time = false) {
const lng = TranslatorService.getCurrentLanguageName();
let dateStr;
if (lng === TranslatorService.AR) {
dateStr =
CommonService.months_ar[date.getMonth()] +
' ' +
date.getDate() +
' ' +
date.getFullYear();
} else {
dateStr =
CommonService.months_en[date.getMonth()] +
' ' +
date.getDate() +
',' +
date.getFullYear();
}
return time ? dateStr + ' ' + this.localizeTime(date) : dateStr;
}
public localizeMonth(monthIndex) {
const lng = TranslatorService.getCurrentLanguageName();
if (lng === TranslatorService.AR) {
return CommonService.months_ar[monthIndex];
} else {
return CommonService.months_en[monthIndex];
}
}
public evaluteDate(dateStr: string, time = false): string {
if (dateStr) {
const utc = parseInt(dateStr.substring(6, dateStr.length - 2), 10);
if (utc) {
const date = new Date(utc);
if (date instanceof Date && !isNaN(date.getTime())) {
// return this.datePipe.transform( appoDate, 'dd-MM-yyyy');
return this.localizeDate(date, time);
}
}
}
return dateStr;
}
public evaluateDateShort(dateStr: string): string {
const date = this.evaluteDateAsObject(dateStr);
if (date) {
return (
date.getMonth() +
1 +
'/' +
date
.getFullYear()
.toString()
.substr(2)
);
} else {
return '--';
}
}
public convertISODateToJsonDate(isoDate: string): string {
return '/Date(' + Date.parse(isoDate) + ')/';
}
public convertDateToJsonDate(date: Date): string {
return '/Date(' + date.getTime() + ')/';
}
public convertDateToJsonDateUpdated(date: Date): string {
const newDate = new Date(date);
return '/Date(' + newDate.getTime() + ')/';
}
/*
date iso format
and time is 24 format hh:mm:ss
*/
public convertIsoDateToObject(isoDate: string, isoTime: string): Date {
const date = new Date(isoDate);
const parts = isoTime.split(':');
if (this.hasData(parts)) {
// remove if numbers start with 0
let hrsStr = parts[0];
let msStr = parts[1];
hrsStr = hrsStr[0] == '0' ? hrsStr.substr(1) : hrsStr;
msStr = msStr[0] == '0' ? msStr.substr(1) : msStr;
date.setHours(Number(hrsStr));
date.setMinutes(Number(msStr));
}
return date;
}
public evaluateDateWithTimeZoneOffset(dateStr: string): Date {
if (dateStr) {
const utc = parseInt(dateStr.substring(6, dateStr.length - 2), 10);
let date = new Date(utc);
let timezoneOffset: number = date.getTimezoneOffset() * 60000;
date.setTime(date.getTime() + timezoneOffset);
return date;
}
return null;
}
public evaluteDateAsObject(dateStr: string): Date {
if (dateStr) {
const utc = parseInt(dateStr.substring(6, dateStr.length - 2), 10);
return new Date(utc);
}
return null;
}
public getDateISO(date: Date): string {
return (
date.getFullYear().toString() +
'-' +
this.trailerZero(date.getMonth() + 1) +
'-' +
this.trailerZero(date.getDate())
);
}
public getTodayISO(): string {
return this.getDateISO(new Date());
}
public getTimeISO(date: Date): string {
return (
this.trailerZero(date.getHours()) +
':' +
this.trailerZero(date.getMinutes()) +
':00'
);
}
public getDateTimeISO(date: Date): string {
return this.getDateISO(date) + ' ' + this.getTimeISO(date);
}
public getDateTimeISOFromString(dateStr: string): string {
const date = this.evaluteDateAsObject(dateStr);
return this.getDateTimeISO(date) + ' ' + this.getTimeISO(date);
}
public getDateTimeISOFromStringUpdated(dateStr: string): string {
const date = this.evaluteDateAsObject(dateStr);
return this.getDateTimeISO(date);
}
public getCurrentTimeISO(): string {
return this.getTimeISO(new Date());
}
private trailerZero(value: number): string {
const str = value.toString();
return str.length > 1 ? str : '0' + str;
}
public hasData(array: any[]): boolean {
return array != null && array.length > 0;
}
public extractNumber(message: string): string {
if (message != null && message.length > 0) {
let startIndex = null;
let endIndex = message.length - 1;
for (let i = 0; i < message.length; i++) {
const code = message.charCodeAt(i);
if (this.inNumberRange(code)) {
if (!startIndex) {
startIndex = i;
}
} else {
if (startIndex) {
endIndex = i;
break;
}
}
}
return startIndex ? message.substring(startIndex, endIndex) : '';
}
return null;
}
public inNumberRange(targetCode: number): boolean {
const minDigit = '0'.charCodeAt(0);
const maxDigit = '9'.charCodeAt(0);
return targetCode >= minDigit && targetCode <= maxDigit;
}
public enterPage() { }
private smsAlertDialog = null;
public presentSMSPasswordDialog(
onAccept: any,
smsCode?: string,
title?: string
) {
this.dismissSMSDialog().subscribe(removed => {
this.createSMSPAsswordDialog(onAccept, smsCode, title);
});
}
async createSMSPAsswordDialog(
onAccept: any,
smsCode?: string,
title?: string
) {
this.smsAlertDialog = await this.alertControllerIonic.create({
header: title || this.ts.trPK('general', 'enter-sms-code'),
inputs: [
{
name: 'sms',
type: 'number',
value: smsCode,
placeholder: this.ts.trPK('general', 'enter-sms')
}
],
buttons: [
{
text: this.ts.trPK('general', 'cancel'),
role: 'cancel',
cssClass: 'cancel-button',
handler: () => { }
},
{
text: this.ts.trPK('general', 'ok'),
handler: data => {
onAccept(data.sms);
}
}
]
});
await this.smsAlertDialog.present();
}
public getStartOfDay(date: Date): Date {
date.setHours(0, 0, 0, 0);
return date;
}
public dismissSMSDialog(): Observable<boolean> {
return Observable.create(observer => {
this.alertControllerIonic.getTop().then(
() => {
this.alertControllerIonic.dismiss().then(
() => {
observer.next(true);
observer.complete();
},
() => {
observer.next(false);
observer.complete();
}
);
},
() => {
observer.next(false);
observer.complete();
}
);
});
}
public getStartOfToday(): number {
const date = new Date();
date.setHours(0, 0, 0, 0);
return date.getTime();
}
public getGraphSeries(
xLabels: string[],
data: number[],
title: string,
color: string,
fill = false
): any {
return {
labels: xLabels,
datasets: [
{
label: title,
data: data,
fill: fill,
borderColor: color,
backgroundColor: color
}
]
};
}
public getGraphDataSet(
title: string,
data: number[],
color: string,
fill = false
) {
return {
label: title,
data: data,
fill: fill,
borderColor: color,
backgroundColor: color
};
}
public getGraphMultiSeries(xLabels: string[], datasets: any[]): any {
return {
labels: xLabels,
datasets: datasets
};
}
public get2SeriesMultiGraphData(
dataList: any[],
value1Key,
title1,
value2Key,
title2,
labels: string[]
) {
const series1: number[] = [];
const series2: number[] = [];
for (const data of dataList) {
series1.push(data[value1Key]);
series2.push(data[value2Key]);
}
const dataSets = [
this.getGraphDataSet(this.ts.trInline(title1), series1, '#d12026'),
this.getGraphDataSet(this.ts.trInline(title2), series2, '#60686b')
];
return this.getGraphMultiSeries(labels, dataSets);
}
async setBadge(count: number) {
this.platform.ready().then(() => {
if (count > 0) {
this.badge.set(count);
} else {
this.badge.clear();
}
});
}
public isHtml5VideoSupported(): boolean {
const v = document.createElement('video');
if (v.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"')) {
return true;
}
if (v.canPlayType('video/ogg; codecs="theora, vorbis"')) {
return true;
}
if (v.canPlayType('video/webm; codecs="vp8, vorbis"')) {
return true;
}
return false;
}
public isCordova(): boolean {
return this.platform.is('cordova');
}
public pageRevisited(pageName: string): Observable<boolean> {
return this.lifeCycle.pageRevisited(pageName);
}
/*
open calls
*/
public openAttenTrackingpage() {
this.nav.navigateForward(['/attendance-tracking/home']);
}
public openAttendanceOptionsComponent() {
this.nav.navigateForward(['/home/attendance-option']);
}
public openEitListPage() {
this.nav.navigateForward(['/eit/eit-list']);
}
public openAddEitPage() {
this.nav.navigateForward(['/eit/add-eit']);
}
public openAddCEIPage() {
this.nav.navigateForward(['/eit/add-cei']);
}
public openConfirmEitPage() {
this.nav.navigateForward(['/eit/confirm-add-eit']);
}
public openConfirmCEIPage() {
this.nav.navigateForward(['/eit/confirm-cei']);
}
public openConfirmBasicDetailsPage() {
this.nav.navigateForward(['/profile/confirm-basic']);
}
public openHome() {
this.nav.navigateRoot(['/home']);
}
public openForgotPassword() {
this.nav.navigateForward(['/authentication/forgot']);
}
public openChangePassword() {
this.nav.navigateForward(['/authentication/changepassowrd']);
}
// public openProfile() {
// this.nav.navigateForward(['/profile/home']);
// }
public openProfile(target: any) {
const navigationExtras: NavigationExtras = {
queryParams: {
targetValue: target
}
};
this.nav.navigateForward(['/profile/home'], navigationExtras);
}
public openEditProfile() {
this.nav.navigateForward(['/profile/editprofile']);
}
public openAddBasicDetails(target: string) {
const navigationExtras: NavigationExtras = {
queryParams: {
targetValue: target
}
};
this.nav.navigateForward(['/profile/addBasicDetails'], navigationExtras);
}
public openAccuralPage() {
this.nav.navigateForward(['/accrual-balances/home']);
}
public openEITPage() {
this.nav.navigateForward(['/eit/homepage']);
}
public openMyTeamPage() {
console.log('someeeeeeee');
this.nav.navigateForward(['/my-team/home']);
}
public openMyTeamDetailPage() {
this.nav.navigateForward(['/my-team/details']);
}
public openSubordinateLeavePage() {
this.nav.navigateForward(['/my-team/subordinate-leave']);
}
public openMyRequestPage() {
this.nav.navigateForward(['/mowadhafi/my-request']);
}
public openHRRequestPage() {
this.nav.navigateForward(['/mowadhafi/hr-request']);
}
public openHRRequestFormPage() {
this.nav.navigateForward(['/mowadhafi/hr-request-form']);
}
public openRequestDetailsPage() {
this.nav.navigateForward(['/mowadhafi/request-details']);
}
public openPage(link: string) {
this.nav.navigateForward([link]);
}
public static myTeamDetailUrl = ['/my-team/details', '/my-team/details-2']
public openMyTeamDetails() {
this.alternateNavigate(CommonService.myTeamDetailUrl, 'teamDetail-open', true);
// this.nav.navigateForward(["/my-team/details"]);
}
public openAbsencePage() {
this.nav.navigateForward(['/absence/home']);
}
public openSubmitAbsencePage() {
this.nav.navigateForward(['/absence/submit-absence']);
}
public openConfirmAbsece() {
this.nav.navigateForward(['/absence/confirm-absence']);
}
public openWorkListAttachViewPage() {
this.nav.navigateForward(['/notification/work-list-attach-view']);
}
public openviewAbsenceAttachment() {
this.nav.navigateForward(['/absence/view-attachements']);
}
public openNotificationPage() {
this.nav.navigateForward(['/notification/homepage']);
}
public openWorklistMainPage() {
this.nav.navigateForward(['/notification/worklist-main']);
}
public openWorklistSettingsPage() {
this.nav.navigateForward(['/notification/worklist-settings']);
}
public openWorklistMainPRPage() {
this.nav.navigateForward(['/notification/worklist-main-PR']);
}
public openWorklistMainPOPage() {
this.nav.navigateForward(['/notification/worklist-main-PO']);
}
public openWorklistReplacementRollPage() {
this.nav.navigateForward(['/notification/work-list-replacement-roll']);
}
public openNotificationDetailsPage() {
this.nav.navigateForward(['/notification/work-list-details']);
}
public openWorklistHistoryPage() {
this.nav.navigateForward(['/notification/work-list-action-history']);
}
public openWorklistAttachPage() {
this.nav.navigateForward(['/notification/work-list-attach']);
}
public openWorklistRFCPage() {
this.nav.navigateForward(['/notification/work-list-rfc']);
}
public openWorklistRollReplacement() {
this.nav.navigateForward(['/notification/work-list-replacement-roll']);
}
public openItemHistoryPage() {
this.nav.navigateForward(['/notification/item-history-PO']);
}
public openMOItemHistoryPage() {
this.nav.navigateForward(['/notification/item-history-MO']);
}
public openQutationAnalysisPage() {
this.nav.navigateForward(['/notification/qutation-analysis-PO']);
}
public openWorklistMainMRPage() {
this.nav.navigateForward(['/notification/worklist-main-MR']);
}
public openWorklistMainICPage() {
this.nav.navigateForward(['/notification/item-creation-IC']);
}
public openWorklistITGPage() {
this.nav.navigateForward(['/notification/worklist-main-ITG']);
}
public openMySpecialistPage() {
this.nav.navigateForward(['/my-specialist/home']);
}
public openMySubordinatePage() {
this.nav.navigateForward(['/my-subordinate/home']);
}
public openChangeImagePage() {
this.nav.navigateForward(['/profile/profileImg']);
}
public openPayslipPage() {
this.nav.navigateForward(['/payslip/home']);
}
public openTimeCardPage() {
this.nav.navigateForward(['/time-card/time-card-details']);
}
public openEarningsPage() {
this.nav.navigateForward(['/payslip/Earnings']);
}
public openDeductionsPage() {
this.nav.navigateForward(['/payslip/Deductions']);
}
public openConfirmLoginPage() {
this.nav.navigateForward(['/authentication/confirmLogin']);
}
public openEditprofile() {
this.nav.navigateForward(['/profile/editProfile']);
}
public openAddAddress() {
this.nav.navigateForward(['/profile/add-address']);
}
public openAddContact() {
this.nav.navigateForward(['/profile/contact']);
}
public openAddUpdateContact() {
this.nav.navigateForward(['/profile/add-update-contact']);
}
public confirmContact() {
this.nav.navigateForward(['/profile/confirm-contact']);
}
public openConfirmAddAddress() {
this.nav.navigateForward(['/profile/confirm-add-address']);
}
public openPerformanceevaluation() {
this.nav.navigateForward(['/profile/performanceevaluation']);
}
public eitUpdate() {
this.nav.navigateForward(['/eit/eit-update-list']);
}
public openCEIPage() {
this.nav.navigateForward(['/eit/cei-homepage']);
}
public openCEIListPage() {
this.nav.navigateForward(['/eit/cei-list']);
}
public openAnnouncement() {
this.nav.navigateForward(['/backend-integrations/announcement']);
}
public openConcurrentReport() {
this.nav.navigateForward(['/reports/concurrent-report']);
}
public openConcurrentTransaction() {
this.nav.navigateForward(['/reports/transaction-list']);
}
public openConcurrentTransactionsHome() {
this.nav.navigateForward(['/reports/transactions']);
}
public openTermination() {
this.nav.navigateForward(['/termination/termination-form']);
}
public confirmTermination() {
this.nav.navigateForward(['/termination/confirm-termination']);
}
public openTransactions() {
this.nav.navigateForward(['/pending-transaction/home']);
}
public openItemForSale() {
this.nav.navigateForward('/itemforsale/items');
}
public openCreateitems() {
this.nav.navigateForward('/itemforsale/home');
}
public filterItemforSale() {
this.nav.navigateForward('/itemforsale/filter');
}
public navigatePage(path) {
this.nav.navigateForward([path]);
}
public reload(url: string, from: string) {
console.log('force reload called from:' + from);
// window.location.reload();
location.href = url;
}
public navigateRoot(url: string) {
this.nav.navigateRoot([url]);
}
public navigateByURL(url: string) {
this.router.navigateByUrl(url);
// this.router.navigateByUrl([url);
}
public navigateForward(url: string) {
this.nav.navigateForward([url]);
}
public navigateBack(url: string) {
this.nav.navigateBack([url]);
}
private alternateNavigate(paths: string[], key: string, root = false) {
let url: string;
if (localStorage.getItem(key) === 'yes') {
localStorage.setItem(key, 'no');
url = paths[0];
} else {
localStorage.setItem(key, 'yes');
url = paths[1];
}
if (root) {
this.nav.navigateRoot([url]);
} else {
this.nav.navigateForward([url]);
}
}
public openLogin() {
this.nav.navigateRoot(['/authentication/login']);
}
public openUserForgot() {
this.nav.navigateForward(['/authentication/checkuser']);
}
public openSMSPage() {
this.nav.navigateForward(['/authentication/smspage']);
}
public navigateTo(url: string) {
this.nav.navigateForward([url]);
}
public keysInObject(obj): any[] {
const keys: any = [];
if (obj != null) {
for (const key in obj) {
keys.push(key);
}
}
return keys.length > 0 ? keys : null;
}
public keysCountInObject(obj): number {
let count = 0;
if (obj != null) {
for (const key in obj) {
count++;
}
}
return count;
}
public checkBlueTooth(feedback: any) {
this.platform.ready().then(() => {
this.diagnostic
.getBluetoothState()
.then(state => {
if (state == this.diagnostic.bluetoothState.POWERED_ON) {
feedback();
} else {
this.presentAlert(this.ts.trPK('bluetooth', 'start'));
}
})
.catch(e => {
this.presentAlert(this.ts.trPK('bluetooth', 'start'));
});
});
}
list_to_tree(list) {
let map = {},
node,
roots = [],
i;
for (i = 0; i < list.length; i += 1) {
map[list[i].MENU_NAME] = i; // initialize the map
list[i].children = []; // initialize the children
}
for (i = 0; i < list.length; i += 1) {
node = list[i];
if (node.PARENT_MENU_NAME !== '') {
// if you have dangling branches check that map[node.parentId] exists
list[map[node.PARENT_MENU_NAME]].children.push(node);
} else {
roots.push(node);
}
}
return roots;
}
public reverseFormatDate(date) {
let FormatedDate;
if (date) {
FormatedDate = date.replace(/\//g, '-');
FormatedDate = FormatedDate.replace(/ 00:00:00/g, '');
} else {
FormatedDate = date;
}
return FormatedDate;
}
public formatStandardDate(date) {
let FormatedDate;
if (date) {
FormatedDate = date.replace(/-/g, '/');
} else {
FormatedDate = date;
}
return FormatedDate;
}
public reverseFormatStandardDate(date) {
let FormatedDate;
if (date) {
FormatedDate = date.replace(/\//g, '-');
} else {
FormatedDate = date;
}
return FormatedDate;
}
public formatDate(date) {
let FormatedDate;
console.log(date);
if (date) {
date = date.slice(0, 10);
FormatedDate = date.replace(/-/g, '/');
FormatedDate = FormatedDate + ' 00:00:00';
} else {
FormatedDate = date;
}
return FormatedDate;
}
public formatDateNew(date) {
let FormatedDate;
console.log(date);
if (date) {
// FormatedDate = date.replace(/-/g, "/");
FormatedDate = date.split('T')[0];
FormatedDate = FormatedDate + ' 00:00:00';
console.log(FormatedDate);
} else {
FormatedDate = date;
}
return FormatedDate;
}
public setUpdateImage(image, status?) {
console.log('setUpdateImage');
this.setUpdateImg = image;
this.updateImage = status;
}
public getUpdateImage() {
console.log('getUpdateImage');
const objImg = {
img: this.setUpdateImg,
status: this.updateImage
}
return objImg;
}
setDeviceToken(deviceToken) {
this.DT = deviceToken;
}
getDeviceToken() {
return this.DT;
}
setActiveTypeLogin(activeType) {
this.activeType = activeType;
}
getActiveTypeLogin() {
return this.activeType;
}
public totalCounter = 0;
getTotalNumberOfWorklistRequest() {
console.log(this.sharedService.getSharedData('total-count', false));
this.totalCounter = parseInt(this.sharedService.getSharedData('total-count', false));
return this.totalCounter ? this.totalCounter : 0;
}
setTotalNumberOfWorklistRequest() {
if (this.totalCounter > 0) {
this.totalCounter -= 1;
}
this.sharedService.setSharedData(this.totalCounter, 'total-count');
}
public setFilterValues(data) {
for (const notification of data) {
this.filterKeys[notification.ITEM_TYPE] = notification.OPEN_NTF_NUMBER
}
}
public filters = [
{
value: 0,
name: 'HR',
active: false,
color: '#18a169',
key: 'HRSSA',
disable: false,
total: 0
},
{
value: 0,
name: 'MR',
active: false,
color: '#3cb9d5',
key: 'INVMOA',
disable: false,
total: 0
},
{
value: 0,
name: 'PR',
active: false,
color: '#114475',
key: 'REQAPPRV',
disable: false,
total: 0
},
{
value: 0,
name: 'PO',
active: false,
color: '#38c9b3',
key: 'POAPPRV',
disable: false,
total: 0
},
{
value: 0,
name: 'ITG',
active: false,
color: '#cc3232',
key: 'ITG',
disable: false,
total: 0
},
{
value: 0,
name: 'IC',
active: false,
color: '#9e7e97',
key: 'INVITEM',
disable: false,
total: 0
},
{
value: 0,
name: 'STAMP',
active: false,
color: '#ff9800',
key: 'STAMP',
disable: false,
total: 0,
},
{
value: 0,
name: 'COC',
active: false,
color: '#787299',
key: 'COC',
disable: true,
total: 0,
}
];
public data = {
datasets: [
{
data: [0, 0, 0, 0, 0, 0, 0, 0],
backgroundColor: [
'#18a169',
'#3cb9d5',
'#114475',
'#38c9b3',
'#cc3232',
'#9e7e97',
'#ff9800',
'#787299'
],
borderWidth: 6
}]
};
getFiltersData() {
// for (const notification of openNotificationsArray) {
// if (notification.ITEM_TYPE === 'HRSSA') {
this.filters[0].value = this.filterKeys['HRSSA'];
this.data.datasets[0].data[0] = this.filterKeys['HRSSA'];
// } else if (notification.ITEM_TYPE === 'INVMOA') {
this.filters[1].value = this.filterKeys['INVMOA'];
this.data.datasets[0].data[1] = this.filterKeys['INVMOA'];
// } else if (notification.ITEM_TYPE === 'REQAPPRV') {
this.filters[2].value = this.filterKeys['REQAPPRV'];
this.data.datasets[0].data[2] = this.filterKeys['REQAPPRV'];
// } else if (notification.ITEM_TYPE === 'POAPPRV') {
this.filters[3].value = this.filterKeys['POAPPRV'];
this.data.datasets[0].data[3] = this.filterKeys['POAPPRV'];
// } else if (notification.ITEM_TYPE === 'INVITEM') {
this.filters[5].value = this.filterKeys['INVITEM'];
this.data.datasets[0].data[5] = this.filterKeys['INVITEM'];
// } else if (notification.ITEM_TYPE === 'STAMP') {
this.filters[6].value = this.filterKeys['STAMP'];
this.data.datasets[0].data[6] = this.filterKeys['STAMP'];
this.filters[7].value = this.filterKeys['COC'];
this.data.datasets[0].data[7] = this.filterKeys['COC'];
let val = { 'filters': [], 'data': {} };
val.filters = this.filters;
val.data = this.data;
return val;
}
}