Update tags for multiple pads at once

pull/1/head
yflory 5 years ago
parent a62ea39122
commit 5d111c6237

@ -46,28 +46,69 @@ define([
return mB + Messages.MB; return mB + Messages.MB;
}; };
UIElements.updateTags = function (common, href) { UIElements.updateTags = function (common, hrefs) {
var existing, tags; var existing, tags;
var allTags = {};
if (!hrefs || typeof (hrefs) === "string") {
hrefs = [hrefs];
}
NThen(function(waitFor) { NThen(function(waitFor) {
common.getSframeChannel().query("Q_GET_ALL_TAGS", null, waitFor(function(err, res) { common.getSframeChannel().query("Q_GET_ALL_TAGS", null, waitFor(function(err, res) {
if (err || res.error) { return void console.error(err || res.error); } if (err || res.error) { return void console.error(err || res.error); }
existing = Object.keys(res.tags).sort(); existing = Object.keys(res.tags).sort();
})); }));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
var _err;
hrefs.forEach(function (href) {
common.getPadAttribute('tags', waitFor(function (err, res) { common.getPadAttribute('tags', waitFor(function (err, res) {
if (err) { if (err) {
if (err === 'NO_ENTRY') { if (err === 'NO_ENTRY') {
UI.alert(Messages.tags_noentry); UI.alert(Messages.tags_noentry);
} }
waitFor.abort(); waitFor.abort();
_err = err;
return void console.error(err); return void console.error(err);
} }
allTags[href] = res || [];
if (tags) {
// Intersect with tags from previous pads
tags = (res || []).filter(function (tag) {
return tags.indexOf(tag) !== -1;
});
} else {
tags = res || []; tags = res || [];
}
}), href); }), href);
});
}).nThen(function () { }).nThen(function () {
UI.dialog.tagPrompt(tags, existing, function (newTags) { UI.dialog.tagPrompt(tags, existing, function (newTags) {
if (!Array.isArray(newTags)) { return; } if (!Array.isArray(newTags)) { return; }
common.setPadAttribute('tags', newTags, null, href); var added = [];
var removed = [];
newTags.forEach(function (tag) {
if (tags.indexOf(tag) === -1) {
added.push(tag);
}
});
tags.forEach(function (tag) {
if (newTags.indexOf(tag) === -1) {
removed.push(tag);
}
});
var update = function (oldTags) {
Array.prototype.push.apply(oldTags, added);
removed.forEach(function (tag) {
var idx = oldTags.indexOf(tag);
oldTags.splice(idx, 1);
});
};
hrefs.forEach(function (href) {
var oldTags = allTags[href] || [];
update(oldTags);
common.setPadAttribute('tags', Util.deduplicateString(oldTags), null, href);
});
}); });
}); });
}; };

@ -1294,7 +1294,6 @@ define([
hide.push('properties', 'access'); hide.push('properties', 'access');
hide.push('rename'); hide.push('rename');
hide.push('openparent'); hide.push('openparent');
hide.push('hashtag');
hide.push('download'); hide.push('download');
hide.push('share'); hide.push('share');
hide.push('savelocal'); hide.push('savelocal');
@ -4370,12 +4369,12 @@ define([
}); });
} }
else if ($this.hasClass("cp-app-drive-context-hashtag")) { else if ($this.hasClass("cp-app-drive-context-hashtag")) {
if (paths.length !== 1) { return; } var hrefs = paths.map(function (p) {
el = manager.find(paths[0].path); var el = manager.find(p.path);
data = manager.getFileData(el); var data = manager.getFileData(el);
if (!data) { return void console.error("Expected to find a file"); } return data.href || data.roHref;
var href = data.href || data.roHref; }).filter(Boolean);
common.updateTags(href); common.updateTags(hrefs);
} }
else if ($this.hasClass("cp-app-drive-context-empty")) { else if ($this.hasClass("cp-app-drive-context-empty")) {
if (paths.length !== 1 || !paths[0].element if (paths.length !== 1 || !paths[0].element

Loading…
Cancel
Save