client/tags: merging can now also add aliases
This commit is contained in:
parent
5681fd11ef
commit
49feb932f3
4 changed files with 32 additions and 14 deletions
|
@ -2,12 +2,14 @@
|
|||
<form>
|
||||
<ul class='input'>
|
||||
<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>
|
||||
<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.'}) %>
|
||||
</li>
|
||||
|
|
|
@ -97,11 +97,14 @@ class TagController {
|
|||
_evtMerge(e) {
|
||||
this._view.clearMessages();
|
||||
this._view.disableForm();
|
||||
e.detail.tag.merge(e.detail.targetTagName).then(() => {
|
||||
e.detail.tag
|
||||
.merge(e.detail.targetTagName, e.detail.addAlias)
|
||||
.then(() => {
|
||||
this._view.showSuccess('Tag merged.');
|
||||
this._view.enableForm();
|
||||
router.replace(
|
||||
uri.formatClientLink('tag', e.detail.targetTagName, 'merge'),
|
||||
uri.formatClientLink(
|
||||
'tag', e.detail.targetTagName, 'merge'),
|
||||
null, false);
|
||||
}, error => {
|
||||
this._view.showError(error.message);
|
||||
|
|
|
@ -75,7 +75,7 @@ class Tag extends events.EventTarget {
|
|||
});
|
||||
}
|
||||
|
||||
merge(targetName) {
|
||||
merge(targetName, addAlias) {
|
||||
return api.get(uri.formatApiLink('tag', targetName))
|
||||
.then(response => {
|
||||
return api.post(uri.formatApiLink('tag-merge'), {
|
||||
|
@ -84,6 +84,14 @@ class Tag extends events.EventTarget {
|
|||
mergeToVersion: response.version,
|
||||
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 => {
|
||||
this._updateFromResponse(response);
|
||||
this.dispatchEvent(new CustomEvent('change', {
|
||||
|
|
|
@ -51,6 +51,7 @@ class TagMergeView extends events.EventTarget {
|
|||
detail: {
|
||||
tag: this._tag,
|
||||
targetTagName: this._targetTagFieldNode.value,
|
||||
addAlias: this._addAliasCheckboxNode.checked,
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
@ -60,7 +61,11 @@ class TagMergeView extends events.EventTarget {
|
|||
}
|
||||
|
||||
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]');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue