Ghost/ghost/admin/app/routes/collections.js
Naz cc4ff8c6d4 Added collections CRUD UI
refs https://github.com/TryGhost/Team/issues/3168

- This is basic scaffolding for collection resources UI in Admin. For the most part it's a copy-paste of tags code with slight modifications to fit the collections usecase
2023-05-23 17:26:47 +07:00

32 lines
1.1 KiB
JavaScript

import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
export default class CollectionsRoute extends AuthenticatedRoute {
// authors aren't allowed to manage tags
beforeModel() {
super.beforeModel(...arguments);
if (this.session.user.isAuthorOrContributor) {
return this.transitionTo('home');
}
}
// set model to a live array so all collections are shown and created/deleted collections
// are automatically added/removed. Also load all collections in the background,
// pausing to show the loading spinner if no collections have been loaded yet
model() {
let promise = this.store.query('collection', {limit: 'all', include: 'count.posts'});
let collections = this.store.peekAll('collection');
if (this.store.peekAll('collection').get('length') === 0) {
return promise.then(() => collections);
} else {
return collections;
}
}
buildRouteInfoMetadata() {
return {
titleToken: 'Collections'
};
}
}