Commit 71a17529 authored by Sandeep Sagar Panjala's avatar Sandeep Sagar Panjala

initial commit

parent 476e4126
import { Pipe, PipeTransform } from "@angular/core";
import * as moment from "moment";
@Pipe({
name: "age"
})
export class AgePipe implements PipeTransform {
//transform(value: Date): string {
// let today = moment();
// let birthdate = moment(value);
// let years = today.diff(birthdate, 'years');
// let html: string = years + " yr ";
// html += today.subtract(years, 'years').diff(birthdate, 'months') + " mo";
// return html; // only yr ,m
//}
transform(value: Date | string, precision: "years" | "months" | "days" = "years") {
if (!value) {
return "";
}
const today = moment();
const birthdate = moment(value);
let age = '';
switch (precision) {
case "days":
age += today.diff(birthdate, 'years') + 'Y '; //years
const y = today.diff(birthdate, 'years'); //yr
age += today.subtract(y, 'years').diff(birthdate, 'months') + 'M '; // months
var m = today.diff(birthdate, 'months'); //m
birthdate.add(m, 'months');
age += today.diff(birthdate, 'days') + 'D'; //days
break;
case "months":
age += today.diff(birthdate, 'years') + 'Y '; //years
const yr = today.diff(birthdate, 'years'); //yr
age += today.subtract(yr, 'years').diff(birthdate, 'months') + 'M'; // months
break;
default:
age += today.diff(birthdate, 'years') + 'Y '; //years
break;
}
return age;
}
}
\ No newline at end of file
import { Pipe, PipeTransform } from "@angular/core";
function formatBytes(a: number, b: number) { if (0 === a) return "0 Bytes"; const c = 0 > b ? 0 : b, d = Math.floor(Math.log(a) / Math.log(1024)); return parseFloat((a / Math.pow(1024, d)).toFixed(c)) + " " + ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"][d] }
@Pipe({
name: "formatBytes"
})
export class FormatBytesPipe implements PipeTransform {
transform(size: number, length = 2) {
if (!size) {
return "";
}
return formatBytes(size, length);
}
}
\ No newline at end of file
import { Pipe, PipeTransform } from "@angular/core";
@Pipe({
name: "fromArray"
})
export class FromArrayPipe implements PipeTransform {
transform(value: Array<string>) {
if (!value && !value.length) {
return "";
}
return value.join(", ");
}
}
\ No newline at end of file
import { Pipe, PipeTransform } from "@angular/core";
@Pipe({
name: "gender"
})
export class GenderPipe implements PipeTransform {
transform(val: string) {
switch (val) {
case "M":
return "Male";
case "F":
return "Female";
case "O":
return "Other";
case "A":
return "Ambiguous";
default:
return "N/A";
}
}
}
\ No newline at end of file
export * from "./safe.pipe";
export * from "./initials.pipe";
export * from "./utc-to-local.pipe";
export * from "./format-bytes.pipe";
export * from "./gender.pipe";
export * from "./marital-status.pipe";
export * from "./from-array.pipe";
export * from "./to-array.pipe";
export * from "./minute-seconds.pipe";
export * from "./search.pipe";
export * from "./sort-form-array.pipe";
export * from "./sort-form.pipe";
export * from "./age.pipe";
\ No newline at end of file
import { Pipe, PipeTransform } from "@angular/core";
@Pipe({
name: "initials"
})
export class InitialsPipe implements PipeTransform {
transform(value: any) {
if (!value) {
return "";
}
if (value.indexOf(" ") > 0) {
const titles = value.split(" ");
return titles[0].substring(0, 1).toUpperCase() + titles[titles.length - 1].substring(0, 1).toUpperCase();
} else {
return value.substring(0, 2).toUpperCase();
}
}
}
@Pipe({
name: "spaceTitle"
})
export class TitlePipe implements PipeTransform {
transform(value: any) {
if (!value) {
return "";
}
return value.replace(/([A-Z])/g, " $1").replace("Mi Qlave", "MiQlave").trim();
}
}
\ No newline at end of file
import { Pipe, PipeTransform } from "@angular/core";
@Pipe({
name: "maritalStatus"
})
export class MaritalStatusPipe implements PipeTransform {
transform(val: string) {
switch (val) {
case "M":
return "Married";
case "S":
return "Single";
case "D":
return "Divorced";
case "W":
return "Widowed";
case "O":
return "Other";
default:
return "N/A";
}
}
}
\ No newline at end of file
import { Pipe, PipeTransform } from "@angular/core";
@Pipe({
name: "minuteSeconds"
})
export class MinuteSecondsPipe implements PipeTransform {
transform(value: number): string {
if (!value) {
return "";
}
const minutes = Math.floor(value / 60);
return minutes.toString().padStart(2, "0") + ":" + (value - minutes * 60).toString().padStart(2, "0");
}
}
\ No newline at end of file
import { Pipe, PipeTransform } from "@angular/core";
import { DomSanitizer } from "@angular/platform-browser";
@Pipe({
name: "safe"
})
export class SafePipe implements PipeTransform {
constructor(private readonly sanitizer: DomSanitizer) { }
transform(url: string) {
return this.sanitizer.bypassSecurityTrustResourceUrl(url);
}
}
\ No newline at end of file
import { Pipe, PipeTransform } from "@angular/core";
@Pipe({
name: "search"
})
export class SearchPipe implements PipeTransform {
transform(value, keys: string, term: string) {
if (!term) {
return value;
}
return (value || []).filter(item => keys.split(",").some(key => item.hasOwnProperty(key) && new RegExp(term, "gi").test(item[key])));
}
}
\ No newline at end of file
import { Pipe, PipeTransform } from "@angular/core";
@Pipe({
name: "sortFormArray",
pure: false
})
export class SortFormArrayPipe implements PipeTransform {
transform(array: Array<string>, property: string): Array<string> {
if (array !== undefined) {
return array.sort((a: any, b: any) => {
const aValue = a[property];
const bValue = b[property];
if (aValue < bValue) {
return -1;
} else if (aValue > bValue) {
return 1;
} else {
return 0;
}
});
}
return array;
}
}
\ No newline at end of file
import { Pipe, PipeTransform } from "@angular/core";
@Pipe({
name: "sortForm",
pure: false
})
export class SortFormPipe implements PipeTransform {
transform(array: Array<any>, property: string): Array<string> {
if (array !== undefined) {
return array.sort((a: any, b: any) => {
const aValue = a.value[property];
const bValue = b.value[property];
if (aValue < bValue) {
return -1;
} else if (aValue > bValue) {
return 1;
} else {
return 0;
}
});
}
return array;
}
}
\ No newline at end of file
import { Pipe, PipeTransform } from "@angular/core";
@Pipe({
name: "toArray"
})
export class ToArrayPipe implements PipeTransform {
transform(value: any) {
if (!value) {
return [];
}
if (value.indexOf(",") < 0) {
return [value];
}
return value.split(",");
}
}
\ No newline at end of file
import { Pipe, PipeTransform } from "@angular/core";
import * as moment from "moment";
@Pipe({
name: "utcToLocal"
})
export class UTCToLocalPipe implements PipeTransform {
transform(date: string | Date, isTimestamp?: boolean, format?: string) {
if (!date) {
return "";
}
isTimestamp = isTimestamp === null || isTimestamp === undefined ? true : isTimestamp;
const dateFormat = isTimestamp ? "MM/DD/YYYY hh:mm a" : "MM/DD/YYYY";
const utcTime = date;
const offset = moment().utcOffset();
return moment.utc(utcTime).utcOffset(offset).format(format ? format : dateFormat);
}
}
\ No newline at end of file
import { Injectable } from "@angular/core";
import { BehaviorSubject, Observable, Subject } from "rxjs";
import { HealthCard } from "../entities";
@Injectable()
export class AppointmentRefreshService {
private jitsiSource = new BehaviorSubject(null);
jitsiAccount: Observable<any> = this.jitsiSource.asObservable();
refresh(isRefreshed: boolean) {
this.jitsiSource.next(isRefreshed);
}
private source = new BehaviorSubject(null);
appointment: Observable<any> = this.source.asObservable();
refreshAppointment(isRefreshed: boolean) {
this.source.next(isRefreshed);
}
private conditionalRefreshSource = new BehaviorSubject(null);
conditionalRefresh: Observable<any> = this.conditionalRefreshSource.asObservable();
conditionalRefreshAppointment(model: {}) {
this.conditionalRefreshSource.next(model);
}
private healthCard = new Subject();
healthCardDetail: Observable<any> = this.healthCard.asObservable();
onClickHealthCard(item:HealthCard) {
this.healthCard.next(item);
}
}
import { Injectable } from "@angular/core";
import { Observable, Subject } from "rxjs";
@Injectable()
export class AppointmentToggleService {
private source = new Subject<boolean>();
subscriber: Observable<boolean> = this.source.asObservable();
toggle(is: boolean) {
this.source.next(is);
}
}
import { Injectable } from "@angular/core";
import { ApiResources, UtilHelper } from "../helpers";
import { HttpService } from ".";
import { Setting } from "../entities";
@Injectable()
export class BannerService {
constructor(private readonly httpService: HttpService) { }
//get(callback?: Function) {
// const request = {
// imageType: "Banner"
// };
// this.httpService
// .get(ApiResources.getURI(ApiResources.setting.base, ApiResources.setting.applyLogo), request)
// .subscribe(
// (response: ImageReports) => {
// callback(response);
// },
// () => {
// callback();
// }
// );
//}
getBannerImage(callback?: Function) {
this.httpService
.get<Array<Setting>>(ApiResources.getURI(ApiResources.setting.base, ApiResources.setting.fetch), { type: "Banner", active: true }, true)
.subscribe(
(response: Array<Setting>) => {
if (response && response.length > 0) {
if (UtilHelper.isEmpty(response[0].imageUrl)) {
response[0].imageUrl = `${ApiResources.getURI(ApiResources.resources.base, ApiResources.resources.getProfileImage)}?imagePath=${response[0].imageUrl}`;
callback(response[0].imageUrl);
}
}
},
() => {
callback();
}
);
}
}
import { Injectable } from "@angular/core";
import { HttpService } from "./http.service";
import { ApiResources } from "../helpers";
import { NotifyService } from "./notify.service";
import { MasterBillModel } from "../entities";
import { Router } from "@angular/router";
@Injectable()
export class BillNotificationService {
masterBill: Array<MasterBillModel>;
constructor(
private readonly httpService: HttpService,
private readonly notifyService: NotifyService,
private readonly router: Router,
) {
this.masterBill = new Array<MasterBillModel>();
}
get(patientId?: number) {
const request = {
patientId: patientId
}
this.httpService
.post(ApiResources.getURI(ApiResources.masterbill.base, ApiResources.masterbill.fetchPatientDue), request)
.subscribe(
(response: Array<MasterBillModel>) => {
this.masterBill = response;
if (response && response.length > 0) {
this.notifyService.confirm(`You are having Payment Due in <b>${this.masterBill[0].modulesName}</b>, Do you want to pay ?`, () => {
this.onPayDue(this.masterBill[0].encryptedPatientId)
}, () => { $("#printButton").click(); })
}
},
() => {
}
);
}
onPayDue(encryptedPatientId: string) {
this.router.navigateByUrl(`app/masters/final-master-bill/${encryptedPatientId}`);
}
}
\ No newline at end of file
import { EventEmitter, Injectable } from '@angular/core';
import { HttpTransportType, HubConnection, HubConnectionBuilder, IHttpConnectionOptions, LogLevel } from '@microsoft/signalr';
import { AppConfig } from "@shared/services";
import { UtilHelper } from '../helpers';
import { CommunicationMessageModel } from '../models';
@Injectable()
export class CommunicationService {
public connectionStatus: boolean;
public individualConnectionStatus: boolean;
public hubConnection: HubConnection;
public customGroups: Array<CommunicationGroupMeta>;
messageReceived = new EventEmitter<CommunicationMessageModel>();
public uniqueId: string;
public appConfigUrl: any;
constructor() {
this.customGroups = new Array<CommunicationGroupMeta>();
}
/* Initial Connections */
public createConnection(callback?: Function) {
const myInterval = setInterval(() => {
const appConfigUrl = { ...AppConfig.settings };
if (UtilHelper.isEmpty(appConfigUrl["signalR"])) {
const url = appConfigUrl["signalR"];
this.create(url);
clearInterval(myInterval);
callback && callback()
}
}, 10);
}
private create(url: string) {
const options = {
transport: HttpTransportType.ServerSentEvents,
logging: LogLevel.Information,
// accessTokenFactory: () => { return Token.getToken() }
} as IHttpConnectionOptions;
this.hubConnection = new HubConnectionBuilder()
.withUrl(url, options)
.withAutomaticReconnect()
.build();
}
public startConnection(id: string, callback?: Function): void {
this.hubConnection
.start()
.then(() => {
console.info("Communication Started.");
this.connectionStatus = true;
this.subscribeToGroup(id, true, () => {
callback && callback();
});
})
.catch(err => {
console.info("Communication failed to start.");
console.error(err);
this.connectionStatus = false;
//setTimeout(() => {
// this.startConnection(id);
//}, 5000);
});
}
public stopConnection(): void {
this.unsubscribeToAllGroup();
this.hubConnection
.stop()
.then(() => {
console.info("Communication stopped.");
this.connectionStatus = false;
this.customGroups = new Array<CommunicationGroupMeta>();
})
.catch(err => {
console.log("Communication failed to stop.");
console.error(err);
//setTimeout(() => {
// this.stopConnection();
//}, 10000);
});
}
/* Groups */
public subscribeToGroup(groupName: string, isIndividual = false, onSuccess: () => void = () => { }, onFailure: () => void = () => { }) {
if (!this.connectionStatus) {
onFailure();
return;
}
this.hubConnection.invoke("SubscribeToGroup", groupName)
.then(() => {
if (isIndividual) {
this.individualConnectionStatus = true;
} else {
let group = this.customGroups.find(x => x.groupName === groupName);
if (!group) {
group = new CommunicationGroupMeta();
group.groupName = groupName;
group.status = true;
this.customGroups.push(group);
} else {
group.status = true;
}
}
onSuccess();
}).catch(err => {
console.log("Cominication failed to subscribe to group");
console.error(err);
if (isIndividual) {
this.individualConnectionStatus = false;
} else {
const group = this.customGroups.find(x => x.groupName === groupName);
if (group) {
group.status = false;
}
}
//if (isIndividual) {
// setTimeout(() => {
// this.subscribeToGroup(groupName, true);
// }, 10000);
//}
});
}
public unsubscribeToGroup(groupName: string) {
this.hubConnection.invoke("UnsubscribeToGroup", groupName)
.then(() => {
this.customGroups = this.customGroups.filter(x => x.groupName !== groupName);
})
.catch(err => {
console.log("Cominication failed to unsubscribe from group");
console.error(err);
});
}
public unsubscribeToAllGroup() {
this.customGroups.forEach(groupName => {
this.hubConnection.invoke("UnsubscribeToGroup", groupName)
.catch(err => {
console.log("Cominication failed to unsubscribe from all group");
console.error(err);
});
});
}
sendMessage(message: CommunicationMessageModel) {
this.hubConnection.invoke("Communication", message);
}
/* Send Messages */
public sendGlobalMessage(message: CommunicationMessageMeta) {
this.hubConnection.invoke("CommunicationGlobal", message);
}
public sendGroupMessage(message: CommunicationMessageMeta) {
this.hubConnection.invoke("CommunicationGroup", message);
}
/* Helpers */
public getConnectionStatus(groupName: string): boolean | null {
const group = this.customGroups.find(x => x.groupName === groupName);
return group ? group.status : null;
}
//private subscribeToIndividualCommunication(id: string) {
// this.hubConnection.invoke(Wordings.subscribeIndividual, id)
// .then(() => {
// this.individualConnectionStatus = true;
// }).catch(err => {
// this.individualConnectionStatus = false;
// console.error(err.toString());
// setTimeout(() => {
// this.subscribeToIndividualCommunication(id);
// }, 5000);
// });
//}
//private unsubscribeToIndividualCommunication(id: string) {
// this.hubConnection.invoke(Wordings.unsubscribeIndividual, id)
// .catch(err => console.error(err.toString()));
//}
}
export class CommunicationGroupMeta {
groupName: string;
status: boolean;
}
export class CommunicationMessageMeta {
type: number;
uniqueId: string;
mainEid: string;
subEid: string;
message: string;
groupName: string;
ownerEid: string;
}
import { Injectable } from "@angular/core";
import { ControlType } from "../enums/control-type.enum";
@Injectable()
export class DashboardService {
getControlType = (dataType: string) => {
switch (dataType) {
case "boolean":
case "bool":
return ControlType.Boolean;
case "date":
return ControlType.Date;
case "varchar":
case "text":
return ControlType.Text;
default:
return ControlType.Number;
}
}
}
import { Injectable } from "@angular/core";
import { Observable, Subject } from "rxjs";
@Injectable()
export class FinalBillService {
private source = new Subject<boolean>();
get: Observable<boolean> = this.source.asObservable();
set(isRefresh: boolean) {
this.source.next(isRefresh);
}
}
import { Injectable } from "@angular/core";
import { HttpErrorInfo } from '../models';
@Injectable()
export class HttpErrorService {
messages: Array<HttpErrorInfo>;
timeout: any;
constructor() {
this.messages = new Array<HttpErrorInfo>();
}
add(model: HttpErrorInfo) {
this.messages = new Array<HttpErrorInfo>();
this.messages.push(model);
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
this.messages = new Array<HttpErrorInfo>();
}, 3000);
}
close = () => {
clearTimeout(this.timeout);
this.messages = new Array<HttpErrorInfo>();
}
}
import { HttpClient, HttpHeaders } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
@Injectable()
export class HttpService {
constructor(
private readonly http: HttpClient
) {
}
get<TResponse>(apiEndPoint: string, request?: any, auth = true): Observable<TResponse> {
let headers = new HttpHeaders();
if (!auth) {
headers = headers.append("Auth", "True");
}
return this.http.get<TResponse>(apiEndPoint, { headers: headers, params: request });
}
post<TResponse>(apiEndPoint: string, request: any, auth = true): Observable<TResponse> {
let headers = new HttpHeaders();
if (!auth) {
headers = headers.append("Auth", "False");
}
return this.http.post<TResponse>(apiEndPoint, request, { headers: headers });
}
put<TResponse>(apiEndPoint: string, request: any, auth = true): Observable<TResponse> {
let headers = new HttpHeaders();
if (!auth) {
headers = headers.append("Auth", "False");
}
return this.http.put<TResponse>(apiEndPoint, request, { headers: headers });
}
delete<TResponse>(apiEndPoint: string, request?: any, auth = true): Observable<TResponse> {
let headers = new HttpHeaders();
if (!auth) {
headers = headers.append("Auth", "True");
}
return this.http.delete<TResponse>(apiEndPoint, { headers: headers, params: request });
}
postFile<TResponse>(apiEndPoint: string, request: any, auth = true): Observable<TResponse> {
let headers = new HttpHeaders();
if (!auth) {
headers = headers.append("Auth", "True");
}
return this.http.post<TResponse>(apiEndPoint, request, { headers: headers, reportProgress: true });
}
}
\ No newline at end of file
import { Injectable } from "@angular/core";
import { HttpService } from ".";
import { Setting } from "../entities";
import { ApiResources, UtilHelper } from "../helpers";
@Injectable()
export class IconService {
constructor(private readonly httpService: HttpService) { }
getIconImage(callback?: Function) {
this.httpService
.get<Array<Setting>>(ApiResources.getURI(ApiResources.setting.base, ApiResources.setting.fetch), { type: "Icon", active: true }, true)
.subscribe({
next: (response: Array<Setting>) => {
if (response && response.length > 0) {
if (response[0].active) {
if (UtilHelper.isEmpty(response[0].imageUrl)) {
response[0].imageUrl = `${ApiResources.getURI(ApiResources.resources.base, ApiResources.resources.getProfileImage)}?imagePath=${response[0].imageUrl}`;
callback(response[0].imageUrl);
}
}
}
},
error: () => {
callback();
}
});
}
}
import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
import { Observable } from "rxjs";
import { ApiResources } from "@shared/helpers";
import { IUserAccount, IAuthToken } from "@shared/models";
export const appUrls = {
login: "/login",
home: "/app/dashboard",
notFound: "/not-found",
serverError: "/server-error",
forbidden: "/forbidden"
}
@Injectable()
export class IdentityService {
headers: Object = { headers: { ignoreLoadingBar: "", "Auth": "False" } };
constructor(
private readonly http: HttpClient,
private readonly modalService: NgbModal
) {
}
signIn(account: IUserAccount): Observable<Response> {
return this.http.post<Response>(location.origin + location.pathname + "api/identity/sign-in", account, this.headers);
}
signOut(): Observable<Response> {
if (this.modalService.hasOpenModals()) {
this.modalService.dismissAll();
}
return this.http.post<Response>(location.origin + location.pathname + "api/identity/sign-out", {}, this.headers);
}
status(): Observable<number> {
return this.http.post<number>(location.origin + location.pathname + "api/identity/status", {}, this.headers);
}
get(): Observable<IUserAccount> {
return this.http.post<IUserAccount>(location.origin + location.pathname + "api/identity/get", {}, this.headers);
}
update(authToken: IAuthToken): Observable<Response> {
return this.http.post<Response>(location.origin + location.pathname + "api/identity/update", authToken, this.headers);
}
refreshToken(reference: string): Observable<IAuthToken> {
const request = { token: reference };
const apiEndPoint = ApiResources.getURI(ApiResources.account.base, ApiResources.account.refresh);
return this.http.put<IAuthToken>(apiEndPoint, request);
}
}
\ No newline at end of file
export * from "../../app.config";
export * from "../../app.data";
export * from "./appointment-refresh.service";
export * from "./appointment-toggle.service";
export * from "./banner.service";
export * from "./bill-notificaton.service";
export * from "./communication.service";
export * from "./dashboard.service";
export * from "./final-bill.service";
export * from "./http-error.service";
export * from "./http.service";
export * from "./icon.service";
export * from "./identity.service";
export * from "./jitsi.service";
export * from "./menu.service";
export * from "./notify.service";
export * from "./print-option.service";
export * from "./print.service";
export * from "./queue.service";
export * from "./redirect-appointment.service";
export * from "./resource.service";
export * from "./setting.service";
export * from "./shared.service";
export * from "./timeline-toggle.service";
export * from "./url.service";
export * from "./validator.service";
export * from "./video-link.service";
import { Injectable } from "@angular/core";
import { Observable, Subject } from "rxjs";
@Injectable()
export class JitsiService {
isRoomActive = false;
ipAddress: string;
private jitsiSource = new Subject();
jitsiAccount: Observable<any> = this.jitsiSource.asObservable();
call(accountId: {}) {
this.jitsiSource.next(accountId);
}
private callSource = new Subject();
callAccount: Observable<any> = this.callSource.asObservable();
joinCall(roomName: {}) {
this.callSource.next(roomName);
}
private closeSource = new Subject<boolean>();
closeAccount: Observable<boolean> = this.closeSource.asObservable();
closeCall(is: boolean) {
this.closeSource.next(is);
}
private emergencySource = new Subject<object>();
emergencyAccount: Observable<object> = this.emergencySource.asObservable();
emergency(is: object) {
this.emergencySource.next(is);
}
private endSource = new Subject<string>();
endAccount: Observable<string> = this.endSource.asObservable();
endCall(roomName: string) {
this.endSource.next(roomName);
}
}
import { Injectable } from "@angular/core";
import { ActivatedRoute, Params } from "@angular/router";
import { AllowType, MenuType } from "../enums";
import { ApiResources } from "../helpers";
import { IMenuModel, IMenuOverAllModel } from "../models";
import { HttpService } from "./http.service";
import { NotifyService } from "./notify.service";
@Injectable()
export class MenuService {
private records: Array<IMenuModel>;
private access: boolean;
isHitMenu = true;
private menuButtonCodes: Array<string>;
constructor(
private readonly notifyService: NotifyService,
private readonly httpService: HttpService,
) { }
private setFromLocal = () => {
if (!this.records) {
const localMenus = localStorage.getItem("menus");
if (localMenus) {
const data = (JSON.parse(localMenus) as IMenuOverAllModel);
this.records = data.menus;
this.access = data.isFullAccess;
this.menuButtonCodes = data.menuButtonCodes;
this.isHitMenu = true;
}
}
}
private compare = (a: IMenuModel, b: IMenuModel) => {
if (a.priority < b.priority) {
return -1;
}
if (a.priority > b.priority) {
return 1;
}
return 0;
}
fetch = (accountId: number, roleId: number, callback?: Function) => {
this.httpService
.post<IMenuOverAllModel>(ApiResources.getURI(ApiResources.account.base,
ApiResources.account.getMenus),
{ accountId: accountId, roleId: roleId }, false)
.subscribe((data: IMenuOverAllModel) => {
this.setMenus = data;
this.isHitMenu = false;
callback();
});
}
getFirstSubMenuByUrl = (url: string) => {
const lastIndex = url.lastIndexOf("/");
url = url.substring(0, lastIndex);
const record = this.records.find(x => x.url.toLowerCase() === url.toLowerCase());
if (record) {
const subMenu = this.records.filter(x =>
x.menuTypeId === MenuType.SubMenu &&
x.mainPage === record.mainPage &&
x.url.indexOf(":") === -1);
if (subMenu.length > 0) {
return subMenu[0].url;
}
}
return null;
}
menus = (menuType: MenuType = null, mainPage: string = null, subPage: string = null): Array<IMenuModel> => {
this.setFromLocal();
if (!this.records) return new Array<IMenuModel>();
let filtered = this.records;
if (menuType) {
filtered = filtered.filter(x => MenuType.SubMenu === menuType
? x.menuTypeId === menuType || x.menuTypeId === MenuType.CategoryMenu
: x.menuTypeId === menuType);
}
if (mainPage) {
filtered = filtered.filter(x => x.mainPage === mainPage);
}
if (subPage) {
filtered = filtered.filter(x => x.subPage === subPage);
}
const final = filtered.sort(this.compare);
final.forEach(item => {
const urlTokens = item.url.split("/");
for (let i = urlTokens.length - 1; i >= 0; i--) {
if (urlTokens[i].indexOf(":") === -1) {
item.subPage = urlTokens[i];
break;
}
}
});
return final;
}
set setMenus(data: IMenuOverAllModel) {
this.records = data.menus;
this.access = data.isFullAccess;
this.menuButtonCodes = data.menuButtonCodes;
localStorage.setItem("menus", JSON.stringify(data));
}
get getDefaultRoute(): string {
this.setFromLocal();
return this.records && this.records.length > 0 ? this.records[0].url : "login";
}
removeFromLocal = () => {
localStorage.removeItem("menus");
}
isMenuButtonAllowed = (code: string) => {
if(!this.menuButtonCodes) {
this.setFromLocal();
}
return this.access || (this.menuButtonCodes || [] as Array<string>).find(x => x === code);
}
isAllowed = (uri: string, showNotify = false): AllowType | string => {
this.setFromLocal();
if (!this.records) return AllowType.BreakIt;
if (this.access) return AllowType.Allowed;
const currentSplit = uri.split("/");
let isOverallPass = false;
const matchedUrls = this.records.filter(x => x.count === currentSplit.length);
for (let i = 0; i < matchedUrls.length; i++) {
const url = matchedUrls[i].url;
let isPass = false;
const existingSplit = url.split("/");
for (let j = 0; j < existingSplit.length; j++) {
const item = existingSplit[j];
if (item.indexOf(":") !== -1) {
isPass = true;
continue;
}
if (j >= currentSplit.length) {
isPass = false;
break;
}
if (item === currentSplit[j]) {
isPass = true;
} else {
isPass = false;
break;
}
}
if (isPass) {
isOverallPass = true;
break;
}
}
if (showNotify && !isOverallPass) {
this.notifyService.hideAll();
const isAlternative = this.getFirstSubMenuByUrl(uri);
if (isAlternative) {
return isAlternative;
} else {
this.notifyService.info(`You do not have access to this page (${uri}).`);
}
}
return isOverallPass ? AllowType.Allowed : AllowType.NotAllowed;
}
getNextRoute = (url: string, params: Params, route: ActivatedRoute): Promise<string> => {
return new Promise(async (resolve) => {
let foundUrl = decodeURIComponent(decodeURIComponent(url));
const parentParams = route.parent.params["value"] || {};
const childParams = (params.params ? params.params : params) || {};
const allParams = { ...parentParams, ...childParams };
Object.keys(allParams).forEach((key) => {
const decodedValue = decodeURIComponent(decodeURIComponent(allParams[key]));
foundUrl = foundUrl.replace(`/${decodedValue}/`, `/:${key}/`);
})
const currentRoute = this.records.find((x) => x.url === foundUrl);
if (currentRoute) {
let nextRoute = this.records.find((x) => {
const basicCondition = this.basicCondition(x, currentRoute);
return currentRoute.menuTypeId === MenuType.CategoryMenu
? basicCondition && x.category === currentRoute.category
: basicCondition;
});
if (nextRoute) {
resolve(this.getReverseStrategyLink(nextRoute.url, allParams));
}
if (currentRoute.menuTypeId === MenuType.CategoryMenu) {
nextRoute = this.records.find((x) => this.basicCondition(x, currentRoute));
if (nextRoute) {
resolve(this.getReverseStrategyLink(nextRoute.url, allParams));
}
}
nextRoute = this.records.find((x) => x.mainPage === currentRoute.mainPage && x.menuTypeId === MenuType.SubMenu && x.priority === 1);
if (nextRoute) {
resolve(this.getReverseStrategyLink(nextRoute.url, allParams));
}
}
return resolve(null);
})
}
getCurrentRoute = (url: string, params: Params, route: ActivatedRoute): Promise<IMenuModel> => {
return new Promise(async (resolve) => {
let foundUrl = decodeURIComponent(decodeURIComponent(url));
const parentParams = route.parent.params["value"] || {};
const childParams = (params.params ? params.params : params) || {};
const allParams = { ...parentParams, ...childParams };
Object.keys(allParams).forEach((key) => {
const decodedValue = decodeURIComponent(decodeURIComponent(allParams[key]));
foundUrl = foundUrl.replace(`/${decodedValue}`, `/:${key}`);
})
const currentRoute = this.records.find((x) => x.url === foundUrl);
return resolve(currentRoute);
})
}
private getReverseStrategyLink = (url: string, params: Params) => {
let foundUrl = url;
const obj = params;
Object.keys(obj).forEach((key) => {
const encodedValue = encodeURIComponent(decodeURIComponent(decodeURIComponent(obj[key])));
foundUrl = foundUrl.replace(`:${key}`, encodedValue);
})
return foundUrl;
}
private basicCondition = (compateTo: IMenuModel, compareWith: IMenuModel) => {
if (compareWith) {
return compateTo.mainPage === compareWith.mainPage && compateTo.priority === (compareWith.priority + 1);
}
return false;
}
}
import { Injectable } from "@angular/core";
import * as bootbox from "bootbox";
import { ToastrService } from "ngx-toastr";
function emptyFunction() { }
@Injectable()
export class NotifyService {
constructor(private readonly toastrService: ToastrService) { }
hideAll() {
return bootbox.hideAll();
}
warningToast(message: string) {
this.toastrService.warning(message, "Warning!");
}
infoToast(message: string) {
this.toastrService.info(message, "Information!");
}
successToast(message: string) {
this.toastrService.success(message, "Success!");
}
errorToast(message: string) {
this.toastrService.error(message, "Error!");
}
defaultErrorToast() {
this.toastrService.error("Sorry! Error occurred. Please try again later.", "Error!");
}
warning(message: string, callback?: any) {
message = message || "Warning";
return bootbox.dialog({
title: `<i class="fe-alert-triangle h1 text-warning"></i>`,
message: message,
closeButton: false,
className: "modal fade effect-scale",
buttons: {
yes: {
label: "Ok",
className: "btn-sm btn-warning",
callback: callback === null ? emptyFunction : callback
}
}
});
}
info(message: string, callback?: any) {
message = message || "Information";
return bootbox.dialog({
title: `<i class="fe-info h1 text-info"></i>`,
message: message,
closeButton: false,
className: "modal fade effect-scale",
buttons: {
yes: {
label: "Ok",
className: "btn-sm btn-info",
callback: callback === null ? emptyFunction : callback
}
}
});
}
success(message: string, callback?: any) {
message = message || "Success";
return bootbox.dialog({
title: `<i class="fe-check-circle h1 text-success"></i>`,
message: message,
closeButton: false,
className: "modal fade effect-scale",
buttons: {
yes: {
label: "Ok",
className: "btn-sm btn-success",
callback: callback === null ? emptyFunction : callback
}
}
});
}
error(message: string, callback?: any) {
message = message || "Error";
return bootbox.dialog({
title: `<i class="fe-alert-circle h1 text-danger"></i>`,
message: message,
closeButton: false,
className: "modal fade effect-scale",
buttons: {
yes: {
label: "Ok",
className: "btn-sm btn-danger",
callback: callback === null ? emptyFunction : callback
}
}
});
}
defaultError(callback?: any) {
return bootbox.dialog({
title: `<i class="fe-alert-circle h1 text-danger"></i>`,
message: "Sorry error occurred. Please try again later.",
closeButton: false,
className: "modal fade effect-scale",
buttons: {
yes: {
label: "Ok",
className: "btn-sm btn-danger",
callback: callback === null ? emptyFunction : callback
}
}
});
}
delete(yesCallback?: any, noCallback?: any) {
return bootbox.dialog({
title: `<i class="fe-help-circle h1 text-danger"></i><h4>Are you sure?</h4>`,
message: "Do you really want to delete this record? This process cannot be undone.",
closeButton: false,
className: "modal fade effect-scale",
buttons: {
yes: {
label: "Yes! Delete",
className: "btn-sm btn-danger mr-1",
callback: yesCallback === null ? emptyFunction : yesCallback
},
no: {
label: "No! Cancel",
className: "btn-sm btn-light",
callback: noCallback === null ? emptyFunction : noCallback
}
}
});
}
confirm(message: string, yesCallback?: any, noCallback?: any) {
return bootbox.dialog({
title: `<i class="fe-help-circle h1 text-danger"></i><h4>Are you sure?</h4>`,
message: message,
closeButton: false,
className: "modal fade effect-scale",
buttons: {
yes: {
label: "Yes! Confirm",
className: "btn-sm btn-success mr-1",
callback: yesCallback === null ? emptyFunction : yesCallback
},
no: {
label: "No! Cancel",
className: "btn-sm btn-danger",
callback: noCallback === null ? emptyFunction : noCallback
}
}
});
}
advancedConfirm(message: string, yesLabel: string, yesCallback?: any) {
return bootbox.dialog({
title: `<i class="fe-help-circle h1 text-primary"></i><h4>Are you sure?</h4>`,
message: message,
closeButton: false,
className: "modal fade effect-scale",
buttons: {
yes: {
label: yesLabel,
className: "btn-sm btn-primary mr-1",
callback: yesCallback === null ? emptyFunction : yesCallback
}
}
});
}
endCallConfirm(message: string, endMeetingCallback?: any, leaveMeetingCallback?: any) {
return bootbox.dialog({
title: `<i class="fe-help-circle h1 text-primary"></i><h4>Are you sure?</h4>`,
message: message,
closeButton: false,
className: "modal fade effect-scale",
buttons: {
yes: {
label: "End Call",
className: "btn-sm btn-danger mr-1",
callback: endMeetingCallback === null ? emptyFunction : endMeetingCallback
},
leave: {
label: "Leave Call",
className: "btn-sm btn-warning mr-1",
callback: leaveMeetingCallback === null ? emptyFunction : leaveMeetingCallback
},
no: {
label: "Cancel",
className: "btn-sm btn-light"
}
}
});
}
SampleAcceptionConfirm(message: string, endMeetingCallback?: any, leaveMeetingCallback?: any) {
return bootbox.dialog({
title: `<i class="fe-help-circle h1 text-primary"></i><h4>Are you sure?</h4>`,
message: message,
closeButton: false,
className: "modal fade effect-scale",
buttons: {
yes: {
label: "Sample Accept",
className: "btn-sm btn-outline-success mr-1",
callback: endMeetingCallback === null ? emptyFunction : endMeetingCallback
},
leave: {
label: "Sample Reject",
className: "btn-sm btn-outline-danger mr-1",
callback: leaveMeetingCallback === null ? emptyFunction : leaveMeetingCallback
},
no: {
label: "Back",
className: "btn-sm btn-light"
}
}
});
}
}
\ No newline at end of file
import { Injectable } from "@angular/core";
import { ApiResources, UtilHelper } from "../helpers";
//import { PrintSetting } from "../entities/print-setting.entity";
import { HttpService } from ".";
import { Setting } from "../entities";
@Injectable()
export class PrintOptionService {
constructor(private readonly httpService: HttpService,) { }
get(callback?: Function) {
this.httpService
.get<Array<Setting>>(ApiResources.getURI(ApiResources.setting.base, ApiResources.setting.fetch), { name: "IsPrintLogo", active: true }, true)
.subscribe(
(response:Array<Setting>) => {
if (response && response.length > 0 ) {
if (response[0].active) {
UtilHelper.removeWithOutLogoStyleFile();
} else {
//UtilHelper.addWithOutLogoStyleFile();
}
callback(response[0].active);
}
},
() => {
callback(true);
}
);
}
}
import { Injectable } from "@angular/core";
import { NotifyService } from "./notify.service";
declare let qz: any;
@Injectable()
export class PrintService {
printer: any;
printerName: any;
isDotMatrixPrinting: boolean;
dotMatrixStatus: string;
constructor(private readonly notifyService: NotifyService) { }
getPrinterName = () => {
return localStorage.getItem("DotMatrixPrinterName");
}
setPrinterName = (name: string) => {
localStorage.setItem("DotMatrixPrinterName", name);
this.printerName = localStorage.getItem("DotMatrixPrinterName");
}
getPrinters = (callback?: Function) => {
qz.printers.find().then((data: Array<any>) => {
callback(data);
}).catch((e) => {
callback(new Array<any>());
this.notifyService.warning(e);
});
}
getAvailablePrinters = (callback?: Function) => {
if (!qz.websocket.isActive()) {
qz.websocket.connect().then(() => {
this.getPrinters(callback);
}).catch((e) => {
this.notifyService.warning(e);
});
} else {
this.getPrinters(callback);
}
}
private findPrinter(callback?: Function) {
this.printerName = this.getPrinterName();
if (!this.printerName) {
this.notifyService.warning("Please select printer.");
callback();
}
qz.printers.find(this.printerName).then((data) => {
this.printer = data;
this.dotMatrixStatus = "Connected";
callback();
}).catch((e) => {
this.notifyService.warning(e);
this.isDotMatrixPrinting = false;
});
}
private connect(callback?: Function) {
this.dotMatrixStatus = "Connecting...";
qz.websocket.connect().then(() => {
this.findPrinter(() => {
callback();
});
}).catch((e) => {
this.notifyService.warning(e);
this.isDotMatrixPrinting = false;
});
}
private print(htmlToRender: any, configObj: any, callback?: Function) {
this.dotMatrixStatus = "Printing...";
const data = [{
type: 'pixel',
format: 'html',
flavor: 'plain',
data: htmlToRender
}];
const config = qz.configs.create(null, configObj);
if (!this.printer) {
this.findPrinter(() => {
config.setPrinter(this.printer);
qz.print(config, data).then(() => {
this.dotMatrixStatus = "Printed";
this.isDotMatrixPrinting = false;
callback();
}).catch((e) => {
this.notifyService.warning(e);
this.isDotMatrixPrinting = false;
});
});
} else {
config.setPrinter(this.printer);
qz.print(config, data).then(() => {
this.dotMatrixStatus = "Printed";
this.isDotMatrixPrinting = false;
callback();
}).catch((e) => {
this.notifyService.warning(e);
this.isDotMatrixPrinting = false;
});
}
}
start = (htmlToRender: any, config: any, callback?: Function) => {
this.dotMatrixStatus = "checking...";
this.isDotMatrixPrinting = true;
try {
if (!qz.websocket.isActive()) {
this.connect(() => {
this.print(htmlToRender,
config,
() => {
this.isDotMatrixPrinting = false;
callback();
});
});
} else {
this.print(htmlToRender,
() => {
this.isDotMatrixPrinting = false;
callback();
});
}
} catch (e) {
this.notifyService.warning(e);
this.isDotMatrixPrinting = false;
}
}
disconnect = () => {
if (qz.websocket.isActive()) {
qz.websocket.disconnect();
}
}
}
import { Injectable } from "@angular/core";
@Injectable()
export class QueueService {
selectedProvider: BasicProvider;
isInterval: any;
}
export interface BasicProvider {
name: string;
id: number;
}
import { Injectable } from "@angular/core";
import { BehaviorSubject, Observable } from "rxjs";
@Injectable()
export class RedirectAppointmentService {
private source = new BehaviorSubject(null);
account: Observable<string> = this.source.asObservable();
set(accountId: string) {
this.source.next(accountId);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment