import angular from 'angular' ; import { Component , OnInit } from 'angular-ts-decorators' ; import autobind from 'autobind-decorator' ; import { AppEventType } from '../../../app/app.enum' ; import { AppBookmarkComponent } from '../../../app/app-bookmark/app-bookmark.component' ; import { AppHelperService } from '../../../app/shared/app-helper/app-helper.service' ; import { AlertType } from '../../../shared/alert/alert.enum' ; import { AlertService } from '../../../shared/alert/alert.service' ; import { Bookmark , BookmarkMetadata } from '../../../shared/bookmark/bookmark.interface' ; import { BookmarkHelperService } from '../../../shared/bookmark/bookmark-helper/bookmark-helper.service' ; import { ExceptionHandler } from '../../../shared/errors/errors.interface' ; import Globals from '../../../shared/global-shared.constants' ; import { PlatformService } from '../../../shared/global-shared.interface' ; import { LogService } from '../../../shared/log/log.service' ; import { SettingsService } from '../../../shared/settings/settings.service' ; import { SyncType } from '../../../shared/sync/sync.enum' ; import { SyncService } from '../../../shared/sync/sync.service' ; import { UtilityService } from '../../../shared/utility/utility.service' ; import { WorkingService } from '../../../shared/working/working.service' ; import { AndroidPlatformService } from '../../android-shared/android-platform/android-platform.service' ; import { AndroidAlert } from '../android-app.interface' ; import { AndroidAppHelperService } from '../shared/android-app-helper/android-app-helper.service' ; @ autobind @ Component ( { controllerAs : 'vm' , selector : 'appBookmark' , styles : [ require ( './android-app-bookmark.component.scss' ) ] , template : require ( '../../../app/app-bookmark/app-bookmark.component.html' ) } ) export class AndroidAppBookmarkComponent extends AppBookmarkComponent implements OnInit { appHelperSvc : AndroidAppHelperService ; logSvc : LogService ; platformSvc : AndroidPlatformService ; settingsSvc : SettingsService ; syncSvc : SyncService ; static $inject = [ '$exceptionHandler' , '$q' , '$routeParams' , '$scope' , '$timeout' , 'AlertService' , 'AppHelperService' , 'BookmarkHelperService' , 'LogService' , 'PlatformService' , 'SettingsService' , 'SyncService' , 'UtilityService' , 'WorkingService' ] ; constructor ( $exceptionHandler , $q , $routeParams , $scope , $timeout , AlertSvc , AppHelperSvc , BookmarkHelperSvc , LogSvc , PlatformSvc , SettingsSvc , SyncSvc , UtilitySvc , WorkingSvc ) { super ( $exceptionHandler , $q , $routeParams , $scope , $timeout , AlertSvc , AppHelperSvc , BookmarkHelperSvc , PlatformSvc , UtilitySvc , WorkingSvc ) ; this . logSvc = LogSvc ; this . settingsSvc = SettingsSvc ; this . syncSvc = SyncSvc ; $scope . $on ( AppEventType . WorkingCancelAction , ( ) => { if ( this . platformSvc . cancelGetPageMetadata ) { this . platformSvc . cancelGetPageMetadata ( ) ; } } ) ; } createBookmark ( ) { return super . createBookmark ( ) . then ( ( result ) => { this . $timeout ( ( ) => { this . alertSvc . setCurrentAlert ( { message : this . platformSvc . getI18nString ( this . Strings . Alert . BookmarkCreated ) } as AndroidAlert ) ; } , Globals . InterfaceReadyTimeout ) ; } ) ; } deleteBookmark ( ) { return this . bookmarkHelperSvc . getCachedBookmarks ( ) . then ( ( cachedBookmarks ) => { return super . deleteBookmark ( ) . then ( ( ) => { this . $timeout ( ( ) => { this . alertSvc . setCurrentAlert ( { action : this . platformSvc . getI18nString ( this . Strings . Button . Undo ) , actionCallback : ( ) => this . undoBookmarkAction ( cachedBookmarks ) , message : this . platformSvc . getI18nString ( this . Strings . Alert . BookmarkDeleted ) } as AndroidAlert ) ; } , Globals . InterfaceReadyTimeout ) ; } ) ; } ) ; } getMetadataForCurrentPage ( ) { if ( angular . isUndefined ( this . platformSvc . currentPage ) ) { return this . $q . resolve ( undefined ) ; } if ( angular . isUndefined ( this . platformSvc . currentPage . url ) ) { this . alertSvc . setCurrentAlert ( { message : this . platformSvc . getI18nString ( this . Strings . View . Bookmark . InvalidUrlShared ) , type : AlertType . Error } ) ; return this . $q . resolve ( ) . then ( ( ) => false ) ; } this . bookmarkFormData = this . platformSvc . currentPage ; this . originalUrl = this . bookmarkFormData . url ; return this . settingsSvc . autoFetchMetadata ( ) . then ( ( autoFetchMetadata ) => { if ( ! autoFetchMetadata ) { this . displayUpdatePropertiesButton = true ; return this . platformSvc . currentPage ; } return super . getMetadataForCurrentPage ( ) ; } ) ; } ngOnInit ( ) { return super . ngOnInit ( ) . finally ( ( ) => { this . platformSvc . currentPage = undefined ; } ) ; } undoBookmarkAction ( bookmarks ) { this . workingSvc . show ( ) ; this . platformSvc . queueSync ( { bookmarks , type : SyncType . LocalAndRemote } ) . finally ( ( ) => this . utilitySvc . broadcastEvent ( AppEventType . RefreshBookmarkSearchResults ) ) ; } updateBookmark ( ) { return this . bookmarkHelperSvc . getCachedBookmarks ( ) . then ( ( cachedBookmarks ) => { return super . updateBookmark ( ) . then ( ( ) => { this . $timeout ( ( ) => { this . alertSvc . setCurrentAlert ( { action : this . platformSvc . getI18nString ( this . Strings . Button . Undo ) , actionCallback : ( ) => this . undoBookmarkAction ( cachedBookmarks ) , message : this . platformSvc . getI18nString ( this . Strings . Alert . BookmarkUpdated ) } as AndroidAlert ) ; } , Globals . InterfaceReadyTimeout ) ; } ) ; } ) ; } }