diff --git a/client/components/lists/listBody.jade b/client/components/lists/listBody.jade index b286347a9..e1e921e70 100644 --- a/client/components/lists/listBody.jade +++ b/client/components/lists/listBody.jade @@ -4,6 +4,17 @@ template(name="listBody") if cards.count +inlinedForm(autoclose=false position="top") +addCardForm(listId=_id position="top") + ul.sidebar-list + each customFieldsSum + li + +viewer + = name + if $eq customFieldsSum.type "number" + +viewer + = value + if $eq customFieldsSum.type "currency" + +viewer + = formattedCurrencyCustomFieldValue(value) each (cardsWithLimit (idOrNull ../../_id)) a.minicard-wrapper.js-minicard(href=originRelativeUrl class="{{#if cardIsSelected}}is-selected{{/if}}" diff --git a/client/components/lists/listBody.js b/client/components/lists/listBody.js index 5d1e76aa0..f29ba74ca 100644 --- a/client/components/lists/listBody.js +++ b/client/components/lists/listBody.js @@ -13,6 +13,13 @@ BlazeComponent.extendComponent({ return []; }, + customFieldsSum() { + return CustomFields.find({ + boardIds: { $in: [Session.get('currentBoard')] }, + showSumAtTopOfList: true, + }); + }, + openForm(options) { options = options || {}; options.position = options.position || 'top'; diff --git a/client/components/sidebar/sidebarCustomFields.jade b/client/components/sidebar/sidebarCustomFields.jade index d1970ef1a..339159854 100644 --- a/client/components/sidebar/sidebarCustomFields.jade +++ b/client/components/sidebar/sidebarCustomFields.jade @@ -77,6 +77,12 @@ template(name="createCustomFieldPopup") span {{_ 'showLabel-field-on-card'}} + + a.flex.js-field-show-sum-at-top-of-list(class="{{#if showSumAtTopOfList}}is-checked{{/if}}") + .materialCheckBox(class="{{#if showSumAtTopOfList}}is-checked{{/if}}") + + span {{_ 'showSum-field-on-list'}} + button.primary.wide.left(type="button") | {{_ 'save'}} if _id diff --git a/client/components/sidebar/sidebarCustomFields.js b/client/components/sidebar/sidebarCustomFields.js index 2f1fa7dd6..dcd77aa16 100644 --- a/client/components/sidebar/sidebarCustomFields.js +++ b/client/components/sidebar/sidebarCustomFields.js @@ -234,6 +234,14 @@ const CreateCustomFieldPopup = BlazeComponent.extendComponent({ $target.find('.materialCheckBox').toggleClass('is-checked'); $target.toggleClass('is-checked'); }, + 'click .js-field-show-sum-at-top-of-list'(evt) { + let $target = $(evt.target); + if (!$target.hasClass('js-field-show-sum-at-top-of-list')) { + $target = $target.parent(); + } + $target.find('.materialCheckBox').toggleClass('is-checked'); + $target.toggleClass('is-checked'); + }, 'click .primary'(evt) { evt.preventDefault(); @@ -248,6 +256,8 @@ const CreateCustomFieldPopup = BlazeComponent.extendComponent({ this.find('.js-field-automatically-on-card.is-checked') !== null, alwaysOnCard: this.find('.js-field-always-on-card.is-checked') !== null, + showSumAtTopOfList: + this.find('.js-field-show-sum-at-top-of-list.is-checked') !== null, }; // insert or update diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index ca0fdf92e..cf4f40480 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -652,6 +652,7 @@ "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", + "showSum-field-on-list": "Show sum of fields at top of list", "yes": "Yes", "no": "No", "accounts": "Accounts", diff --git a/models/customFields.js b/models/customFields.js index debd35c6a..bdde9d915 100644 --- a/models/customFields.js +++ b/models/customFields.js @@ -101,6 +101,13 @@ CustomFields.attachSchema( type: Boolean, defaultValue: false, }, + showSumAtTopOfList: { + /** + * should the sum of the custom fields be shown at top of list? + */ + type: Boolean, + defaultValue: false, + }, createdAt: { type: Date, optional: true, @@ -347,6 +354,7 @@ if (Meteor.isServer) { * @param {boolean} showOnCard should we show the custom field on cards? * @param {boolean} automaticallyOnCard should the custom fields automatically be added on cards? * @param {boolean} showLabelOnMiniCard should the label of the custom field be shown on minicards? + * @param {boolean} showSumAtTopOfList should the sum of the custom fields be shown at top of list? * @return_type {_id: string} */ JsonRoutes.add('POST', '/api/boards/:boardId/custom-fields', function( @@ -363,6 +371,7 @@ if (Meteor.isServer) { showOnCard: req.body.showOnCard, automaticallyOnCard: req.body.automaticallyOnCard, showLabelOnMiniCard: req.body.showLabelOnMiniCard, + showSumAtTopOfList: req.body.showSumAtTopOfList, boardIds: [board._id], }); @@ -390,6 +399,7 @@ if (Meteor.isServer) { * @param {boolean} showOnCard should we show the custom field on cards * @param {boolean} automaticallyOnCard should the custom fields automatically be added on cards * @param {boolean} showLabelOnMiniCard should the label of the custom field be shown on minicards + * @param {boolean} showSumAtTopOfList should the sum of the custom fields be shown at top of list * @return_type {_id: string} */ JsonRoutes.add( @@ -444,6 +454,14 @@ if (Meteor.isServer) { ); } + if (req.body.hasOwnProperty('showSumAtTopOfList')) { + CustomFields.direct.update( + { _id: paramFieldId }, + { $set: { showSumAtTopOfList: req.body.showSumAtTopOfList } }, + ); + } + + JsonRoutes.sendResult(res, { code: 200, data: { _id: paramFieldId },