added notification service with alertify as the concrete implementation
This commit is contained in:
parent
2e7f6cced6
commit
70f0ea8054
@ -35,6 +35,7 @@
|
||||
"dompurify": "global:DOMPurify",
|
||||
"fuse.js": "global:Fuse",
|
||||
"sjcl": "global:sjcl",
|
||||
"sprintf": "global:sprintf"
|
||||
"sprintf-js": "global:sprintf2",
|
||||
"alertifyjs": "global:alertify"
|
||||
}
|
||||
}
|
@ -19,7 +19,9 @@ import { MessageCipherDTO } from "./dto/MessageCipherDTO";
|
||||
import { SearchService } from "./service/SearchService";
|
||||
import { FuseSearchService } from "./service/FuseSearchService";
|
||||
import { ChatMessageDTO } from "./dto/ChatMessageDTO";
|
||||
|
||||
import { NotificationService } from "./service/NotificationService";
|
||||
import { AlertifyNotificationService } from "./service/AlertifyNotificationService";
|
||||
import * as sprintf2 from "sprintf-js";
|
||||
|
||||
const usersListElement = document.getElementById('contacts-box');
|
||||
const userSearchButton = document.getElementById('user-search');
|
||||
@ -83,3 +85,9 @@ Handlebars.registerHelper('avatar', function() {
|
||||
|
||||
const testList: ChatMessageDTO[] = [];
|
||||
const cmSearchService: SearchService<ChatMessageDTO> = new FuseSearchService(["userName"]);
|
||||
// @ts-ignore
|
||||
log.info(sprintf("test sprintf"))
|
||||
log.info(sprintf2.sprintf("test sprintf"))
|
||||
const ns: NotificationService = new AlertifyNotificationService();
|
||||
ns.success("Welcome");
|
||||
// ns.errorWithDelay("Hmm very long error notif", 10);
|
@ -0,0 +1,27 @@
|
||||
import { NotificationService } from "./NotificationService";
|
||||
// @ts-ignore
|
||||
import * as alertify from "alertifyjs";
|
||||
export class AlertifyNotificationService implements NotificationService {
|
||||
private readonly _alertify = alertify;
|
||||
constructor() {
|
||||
this._alertify.set('notifier', 'position', 'top-center');
|
||||
}
|
||||
success(message: string): void {
|
||||
this._alertify.success(message)
|
||||
}
|
||||
error(message: string): void {
|
||||
this._alertify.error(message);
|
||||
}
|
||||
errorWithDelay(message: string, delay: number): void {
|
||||
const _delay = this._alertify.get('notifier', 'delay');
|
||||
this._alertify.set('notifier', 'delay', delay);
|
||||
this._alertify.error(message);
|
||||
this._alertify.set('notifier', 'delay', _delay);
|
||||
}
|
||||
warning(message: string): void {
|
||||
this._alertify.warning(message);
|
||||
}
|
||||
message(message: string): void {
|
||||
this._alertify.message(message);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import { MessageCipherDTO } from "../dto/MessageCipherDTO";
|
||||
|
||||
export interface EncryptionService {
|
||||
encrypt(passphrase: string, plainText: string): any,
|
||||
decrypt(passphrase: string, cipher: MessageCipherDTO): string
|
||||
encrypt(passphrase: string, plainText: string): any;
|
||||
decrypt(passphrase: string, cipher: MessageCipherDTO): string;
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
export interface NotificationService {
|
||||
success(message: string): void;
|
||||
error(message: string): void;
|
||||
errorWithDelay(message: string, delay: number): void;
|
||||
warning(message: string): void;
|
||||
message(message: string): void;
|
||||
}
|
@ -1,22 +1,25 @@
|
||||
import { sprintf } from "sprintf-js";
|
||||
import { NotificationService } from "../service/NotificationService";
|
||||
import { AlertifyNotificationService } from "../service/AlertifyNotificationService";
|
||||
|
||||
export function fetchHandler(response: any) {
|
||||
const ns: NotificationService = new AlertifyNotificationService();
|
||||
if (response.ok) {
|
||||
return response.json().then((json: any) => {
|
||||
// the status was ok and there is a json body
|
||||
// return Promise.resolve({ json: json, response: response });
|
||||
// alertify.success('Message sent succesfully' + sprintf(" (http code %d)", response.status));
|
||||
ns.success('Message sent succesfully' + sprintf(" (http code %d)", response.status));
|
||||
}).catch((err: any) => {
|
||||
// the status was ok but there is no json body
|
||||
// return Promise.resolve({ response: response });
|
||||
// alertify.success('Message sent succesfully' + sprintf(" (http code %d)", response.status));
|
||||
ns.success('Message sent succesfully' + sprintf(" (http code %d)", response.status));
|
||||
});
|
||||
|
||||
} else {
|
||||
return response.json().catch((err: any) => {
|
||||
// the status was not ok and there is no json body
|
||||
// throw new Error(response.statusText);
|
||||
// alertify.error('Some error occured. Please try again.');
|
||||
ns.error('Some error occured. Please try again.');
|
||||
}).then((json: any) => {
|
||||
// the status was not ok but there is a json body
|
||||
// throw new Error(json.error.message); // example error message returned by a REST
|
||||
@ -26,7 +29,7 @@ export function fetchHandler(response: any) {
|
||||
json.errors.forEach(function(data: any) {
|
||||
errorMessage += sprintf("Field Name: %s \n Rejected value: %s \n Reason: %s \n", data.field_name, data.rejected_value, data.error_message);
|
||||
});
|
||||
// alertify.error(sprintf('There were errors in your message - %s', errorMessage));
|
||||
ns.errorWithDelay(sprintf('There were errors in your message - %s', errorMessage), 30);
|
||||
// alertify.set('notifier', 'delay', delay);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user