From d87191f17ee1cd49def9ca5a4d3d1568b041e6a2 Mon Sep 17 00:00:00 2001 From: Pouyan Savoli Date: Wed, 30 Aug 2017 02:54:54 +0200 Subject: card model and card ui preparation for custom fields --- models/cards.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'models/cards.js') diff --git a/models/cards.js b/models/cards.js index 0a440697..6896970c 100644 --- a/models/cards.js +++ b/models/cards.js @@ -38,6 +38,21 @@ Cards.attachSchema(new SimpleSchema({ } }, }, + customFields: { + type: [Object], + optional: true, + }, + 'customFields.$': { + type: new SimpleSchema({ + _id: { + type: String, + }, + value: { + type: Match.OneOf(String,Number,Boolean,Date), + optional: true, + }, + }) + }, dateLastActivity: { type: Date, autoValue() { @@ -238,6 +253,24 @@ Cards.mutations({ } }, + assignCustomField(customFieldId) { + console.log("assignCustomField", customFieldId); + return {$push: {customFields: {_id: customFieldId, value: null}}}; + }, + + unassignCustomField(customFieldId) { + console.log("unassignCustomField", customFieldId); + return {$pull: {customFields: {_id: customFieldId}}}; + }, + + toggleCustomField(customFieldId) { + if (this.customFields && this.customFields[customFieldId]) { + return this.unassignCustomField(customFieldId); + } else { + return this.assignCustomField(customFieldId); + } + }, + setCover(coverId) { return {$set: {coverId}}; }, -- cgit v1.2.3-1-g7c22 From 733b14dcd8f4b94047ffd444e7ab7ded49c245c0 Mon Sep 17 00:00:00 2001 From: Pouyan Savoli Date: Wed, 30 Aug 2017 03:23:57 +0200 Subject: card model and card ui preparation for custom fields #2 --- models/cards.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'models/cards.js') diff --git a/models/cards.js b/models/cards.js index 6896970c..670a47cb 100644 --- a/models/cards.js +++ b/models/cards.js @@ -186,6 +186,10 @@ Cards.helpers({ return this.checklistItemCount() !== 0; }, + customFieldIndex(customFieldId) { + return _.pluck(this.customFields, '_id').indexOf(customFieldId); + }, + absoluteUrl() { const board = this.board(); return FlowRouter.url('card', { @@ -255,7 +259,7 @@ Cards.mutations({ assignCustomField(customFieldId) { console.log("assignCustomField", customFieldId); - return {$push: {customFields: {_id: customFieldId, value: null}}}; + return {$addToSet: {customFields: {_id: customFieldId, value: null}}}; }, unassignCustomField(customFieldId) { @@ -264,7 +268,7 @@ Cards.mutations({ }, toggleCustomField(customFieldId) { - if (this.customFields && this.customFields[customFieldId]) { + if (this.customFields && this.customFieldIndex(customFieldId) > -1) { return this.unassignCustomField(customFieldId); } else { return this.assignCustomField(customFieldId); -- cgit v1.2.3-1-g7c22 From 6ff89b43b61ace7ea26d50f091ea6b714fa79c84 Mon Sep 17 00:00:00 2001 From: Pouyan Savoli Date: Tue, 5 Sep 2017 02:34:18 +0200 Subject: show custom fields on cards but still with dummy value --- models/cards.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'models/cards.js') diff --git a/models/cards.js b/models/cards.js index 670a47cb..fe86e642 100644 --- a/models/cards.js +++ b/models/cards.js @@ -190,6 +190,27 @@ Cards.helpers({ return _.pluck(this.customFields, '_id').indexOf(customFieldId); }, + // customFields with definitions + customFieldsWD() { + + // get all definitions + const definitions = CustomFields.find({ + boardId: this.boardId, + }).fetch(); + + // match right definition to each field + return this.customFields.map((customField) => { + return { + _id: customField._id, + value: customField.value, + definition: definitions.find((definition) => { + return definition._id == customField._id; + }) + } + }); + + }, + absoluteUrl() { const board = this.board(); return FlowRouter.url('card', { -- cgit v1.2.3-1-g7c22 From caad952bc1b29bb925c1347a14daa5d1ec8ada81 Mon Sep 17 00:00:00 2001 From: Pouyan Savoli Date: Thu, 14 Sep 2017 00:50:05 +0200 Subject: text custom fields are now editable using inlinedForm --- models/cards.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'models/cards.js') diff --git a/models/cards.js b/models/cards.js index fe86e642..17abf430 100644 --- a/models/cards.js +++ b/models/cards.js @@ -279,12 +279,10 @@ Cards.mutations({ }, assignCustomField(customFieldId) { - console.log("assignCustomField", customFieldId); return {$addToSet: {customFields: {_id: customFieldId, value: null}}}; }, unassignCustomField(customFieldId) { - console.log("unassignCustomField", customFieldId); return {$pull: {customFields: {_id: customFieldId}}}; }, @@ -296,6 +294,16 @@ Cards.mutations({ } }, + setCustomField(customFieldId, value) { + // todo + const index = this.customFieldIndex(customFieldId); + if (index > -1) { + var update = {$set: {}}; + update.$set["customFields." + index + ".value"] = value; + return update; + } + }, + setCover(coverId) { return {$set: {coverId}}; }, -- cgit v1.2.3-1-g7c22 From d6cfac0122dc5e6819c82f73c728488e0600cb70 Mon Sep 17 00:00:00 2001 From: Ignatz Date: Fri, 18 May 2018 10:24:51 +0200 Subject: linter corrections --- models/cards.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'models/cards.js') diff --git a/models/cards.js b/models/cards.js index 8b917ee3..d3a741bb 100644 --- a/models/cards.js +++ b/models/cards.js @@ -51,10 +51,10 @@ Cards.attachSchema(new SimpleSchema({ type: String, }, value: { - type: Match.OneOf(String,Number,Boolean,Date), + type: Match.OneOf(String, Number, Boolean, Date), optional: true, }, - }) + }), }, dateLastActivity: { type: Date, @@ -225,9 +225,9 @@ Cards.helpers({ _id: customField._id, value: customField.value, definition: definitions.find((definition) => { - return definition._id == customField._id; - }) - } + return definition._id === customField._id; + }), + }; }); }, @@ -331,10 +331,13 @@ Cards.mutations({ // todo const index = this.customFieldIndex(customFieldId); if (index > -1) { - var update = {$set: {}}; - update.$set["customFields." + index + ".value"] = value; + const update = {$set: {}}; + update.$set['customFields.${index}.value'] = value; return update; } + // TODO + // Ignatz 18.05.2018: Return null to silence ESLint. No Idea if that is correct + return null; }, setCover(coverId) { -- cgit v1.2.3-1-g7c22 From 838578657da4ed46be0e32091120c7554b07c102 Mon Sep 17 00:00:00 2001 From: Ignatz Date: Fri, 18 May 2018 10:43:43 +0200 Subject: template literals correction --- models/cards.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'models/cards.js') diff --git a/models/cards.js b/models/cards.js index d3a741bb..c77cd682 100644 --- a/models/cards.js +++ b/models/cards.js @@ -332,7 +332,7 @@ Cards.mutations({ const index = this.customFieldIndex(customFieldId); if (index > -1) { const update = {$set: {}}; - update.$set['customFields.${index}.value'] = value; + update.$set[`customFields.${index}.value`] = value; return update; } // TODO -- cgit v1.2.3-1-g7c22