import { Component } from "@angular/core" ; import { NavParams , ViewController , IonicPage , Platform } from "ionic-angular" ; import { Storage } from "@ionic/storage" ; import { NovelsService } from "../../providers/novels-service" ; import { Genre } from "../../common/models/genre" ; @ IonicPage ( ) @ Component ( { selector : "ln-novel-filter-modal" , templateUrl : "ln-novel-filter-modal.html" , } ) export class LnNovelFilterModal { status : number = 0 ; genres : Genre [ ] ; constructor ( public navParams , private viewCtrl , private platform , private storage , private novelsService ) { } ionViewDidLoad ( ) { console . log ( "ionViewDidLoad LnNovelFilterModal" ) ; this . novelsService . getGenres ( ) . subscribe ( genres => { this . genres = genres ; this . storage . get ( "checkedGenres" ) . then ( ( genres ) => { this . genres . forEach ( genre => { genre . checked = genres == null || genres . indexOf ( genre . id ) != - 1 ; } ) ; } ) ; } ) ; this . storage . get ( "selectedStatus" ) . then ( val => this . status = val || 0 ) ; } get checkedGenres ( ) { let checked = [ ] ; this . genres . forEach ( genre => { if ( genre . checked ) { checked . push ( genre . id ) ; } } ) ; return checked ; } save ( ) { this . storage . set ( "checkedGenres" , this . checkedGenres ) ; this . storage . set ( "selectedStatus" , this . status ) ; this . viewCtrl . dismiss ( { genres : this . checkedGenres , status : this . status } ) ; } dismiss ( ) { this . viewCtrl . dismiss ( ) ; } }