Ver Fonte

Copy card at card details copies now attachments

Martin Filser há 2 anos atrás
pai
commit
e37bf2b51d
2 ficheiros alterados com 35 adições e 11 exclusões
  1. 1 11
      client/components/cards/cardDetails.js
  2. 34 0
      models/cards.js

+ 1 - 11
client/components/cards/cardDetails.js

@@ -1035,18 +1035,8 @@ class DialogWithBoardSwimlaneList extends BlazeComponent {
     const title = textarea.val().trim();
     const title = textarea.val().trim();
 
 
     if (title) {
     if (title) {
-      const oldTitle = card.title;
-      card.title = title;
-      card.coverId = '';
-
       // insert new card to the top of new list
       // insert new card to the top of new list
-      const minOrder = card.getMinSort(listId, swimlaneId);
-      card.sort = minOrder - 1;
-
-      const newCardId = card.copy(boardId, swimlaneId, listId);
-
-      // restore the old card title, otherwise the card title would change in the current view (only temporary)
-      card.title = oldTitle;
+      const newCardId = Meteor.call('copyCard', card._id, boardId, swimlaneId, listId, true, {title: title});
 
 
       // In case the filter is active we need to add the newly inserted card in
       // In case the filter is active we need to add the newly inserted card in
       // the list of exceptions -- cards that are not filtered. Otherwise the
       // the list of exceptions -- cards that are not filtered. Otherwise the

+ 34 - 0
models/cards.js

@@ -3038,6 +3038,40 @@ const addCronJob = _.debounce(
 );
 );
 
 
 if (Meteor.isServer) {
 if (Meteor.isServer) {
+  Meteor.methods({
+    /** copies a card
+     * <li> this method is needed on the server because attachments can only be copied on the server (access to file system)
+     * @param card id to copy
+     * @param boardId copy to this board
+     * @param swimlandeId copy to this swimlane id
+     * @param listId copy to this list id
+     * @param insertAtTop insert the card at the top?
+     * @param mergeCardValues this values into the copied card
+     * @return the new card id
+     */
+    copyCard(cardId, boardId, swimlaneId, listId, insertAtTop, mergeCardValues) {
+      check(cardId, String);
+      check(boardId, String);
+      check(swimlaneId, String);
+      check(listId, String);
+      check(insertAtTop, Boolean);
+      check(mergeCardValues, Object);
+
+      const card = Cards.findOne({_id: cardId});
+      Object.assign(card, mergeCardValues);
+
+      const sort = card.getSort(listId, swimlaneId, insertAtTop);
+      if (insertAtTop) {
+        card.sort = sort - 1;
+      } else
+      {
+        card.sort = sort + 1;
+      }
+
+      const ret = card.copy(boardId, swimlaneId, listId);
+      return ret;
+    },
+  });
   // Cards are often fetched within a board, so we create an index to make these
   // Cards are often fetched within a board, so we create an index to make these
   // queries more efficient.
   // queries more efficient.
   Meteor.startup(() => {
   Meteor.startup(() => {