import { Injectable , OnDestroy } from '@angular/core' ; import * as diff from 'diff' ; import { Subscription } from 'rxjs' ; import { Author } from '../core/Author' ; import { Doc } from '../core/Doc' ; @ Injectable ( ) export class HistoryService implements OnDestroy { private subs : Subscription [ ] ; constructor ( ) { this . subs = [ ] ; } getDiff ( strA , strB ) { return diff . diffChars ( strA , strB ) ; } getOperations ( doc ) { return new Promise ( ( resolve ) => { doc . fetchContent ( ) . then ( ( body ) => { } ) . catch ( ( err ) => { log . error ( 'Error getting document body of: ' , doc ) ; } ) ; } ) ; } getAuthors ( doc ) { return new Promise ( ( resolve ) => { const docAuthors = [ ] ; this . getOperations ( doc ) . then ( ( ops ) => { for ( const o of ops ) { const author = new Author ( o . authorName , o . authorId , '#9CCC65' ) ; if ( docAuthors . filter ( ( e ) => { return e . getId ( ) === author . getId ( ) ; } ) . length === 0 ) { docAuthors . push ( author ) ; } } resolve ( docAuthors ) ; } ) ; } ) ; } ngOnDestroy ( ) { this . subs . forEach ( ( sub ) => sub . unsubscribe ( ) ) ; } } export interface IDelete { authorId : number ; authorName : string ; } export interface IInsert { authorId : number ; authorName : string ; }