2016-12-31 18:12:50 -05:00
|
|
|
/// <reference path="../../../typings/browser/ambient/jquery/index.d.ts" />
|
2016-12-02 13:00:55 -05:00
|
|
|
import { Component } from '@angular/core';
|
|
|
|
import { NavController } from 'ionic-angular';
|
|
|
|
import { Storage } from '@ionic/storage';
|
2017-01-18 17:51:06 -05:00
|
|
|
import { SavedPage, UserProfile } from '../../libs/UserProfile';
|
2016-12-02 13:00:55 -05:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'settings',
|
|
|
|
templateUrl: 'settings.html'
|
|
|
|
})
|
2016-12-27 21:10:00 -05:00
|
|
|
export class SettingsPage
|
|
|
|
{
|
2016-12-31 18:12:50 -05:00
|
|
|
textSize: number = 0;
|
|
|
|
userProfile: UserProfile;
|
2016-12-27 21:10:00 -05:00
|
|
|
|
|
|
|
constructor(public navCtrl: NavController, public local: Storage)
|
|
|
|
{
|
2016-12-31 18:12:50 -05:00
|
|
|
this.userProfile = new UserProfile(UserProfile.createDefaultUser());
|
|
|
|
|
2016-12-01 15:21:07 -05:00
|
|
|
// Check if there is a profile saved in local storage
|
2016-12-27 21:10:00 -05:00
|
|
|
this.local.get('profile').then(profile =>
|
|
|
|
{
|
2016-12-31 18:12:50 -05:00
|
|
|
let t = this.userProfile;
|
2016-12-28 15:57:16 -05:00
|
|
|
|
|
|
|
if (profile !== null)
|
|
|
|
t = JSON.parse(profile);
|
|
|
|
|
2016-12-31 18:12:50 -05:00
|
|
|
this.userProfile.update(t, local);
|
2016-12-27 21:10:00 -05:00
|
|
|
}).catch(error =>
|
|
|
|
{
|
2016-12-01 15:21:07 -05:00
|
|
|
console.log(error);
|
2016-12-02 13:00:55 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-12-31 18:12:50 -05:00
|
|
|
textSizeChanged()
|
2016-12-27 21:10:00 -05:00
|
|
|
{
|
2016-12-31 18:12:50 -05:00
|
|
|
this.userProfile.textSizeChanged();
|
|
|
|
this.save();
|
2016-12-02 13:00:55 -05:00
|
|
|
}
|
|
|
|
|
2016-12-31 18:12:50 -05:00
|
|
|
save()
|
2016-12-27 21:10:00 -05:00
|
|
|
{
|
2016-12-31 18:12:50 -05:00
|
|
|
this.userProfile.save(this.local);
|
2016-12-27 21:10:00 -05:00
|
|
|
}
|
|
|
|
|
2016-12-31 18:12:50 -05:00
|
|
|
reset()
|
2016-12-27 21:10:00 -05:00
|
|
|
{
|
2016-12-31 18:12:50 -05:00
|
|
|
this.userProfile.reset(this.local);
|
2016-12-02 13:00:55 -05:00
|
|
|
}
|
2017-01-18 17:51:06 -05:00
|
|
|
|
|
|
|
removePage(page: SavedPage)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2016-12-01 15:21:07 -05:00
|
|
|
}
|