6a3cfc2ca8
requires https://github.com/TryGhost/Ghost/pull/9426 - fixed default token component display in {{gh-token-input}} - if no `tokenComponent` is passed to `{{gh-token-input}}` then it should default to the ember-drag-drop `draggable-object` component but instead it didn't output anything - put `draggable-object` in quotes because `{{component}}` needs a component name rather than an object - rename `option` attribute to `content` to match the default `{{draggable-object}}` interface - add embedded `authors` attr to the Post model - ensure authors is populated when starting new post - add validation for empty authors list - swap author dropdown for a token input in PSM - show all post authors in posts list - update tests for `authors` - always provide through an authors array - fix mirage serialisation for paginated responses (embedded records were not being serialised) - unify tags and author inputs design - remove highlight of primary tags - highlight internal tags - remove unnecessary/redundant title attributes on tags - use SVG icon for "remove option" button in token inputs
82 lines
2.4 KiB
JavaScript
82 lines
2.4 KiB
JavaScript
import {Response} from 'ember-cli-mirage';
|
|
import {dasherize} from '@ember/string';
|
|
import {isBlank} from '@ember/utils';
|
|
import {paginateModelCollection} from '../utils';
|
|
|
|
export default function mockPosts(server) {
|
|
server.post('/posts', function ({posts, users}) {
|
|
let attrs = this.normalizedRequestAttrs();
|
|
let authors = [];
|
|
|
|
// NOTE: this is necessary so that ember-cli-mirage has a valid user
|
|
// schema object rather than a plain object
|
|
// TODO: should ember-cli-mirage be handling this automatically?
|
|
attrs.authors.forEach((author) => {
|
|
authors.push(users.find(author.id));
|
|
});
|
|
|
|
attrs.authors = authors;
|
|
|
|
if (isBlank(attrs.slug) && !isBlank(attrs.title)) {
|
|
attrs.slug = dasherize(attrs.title);
|
|
}
|
|
|
|
return posts.create(attrs);
|
|
});
|
|
|
|
// TODO: handle author filter
|
|
server.get('/posts/', function ({posts}, {queryParams}) {
|
|
let page = +queryParams.page || 1;
|
|
let limit = +queryParams.limit || 15;
|
|
let {status, staticPages} = queryParams;
|
|
let query = {};
|
|
|
|
if (status && status !== 'all') {
|
|
query.status = status;
|
|
}
|
|
|
|
if (staticPages === 'false') {
|
|
query.page = false;
|
|
}
|
|
|
|
if (staticPages === 'true') {
|
|
query.page = true;
|
|
}
|
|
|
|
let collection = posts.where(query);
|
|
|
|
return paginateModelCollection('posts', collection, page, limit);
|
|
});
|
|
|
|
server.get('/posts/:id/', function ({posts}, {params}) {
|
|
let {id} = params;
|
|
let post = posts.find(id);
|
|
|
|
return post || new Response(404, {}, {
|
|
errors: [{
|
|
errorType: 'NotFoundError',
|
|
message: 'Post not found.'
|
|
}]
|
|
});
|
|
});
|
|
|
|
server.put('/posts/:id/', function ({posts, users}, {params}) {
|
|
let attrs = this.normalizedRequestAttrs();
|
|
let post = posts.find(params.id);
|
|
let authors = [];
|
|
|
|
// NOTE: this is necessary so that ember-cli-mirage has a valid user
|
|
// schema object rather than a plain object
|
|
// TODO: should ember-cli-mirage be handling this automatically?
|
|
attrs.authors.forEach((author) => {
|
|
authors.push(users.find(author.id));
|
|
});
|
|
|
|
attrs.authors = authors;
|
|
|
|
return post.update(attrs);
|
|
});
|
|
|
|
server.del('/posts/:id/');
|
|
}
|