Added ability to set config from settings

theme slide toggle is now in top right menu
This commit is contained in:
Isaac Grynsztein
2020-03-05 22:38:23 -05:00
parent e57839e8de
commit ae605d5f70
10 changed files with 273 additions and 8 deletions

View File

@@ -8,17 +8,41 @@ import { PostsService } from 'app/posts.services';
})
export class SettingsComponent implements OnInit {
initial_config = null;
new_config = null
loading_config = false;
constructor(private postsService: PostsService) { }
ngOnInit() {
this.getConfig();
}
getConfig() {
this.loading_config = true;
this.postsService.loadNavItems().subscribe(res => {
this.loading_config = false;
// successfully loaded config
this.initial_config = !this.postsService.debugMode ? res['config_file']['YoutubeDLMaterial'] : res['YoutubeDLMaterial'];
this.new_config = JSON.parse(JSON.stringify(this.initial_config));
});
}
setSetting() {
settingsSame() {
return JSON.stringify(this.new_config) === JSON.stringify(this.initial_config);
}
saveSettings() {
const settingsToSave = {'YoutubeDLMaterial': this.new_config};
this.postsService.setConfig(settingsToSave).subscribe(res => {
if (res['success']) {
// sets new config as old config
this.initial_config = JSON.parse(JSON.stringify(this.new_config));
}
}, err => {
console.error('Failed to save config!');
})
}
}