/// import { Component } from '@angular/core'; import { NavController, AlertController } from 'ionic-angular'; import { Storage } from '@ionic/storage'; import { SavedPage, UserProfile } from '../../libs/UserProfile'; @Component({ selector: 'settings', templateUrl: 'settings.html' }) export class SettingsPage { textSize: number = 0; userProfile: UserProfile; constructor( public navCtrl: NavController , public local: Storage , private alertCtrl: AlertController) { this.userProfile = new UserProfile(UserProfile.createDefaultUser()); // Check if there is a profile saved in local storage this.local.get('profile').then(profile => { let t = this.userProfile; if (profile !== null) t = JSON.parse(profile); this.userProfile.update(t, local); }).catch(error => { console.log(error); }); } textSizeChanged() { this.userProfile.textSizeChanged(); this.save(); } save() { this.userProfile.save(this.local); } reset() { this.userProfile.reset(this.local); } removePage(page: SavedPage) { let alert = this.alertCtrl.create({ title: 'Confirm Delete', message: 'Do you want to delete the ' + page.title + ' page?', buttons: [ { text: 'Cancel', role: 'cancel', handler: () => { console.log('Cancel clicked'); } }, { text: 'Ok', handler: () => { let idx = this.userProfile.user.saved_pages.indexOf(page); this.userProfile.user.saved_pages.splice(idx, 1); // save the users settings. this.userProfile.save(this.local); } } ] }); alert.present(); } }