client/tags: merging can now also add aliases

This commit is contained in:
rr- 2017-03-04 16:55:53 +01:00
parent 5681fd11ef
commit 49feb932f3
4 changed files with 32 additions and 14 deletions

View file

@ -2,12 +2,14 @@
<form> <form>
<ul class='input'> <ul class='input'>
<li class='target'> <li class='target'>
<%= ctx.makeTextInput({required: true, text: 'Target tag', pattern: ctx.tagNamePattern}) %> <%= ctx.makeTextInput({name: 'target-tag', required: true, text: 'Target tag', pattern: ctx.tagNamePattern}) %>
</li> </li>
<li> <li>
<p>Usages in posts, suggestions and implications will be <p>Usages in posts, suggestions and implications will be
merged. Category and aliases need to be handled manually.</p> merged. Category needs to be handled manually.</p>
<%= ctx.makeCheckbox({name: 'alias', text: 'Make this tag an alias of the target tag.'}) %>
<%= ctx.makeCheckbox({required: true, text: 'I confirm that I want to merge this tag.'}) %> <%= ctx.makeCheckbox({required: true, text: 'I confirm that I want to merge this tag.'}) %>
</li> </li>

View file

@ -97,16 +97,19 @@ class TagController {
_evtMerge(e) { _evtMerge(e) {
this._view.clearMessages(); this._view.clearMessages();
this._view.disableForm(); this._view.disableForm();
e.detail.tag.merge(e.detail.targetTagName).then(() => { e.detail.tag
this._view.showSuccess('Tag merged.'); .merge(e.detail.targetTagName, e.detail.addAlias)
this._view.enableForm(); .then(() => {
router.replace( this._view.showSuccess('Tag merged.');
uri.formatClientLink('tag', e.detail.targetTagName, 'merge'), this._view.enableForm();
null, false); router.replace(
}, error => { uri.formatClientLink(
this._view.showError(error.message); 'tag', e.detail.targetTagName, 'merge'),
this._view.enableForm(); null, false);
}); }, error => {
this._view.showError(error.message);
this._view.enableForm();
});
} }
_evtDelete(e) { _evtDelete(e) {

View file

@ -75,7 +75,7 @@ class Tag extends events.EventTarget {
}); });
} }
merge(targetName) { merge(targetName, addAlias) {
return api.get(uri.formatApiLink('tag', targetName)) return api.get(uri.formatApiLink('tag', targetName))
.then(response => { .then(response => {
return api.post(uri.formatApiLink('tag-merge'), { return api.post(uri.formatApiLink('tag-merge'), {
@ -84,6 +84,14 @@ class Tag extends events.EventTarget {
mergeToVersion: response.version, mergeToVersion: response.version,
mergeTo: targetName, mergeTo: targetName,
}); });
}).then(response => {
if (!addAlias) {
return Promise.resolve(response);
}
return api.put(uri.formatApiLink('tag', targetName), {
version: response.version,
names: response.names.concat(this._names),
});
}).then(response => { }).then(response => {
this._updateFromResponse(response); this._updateFromResponse(response);
this.dispatchEvent(new CustomEvent('change', { this.dispatchEvent(new CustomEvent('change', {

View file

@ -51,6 +51,7 @@ class TagMergeView extends events.EventTarget {
detail: { detail: {
tag: this._tag, tag: this._tag,
targetTagName: this._targetTagFieldNode.value, targetTagName: this._targetTagFieldNode.value,
addAlias: this._addAliasCheckboxNode.checked,
}, },
})); }));
} }
@ -60,7 +61,11 @@ class TagMergeView extends events.EventTarget {
} }
get _targetTagFieldNode() { get _targetTagFieldNode() {
return this._formNode.querySelector('.target input'); return this._formNode.querySelector('input[name=target-tag]');
}
get _addAliasCheckboxNode() {
return this._formNode.querySelector('input[name=alias]');
} }
} }