import { CookieService } from 'ngx-cookie-service' ; import { Injectable } from '@angular/core' ; @ Injectable ( { providedIn : 'root' , } ) export class HsHistoryListService { items : any = { } ; constructor ( private CookieService ) { } readSourceHistory ( forWhat ) { if ( forWhat !== undefined ) { let sourceString = this . CookieService . get ( `last${ forWhat }Sources` ) ; if ( sourceString !== undefined ) { this . items [ forWhat ] = { history : [ ] , } ; if ( sourceString !== '' ) { sourceString = sourceString . replace ( /[\[\]\"]/gi , '' ) ; const historyArray = sourceString . split ( ',' ) ; for ( const item of historyArray ) { this . items [ forWhat ] . history . push ( item ) ; } } } else { this . items [ forWhat ] . history = [ ] ; } return this . items [ forWhat ] . history ; } } uniq ( a ) { return a . sort ( ) . filter ( ( item , pos , ary ) => { return ! pos || item != ary [ pos - 1 ] ; } ) ; } addSourceHistory ( forWhat , url ) { if ( url === null || url === undefined ) { return ; } if ( this . items [ forWhat ] ?. history === undefined ) { this . items [ forWhat ] = { history : [ ] , } ; } if ( ! this . items [ forWhat ] ?. history ?. includes ( url ) ) { this . items [ forWhat ] . history . push ( url ) ; this . CookieService . set ( `last${ forWhat }Sources` , JSON . stringify ( this . items [ forWhat ] . history ) ) ; } } }