Преглед изворни кода

add option to get asked whether unsaved card descriptions should be saved to db on e.g. unintentional click out of card details pane

viehlieb пре 2 година
родитељ
комит
b3056626f3

+ 15 - 12
client/components/cards/cardDetails.js

@@ -1714,19 +1714,22 @@ BlazeComponent.extendComponent({
 EscapeActions.register(
   'detailsPane',
   () => {
-    currentDescription = document.getElementsByClassName("editor js-new-description-input").item(0)
-    //save description editing on EscapeAction
-    if (currentDescription?.value && !(currentDescription.value === Utils.getCurrentCard().getDescription()))
+    // if card description diverges from database due to editing
+    // ask user whether changes should be applied
+    if(currentUser.profile.rescueCardDescription== true)
     {
-      console.log("equal?",!(currentDescription === Utils.getCurrentCard().getDescription()));
-      if (confirm('Are you sure you want to save this thing into the database?')) {
-        Utils.getCurrentCard().setDescription(document.getElementsByClassName("editor js-new-description-input").item(0).value);
-        // Save it!
-        console.log(document.getElementsByClassName("editor js-new-description-input").item(0).value);
-        console.log("current description",Utils.getCurrentCard().getDescription());
-      } else {
-        // Do nothing!
-        console.log('Thing was not saved to the database.');
+      currentDescription = document.getElementsByClassName("editor js-new-description-input").item(0)
+      if (currentDescription?.value && !(currentDescription.value === Utils.getCurrentCard().getDescription()))
+      {
+        if (confirm(TAPi18n.__('rescue-card-description-dialogue'))) {
+          Utils.getCurrentCard().setDescription(document.getElementsByClassName("editor js-new-description-input").item(0).value);
+          // Save it!
+          console.log(document.getElementsByClassName("editor js-new-description-input").item(0).value);
+          console.log("current description",Utils.getCurrentCard().getDescription());
+        } else {
+          // Do nothing!
+          console.log('Description changes were not saved to the database.');
+        }
       }
     }
     if (Session.get('cardDetailsIsDragging')) {

+ 7 - 0
client/components/users/userHeader.jade

@@ -180,6 +180,13 @@ template(name="changeSettingsPopup")
               option(selected="true", value="#{day.value}") #{day.name}
             else
               option(value="#{day.value}") #{day.name}
+        label.bold.clear
+          {{_ 'card-settings'}}
+        ul#cards.card-description-rescued
+          a.flex.js-rescue-card-description(title="{{_ 'rescue-card-description'}}")
+            b  
+            #rescue-card-description.materialCheckBox.left(class="{{#if rescueCardDescription}}is-checked{{/if}}", value=rescueCardDescription)
+            span {{_ 'rescue-card-description'}}
         input.js-apply-user-settings.left(type="submit" value="{{_ 'apply'}}")
 
 template(name="userDeletePopup")

+ 13 - 0
client/components/users/userHeader.js

@@ -297,6 +297,16 @@ Template.changeSettingsPopup.helpers({
       return false;
     }
   },
+  rescueCardDescription() {
+    currentUser = Meteor.user();
+    if (currentUser) {
+      return (currentUser.profile || {}).rescueCardDescription;
+    } else if (window.localStorage.getItem('rescueCardDescription')) {
+      return true;
+    } else {
+      return false;
+    }
+  },
   showCardsCountAt() {
     currentUser = Meteor.user();
     if (currentUser) {
@@ -356,6 +366,9 @@ Template.changeSettingsPopup.events({
       window.localStorage.setItem('hasHiddenSystemMessages', 'true');
     }
   },
+  'click .js-rescue-card-description'() {
+    Meteor.call('toggleRescueCardDescription')
+    },
   'click .js-apply-user-settings'(event, templateInstance) {
     event.preventDefault();
     let minLimit = parseInt(

+ 4 - 1
imports/i18n/data/de.i18n.json

@@ -541,6 +541,9 @@
     "rename": "Umbenennen",
     "rename-board": "Board umbenennen",
     "restore": "Wiederherstellen",
+    "rescue-card-description": "Vor dem Schließen Dialog für ungespeicherte Änderungen von Kartenbeschreibungen anzeigen",
+    "rescue-card-description-dialogue": "Aktuelle Kartenbeschreibung mit ihren Änderungen überschreiben?",
+    "card-settings": "Karteneinstellungen",
     "save": "Speichern",
     "search": "Suchen",
     "rules": "Regeln",
@@ -1178,4 +1181,4 @@
     "action": "Aktion",
     "board-title": "Board-Titel",
     "attachmentRenamePopup-title": "Umbenennen"
-}
+}

+ 3 - 0
imports/i18n/data/en.i18n.json

@@ -541,6 +541,9 @@
   "rename": "Rename",
   "rename-board": "Rename Board",
   "restore": "Restore",
+  "rescue-card-description": "Show rescue dialogue before closing for unsaved card descriptions",
+  "rescue-card-description-dialogue": "Overwrite current card description with your changes?",
+  "card-settings":"Card Settings",
   "save": "Save",
   "search": "Search",
   "rules": "Rules",

+ 23 - 0
models/users.js

@@ -337,6 +337,13 @@ Users.attachSchema(
       type: Date,
       optional: true,
     },
+    'profile.rescueCardDescription': {
+      /**
+       * show dialog for saving card description on unintentional card closing
+       */
+      type: Boolean,
+      optional: true,
+    },
     'profile.showCardsCountAt': {
       /**
        * showCardCountAt field of the user
@@ -794,6 +801,11 @@ Users.helpers({
     return profile.hiddenMinicardLabelText || false;
   },
 
+  hasRescuedCardDescription(){
+    const profile = this.profile || {};
+    return profile.rescueCardDescription || false;
+  },
+
   getEmailBuffer() {
     const { emailBuffer = [] } = this.profile || {};
     return emailBuffer;
@@ -1004,6 +1016,13 @@ Users.mutations({
       },
     };
   },
+  toggleRescueCardDescription(value = false) {
+    return {
+      $set: {
+        'profile.rescueCardDescription': !value,
+      },
+    };
+  },
 
   addNotification(activityId) {
     return {
@@ -1103,6 +1122,10 @@ Meteor.methods({
     const user = Meteor.user();
     user.toggleLabelText(user.hasHiddenMinicardLabelText());
   },
+  toggleRescueCardDescription() {
+    const user = Meteor.user();
+    user.toggleRescueCardDescription(user.hasRescuedCardDescription());
+  },
   changeLimitToShowCardsCount(limit) {
     check(limit, Number);
     Meteor.user().setShowCardsCountAt(limit);

+ 0 - 6
package-lock.json

@@ -742,15 +742,9 @@
       "dev": true
     },
     "caniuse-lite": {
-<<<<<<< HEAD
-      "version": "1.0.30001334",
-      "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001334.tgz",
-      "integrity": "sha512-kbaCEBRRVSoeNs74sCuq92MJyGrMtjWVfhltoHUCW4t4pXFvGjUBrfo47weBRViHkiV3eBYyIsfl956NtHGazw=="
-=======
       "version": "1.0.30001352",
       "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001352.tgz",
       "integrity": "sha512-GUgH8w6YergqPQDGWhJGt8GDRnY0L/iJVQcU3eJ46GYf52R8tk0Wxp0PymuFVZboJYXGiCqwozAYZNRjVj6IcA=="
->>>>>>> ccea223ef745f0ce91d1ad98f12a6755ae8746a9
     },
     "chai": {
       "version": "4.3.6",