mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Merge pull request #6010 from kevinansfield/drag-drop-tags
Drag-n-drop re-ordering of tags in post settings menu
This commit is contained in:
commit
b0836febf8
3 changed files with 80 additions and 1 deletions
|
@ -3,6 +3,14 @@ import EmberSelectizeComponent from 'ember-cli-selectize/components/ember-select
|
||||||
|
|
||||||
export default EmberSelectizeComponent.extend({
|
export default EmberSelectizeComponent.extend({
|
||||||
|
|
||||||
|
selectizeOptions: Ember.computed(function () {
|
||||||
|
const options = this._super(...arguments);
|
||||||
|
|
||||||
|
options.onChange = Ember.run.bind(this, '_onChange');
|
||||||
|
|
||||||
|
return options;
|
||||||
|
}),
|
||||||
|
|
||||||
_dontOpenWhenBlank: Ember.on('didInsertElement', function () {
|
_dontOpenWhenBlank: Ember.on('didInsertElement', function () {
|
||||||
var openOnFocus = this.get('openOnFocus');
|
var openOnFocus = this.get('openOnFocus');
|
||||||
|
|
||||||
|
@ -59,6 +67,37 @@ export default EmberSelectizeComponent.extend({
|
||||||
this.sendAction('add-item', obj);
|
this.sendAction('add-item', obj);
|
||||||
this.sendAction('add-value', val);
|
this.sendAction('add-value', val);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
_onChange: function (args) {
|
||||||
|
const selection = Ember.get(this, 'selection'),
|
||||||
|
valuePath = Ember.get(this, '_valuePath');
|
||||||
|
|
||||||
|
if (!args || !selection || !Ember.isArray(selection) || args.length !== selection.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let hasNoChanges = selection.every(function (obj, idx) {
|
||||||
|
return Ember.get(obj, valuePath) === args[idx];
|
||||||
|
});
|
||||||
|
|
||||||
|
if (hasNoChanges) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let reorderedSelection = Ember.A([]);
|
||||||
|
|
||||||
|
args.forEach(function (value) {
|
||||||
|
const obj = selection.find(function (item) {
|
||||||
|
return (Ember.get(item, valuePath) + '') === value;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (obj) {
|
||||||
|
reorderedSelection.addObject(obj);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.set('selection', reorderedSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -45,7 +45,8 @@
|
||||||
optionLabelPath="content.name"
|
optionLabelPath="content.name"
|
||||||
openOnFocus=false
|
openOnFocus=false
|
||||||
create-item="addTag"
|
create-item="addTag"
|
||||||
remove-item="removeTag"}}
|
remove-item="removeTag"
|
||||||
|
plugins="remove_button, drag_drop"}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{#unless session.user.isAuthor}}
|
{{#unless session.user.isAuthor}}
|
||||||
|
|
39
core/client/tests/unit/components/gh-selectize-test.js
Normal file
39
core/client/tests/unit/components/gh-selectize-test.js
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/* jshint expr:true */
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import {
|
||||||
|
describeComponent,
|
||||||
|
it
|
||||||
|
} from 'ember-mocha';
|
||||||
|
import Ember from 'ember';
|
||||||
|
|
||||||
|
const {run} = Ember;
|
||||||
|
|
||||||
|
describeComponent(
|
||||||
|
'gh-selectize',
|
||||||
|
'Unit: Component: gh-selectize',
|
||||||
|
{
|
||||||
|
// Specify the other units that are required for this test
|
||||||
|
// needs: ['component:foo', 'helper:bar'],
|
||||||
|
unit: true
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
it('re-orders selection when selectize order is changed', function () {
|
||||||
|
const component = this.subject();
|
||||||
|
|
||||||
|
run(() => {
|
||||||
|
component.set('content', Ember.A(['item 1', 'item 2', 'item 3']));
|
||||||
|
component.set('selection', Ember.A(['item 2', 'item 3']));
|
||||||
|
component.set('multiple', true);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.render();
|
||||||
|
|
||||||
|
run(() => {
|
||||||
|
component._selectize.setValue(['item 3', 'item 2']);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(component.get('value'), 'component value').to.deep.equal(['item 3', 'item 2']);
|
||||||
|
expect(component.get('selection'), 'component selection').to.deep.equal(['item 3', 'item 2']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
Loading…
Add table
Reference in a new issue