diff --git a/chatto/src/main/javascript/ts/src/SprintfTest.d.ts b/chatto/src/main/javascript/ts/src/SprintfTest.d.ts index 650aede..4813e89 100644 --- a/chatto/src/main/javascript/ts/src/SprintfTest.d.ts +++ b/chatto/src/main/javascript/ts/src/SprintfTest.d.ts @@ -5,5 +5,5 @@ import { sprintf } from "sprintf-js"; declare global { // const Hls: typeof Hls; - var Sprintf: typeof sprintf; + export var _sprintf: typeof sprintf; } \ No newline at end of file diff --git a/chatto/src/main/javascript/ts/src/main.ts b/chatto/src/main/javascript/ts/src/main.ts index daeaafe..c187c98 100644 --- a/chatto/src/main/javascript/ts/src/main.ts +++ b/chatto/src/main/javascript/ts/src/main.ts @@ -21,7 +21,7 @@ import { FuseSearchService } from "./service/FuseSearchService"; import { ChatMessageDTO } from "./dto/ChatMessageDTO"; import { NotificationService } from "./service/NotificationService"; import { AlertifyNotificationService } from "./service/AlertifyNotificationService"; -/// + // import "./SprintfTest.d.ts" // import { sprintf } from "sprintf-js"; // import sprintf = require('sprintf-js'); @@ -29,12 +29,13 @@ import { TemplateFactory } from "./template/TemplateFactory"; import { UserViewDeps } from "./view/UserViewDeps"; import { ChatViewDeps } from "./view/ChatViewDeps"; import { MarkDownItMarkDownService } from "./service/MarkDownItMarkDownService"; +import { Sprintf } from "./singleton/Sprintf"; const usersListElement = document.getElementById('contacts-box'); const userSearchButton = document.getElementById('user-search'); const userSearchInputElement = document.getElementById('user-search-term') as HTMLInputElement; const userSearchCancelButton = document.getElementById('user-search-cancel'); -const searchService: SearchService = new FuseSearchService(["userName"]); +const activeUserSearchService: SearchService = new FuseSearchService(["userName"]); log.setLevel("TRACE") @@ -53,7 +54,7 @@ const uvDeps: UserViewDeps = { userSearchButton: userSearchButton, // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'. userSearchCancelButton: userSearchCancelButton, - searchService: searchService, + searchService: activeUserSearchService, userContactOnlineTemplate: TemplateFactory.getTemplate('user-contact-online-template'), userContactOfflineTemplate: TemplateFactory.getTemplate('user-contact-offline-template') } @@ -119,9 +120,10 @@ const testList: ChatMessageDTO[] = []; // @ts-ignore console.log() -// @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); \ No newline at end of file +// ns.errorWithDelay("Hmm very long error notif", 10); + +const ss = FuseSearchService.getInstance([""]); \ No newline at end of file diff --git a/chatto/src/main/javascript/ts/src/model/ChatModel.ts b/chatto/src/main/javascript/ts/src/model/ChatModel.ts index 611f4df..446a1cb 100644 --- a/chatto/src/main/javascript/ts/src/model/ChatModel.ts +++ b/chatto/src/main/javascript/ts/src/model/ChatModel.ts @@ -55,7 +55,6 @@ export class ChatModel implements Subject { public someBusinessMethod(chatMessageList: ChatMessageViewModel[]): void { this.state = chatMessageList; - this.helperMethod(); console.log(`Subject: My state has just changed`); console.log(chatMessageList); this.notify("some user"); @@ -77,15 +76,4 @@ export class ChatModel implements Subject { return cVMs; } - - - - private helperMethod() { } - - public populateMessages(): void { - - } - - - } \ No newline at end of file diff --git a/chatto/src/main/javascript/ts/src/model/ChatModelHelper.ts b/chatto/src/main/javascript/ts/src/model/ChatModelHelper.ts index 4c2cf53..e456604 100644 --- a/chatto/src/main/javascript/ts/src/model/ChatModelHelper.ts +++ b/chatto/src/main/javascript/ts/src/model/ChatModelHelper.ts @@ -17,31 +17,10 @@ export class ChatModelHelper { public static async getMessages(userName: string, passphrase: string, lastMessageTime: string | null, chatModel: ChatModel): Promise { switch (lastMessageTime) { case null: { - // this.getAllMessagesAjax(userName) - // .then((data: ChatMessageDTO[]) => { - // log.debug(`Subject: received all messages`); - // // let userNames = data.map(ChatMessageViewModel => ChatMessageViewModel.fromUser) - // // let sumt = data.map(chatMessageViewModel => { return this.encryptionService.decrypt(passphrase, chatMessageViewModel.messageCipher) }); - // return data.map(vm => this.toChatMessageVM(vm, passphrase)); - // // chatModel.setUserMessages(userName, chatMessageVMs); - // // chatModel.notify(); - // }) - // break; - const data: ChatMessageDTO[] = await this.getAllMessagesAjax(userName); return data.map(vm => this.toChatMessageVM(vm, passphrase)); - } default: { - // this.getNewMessagesAjax(userName, lastMessageTime) - // .then((data: ChatMessageDTO[]) => { - // log.debug(`Subject: received new messages`); - // return data.map(vm => this.toChatMessageVM(vm, passphrase)); - // // chatModel.setUserMessages(userName, chatMessageVMs); - // // this.state = data; - // // chatModel.notify(); - // }) - // break; const data: ChatMessageDTO[] = await this.getNewMessagesAjax(userName, lastMessageTime); return data.map(vm => this.toChatMessageVM(vm, passphrase)); } diff --git a/chatto/src/main/javascript/ts/src/service/FuseSearchService.ts b/chatto/src/main/javascript/ts/src/service/FuseSearchService.ts index 00b877a..99b2c67 100644 --- a/chatto/src/main/javascript/ts/src/service/FuseSearchService.ts +++ b/chatto/src/main/javascript/ts/src/service/FuseSearchService.ts @@ -29,4 +29,20 @@ export class FuseSearchService implements SearchService { return this._fuse.search(searchTerm) as T[]; } + + /** + * + * + * @static + * @param keys + * The keys that must be searched for in the given list + * @template G + * @returns {SearchService} + * @memberof FuseSearchService + */ + static getInstance(keys: string[]): SearchService { + return new FuseSearchService(keys); + } + + } \ No newline at end of file diff --git a/chatto/src/main/javascript/ts/src/singleton/Sprintf.ts b/chatto/src/main/javascript/ts/src/singleton/Sprintf.ts new file mode 100644 index 0000000..fed2126 --- /dev/null +++ b/chatto/src/main/javascript/ts/src/singleton/Sprintf.ts @@ -0,0 +1,5 @@ +// /// +export function Sprintf(message: string, ...args: any[]): string { + // @ts-ignore + return sprintf(message, ...args); +} \ No newline at end of file diff --git a/chatto/src/main/javascript/ts/src/view/FetchHandler.ts b/chatto/src/main/javascript/ts/src/view/FetchHandler.ts index 9ceca62..67e18ee 100644 --- a/chatto/src/main/javascript/ts/src/view/FetchHandler.ts +++ b/chatto/src/main/javascript/ts/src/view/FetchHandler.ts @@ -1,6 +1,6 @@ -import { sprintf } from "sprintf-js"; import { NotificationService } from "../service/NotificationService"; import { AlertifyNotificationService } from "../service/AlertifyNotificationService"; +import { Sprintf } from "../singleton/Sprintf"; export function fetchHandler(response: any) { const ns: NotificationService = new AlertifyNotificationService(); @@ -8,11 +8,11 @@ export function fetchHandler(response: any) { return response.json().then((json: any) => { // the status was ok and there is a json body // return Promise.resolve({ json: json, response: response }); - ns.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 }); - ns.success('Message sent succesfully' + sprintf(" (http code %d)", response.status)); + ns.success('Message sent succesfully' + Sprintf(" (http code %d)", response.status)); }); } else { @@ -27,9 +27,9 @@ export function fetchHandler(response: any) { // alertify.set('notifier', 'delay', 30); let errorMessage = ""; 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); + errorMessage += Sprintf("Field Name: %s \n Rejected value: %s \n Reason: %s \n", data.field_name, data.rejected_value, data.error_message); }); - ns.errorWithDelay(sprintf('There were errors in your message - %s', errorMessage), 30); + ns.errorWithDelay(Sprintf('There were errors in your message - %s', errorMessage), 30); // alertify.set('notifier', 'delay', delay); }); }