Restore "Delete All Automatic Tags" menu option for tag selector. Closes #1660

This commit is contained in:
Adomas Venčkauskas 2019-03-06 16:22:01 +02:00
parent d01038b13b
commit 72fb67d15b
3 changed files with 72 additions and 0 deletions

View file

@ -390,6 +390,43 @@ Zotero.TagSelector = class TagSelectorContainer extends React.Component {
}
}
async deleteAutomatic() {
var num = (await Zotero.Tags.getAutomaticInLibrary(this.libraryID)).length;
if (!num) {
return;
}
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var confirmed = ps.confirm(
window,
Zotero.getString('pane.tagSelector.deleteAutomatic.title'),
Zotero.getString(
'pane.tagSelector.deleteAutomatic.message',
new Intl.NumberFormat().format(num),
num
)
+ "\n\n"
+ Zotero.getString('general.actionCannotBeUndone')
);
if (confirmed) {
Zotero.showZoteroPaneProgressMeter(null, true);
try {
await Zotero.Tags.removeAutomaticFromLibrary(
this.libraryID,
(progress, progressMax) => {
Zotero.updateZoteroPaneProgressMeter(
Math.round(progress / progressMax * 100)
);
}
);
}
finally {
Zotero.hideZoteroPaneOverlays();
}
}
}
get label() {
let count = this.selectedTags.size;
let mod = count === 1 ? 'singular' : count === 0 ? 'none' : 'plural';

View file

@ -54,5 +54,9 @@
type="checkbox"
oncommand="ZoteroPane.tagSelector.toggleDisplayAllTags(); event.stopPropagation();"
/>
<menuitem id="delete-automatic-tags" label="&zotero.tagSelector.deleteAutomaticInLibrary;" type="checkbox"
oncommand="ZoteroPane.tagSelector.deleteAutomatic();
this.setAttribute('checked', false);
event.stopPropagation();"/>
</menupopup>
</overlay>

View file

@ -533,4 +533,35 @@ describe("Tag Selector", function () {
assert.notInclude(getRegularTags(), tag);
})
});
describe("#deleteAutomatic()", function() {
it('should delete automatic tags', async function() {
await selectLibrary(win);
var item = createUnsavedDataObject('item');
item.setTags([
{
tag: "automatic",
type: 1
},
{
tag: 'manual'
}
]);
var promise = waitForTagSelector(win);
await item.saveTx();
await promise;
assert.include(getRegularTags(), "automatic");
assert.include(getRegularTags(), "manual");
var dialogPromise = waitForDialog();
var tagSelectorPromise = waitForTagSelector(win);
tagSelector.deleteAutomatic();
await dialogPromise;
await tagSelectorPromise;
assert.include(getRegularTags(), 'manual');
assert.notInclude(getRegularTags(), 'automatic');
});
});
})