mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
fix(psm): fix author dropdown in post-settings-menu
closes https://github.com/TryGhost/Ghost/issues/8122 - because the PSM is now a component, some of the component lifecycle hooks can be employed to load things
This commit is contained in:
parent
4a1c548e5b
commit
ed843718b2
4 changed files with 53 additions and 28 deletions
|
@ -4,7 +4,6 @@ import computed, {alias} from 'ember-computed';
|
||||||
import {guidFor} from 'ember-metal/utils';
|
import {guidFor} from 'ember-metal/utils';
|
||||||
import injectService from 'ember-service/inject';
|
import injectService from 'ember-service/inject';
|
||||||
import {htmlSafe} from 'ember-string';
|
import {htmlSafe} from 'ember-string';
|
||||||
import observer from 'ember-metal/observer';
|
|
||||||
|
|
||||||
import {invokeAction} from 'ember-invoke-action';
|
import {invokeAction} from 'ember-invoke-action';
|
||||||
|
|
||||||
|
@ -13,10 +12,11 @@ import SettingsMenuMixin from 'ghost-admin/mixins/settings-menu-component';
|
||||||
import boundOneWay from 'ghost-admin/utils/bound-one-way';
|
import boundOneWay from 'ghost-admin/utils/bound-one-way';
|
||||||
import isNumber from 'ghost-admin/utils/isNumber';
|
import isNumber from 'ghost-admin/utils/isNumber';
|
||||||
|
|
||||||
const {ArrayProxy, Handlebars, PromiseProxyMixin} = Ember;
|
const {Handlebars} = Ember;
|
||||||
|
|
||||||
export default Component.extend(SettingsMenuMixin, {
|
export default Component.extend(SettingsMenuMixin, {
|
||||||
selectedAuthor: null,
|
selectedAuthor: null,
|
||||||
|
authors: [],
|
||||||
|
|
||||||
store: injectService(),
|
store: injectService(),
|
||||||
config: injectService(),
|
config: injectService(),
|
||||||
|
@ -26,34 +26,22 @@ export default Component.extend(SettingsMenuMixin, {
|
||||||
session: injectService(),
|
session: injectService(),
|
||||||
timeZone: injectService(),
|
timeZone: injectService(),
|
||||||
|
|
||||||
initializeSelectedAuthor: observer('model', function () {
|
|
||||||
return this.get('model.author').then((author) => {
|
|
||||||
this.set('selectedAuthor', author);
|
|
||||||
return author;
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
|
|
||||||
authors: computed(function () {
|
|
||||||
// Loaded asynchronously, so must use promise proxies.
|
|
||||||
let deferred = {};
|
|
||||||
|
|
||||||
deferred.promise = this.get('store').query('user', {limit: 'all'}).then((users) => {
|
|
||||||
return users.rejectBy('id', 'me').sortBy('name');
|
|
||||||
}).then((users) => {
|
|
||||||
return users.filter((user) => {
|
|
||||||
return user.get('active');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return ArrayProxy
|
|
||||||
.extend(PromiseProxyMixin)
|
|
||||||
.create(deferred);
|
|
||||||
}),
|
|
||||||
|
|
||||||
slugValue: boundOneWay('model.slug'),
|
slugValue: boundOneWay('model.slug'),
|
||||||
metaTitleScratch: alias('model.metaTitleScratch'),
|
metaTitleScratch: alias('model.metaTitleScratch'),
|
||||||
metaDescriptionScratch: alias('model.metaDescriptionScratch'),
|
metaDescriptionScratch: alias('model.metaDescriptionScratch'),
|
||||||
|
|
||||||
|
didReceiveAttrs() {
|
||||||
|
this._super(...arguments);
|
||||||
|
|
||||||
|
this.get('store').query('user', {limit: 'all'}).then((users) => {
|
||||||
|
this.set('authors', users.sortBy('name'));
|
||||||
|
});
|
||||||
|
|
||||||
|
this.get('model.author').then((author) => {
|
||||||
|
this.set('selectedAuthor', author);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
seoTitle: computed('model.titleScratch', 'metaTitleScratch', function () {
|
seoTitle: computed('model.titleScratch', 'metaTitleScratch', function () {
|
||||||
let metaTitle = this.get('metaTitleScratch') || '';
|
let metaTitle = this.get('metaTitleScratch') || '';
|
||||||
|
|
||||||
|
|
|
@ -68,12 +68,12 @@
|
||||||
<span class="input-icon icon-user">
|
<span class="input-icon icon-user">
|
||||||
<span class="gh-select" tabindex="0">
|
<span class="gh-select" tabindex="0">
|
||||||
{{one-way-select
|
{{one-way-select
|
||||||
|
selectedAuthor
|
||||||
id="author-list"
|
id="author-list"
|
||||||
name="post-setting-author"
|
name="post-setting-author"
|
||||||
options=authors
|
options=authors
|
||||||
optionValuePath="id"
|
optionValuePath="id"
|
||||||
optionLabelPath="name"
|
optionLabelPath="name"
|
||||||
value=selectedAuthor
|
|
||||||
update=(action "changeAuthor")
|
update=(action "changeAuthor")
|
||||||
}}
|
}}
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -51,7 +51,18 @@ export default function mockPosts(server) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
server.put('/posts/:id/');
|
// Handle embedded author in post
|
||||||
|
server.put('/posts/:id/', ({posts}, request) => {
|
||||||
|
let {posts: [post]} = JSON.parse(request.requestBody);
|
||||||
|
let {author} = post;
|
||||||
|
delete post.author;
|
||||||
|
|
||||||
|
let savedPost = posts.find(request.params.id).update(post);
|
||||||
|
savedPost.authorId = author;
|
||||||
|
savedPost.save();
|
||||||
|
|
||||||
|
return savedPost;
|
||||||
|
});
|
||||||
|
|
||||||
server.del('/posts/:id/');
|
server.del('/posts/:id/');
|
||||||
}
|
}
|
||||||
|
|
|
@ -506,5 +506,31 @@ describe('Acceptance: Editor', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('shows author list and allows switching of author in PSM', function () {
|
||||||
|
server.create('post', {authorId: 1});
|
||||||
|
let role = server.create('role', {name: 'Author'});
|
||||||
|
let author = server.create('user', {name: 'Waldo', roles: [role]});
|
||||||
|
|
||||||
|
visit('/editor/1');
|
||||||
|
|
||||||
|
andThen(() => {
|
||||||
|
expect(currentURL(), 'currentURL')
|
||||||
|
.to.equal('/editor/1');
|
||||||
|
});
|
||||||
|
|
||||||
|
click('button.post-settings');
|
||||||
|
|
||||||
|
andThen(() => {
|
||||||
|
expect(find('select[name="post-setting-author"]').val()).to.equal('1');
|
||||||
|
expect(find('select[name="post-setting-author"] option[value="2"]')).to.be.ok;
|
||||||
|
});
|
||||||
|
|
||||||
|
fillIn('select[name="post-setting-author"]', '2');
|
||||||
|
|
||||||
|
andThen(() => {
|
||||||
|
expect(find('select[name="post-setting-author"]').val()).to.equal('2');
|
||||||
|
expect(server.db.posts[0].authorId).to.equal(author.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue