Switch between OR and AND modes for the tags filter in kanban

pull/1/head
yflory 4 years ago
parent 83dde4d111
commit 6b734e7a80

@ -608,6 +608,8 @@ define([
framework._.sfCommon.openUnsafeURL(href);
};
var md = framework._.cpNfInner.metadataMgr.getPrivateData();
var _tagsAnd = Util.find(md, ['settings', 'kanban', 'tagsAnd']);
var kanban = new jKanban({
element: '#cp-app-kanban-content',
@ -615,6 +617,7 @@ define([
widthBoard: '300px',
buttonContent: '❌',
readOnly: framework.isReadOnly(),
tagsAnd: _tagsAnd,
refresh: function () {
onRedraw.fire();
},
@ -830,6 +833,17 @@ define([
boards: boards
});
framework._.cpNfInner.metadataMgr.onChange(function () {
var md = framework._.cpNfInner.metadataMgr.getPrivateData();
var tagsAnd = Util.find(md, ['settings', 'kanban', 'tagsAnd']);
if (_tagsAnd === tagsAnd) { return; }
// If the rendering has changed, update the value and redraw
kanban.options.tagsAnd = tagsAnd;
_tagsAnd = tagsAnd;
kanban.setBoards(kanban.options.boards);
});
if (migrated) { framework.localChange(); }
var addBoardDefault = document.getElementById('kanban-addboard');

@ -506,10 +506,18 @@ define([
nodeItem.appendChild(nodeItemText);
// Check if this card is filtered out
if (Array.isArray(self.options.tags) && self.options.tags.length) {
var hide = !Array.isArray(element.tags) ||
!element.tags.some(function (tag) {
return self.options.tags.indexOf(tag) !== -1;
});
var hide;
if (self.options.tagsAnd) {
hide = !Array.isArray(element.tags) ||
!self.options.tags.every(function (tag) {
return element.tags.indexOf(tag) !== -1;
});
} else {
hide = !Array.isArray(element.tags) ||
!element.tags.some(function (tag) {
return self.options.tags.indexOf(tag) !== -1;
});
}
if (hide) {
nodeItem.classList.add('kanban-item-hidden');
}

@ -167,7 +167,7 @@
}
}
.cp-settings-autostore-radio {
.cp-settings-radio-container {
display: flex;
align-items: center;
flex-wrap: wrap;

@ -86,6 +86,9 @@ define([
'cp-settings-code-font-size',
'cp-settings-code-spellcheck',
],
'kanban': [
'cp-settings-kanban-tags',
],
'subscription': {
onClick: function() {
var urls = common.getMetadataMgr().getPrivateData().accounts;
@ -290,7 +293,7 @@ define([
input: { value: 1 },
label: { class: 'noTitle' }
});
var $div2 = $(h('div.cp-settings-autostore-radio', [
var $div2 = $(h('div.cp-settings-radio-container', [
opt3,
opt2,
opt1
@ -1470,6 +1473,52 @@ define([
};
Messages.settings_kanbanTagsTitle = "Kanban tags filter"; // XXX
Messages.settings_kanbanTagsHint = "Select how you want the tags filter to act when selecting multiple tags: only show cards containing all the selected tags (AND) or show cards containing any of the selected tags (OR)"; // XXX
Messages.settings_kanbanTagsAnd = "AND";
Messages.settings_kanbanTagsOr = "OR";
Messages.settings_cat_kanban = "Kanban";
makeBlock('kanban-tags', function(cb) {
var opt1 = UI.createRadio('cp-settings-kanban-tags', 'cp-settings-kanban-tags-and',
Messages.settings_kanbanTagsAnd, false, {
input: { value: 1 },
label: { class: 'noTitle' }
});
var opt2 = UI.createRadio('cp-settings-kanban-tags', 'cp-settings-kanban-tags-or',
Messages.settings_kanbanTagsOr, true, {
input: { value: 0 },
label: { class: 'noTitle' }
});
var div = h('div.cp-settings-radio-container', [
opt1,
opt2,
]);
var $d = $(div);
var spinner = UI.makeSpinner($d);
$d.find('input[type="radio"]').on('change', function() {
spinner.spin();
var val = $('input:radio[name="cp-settings-kanban-tags"]:checked').val();
val = Number(val) || 0;
common.setAttribute(['kanban', 'tagsAnd'], val, function() {
spinner.done();
});
});
common.getAttribute(['kanban', 'tagsAnd'], function(e, val) {
if (e) { return void console.error(e); }
if (val) {
$(opt1).find('input').attr('checked', 'checked');
}
});
cb($d);
}, true);
// Settings app
var createUsageButton = function() {

Loading…
Cancel
Save