diff options
author | Lauri Ojansivu <x@xet7.org> | 2018-05-18 16:22:53 +0300 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2018-05-18 16:22:53 +0300 |
commit | 50f751e0a9f8214d690f6fd39136d09a46a8e69a (patch) | |
tree | 3a0e58883030abbfa8eb454d181356a8be299d79 /models/cards.js | |
parent | 61b240d126bcce7adcdb303c5b01a202dc7fa395 (diff) | |
parent | 1984a6b1c80dbd8b4eff89aa92913f943bacc63b (diff) | |
download | wekan-50f751e0a9f8214d690f6fd39136d09a46a8e69a.tar.gz wekan-50f751e0a9f8214d690f6fd39136d09a46a8e69a.tar.bz2 wekan-50f751e0a9f8214d690f6fd39136d09a46a8e69a.zip |
Merge branch 'devel' into greenkeeper/initial
Diffstat (limited to 'models/cards.js')
-rw-r--r-- | models/cards.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/models/cards.js b/models/cards.js index 01f79847..c77cd682 100644 --- a/models/cards.js +++ b/models/cards.js @@ -41,6 +41,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() { @@ -192,6 +207,31 @@ Cards.helpers({ return this.checklistItemCount() !== 0; }, + customFieldIndex(customFieldId) { + 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', { @@ -271,6 +311,35 @@ Cards.mutations({ } }, + assignCustomField(customFieldId) { + return {$addToSet: {customFields: {_id: customFieldId, value: null}}}; + }, + + unassignCustomField(customFieldId) { + return {$pull: {customFields: {_id: customFieldId}}}; + }, + + toggleCustomField(customFieldId) { + if (this.customFields && this.customFieldIndex(customFieldId) > -1) { + return this.unassignCustomField(customFieldId); + } else { + return this.assignCustomField(customFieldId); + } + }, + + setCustomField(customFieldId, value) { + // todo + const index = this.customFieldIndex(customFieldId); + if (index > -1) { + 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) { return {$set: {coverId}}; }, |