import { File } from './../common/File' ; import { IFileVersion } from './../common/IFileVersion' ; export class FileController { see http public static $inject = [ '$rootScope' ] ; /**
     * File object. Passed in as component binding.
     */ public file : File ; /**
     * Whether the parent bucket is versioned. Passed in as component binding.
     */ public versioned : boolean ; /**
     * File versions.
     */ public versions : IFileVersion [ ] ; /**
     * Flag used to indicate a background operation is running.
     */ public working : boolean ; /**
     * Show file versions.
     */ public showVersions : boolean ; /**
     * Create a file controller instance.
     */ constructor ( private $rootScope ) { this . versions = [ ] ; this . working = false ; this . showVersions = false ; } /**
     * Toggle showing file versions.
     */ public toggleVersions ( ) { if ( this . showVersions ) { this . showVersions = false ; return ; } this . working = true ; this . onLoadVersions ( ) . then ( ( versions ) => { this . versions = versions . sort ( this . compareFileVersions ) ; this . showVersions = true ; } ) . catch ( ( ) => { this . versions = [ ] ; this . showVersions = false ; } ) . then ( ( ) => { this . working = false ; this . $rootScope . $digest ( ) ; } ) ; } /**
     * Load file versions. This is overriden by the component binding.
     */ public onLoadVersions ( ) { return new Promise ( ( resolve , reject ) => { reject ( new Error ( 'not implemented' ) ) ; } ) ; } /**
     * Delete a file. This is overriden by the component binding.
     */ public onDelete ( ) { } /**
     * Compare two file versions by the last modified date in newest order first.
     */ private compareFileVersions ( a , b ) { if ( a . lastModified < b . lastModified ) { return 1 ; } if ( a . lastModified > b . lastModified ) { return - 1 ; } return 0 ; } }