mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 11:54:33 +03:00
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
61 lines
2.0 KiB
JavaScript
61 lines
2.0 KiB
JavaScript
/* eslint-disable camelcase */
|
|
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
|
import EmbeddedRecordsMixin from 'ember-data/serializers/embedded-records-mixin';
|
|
import {pluralize} from 'ember-inflector';
|
|
|
|
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
|
|
// settings for the EmbeddedRecordsMixin.
|
|
attrs: {
|
|
authors: {embedded: 'always'},
|
|
tags: {embedded: 'always'},
|
|
publishedAtUTC: {key: 'published_at'},
|
|
createdAtUTC: {key: 'created_at'},
|
|
updatedAtUTC: {key: 'updated_at'}
|
|
},
|
|
|
|
normalizeSingleResponse(store, primaryModelClass, payload) {
|
|
let root = this.keyForAttribute(primaryModelClass.modelName);
|
|
let pluralizedRoot = pluralize(primaryModelClass.modelName);
|
|
|
|
if (payload[pluralizedRoot]) {
|
|
payload[root] = payload[pluralizedRoot][0];
|
|
delete payload[pluralizedRoot];
|
|
}
|
|
|
|
return this._super(...arguments);
|
|
},
|
|
|
|
normalizeArrayResponse() {
|
|
return this._super(...arguments);
|
|
},
|
|
|
|
serializeIntoHash(hash, type, record, options) {
|
|
options = options || {};
|
|
options.includeId = true;
|
|
|
|
// We have a plural root in the API
|
|
let root = pluralize(type.modelName);
|
|
|
|
// TODO: this is throwing a warning when saving a new post:
|
|
// The embedded relationship 'tags' is undefined for 'post' with id 'null'.
|
|
// Please include it in your original payload.
|
|
//
|
|
// This appears to be an issue in Ember Data - needs further investigation
|
|
// and possibly an issue raised
|
|
let data = this.serialize(record, options);
|
|
|
|
// Properties that exist on the model but we don't want sent in the payload
|
|
|
|
delete data.uuid;
|
|
delete data.html;
|
|
// Inserted locally as a convenience.
|
|
delete data.author_id;
|
|
// Read-only virtual property.
|
|
delete data.url;
|
|
// Deprecated property (replaced with data.authors)
|
|
delete data.author;
|
|
|
|
hash[root] = [data];
|
|
}
|
|
});
|