X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNG-UI.git;a=blobdiff_plain;f=src%2Fservices%2FSharedService.ts;fp=src%2Fservices%2FSharedService.ts;h=8abe1d295e80c6b750ca430aece68d7f2639e053;hp=53078b52e6e3cbafaf2b265097625b313b731b65;hb=1b17c432991a95035a1732426f0c11db57e511c9;hpb=50e53afdfc376c2055284bda4be1664acfe4fcee diff --git a/src/services/SharedService.ts b/src/services/SharedService.ts index 53078b5..8abe1d2 100644 --- a/src/services/SharedService.ts +++ b/src/services/SharedService.ts @@ -39,6 +39,7 @@ import { import { environment } from 'environment'; import * as HttpStatus from 'http-status-codes'; import * as untar from 'js-untar'; +import { ActiveToast, ToastrService } from 'ngx-toastr'; import * as pako from 'pako'; import { RestService } from 'RestService'; import { Observable } from 'rxjs'; @@ -98,6 +99,15 @@ export class SharedService { /** Holds OSM Version value @public */ public osmVersion: string; + /** Holds Last Login Toaster Message @public */ + public lastLoginMessage: string; + + /** Holds Failed Attempts Toaster Message @public */ + public failedAttemptsMessage: string; + + /** Holds No Of Days Toaster Message @public */ + public daysMessage: string; + /** express number for time manupulation -2 */ // eslint-disable-next-line @typescript-eslint/no-magic-numbers private epochTimeMinus2: number = -2; @@ -106,10 +116,22 @@ export class SharedService { // eslint-disable-next-line @typescript-eslint/no-magic-numbers private epochTime1000: number = 1000; + /** express number for time manupulation 60 */ + // eslint-disable-next-line @typescript-eslint/no-magic-numbers + private epochTime60: number = 60; + + /** express number for time manupulation 24 */ + // eslint-disable-next-line @typescript-eslint/no-magic-numbers + private epochTime24: number = 24; + /** Random string generator length */ // eslint-disable-next-line @typescript-eslint/no-magic-numbers private randomStringLength: number = 4; + /** Max length of Uint8Array */ + // eslint-disable-next-line @typescript-eslint/no-magic-numbers + private unit8Array: number = 255; + /** Instance of the rest service @private */ private restService: RestService; @@ -124,13 +146,24 @@ export class SharedService { // eslint-disable-next-line @typescript-eslint/no-magic-numbers private directoryCount: number = 2; + /** express number for time manupulation 1000 */ + private toasterSettings: {} = { + enableHtml: true, + closeButton: true, + timeOut: 2000 + }; + /** Contains tranlsate instance @private */ private translateService: TranslateService; - constructor(restService: RestService, router: Router, translateService: TranslateService) { + /** Contains toaster instance @private */ + private toaster: ToastrService; + + constructor(restService: RestService, router: Router, translateService: TranslateService, toaster: ToastrService) { this.restService = restService; this.router = router; this.translateService = translateService; + this.toaster = toaster; } /** convert epoch time function @public */ @@ -153,6 +186,52 @@ export class SharedService { return this.translateService.instant('NODATE'); } + /** convert epoch time function to No of days @public */ + public converEpochToDays(date: string): number { + if (!isNullOrUndefined(date)) { + const today: Date = new Date(); + const accountDate: Date = new Date(date); + return Math.floor((accountDate.getTime() - + today.getTime()) / this.epochTime1000 / this.epochTime60 / this.epochTime60 / this.epochTime24); + } + return this.translateService.instant('N/A'); + } + + /** show toaster for password & account expiry @public */ + public showToaster(lastLogin: string, failedAttempts: string, passwordNoOfDays: string, + accountNoOfDays: string, passwordExpireMessage: string, accountExpireMessage: string, + passwordMessage: string, accountMessage: string): ActiveToast { + this.lastLoginMessage = this.translateService.instant('PAGE.LOGIN.LASTACCESS'); + this.failedAttemptsMessage = this.translateService.instant('PAGE.LOGIN.FAILED'); + return this.toaster.info(this.lastLoginMessage + ':' + ' ' + lastLogin + + '
' + this.failedAttemptsMessage + ':' + ' ' + failedAttempts + + '
' + passwordExpireMessage + ' ' + passwordNoOfDays + ' ' + passwordMessage + + '
' + accountExpireMessage + ' ' + accountNoOfDays + ' ' + accountMessage, + this.translateService.instant('PAGE.LOGIN.LOGINHISTORY'), this.toasterSettings); + } + + /** show toaster for password expiry @public */ + public passwordToaster(lastLogin: string, failedAttempts: string, passwordNoOfDays: string, + passwordExpireMessage: string, passwordMessage: string): ActiveToast { + this.lastLoginMessage = this.translateService.instant('PAGE.LOGIN.LASTACCESS'); + this.failedAttemptsMessage = this.translateService.instant('PAGE.LOGIN.FAILED'); + return this.toaster.info(this.lastLoginMessage + ':' + ' ' + lastLogin + + '
' + this.failedAttemptsMessage + ':' + ' ' + failedAttempts + + '
' + passwordExpireMessage + ' ' + passwordNoOfDays + ' ' + passwordMessage, + this.translateService.instant('PAGE.LOGIN.LOGINHISTORY'), this.toasterSettings); + } + + /** show toaster for account expiry @public */ + public accountToaster(lastLogin: string, failedAttempts: string, + accountNoOfDays: string, accountExpireMessage: string, accountMessage: string): ActiveToast { + this.lastLoginMessage = this.translateService.instant('PAGE.LOGIN.LASTACCESS'); + this.failedAttemptsMessage = this.translateService.instant('PAGE.LOGIN.FAILED'); + return this.toaster.info(this.lastLoginMessage + ':' + ' ' + lastLogin + + '
' + this.failedAttemptsMessage + ':' + ' ' + failedAttempts + + '
' + accountExpireMessage + ' ' + accountNoOfDays + ' ' + accountMessage, + this.translateService.instant('PAGE.LOGIN.LOGINHISTORY'), this.toasterSettings); + } + /** Download Files function @public */ public downloadFiles(name: string, binaryData: Blob[], filetype: string): void { const downloadLink: HTMLAnchorElement = document.createElement('a');