From 74d93a6adce66f28c9f31901c32f0d80845a8187 Mon Sep 17 00:00:00 2001 From: "John R. Supplee" Date: Fri, 22 Jan 2021 21:28:37 +0200 Subject: [PATCH] Option to add custom field to all cards --- client/components/lists/listBody.js | 2 +- .../sidebar/sidebarCustomFields.jade | 4 +++ .../components/sidebar/sidebarCustomFields.js | 10 +++++++ i18n/en.i18n.json | 3 +- models/csvCreator.js | 1 + models/customFields.js | 28 +++++++++++++++++++ models/trelloCreator.js | 1 + models/wekanCreator.js | 1 + 8 files changed, 48 insertions(+), 2 deletions(-) diff --git a/client/components/lists/listBody.js b/client/components/lists/listBody.js index c08f82673..e8c0213e1 100644 --- a/client/components/lists/listBody.js +++ b/client/components/lists/listBody.js @@ -239,7 +239,7 @@ BlazeComponent.extendComponent({ .customFields() .fetch(), function(field) { - if (field.automaticallyOnCard) + if (field.automaticallyOnCard || field.alwaysOnCard) arr.push({ _id: field._id, value: null }); }, ); diff --git a/client/components/sidebar/sidebarCustomFields.jade b/client/components/sidebar/sidebarCustomFields.jade index ffb8d2d16..3f7a3e2ee 100644 --- a/client/components/sidebar/sidebarCustomFields.jade +++ b/client/components/sidebar/sidebarCustomFields.jade @@ -59,6 +59,10 @@ template(name="createCustomFieldPopup") span {{_ 'automatically-field-on-card'}} + a.flex.js-field-always-on-card(class="{{#if alwaysOnCard}}is-checked{{/if}}") + .materialCheckBox(class="{{#if alwaysOnCard}}is-checked{{/if}}") + span {{_ 'always-field-on-card'}} + a.flex.js-field-showLabel-on-card(class="{{#if showLabelOnMiniCard}}is-checked{{/if}}") .materialCheckBox(class="{{#if showLabelOnMiniCard}}is-checked{{/if}}") diff --git a/client/components/sidebar/sidebarCustomFields.js b/client/components/sidebar/sidebarCustomFields.js index bd2ebdefd..fe1c803d8 100644 --- a/client/components/sidebar/sidebarCustomFields.js +++ b/client/components/sidebar/sidebarCustomFields.js @@ -174,6 +174,14 @@ const CreateCustomFieldPopup = BlazeComponent.extendComponent({ $target.find('.materialCheckBox').toggleClass('is-checked'); $target.toggleClass('is-checked'); }, + 'click .js-field-always-on-card'(evt) { + let $target = $(evt.target); + if (!$target.hasClass('js-field-always-on-card')) { + $target = $target.parent(); + } + $target.find('.materialCheckBox').toggleClass('is-checked'); + $target.toggleClass('is-checked'); + }, 'click .js-field-showLabel-on-card'(evt) { let $target = $(evt.target); if (!$target.hasClass('js-field-showLabel-on-card')) { @@ -194,6 +202,8 @@ const CreateCustomFieldPopup = BlazeComponent.extendComponent({ this.find('.js-field-showLabel-on-card.is-checked') !== null, automaticallyOnCard: this.find('.js-field-automatically-on-card.is-checked') !== null, + alwaysOnCard: + this.find('.js-field-always-on-card.is-checked') !== null, }; // insert or update diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index b5d1df9c7..2cd10e4d6 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -601,7 +601,8 @@ "minutes": "minutes", "seconds": "seconds", "show-field-on-card": "Show this field on card", - "automatically-field-on-card": "Auto create field to all cards", + "automatically-field-on-card": "Add field to new cards", + "always-field-on-card": "Add field to all cards", "showLabel-field-on-card": "Show field label on minicard", "yes": "Yes", "no": "No", diff --git a/models/csvCreator.js b/models/csvCreator.js index 72b8a3b44..6228c2ef9 100644 --- a/models/csvCreator.js +++ b/models/csvCreator.js @@ -147,6 +147,7 @@ export class CsvCreator { settings, showOnCard: false, automaticallyOnCard: false, + alwaysOnCard: false, showLabelOnMiniCard: false, boardIds: [boardId], }); diff --git a/models/customFields.js b/models/customFields.js index 61ed41c88..9dde200ea 100644 --- a/models/customFields.js +++ b/models/customFields.js @@ -76,6 +76,12 @@ CustomFields.attachSchema( */ type: Boolean, }, + alwaysOnCard: { + /** + * should the custom field be automatically added to all cards? + */ + type: Boolean, + }, showLabelOnMiniCard: { /** * should the label of the custom field be shown on minicards? @@ -111,6 +117,19 @@ CustomFields.attachSchema( }), ); +CustomFields.addToAllCards = cf => { + Cards.update( + { + boardId: { $in: cf.boardIds }, + customFields: { $not: { $elemMatch: { _id: cf._id } } }, + }, + { + $push: { customFields: { _id: cf._id, value: null } }, + }, + { multi: true }, + ); +}; + CustomFields.mutations({ addBoard(boardId) { if (boardId) { @@ -198,6 +217,10 @@ if (Meteor.isServer) { CustomFields.after.insert((userId, doc) => { customFieldCreation(userId, doc); + + if (doc.alwaysOnCard) { + CustomFields.addToAllCards(doc); + } }); CustomFields.before.update((userId, doc, fieldNames, modifier) => { @@ -224,6 +247,11 @@ if (Meteor.isServer) { } }); + CustomFields.after.update((userId, doc) => { + if (doc.alwaysOnCard) { + CustomFields.addToAllCards(doc); + } + }); CustomFields.before.remove((userId, doc) => { customFieldDeletion(userId, doc); Activities.remove({ diff --git a/models/trelloCreator.js b/models/trelloCreator.js index 8bc17bb2a..97ccf3b18 100644 --- a/models/trelloCreator.js +++ b/models/trelloCreator.js @@ -243,6 +243,7 @@ export class TrelloCreator { showOnCard: field.display.cardFront, showLabelOnMiniCard: field.display.cardFront, automaticallyOnCard: true, + alwaysOnCard: false, type: field.type, boardIds: [boardId], settings: {}, diff --git a/models/wekanCreator.js b/models/wekanCreator.js index 514a9d095..7abf9daba 100644 --- a/models/wekanCreator.js +++ b/models/wekanCreator.js @@ -537,6 +537,7 @@ export class WekanCreator { showOnCard: field.showOnCard, showLabelOnMiniCard: field.showLabelOnMiniCard, automaticallyOnCard: field.automaticallyOnCard, + alwaysOnCard: field.alwaysOnCard, //use date "now" if now created at date is provided (e.g. for very old boards) createdAt: this._now(this.createdAt.customFields[field._id]), modifiedAt: field.modifiedAt,