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;
};
UIElements.updateTags = function (common, href) {
UIElements.updateTags = function (common, hrefs) {
var existing, tags;
var allTags = {};
if (!hrefs || typeof (hrefs) === "string") {
hrefs = [hrefs];
}
NThen(function(waitFor) {
common.getSframeChannel().query("Q_GET_ALL_TAGS", null, waitFor(function(err, res) {
if (err || res.error) { return void console.error(err || res.error); }
existing = Object.keys(res.tags).sort();
}));
}).nThen(function (waitFor) {
var _err;
hrefs.forEach(function (href) {
common.getPadAttribute('tags', waitFor(function (err, res) {
if (err) {
if (err === 'NO_ENTRY') {
UI.alert(Messages.tags_noentry);
}
waitFor.abort();
_err = 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 || [];
}
}), href);
});
}).nThen(function () {
UI.dialog.tagPrompt(tags, existing, function (newTags) {
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('rename');
hide.push('openparent');
hide.push('hashtag');
hide.push('download');
hide.push('share');
hide.push('savelocal');
@ -4370,12 +4369,12 @@ define([
});
}
else if ($this.hasClass("cp-app-drive-context-hashtag")) {
if (paths.length !== 1) { return; }
el = manager.find(paths[0].path);
data = manager.getFileData(el);
if (!data) { return void console.error("Expected to find a file"); }
var href = data.href || data.roHref;
common.updateTags(href);
var hrefs = paths.map(function (p) {
var el = manager.find(p.path);
var data = manager.getFileData(el);
return data.href || data.roHref;
}).filter(Boolean);
common.updateTags(hrefs);
}
else if ($this.hasClass("cp-app-drive-context-empty")) {
if (paths.length !== 1 || !paths[0].element

Loading…
Cancel
Save