2a77c0fe51
no issue - list custom post views in collapsable sidebar navigation - default views: Draft, Scheduled, Published (except for contributors) - record expanded/collapsed state of the navigation menus in user settings via new `navigation` service - adds `customViews` service that manages custom views - provides list of default views - gives access to "active" custom view based on current route and query params - manages loading/saving of custom views to user settings - show "Add view" button in the content filter when the posts list has been filtered - show "Edit view" button in the content filter when the posts list filter matches a saved view Co-authored-by: Peter Zimon <peter.zimon@gmail.com>
54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
import Service from '@ember/service';
|
|
import {action} from '@ember/object';
|
|
import {observes} from '@ember-decorators/object';
|
|
import {inject as service} from '@ember/service';
|
|
import {set} from '@ember/object';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
const DEFAULT_SETTINGS = {
|
|
expanded: {
|
|
posts: true
|
|
}
|
|
};
|
|
|
|
export default class NavigationService extends Service {
|
|
@service session;
|
|
|
|
@tracked settings;
|
|
|
|
constructor() {
|
|
super(...arguments);
|
|
this.updateSettings();
|
|
}
|
|
|
|
// eslint-disable-next-line ghost/ember/no-observers
|
|
@observes('session.user.accessibility')
|
|
async updateSettings() {
|
|
let user = await this.session.user;
|
|
let userSettings = JSON.parse(user.get('accessibility')) || {};
|
|
this.settings = userSettings.navigation || Object.assign({}, DEFAULT_SETTINGS);
|
|
}
|
|
|
|
@action
|
|
async toggleExpansion(key) {
|
|
if (!this.settings.expanded) {
|
|
this.settings.expanded = {};
|
|
}
|
|
|
|
// set is still needed here because we're not tracking deep keys
|
|
// and Ember picks up that our templates are dependent on them and
|
|
// complains. TODO: can we avoid set?
|
|
set(this.settings.expanded, key, !this.settings.expanded[key]);
|
|
|
|
return await this._saveNavigationSettings();
|
|
}
|
|
|
|
async _saveNavigationSettings() {
|
|
let user = await this.session.user;
|
|
let userSettings = JSON.parse(user.get('accessibility'));
|
|
userSettings.navigation = this.settings;
|
|
user.set('accessibility', JSON.stringify(userSettings));
|
|
return user.save();
|
|
}
|
|
}
|