diff options
author | Angelo Gallarello <angelo.gallarell@gmail.com> | 2018-09-14 16:49:06 +0200 |
---|---|---|
committer | Angelo Gallarello <angelo.gallarell@gmail.com> | 2018-09-14 16:49:06 +0200 |
commit | fc73dc5bbcbbd203efc4f10ecb4bd1a66e0d9efb (patch) | |
tree | f1c2af072fb0c80ea031188f53cdf2c9f23efbf4 /models | |
parent | e649c79bb71140a15f8e65fdb98ecb367469c0b7 (diff) | |
download | wekan-fc73dc5bbcbbd203efc4f10ecb4bd1a66e0d9efb.tar.gz wekan-fc73dc5bbcbbd203efc4f10ecb4bd1a66e0d9efb.tar.bz2 wekan-fc73dc5bbcbbd203efc4f10ecb4bd1a66e0d9efb.zip |
Refactoring rules description
Diffstat (limited to 'models')
-rw-r--r-- | models/actions.js | 103 | ||||
-rw-r--r-- | models/triggers.js | 88 |
2 files changed, 164 insertions, 27 deletions
diff --git a/models/actions.js b/models/actions.js index da9b30fb..fd1d03e0 100644 --- a/models/actions.js +++ b/models/actions.js @@ -2,15 +2,100 @@ Actions = new Mongo.Collection('actions'); Actions.allow({ - insert(userId, doc) { - return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); - }, - update(userId, doc) { - return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); - }, - remove(userId, doc) { - return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); - } + insert(userId, doc) { + return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); + }, + update(userId, doc) { + return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); + }, + remove(userId, doc) { + return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId)); + } +}); + + +Actions.helpers({ + description() { + if(this.actionType == "moveCardToTop"){ + if(this.listTitle == "*"){ + return TAPi18n.__('r-d-move-to-top-gen'); + }else{ + return TAPi18n.__('r-d-move-to-top-spec') + " " + this.listTitle; + } + } + if(this.actionType == "moveCardToBottom"){ + if(this.listTitle == "*"){ + return TAPi18n.__('r-d-move-to-bottom-gen'); + }else{ + return TAPi18n.__('r-d-move-to-bottom-spec') + " " + this.listTitle; + } + } + if(this.actionType == "sendEmail"){ + const to = " " + TAPi18n.__('r-d-send-email-to') + ": " + this.emailTo + ", "; + const subject = TAPi18n.__('r-d-send-email-subject') + ": " + this.emailSubject + ", "; + const message = TAPi18n.__('r-d-send-email-message') + ": " + this.emailMsg; + const total = TAPi18n.__('r-d-send-email') + to + subject + message; + return total; + } + if(this.actionType == "archive"){ + return TAPi18n.__('r-d-archive'); + } + if(this.actionType == "unarchive"){ + return TAPi18n.__('r-d-unarchive'); + } + if(this.actionType == "addLabel"){ + const board = Boards.findOne(Session.get('currentBoard')); + const label = board.getLabelById(this.labelId); + let name; + if(label.name == "" || label.name == undefined){ + name = label.color.toUpperCase(); + }else{ + name = label.name; + } + + return TAPi18n.__('r-d-add-label') + ": "+name; + } + if(this.actionType == "removeLabel"){ + const board = Boards.findOne(Session.get('currentBoard')); + const label = board.getLabelById(this.labelId); + let name; + if(label.name == "" || label.name == undefined){ + name = label.color.toUpperCase(); + }else{ + name = label.name; + } + return TAPi18n.__('r-d-remove-label') + ": " + name; + } + if(this.actionType == "addMember"){ + return TAPi18n.__('r-d-add-member') + ": " + this.memberName; + } + if(this.actionType == "removeMember"){ + if(this.memberName == "*"){ + return TAPi18n.__('r-d-remove-all-member'); + } + return TAPi18n.__('r-d-remove-member') + ": "+ this.memberName; + } + if(this.actionType == "checkAll"){ + return TAPi18n.__('r-d-check-all') + ": " + this.checklistName; + } + if(this.actionType == "uncheckAll"){ + return TAPi18n.__('r-d-uncheck-all') + ": "+ this.checklistName; + } + if(this.actionType == "checkItem"){ + return TAPi18n.__('r-d-check-one') + ": "+ this.checkItemName + " " + TAPi18n.__('r-d-check-of-list') + ": " +this.checklistName; + } + if(this.actionType == "uncheckItem"){ + return TAPi18n.__('r-d-check-one') + ": "+ this.checkItemName + " " + TAPi18n.__('r-d-check-of-list') + ": " +this.checklistName; + } + if(this.actionType == "addChecklist"){ + return TAPi18n.__('r-d-add-checklist') + ": "+ this.checklistName; + } + if(this.actionType == "removeChecklist"){ + return TAPi18n.__('r-d-remove-checklist') + ": "+ this.checklistName; + } + + return "Ops not trigger description"; + } }); diff --git a/models/triggers.js b/models/triggers.js index a1437ea6..c5ed849e 100644 --- a/models/triggers.js +++ b/models/triggers.js @@ -24,28 +24,80 @@ Triggers.allow({ Triggers.helpers({ - getRule(){ - return Rules.findOne({triggerId:this._id}); - }, + description(){ + if(this.activityType == "createCard"){ + if(this.listName == "*"){ + return TAPi18n.__('r-when-a-card-is') + " " + TAPi18n.__('r-added-to').toLowerCase() + " " + TAPi18n.__('r-the-board'); + }else{ + return TAPi18n.__('r-when-a-card-is') + " " + TAPi18n.__('r-added-to').toLowerCase() + " " + TAPi18n.__('r-list') + " " +this.listName; + } + } + if(this.activityType == "removeCard"){ + if(this.listName == "*"){ + return TAPi18n.__('r-when-a-card-is') + " " + TAPi18n.__('r-removed-from') + " " + TAPi18n.__('r-the-board'); + }else{ + return TAPi18n.__('r-when-a-card-is') + " " + TAPi18n.__('r-removed-from') + " " + TAPi18n.__('r-list') + " " +this.listName; + } + } + if(this.activityType == "moveCard"){ + if(this.listName = "*"){ + return TAPi18n.__('r-when-a-card-is') + " " + TAPi18n.__('r-moved-from') + " " + this.oldListName; + }else{ + return TAPi18n.__('r-when-a-card-is') + " " + TAPi18n.__('r-moved-to') + " " + this.listName; + } + + } + if(this.activityType = "archivedCard"){ + return TAPi18n.__('r-when-a-card-is') + " " + TAPi18n.__('r-archived'); + } + if(this.activityType = "restoredCard"){ + return TAPi18n.__('r-when-a-card-is') + " " + TAPi18n.__('r-unarchived'); + } + if(this.activityType = "addedLabel"){ + if(this.labelId == "*"){ + return TAPi18n.__('r-when-a-label-is') + " " + TAPi18n.__('r-added-to') + " " + TAPi18n.__('r-a-card'); + }else{ + const board = Boards.findOne(Session.get('currentBoard')); + const label = board.getLabelById(this.labelId); + let name; + if(label.name == "" || label.name == undefined){ + name = label.color.toUpperCase(); + }else{ + name = label.name; + } + } + } + if(this.activityType = "restoredCard"){ + return TAPi18n.__('r-when-a-card-is') + " " + TAPi18n.__('r-unarchived'); + } - fromList() { - return Lists.findOne(this.fromId); - }, - toList() { - return Lists.findOne(this.toId); - }, - findList(title) { - return Lists.findOne({title:title}); - }, + return "No description found"; +}, + +getRule(){ + return Rules.findOne({triggerId:this._id}); +}, + +fromList() { + return Lists.findOne(this.fromId); +}, + +toList() { + return Lists.findOne(this.toId); +}, + +findList(title) { + return Lists.findOne({title:title}); +}, - labels() { - const boardLabels = this.board().labels; - const cardLabels = _.filter(boardLabels, (label) => { - return _.contains(this.labelIds, label._id); - }); - return cardLabels; +labels() { + const boardLabels = this.board().labels; + const cardLabels = _.filter(boardLabels, (label) => { + return _.contains(this.labelIds, label._id); + }); + return cardLabels; }}); |