summaryrefslogtreecommitdiffstats
path: root/client/components/lists
diff options
context:
space:
mode:
authorXavier Priour <xavier.priour@bubblyware.com>2015-10-14 10:54:42 +0200
committerMaxime Quandalle <maxime@quandalle.com>2015-10-14 23:23:16 +0200
commit68518f549719d4c150acc920197587425f2de341 (patch)
tree2134098d3449e1b0397af060a8997b6f07f100fb /client/components/lists
parent432c1ebb5d9165b9c63b10ef489c6f9e84470e72 (diff)
downloadwekan-68518f549719d4c150acc920197587425f2de341.tar.gz
wekan-68518f549719d4c150acc920197587425f2de341.tar.bz2
wekan-68518f549719d4c150acc920197587425f2de341.zip
Import single card: map labels
Diffstat (limited to 'client/components/lists')
-rw-r--r--client/components/lists/listHeader.js43
1 files changed, 33 insertions, 10 deletions
diff --git a/client/components/lists/listHeader.js b/client/components/lists/listHeader.js
index 745d1255..b716f70c 100644
--- a/client/components/lists/listHeader.js
+++ b/client/components/lists/listHeader.js
@@ -50,14 +50,14 @@ Template.listActionPopup.events({
});
Template.listImportCardPopup.events({
- submit(evt, template) {
+ submit(evt) {
// 1. get the json data out of the form and parse it
evt.preventDefault();
const jsonData = $(evt.currentTarget).find('textarea').val();
const data = JSON.parse(jsonData);
// 2. map all fields for the card to create
const firstCardDom = $(`#js-list-${this._id} .js-minicard:first`).get(0);
- sortIndex = Utils.calculateIndex(null, firstCardDom).base;
+ const sortIndex = Utils.calculateIndex(null, firstCardDom).base;
const cardToCreate = {
title: data.name,
description: data.desc,
@@ -65,20 +65,43 @@ Template.listImportCardPopup.events({
boardId: this.boardId,
userId: Meteor.userId(),
sort: sortIndex,
- }
- // 3. insert new card into list
+ };
+ // 3. map labels
+ data.labels.forEach((current) => {
+ const color = current.color;
+ const name = current.name;
+ const existingLabel = this.board().getLabel(name, color);
+ let labelId = undefined;
+ if (existingLabel) {
+ labelId = existingLabel._id;
+ } else {
+ let labelCreated = this.board().addLabel(name, color);
+ // XXX currently mutations return no value so we have to fetch the label we just created
+ // waiting on https://github.com/mquandalle/meteor-collection-mutations/issues/1 to remove...
+ labelCreated = this.board().getLabel(name, color);
+ labelId = labelCreated._id;
+ }
+ if(labelId) {
+ if (!cardToCreate.labelIds) {
+ cardToCreate.labelIds = [];
+ }
+ cardToCreate.labelIds.push(labelId);
+ }
+ });
+ // 4. insert new card into list
const _id = Cards.insert(cardToCreate);
- // 4. parse actions and add comments/activities - if any
- data.actions.forEach((current, i, actions)=>{
- if(current.type == 'commentCard') {
+ // 5. parse actions and add comments
+ data.actions.forEach((current) => {
+ if(current.type === 'commentCard') {
const commentToCreate = {
boardId: this.boardId,
cardId: _id,
userId: Meteor.userId(),
- text: current.data.text
- }
+ text: current.data.text,
+ };
CardComments.insert(commentToCreate);
}
+ // XXX add other type of activities?
Popup.close();
});
@@ -87,7 +110,7 @@ Template.listImportCardPopup.events({
// card will disappear instantly.
// See https://github.com/wekan/wekan/issues/80
Filter.addException(_id);
- }
+ },
});
Template.listMoveCardsPopup.events({