import { Component } from '@angular/core' ; import { IonicPage , NavController , NavParams , PopoverController , App } from 'ionic-angular' ; import { Novel } from "../../common/models/novel" ; import { DownloadService } from "../../providers/download-service" ; import { LnLoadingController } from "../../common/ln-loading-controller" ; import _ from "lodash" ; import { DownloadChapterItem , DownloadStatus } from "../../common/models/download-item" ; @ IonicPage ( ) @ Component ( { selector : 'page-ln-download-novel' , templateUrl : 'ln-download-novel.html' , } ) export class LnDownloadNovelPage { novel : Novel ; chapters : DownloadChapterItem [ ] = [ ] ; chapterDetailsHeader : any ; isUpdated : boolean = false ; constructor ( private navCtrl , private navParams , private popoverCtrl , private downloadService , private loadingCtrl , private app ) { } ionViewDidLoad ( ) { console . log ( 'ionViewDidLoad LnDownloadNovelPage' ) ; this . novel = this . navParams . data ; this . loadingCtrl . presentLoadingMessage ( ) ; this . downloadService . getUndownloadedChapters ( this . novel . id ) . then ( ( chapters ) => { this . isUpdated = chapters . length === 0 ; _ . each ( chapters , chapter => { chapter . checked = true ; chapter . status = DownloadStatus . Pending ; } ) ; this . chapters = chapters . reverse ( ) ; this . loadingCtrl . hideLoadingMessage ( ) ; } ) ; } selectPopover ( evt ) { let popover = this . popoverCtrl . create ( "LnDownloadNovelChaptersPopup" , { chapters : this . chapters } ) ; popover . present ( { ev : evt } ) ; } get selectedChapters ( ) { return _ . filter ( this . chapters , ( chapter ) => chapter . checked ) ; } download ( ) { this . downloadService . addToQueue ( this . novel , this . selectedChapters ) ; this . app . getRootNav ( ) . setRoot ( "LnDownloadsQueuePage" ) ; } }