mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-02 07:43:11 +03:00
Preserve order of tags as entered by the user.
Closes #3133 - Implement an ordered set for the tags property of the tag input controller. Set order is by order added to the post.
This commit is contained in:
parent
6c76b080bb
commit
d75483e4a8
@ -1,6 +1,33 @@
|
||||
var PostTagsInputController = Ember.Controller.extend({
|
||||
|
||||
tags: Ember.computed.alias('parentController.tags'),
|
||||
tagEnteredOrder: Ember.A(),
|
||||
|
||||
tags: Ember.computed('parentController.tags', function () {
|
||||
var proxyTags = Ember.ArrayProxy.create({
|
||||
content: this.get('parentController.tags')
|
||||
}),
|
||||
|
||||
temp = proxyTags.get('arrangedContent').slice();
|
||||
|
||||
proxyTags.get('arrangedContent').clear();
|
||||
|
||||
this.get('tagEnteredOrder').forEach(function (tagName) {
|
||||
var tag = temp.find(function (tag) {
|
||||
return tag.get('name') === tagName;
|
||||
});
|
||||
|
||||
if (tag) {
|
||||
proxyTags.get('arrangedContent').addObject(tag);
|
||||
temp.removeObject(tag);
|
||||
}
|
||||
});
|
||||
|
||||
temp.forEach(function (tag) {
|
||||
proxyTags.get('arrangedContent').addObject(tag);
|
||||
});
|
||||
|
||||
return proxyTags;
|
||||
}),
|
||||
|
||||
suggestions: null,
|
||||
newTagText: null,
|
||||
@ -36,21 +63,25 @@ var PostTagsInputController = Ember.Controller.extend({
|
||||
// otherwise create a new one
|
||||
newTag = this.store.createRecord('tag');
|
||||
newTag.set('name', newTagText);
|
||||
this.get('tags').pushObject(newTag);
|
||||
|
||||
this.send('addTag', newTag);
|
||||
}
|
||||
|
||||
this.send('reset');
|
||||
},
|
||||
|
||||
addTag: function (tag) {
|
||||
if (!Ember.isEmpty(tag) && !this.hasTag(tag.get('name'))) {
|
||||
this.get('tags').pushObject(tag);
|
||||
if (!Ember.isEmpty(tag)) {
|
||||
this.get('tags').addObject(tag);
|
||||
this.get('tagEnteredOrder').addObject(tag.get('name'));
|
||||
}
|
||||
|
||||
this.send('reset');
|
||||
},
|
||||
|
||||
deleteTag: function (tag) {
|
||||
this.get('tags').removeObject(tag);
|
||||
this.get('tagEnteredOrder').removeObject(tag.get('name'));
|
||||
},
|
||||
|
||||
deleteLastTag: function () {
|
||||
|
@ -1,6 +1,6 @@
|
||||
<label class="tag-label" for="tags" title="Tags"><span class="hidden">Tags</span></label>
|
||||
<div class="tags">
|
||||
{{#each tags}}
|
||||
{{#each controller.tags}}
|
||||
{{#view view.tagView tag=this}}
|
||||
{{view.tag.name}}
|
||||
{{/view}}
|
||||
|
Loading…
Reference in New Issue
Block a user