From 0a082a3cdb9e9d1a75bc53f470298b089b92924c Mon Sep 17 00:00:00 2001 From: Ebenezer Monney Date: Fri, 15 May 2020 03:43:04 +0000 Subject: [PATCH] ASP.NET Core 3.1/ Angular 9 Release --- .../controls/user-preferences.component.html | 4 +- .../app/directives/bootstrap-tab.directive.ts | 2 +- .../src/app/services/account.service.ts | 19 +--- .../src/app/services/alert.service.ts | 9 -- .../ClientApp/src/app/services/animations.ts | 14 +-- .../src/app/services/app-title.service.ts | 76 ++++++++------- .../app/services/app-translation.service.ts | 4 - .../src/app/services/auth-guard.service.ts | 42 ++++----- .../services/can-deactivate-guard.service.ts | 8 +- .../src/app/services/configuration.service.ts | 21 +---- .../src/app/services/endpoint-base.service.ts | 2 +- .../ClientApp/src/app/services/jwt-helper.ts | 92 +++++++++---------- .../services/local-store-manager.service.ts | 1 - .../services/notification-endpoint.service.ts | 19 ---- .../src/app/services/notification.service.ts | 19 ---- .../ClientApp/src/app/services/utilities.ts | 14 +-- 16 files changed, 128 insertions(+), 218 deletions(-) diff --git a/QuickApp/ClientApp/src/app/components/controls/user-preferences.component.html b/QuickApp/ClientApp/src/app/components/controls/user-preferences.component.html index c1974aac0..de4374f73 100644 --- a/QuickApp/ClientApp/src/app/components/controls/user-preferences.component.html +++ b/QuickApp/ClientApp/src/app/components/controls/user-preferences.component.html @@ -21,7 +21,7 @@
- {{'preferences.English' | translate}} ({{'preferences.Default' | translate}}) + {{'preferences.English' | translate}} ({{'preferences.Default' | translate}}) {{'preferences.French' | translate}} {{'preferences.German' | translate}} {{'preferences.Portuguese' | translate}} @@ -44,7 +44,7 @@
- {{'preferences.Dashboard' | translate}} ({{'preferences.Default' | translate}}) + {{'preferences.Dashboard' | translate}} ({{'preferences.Default' | translate}}) {{'preferences.Customers' | translate}} {{'preferences.Products' | translate}} {{'preferences.Orders' | translate}} diff --git a/QuickApp/ClientApp/src/app/directives/bootstrap-tab.directive.ts b/QuickApp/ClientApp/src/app/directives/bootstrap-tab.directive.ts index de736103c..2fbd3998e 100644 --- a/QuickApp/ClientApp/src/app/directives/bootstrap-tab.directive.ts +++ b/QuickApp/ClientApp/src/app/directives/bootstrap-tab.directive.ts @@ -9,7 +9,7 @@ import { Subscription, fromEvent } from 'rxjs'; declare var $: any; -interface EventArg { type: string; target: Element; relatedTarget: Element } +interface EventArg { type: string; target: Element; relatedTarget: Element; } @Directive({ selector: '[appBootstrapTab]', diff --git a/QuickApp/ClientApp/src/app/services/account.service.ts b/QuickApp/ClientApp/src/app/services/account.service.ts index 320cb6b71..fbd354a8b 100644 --- a/QuickApp/ClientApp/src/app/services/account.service.ts +++ b/QuickApp/ClientApp/src/app/services/account.service.ts @@ -11,7 +11,7 @@ import { AccountEndpoint } from './account-endpoint.service'; import { AuthService } from './auth.service'; import { User } from '../models/user.model'; import { Role } from '../models/role.model'; -import { Permission, PermissionNames, PermissionValues } from '../models/permission.model'; +import { Permission, PermissionValues } from '../models/permission.model'; import { UserEdit } from '../models/user-edit.model'; export type RolesChangedOperation = 'add' | 'delete' | 'modify'; @@ -54,7 +54,6 @@ export class AccountService { this.accountEndpoint.getRolesEndpoint()]); } - updateUser(user: UserEdit) { if (user.id) { return this.accountEndpoint.getUpdateUserEndpoint(user, user.id); @@ -71,7 +70,6 @@ export class AccountService { return this.accountEndpoint.getNewUserEndpoint(user); } - getUserPreferences() { return this.accountEndpoint.getUserPreferencesEndpoint(); } @@ -80,14 +78,11 @@ export class AccountService { return this.accountEndpoint.getUpdateUserPreferencesEndpoint(configuration); } - deleteUser(userOrUserId: string | User): Observable { - if (typeof userOrUserId === 'string' || userOrUserId instanceof String) { return this.accountEndpoint.getDeleteUserEndpoint(userOrUserId as string).pipe( tap(data => this.onRolesUserCountChanged(data.roles))); } else { - if (userOrUserId.id) { return this.deleteUser(userOrUserId.id); } else { @@ -97,17 +92,14 @@ export class AccountService { } } - unblockUser(userId: string) { return this.accountEndpoint.getUnblockUserEndpoint(userId); } - userHasPermission(permissionValue: PermissionValues): boolean { return this.permissions.some(p => p === permissionValue); } - refreshLoggedInUser() { return this.accountEndpoint.refreshLogin(); } @@ -117,7 +109,6 @@ export class AccountService { return this.accountEndpoint.getRolesEndpoint(page, pageSize); } - getRolesAndPermissions(page?: number, pageSize?: number) { return forkJoin([ @@ -125,7 +116,6 @@ export class AccountService { this.accountEndpoint.getPermissionsEndpoint()]); } - updateRole(role: Role) { if (role.id) { return this.accountEndpoint.getUpdateRoleEndpoint(role, role.id).pipe( @@ -140,13 +130,11 @@ export class AccountService { } } - newRole(role: Role) { return this.accountEndpoint.getNewRoleEndpoint(role).pipe( tap(data => this.onRolesChanged([role], AccountService.roleAddedOperation))); } - deleteRole(roleOrRoleId: string | Role): Observable { if (typeof roleOrRoleId === 'string' || roleOrRoleId instanceof String) { @@ -168,23 +156,18 @@ export class AccountService { return this.accountEndpoint.getPermissionsEndpoint(); } - private onRolesChanged(roles: Role[] | string[], op: RolesChangedOperation) { this.rolesChanged.next({ roles, operation: op }); } - onRolesUserCountChanged(roles: Role[] | string[]) { return this.onRolesChanged(roles, AccountService.roleModifiedOperation); } - getRolesChangedEvent(): Observable { return this.rolesChanged.asObservable(); } - - get permissions(): PermissionValues[] { return this.authService.userPermissions; } diff --git a/QuickApp/ClientApp/src/app/services/alert.service.ts b/QuickApp/ClientApp/src/app/services/alert.service.ts index f627a65b3..cc260bfe7 100644 --- a/QuickApp/ClientApp/src/app/services/alert.service.ts +++ b/QuickApp/ClientApp/src/app/services/alert.service.ts @@ -10,8 +10,6 @@ import { Observable, Subject } from 'rxjs'; import { Utilities } from '../services/utilities'; - - @Injectable() export class AlertService { private messages = new Subject(); @@ -33,14 +31,11 @@ export class AlertService { this.dialogs.next({ message, type, okCallback, cancelCallback, okLabel, cancelLabel, defaultValue }); } - - showMessage(summary: string); showMessage(summary: string, detail: string, severity: MessageSeverity); showMessage(summaryAndDetails: string[], summaryAndDetailsSeparator: string, severity: MessageSeverity); showMessage(response: HttpResponseBase, ignoreValueUseNull: string, severity: MessageSeverity); showMessage(data: any, separatorOrDetail?: string, severity?: MessageSeverity) { - if (!severity) { severity = MessageSeverity.default; } @@ -61,7 +56,6 @@ export class AlertService { } } - showStickyMessage(summary: string); showStickyMessage(summary: string, detail: string, severity: MessageSeverity, error?: any); showStickyMessage(summary: string, detail: string, severity: MessageSeverity, error?: any, onRemove?: () => any); @@ -78,7 +72,6 @@ export class AlertService { separatorOrDetail = Utilities.captionAndMessageSeparator; } - if (data instanceof Array) { for (const message of data) { const msgObject = Utilities.splitInTwo(message, separatorOrDetail); @@ -86,9 +79,7 @@ export class AlertService { this.showMessageHelper(msgObject.firstPart, msgObject.secondPart, severity, true); } } else { - if (error) { - const msg = `Severity: "${MessageSeverity[severity]}", Summary: "${data}", Detail: "${separatorOrDetail}", Error: "${Utilities.safeStringify(error)}"`; switch (severity) { diff --git a/QuickApp/ClientApp/src/app/services/animations.ts b/QuickApp/ClientApp/src/app/services/animations.ts index 190f6fc68..4198d49c8 100644 --- a/QuickApp/ClientApp/src/app/services/animations.ts +++ b/QuickApp/ClientApp/src/app/services/animations.ts @@ -8,16 +8,16 @@ import { animate, state, style, transition, trigger } from '@angular/animations' export const fadeInOut = trigger('fadeInOut', [ - transition(':enter', [style({ opacity: 0 }), animate('0.4s ease-in', style({ opacity: 1 }))]), - transition(':leave', [animate('0.4s 10ms ease-out', style({ opacity: 0 }))]) + transition(':enter', [style({ opacity: 0 }), animate('0.4s ease-in', style({ opacity: 1 }))]), + transition(':leave', [animate('0.4s 10ms ease-out', style({ opacity: 0 }))]) ]); export function flyInOut(duration: number = 0.2) { - return trigger('flyInOut', [ - state('in', style({ opacity: 1, transform: 'translateX(0)' })), - transition('void => *', [style({ opacity: 0, transform: 'translateX(-100%)' }), animate(`${duration}s ease-in`)]), - transition('* => void', [animate(`${duration}s 10ms ease-out`, style({ opacity: 0, transform: 'translateX(100%)' }))]) - ]); + return trigger('flyInOut', [ + state('in', style({ opacity: 1, transform: 'translateX(0)' })), + transition('void => *', [style({ opacity: 0, transform: 'translateX(-100%)' }), animate(`${duration}s ease-in`)]), + transition('* => void', [animate(`${duration}s 10ms ease-out`, style({ opacity: 0, transform: 'translateX(100%)' }))]) + ]); } diff --git a/QuickApp/ClientApp/src/app/services/app-title.service.ts b/QuickApp/ClientApp/src/app/services/app-title.service.ts index 0c7dd9792..86b9d2e6c 100644 --- a/QuickApp/ClientApp/src/app/services/app-title.service.ts +++ b/QuickApp/ClientApp/src/app/services/app-title.service.ts @@ -11,46 +11,44 @@ import { Title } from '@angular/platform-browser'; import { Utilities } from './utilities'; - @Injectable() export class AppTitleService { - - sub: Subscription; - appName: string; - - constructor(private titleService: Title, private router: Router) { - this.sub = this.router.events.pipe( - filter(event => event instanceof NavigationEnd), - map(_ => this.router.routerState.root), - map(route => { - while (route.firstChild) { - route = route.firstChild; - } - - return route; - }), - flatMap(route => route.data)) - .subscribe(data => { - let title = data.title; - - if (title) { - const fragment = this.router.url.split('#')[1]; - - if (fragment) { - title += ' | ' + Utilities.toTitleCase(fragment); - } - } - - if (title && this.appName) { - title += ' - ' + this.appName; - } else if (this.appName) { - title = this.appName; - } - - if (title) { - this.titleService.setTitle(title); - } - }); - } + sub: Subscription; + appName: string; + + constructor(private titleService: Title, private router: Router) { + this.sub = this.router.events.pipe( + filter(event => event instanceof NavigationEnd), + map(_ => this.router.routerState.root), + map(route => { + while (route.firstChild) { + route = route.firstChild; + } + + return route; + }), + flatMap(route => route.data)) + .subscribe(data => { + let title = data.title; + + if (title) { + const fragment = this.router.url.split('#')[1]; + + if (fragment) { + title += ' | ' + Utilities.toTitleCase(fragment); + } + } + + if (title && this.appName) { + title += ' - ' + this.appName; + } else if (this.appName) { + title = this.appName; + } + + if (title) { + this.titleService.setTitle(title); + } + }); + } } diff --git a/QuickApp/ClientApp/src/app/services/app-translation.service.ts b/QuickApp/ClientApp/src/app/services/app-translation.service.ts index 219b01ee8..04c8fb6cf 100644 --- a/QuickApp/ClientApp/src/app/services/app-translation.service.ts +++ b/QuickApp/ClientApp/src/app/services/app-translation.service.ts @@ -72,12 +72,10 @@ export class AppTranslationService { return language; } - getTranslation(key: string | Array, interpolateParams?: object): string | any { return this.translate.instant(key, interpolateParams); } - getTranslationAsync(key: string | Array, interpolateParams?: object): Observable { return this.translate.get(key, interpolateParams); } @@ -88,9 +86,7 @@ export class AppTranslationService { export class TranslateLanguageLoader implements TranslateLoader { public getTranslation(lang: string): any { - // Note Dynamic require(variable) will not work. Require is always at compile time - switch (lang) { case 'en': return of(require('../assets/locale/en.json')); diff --git a/QuickApp/ClientApp/src/app/services/auth-guard.service.ts b/QuickApp/ClientApp/src/app/services/auth-guard.service.ts index e67e641c8..964728a80 100644 --- a/QuickApp/ClientApp/src/app/services/auth-guard.service.ts +++ b/QuickApp/ClientApp/src/app/services/auth-guard.service.ts @@ -4,39 +4,39 @@ // ============================= import { Injectable } from '@angular/core'; -import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild, NavigationExtras, CanLoad, Route } from '@angular/router'; +import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild, CanLoad, Route } from '@angular/router'; import { AuthService } from './auth.service'; @Injectable() export class AuthGuard implements CanActivate, CanActivateChild, CanLoad { - constructor(private authService: AuthService, private router: Router) { } + constructor(private authService: AuthService, private router: Router) { } - canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { + canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { - const url: string = state.url; - return this.checkLogin(url); - } + const url: string = state.url; + return this.checkLogin(url); + } - canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { - return this.canActivate(route, state); - } + canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { + return this.canActivate(route, state); + } - canLoad(route: Route): boolean { + canLoad(route: Route): boolean { - const url = `/${route.path}`; - return this.checkLogin(url); - } + const url = `/${route.path}`; + return this.checkLogin(url); + } - checkLogin(url: string): boolean { + checkLogin(url: string): boolean { - if (this.authService.isLoggedIn) { - return true; - } + if (this.authService.isLoggedIn) { + return true; + } - this.authService.loginRedirectUrl = url; - this.router.navigate(['/login']); + this.authService.loginRedirectUrl = url; + this.router.navigate(['/login']); - return false; - } + return false; + } } diff --git a/QuickApp/ClientApp/src/app/services/can-deactivate-guard.service.ts b/QuickApp/ClientApp/src/app/services/can-deactivate-guard.service.ts index 0e472744b..490f2a114 100644 --- a/QuickApp/ClientApp/src/app/services/can-deactivate-guard.service.ts +++ b/QuickApp/ClientApp/src/app/services/can-deactivate-guard.service.ts @@ -8,12 +8,12 @@ import { CanDeactivate } from '@angular/router'; import { Observable } from 'rxjs'; export interface CanComponentDeactivate { - canDeactivate: () => Observable | Promise | boolean; + canDeactivate: () => Observable | Promise | boolean; } @Injectable() export class CanDeactivateGuard implements CanDeactivate { - canDeactivate(component: CanComponentDeactivate) { - return component.canDeactivate ? component.canDeactivate() : true; - } + canDeactivate(component: CanComponentDeactivate) { + return component.canDeactivate ? component.canDeactivate() : true; + } } diff --git a/QuickApp/ClientApp/src/app/services/configuration.service.ts b/QuickApp/ClientApp/src/app/services/configuration.service.ts index 46763ca28..54454299c 100644 --- a/QuickApp/ClientApp/src/app/services/configuration.service.ts +++ b/QuickApp/ClientApp/src/app/services/configuration.service.ts @@ -43,7 +43,6 @@ export class ConfigurationService { return this._language || ConfigurationService.defaultLanguage; } - set themeId(value: number) { value = +value; this._themeId = value; @@ -54,7 +53,6 @@ export class ConfigurationService { return this._themeId || ConfigurationService.defaultThemeId; } - set homeUrl(value: string) { this._homeUrl = value; this.saveToLocalStore(value, DBkeys.HOME_URL); @@ -63,7 +61,6 @@ export class ConfigurationService { return this._homeUrl || ConfigurationService.defaultHomeUrl; } - set showDashboardStatistics(value: boolean) { this._showDashboardStatistics = value; this.saveToLocalStore(value, DBkeys.SHOW_DASHBOARD_STATISTICS); @@ -72,7 +69,6 @@ export class ConfigurationService { return this._showDashboardStatistics != null ? this._showDashboardStatistics : ConfigurationService.defaultShowDashboardStatistics; } - set showDashboardNotifications(value: boolean) { this._showDashboardNotifications = value; this.saveToLocalStore(value, DBkeys.SHOW_DASHBOARD_NOTIFICATIONS); @@ -81,7 +77,6 @@ export class ConfigurationService { return this._showDashboardNotifications != null ? this._showDashboardNotifications : ConfigurationService.defaultShowDashboardNotifications; } - set showDashboardTodo(value: boolean) { this._showDashboardTodo = value; this.saveToLocalStore(value, DBkeys.SHOW_DASHBOARD_TODO); @@ -90,7 +85,6 @@ export class ConfigurationService { return this._showDashboardTodo != null ? this._showDashboardTodo : ConfigurationService.defaultShowDashboardTodo; } - set showDashboardBanner(value: boolean) { this._showDashboardBanner = value; this.saveToLocalStore(value, DBkeys.SHOW_DASHBOARD_BANNER); @@ -98,7 +92,6 @@ export class ConfigurationService { get showDashboardBanner() { return this._showDashboardBanner != null ? this._showDashboardBanner : ConfigurationService.defaultShowDashboardBanner; } - public static readonly appVersion: string = '4.0.0'; // ***Specify default configurations here*** @@ -123,14 +116,11 @@ export class ConfigurationService { private _showDashboardNotifications: boolean = null; private _showDashboardTodo: boolean = null; private _showDashboardBanner: boolean = null; - private onConfigurationImported: Subject = new Subject(); - configurationImported$ = this.onConfigurationImported.asObservable(); - + configurationImported$ = this.onConfigurationImported.asObservable(); private loadLocalChanges() { - if (this.localStorage.exists(DBkeys.LANGUAGE)) { this._language = this.localStorage.getDataObject(DBkeys.LANGUAGE); this.translationService.changeLanguage(this._language); @@ -138,7 +128,6 @@ export class ConfigurationService { this.resetLanguage(); } - if (this.localStorage.exists(DBkeys.THEME_ID)) { this._themeId = this.localStorage.getDataObject(DBkeys.THEME_ID); this.themeManager.installTheme(this.themeManager.getThemeByID(this._themeId)); @@ -146,7 +135,6 @@ export class ConfigurationService { this.resetTheme(); } - if (this.localStorage.exists(DBkeys.HOME_URL)) { this._homeUrl = this.localStorage.getDataObject(DBkeys.HOME_URL); } @@ -168,14 +156,11 @@ export class ConfigurationService { } } - private saveToLocalStore(data: any, key: string) { setTimeout(() => this.localStorage.savePermanentData(data, key)); } - public import(jsonValue: string) { - this.clearLocalChanges(); if (jsonValue) { @@ -213,9 +198,7 @@ export class ConfigurationService { this.onConfigurationImported.next(); } - public export(changesOnly = true): string { - const exportValue: UserConfiguration = { language: changesOnly ? this._language : this.language, themeId: changesOnly ? this._themeId : this.themeId, @@ -229,7 +212,6 @@ export class ConfigurationService { return JSON.stringify(exportValue); } - public clearLocalChanges() { this._language = null; this._themeId = null; @@ -251,7 +233,6 @@ export class ConfigurationService { this.resetTheme(); } - private resetLanguage() { const language = this.translationService.useBrowserLanguage(); diff --git a/QuickApp/ClientApp/src/app/services/endpoint-base.service.ts b/QuickApp/ClientApp/src/app/services/endpoint-base.service.ts index b8a9eded1..631c2d5df 100644 --- a/QuickApp/ClientApp/src/app/services/endpoint-base.service.ts +++ b/QuickApp/ClientApp/src/app/services/endpoint-base.service.ts @@ -4,7 +4,7 @@ // ============================= import { Injectable } from '@angular/core'; -import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable, Subject, from, throwError } from 'rxjs'; import { mergeMap, switchMap, catchError } from 'rxjs/operators'; diff --git a/QuickApp/ClientApp/src/app/services/jwt-helper.ts b/QuickApp/ClientApp/src/app/services/jwt-helper.ts index 22f8753c0..42fd2ce83 100644 --- a/QuickApp/ClientApp/src/app/services/jwt-helper.ts +++ b/QuickApp/ClientApp/src/app/services/jwt-helper.ts @@ -12,64 +12,64 @@ import { Injectable } from '@angular/core'; @Injectable() export class JwtHelper { - public urlBase64Decode(str: string): string { - let output = str.replace(/-/g, '+').replace(/_/g, '/'); - switch (output.length % 4) { - case 0: { break; } - case 2: { output += '=='; break; } - case 3: { output += '='; break; } - default: { - throw new Error('Illegal base64url string!'); - } - } - return this.b64DecodeUnicode(output); + public urlBase64Decode(str: string): string { + let output = str.replace(/-/g, '+').replace(/_/g, '/'); + switch (output.length % 4) { + case 0: { break; } + case 2: { output += '=='; break; } + case 3: { output += '='; break; } + default: { + throw new Error('Illegal base64url string!'); + } } + return this.b64DecodeUnicode(output); + } - // https://developer.mozilla.org/en/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem - private b64DecodeUnicode(str: any) { - return decodeURIComponent(Array.prototype.map.call(atob(str), (c: any) => { - return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); - }).join('')); - } - - public decodeToken(token: string): any { - const parts = token.split('.'); - - if (parts.length !== 3) { - throw new Error('JWT must have 3 parts'); - } + // https://developer.mozilla.org/en/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem + private b64DecodeUnicode(str: any) { + return decodeURIComponent(Array.prototype.map.call(atob(str), (c: any) => { + return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); + }).join('')); + } - const decoded = this.urlBase64Decode(parts[1]); - if (!decoded) { - throw new Error('Cannot decode the token'); - } + public decodeToken(token: string): any { + const parts = token.split('.'); - return JSON.parse(decoded); + if (parts.length !== 3) { + throw new Error('JWT must have 3 parts'); } - public getTokenExpirationDate(token: string): Date { - let decoded: any; - decoded = this.decodeToken(token); + const decoded = this.urlBase64Decode(parts[1]); + if (!decoded) { + throw new Error('Cannot decode the token'); + } - if (!decoded.hasOwnProperty('exp')) { - return null; - } + return JSON.parse(decoded); + } - const date = new Date(0); // The 0 here is the key, which sets the date to the epoch - date.setUTCSeconds(decoded.exp); + public getTokenExpirationDate(token: string): Date { + let decoded: any; + decoded = this.decodeToken(token); - return date; + if (!decoded.hasOwnProperty('exp')) { + return null; } - public isTokenExpired(token: string, offsetSeconds?: number): boolean { - const date = this.getTokenExpirationDate(token); - offsetSeconds = offsetSeconds || 0; + const date = new Date(0); // The 0 here is the key, which sets the date to the epoch + date.setUTCSeconds(decoded.exp); + + return date; + } - if (date == null) { - return false; - } + public isTokenExpired(token: string, offsetSeconds?: number): boolean { + const date = this.getTokenExpirationDate(token); + offsetSeconds = offsetSeconds || 0; - // Token expired? - return !(date.valueOf() > (new Date().valueOf() + (offsetSeconds * 1000))); + if (date == null) { + return false; } + + // Token expired? + return !(date.valueOf() > (new Date().valueOf() + (offsetSeconds * 1000))); + } } diff --git a/QuickApp/ClientApp/src/app/services/local-store-manager.service.ts b/QuickApp/ClientApp/src/app/services/local-store-manager.service.ts index 2c4258cea..b6aa34642 100644 --- a/QuickApp/ClientApp/src/app/services/local-store-manager.service.ts +++ b/QuickApp/ClientApp/src/app/services/local-store-manager.service.ts @@ -32,7 +32,6 @@ export class LocalStoreManager { 'clearAllSessionsStorage' ]; - public initialiseStorageSyncListener() { if (LocalStoreManager.syncListenerInitialised === true) { return; diff --git a/QuickApp/ClientApp/src/app/services/notification-endpoint.service.ts b/QuickApp/ClientApp/src/app/services/notification-endpoint.service.ts index 51c4f3fe4..45772f576 100644 --- a/QuickApp/ClientApp/src/app/services/notification-endpoint.service.ts +++ b/QuickApp/ClientApp/src/app/services/notification-endpoint.service.ts @@ -9,10 +9,8 @@ import { Observable, of } from 'rxjs'; - @Injectable() export class NotificationEndpoint { - private demoNotifications = [ { id: 1, @@ -40,8 +38,6 @@ export class NotificationEndpoint { } ]; - - getNotificationEndpoint(notificationId: number): Observable { const notification = this.demoNotifications.find(val => val.id === notificationId); @@ -56,8 +52,6 @@ export class NotificationEndpoint { return of(response.body); } - - getNotificationsEndpoint(page: number, pageSize: number): Observable { const notifications = this.demoNotifications; @@ -66,8 +60,6 @@ export class NotificationEndpoint { return of(response.body); } - - getUnreadNotificationsEndpoint(userId?: string): Observable { const unreadNotifications = this.demoNotifications.filter(val => !val.isRead); @@ -76,8 +68,6 @@ export class NotificationEndpoint { return of(response.body); } - - getNewNotificationsEndpoint(lastNotificationDate?: Date): Observable { const unreadNotifications = this.demoNotifications; @@ -86,8 +76,6 @@ export class NotificationEndpoint { return of(response.body); } - - getPinUnpinNotificationEndpoint(notificationId: number, isPinned?: boolean, ): Observable { const notification = this.demoNotifications.find(val => val.id === notificationId); @@ -110,10 +98,7 @@ export class NotificationEndpoint { return of(response.body); } - - getReadUnreadNotificationEndpoint(notificationIds: number[], isRead: boolean, ): Observable { - for (const notificationId of notificationIds) { const notification = this.demoNotifications.find(val => val.id === notificationId); @@ -127,8 +112,6 @@ export class NotificationEndpoint { return of(response.body); } - - getDeleteNotificationEndpoint(notificationId: number): Observable { const notification = this.demoNotifications.find(val => val.id === notificationId); @@ -144,8 +127,6 @@ export class NotificationEndpoint { return of(response.body); } - - private createResponse(body, status: number) { return new HttpResponse({ body, status }); } diff --git a/QuickApp/ClientApp/src/app/services/notification.service.ts b/QuickApp/ClientApp/src/app/services/notification.service.ts index 716f6447d..d899c497e 100644 --- a/QuickApp/ClientApp/src/app/services/notification.service.ts +++ b/QuickApp/ClientApp/src/app/services/notification.service.ts @@ -13,7 +13,6 @@ import { Notification } from '../models/notification.model'; @Injectable() export class NotificationService { - private lastNotificationDate: Date; private _recentNotifications: Notification[]; @@ -29,20 +28,16 @@ export class NotificationService { this._recentNotifications = notifications; } - - constructor(private notificationEndpoint: NotificationEndpoint, private authService: AuthService) { } - getNotification(notificationId?: number) { return this.notificationEndpoint.getNotificationEndpoint(notificationId).pipe( map(response => Notification.Create(response))); } - getNotifications(page: number, pageSize: number) { return this.notificationEndpoint.getNotificationsEndpoint(page, pageSize).pipe( @@ -51,20 +46,17 @@ export class NotificationService { })); } - getUnreadNotifications(userId?: string) { return this.notificationEndpoint.getUnreadNotificationsEndpoint(userId).pipe( map(response => this.getNotificationsFromResponse(response))); } - getNewNotifications() { return this.notificationEndpoint.getNewNotificationsEndpoint(this.lastNotificationDate).pipe( map(response => this.processNewNotificationsFromResponse(response))); } - getNewNotificationsPeriodically() { return interval(10000).pipe( startWith(0), @@ -74,9 +66,6 @@ export class NotificationService { })); } - - - pinUnpinNotification(notificationOrNotificationId: number | Notification, isPinned?: boolean): Observable { if (typeof notificationOrNotificationId === 'number' || notificationOrNotificationId instanceof Number) { @@ -86,15 +75,11 @@ export class NotificationService { } } - readUnreadNotification(notificationIds: number[], isRead: boolean): Observable { return this.notificationEndpoint.getReadUnreadNotificationEndpoint(notificationIds, isRead); } - - - deleteNotification(notificationOrNotificationId: number | Notification): Observable { if (typeof notificationOrNotificationId === 'number' || notificationOrNotificationId instanceof Number) { // Todo: Test me if its check is valid @@ -108,9 +93,6 @@ export class NotificationService { } } - - - private processNewNotificationsFromResponse(response) { const notifications = this.getNotificationsFromResponse(response); @@ -123,7 +105,6 @@ export class NotificationService { return notifications; } - private getNotificationsFromResponse(response) { const notifications: Notification[] = []; diff --git a/QuickApp/ClientApp/src/app/services/utilities.ts b/QuickApp/ClientApp/src/app/services/utilities.ts index ed26c8db4..e80639cb2 100644 --- a/QuickApp/ClientApp/src/app/services/utilities.ts +++ b/QuickApp/ClientApp/src/app/services/utilities.ts @@ -271,14 +271,14 @@ export class Utilities { } } - public static GetObjectWithLoweredPropertyNames(obj: any) { - const loweredObj = Object.keys(obj).reduce((newObj, k) => { - newObj[k.toLowerCase()] = obj[k]; - return newObj; - }, {}); + public static GetObjectWithLoweredPropertyNames(obj: any) { + const loweredObj = Object.keys(obj).reduce((newObj, k) => { + newObj[k.toLowerCase()] = obj[k]; + return newObj; + }, {}); - return loweredObj; - } + return loweredObj; + } public static TestIsObjectEmpty(obj: any) { for (const prop in obj) {