Browse Source

add custom field "stringtemplate"

tod31 4 years ago
parent
commit
b8dc7ff18e

+ 20 - 0
client/components/cards/cardCustomFields.jade

@@ -119,3 +119,23 @@ template(name="cardCustomField-dropdown")
         if value
             +viewer
                 = selectedItem
+
+template(name="cardCustomField-stringtemplate")
+    if canModifyCard
+        +inlinedForm(classNames="js-card-customfield-stringtemplate")
+            +editor(autofocus=true)
+                = data.value
+            .edit-controls.clearfix
+                button.primary(type="submit") {{_ 'save'}}
+                a.fa.fa-times-thin.js-close-inlined-form
+        else
+            a.js-open-inlined-form
+                if value
+                    +viewer
+                        = formattedValue
+                else
+                    | {{_ 'edit'}}
+    else
+        if value
+            +viewer
+                = formattedValue

+ 30 - 0
client/components/cards/cardCustomFields.js

@@ -234,3 +234,33 @@ CardCustomField.register('cardCustomField');
     ];
   }
 }.register('cardCustomField-dropdown'));
+
+// cardCustomField-stringtemplate
+(class extends CardCustomField {
+  onCreated() {
+    super.onCreated();
+
+    this.stringtemplateFormat = this.data().definition.settings.stringtemplateFormat;
+  }
+
+  formattedValue() {
+    lines = this.data().value.replace(/\r\n|\n\r|\n|\r/g, '\n').split('\n');
+    lines = lines.map(line =>
+      this.stringtemplateFormat.replace(/%\{value\}/gi, line)
+    );
+
+    return lines.join(' ');
+  }
+
+  events() {
+    return [
+      {
+        'submit .js-card-customfield-stringtemplate'(event) {
+          event.preventDefault();
+          const value = this.currentComponent().getValue();
+          this.card.setCustomField(this.customFieldId, value);
+        },
+      },
+    ];
+  }
+}.register('cardCustomField-stringtemplate'));

+ 3 - 0
client/components/cards/minicard.jade

@@ -82,6 +82,9 @@ template(name="minicard")
                     +minicardCustomFieldDate
                 else if $eq definition.type "checkbox"
                   .materialCheckBox(class="{{#if value }}is-checked{{/if}}")
+                else if $eq definition.type "stringtemplate"
+                  +viewer
+                    = formattedStringtemplateCustomFieldValue(definition)
                 else
                   +viewer
                     = trueValue

+ 17 - 0
client/components/cards/minicard.js

@@ -21,6 +21,23 @@ BlazeComponent.extendComponent({
     }).format(customFieldTrueValue);
   },
 
+  formattedStringtemplateCustomFieldValue(definition) {
+    const customField = this.data()
+      .customFieldsWD()
+      .find(f => f._id === definition._id);
+
+    if(customField && customField.trueValue) {
+      lines = customField.trueValue.replace(/\r\n|\n\r|\n|\r/g, '\n').split('\n');
+      lines = lines.map(line =>
+        definition.settings.stringtemplateFormat.replace(/%\{value\}/gi, line)
+      );
+
+      return lines.join(' ');
+    } else {
+      return '';
+    }
+  },
+
   events() {
     return [
       {

+ 6 - 0
client/components/sidebar/sidebarCustomFields.jade

@@ -50,6 +50,12 @@ template(name="createCustomFieldPopup")
             each dropdownItems.get
                 input.js-dropdown-item(type="text" value=name placeholder="")
             input.js-dropdown-item.last(type="text" value="" placeholder="{{_ 'custom-field-dropdown-options-placeholder'}}")
+
+        div.js-field-settings.js-field-settings-paramlink(class="{{#if isTypeNotSelected 'stringtemplate'}}hide{{/if}}")
+            label
+                | {{_ 'custom-field-stringtemplate-format'}}
+            input.js-field-stringtemplate(type="text" value=getStringtemplateFormat)
+
         a.flex.js-field-show-on-card(class="{{#if showOnCard}}is-checked{{/if}}")
             .materialCheckBox(class="{{#if showOnCard}}is-checked{{/if}}")
 

+ 20 - 1
client/components/sidebar/sidebarCustomFields.js

@@ -16,7 +16,7 @@ BlazeComponent.extendComponent({
 }).register('customFieldsSidebar');
 
 const CreateCustomFieldPopup = BlazeComponent.extendComponent({
-  _types: ['text', 'number', 'date', 'dropdown', 'currency', 'checkbox'],
+  _types: ['text', 'number', 'date', 'dropdown', 'currency', 'checkbox', 'stringtemplate'],
 
   _currencyList: [
     {
@@ -77,6 +77,12 @@ const CreateCustomFieldPopup = BlazeComponent.extendComponent({
         ? this.data().settings.dropdownItems
         : [],
     );
+
+    this.stringtemplateFormat = new ReactiveVar(
+      this.data().settings && this.data().settings.stringtemplateFormat
+        ? this.data().settings.stringtemplateFormat
+        : "",
+    );
   },
 
   types() {
@@ -121,6 +127,10 @@ const CreateCustomFieldPopup = BlazeComponent.extendComponent({
     return items;
   },
 
+  getStringtemplateFormat() {
+    return this.stringtemplateFormat.get();
+  },
+
   getSettings() {
     const settings = {};
     switch (this.type.get()) {
@@ -136,6 +146,11 @@ const CreateCustomFieldPopup = BlazeComponent.extendComponent({
         settings.dropdownItems = dropdownItems;
         break;
       }
+      case 'stringtemplate': {
+        const stringtemplateFormat = this.stringtemplateFormat.get();
+        settings.stringtemplateFormat = stringtemplateFormat;
+        break;
+      }
     }
     return settings;
   },
@@ -158,6 +173,10 @@ const CreateCustomFieldPopup = BlazeComponent.extendComponent({
             evt.target.value = '';
           }
         },
+        'input .js-field-stringtemplate'(evt) {
+          const value = evt.target.value;
+          this.stringtemplateFormat.set(value);
+        },
         'click .js-field-show-on-card'(evt) {
           let $target = $(evt.target);
           if (!$target.hasClass('js-field-show-on-card')) {

+ 3 - 1
i18n/en.i18n.json

@@ -988,5 +988,7 @@
   "hide-system-messages-of-all-users": "Hide system messages of all users",
   "now-system-messages-of-all-users-are-hidden": "Now system messages of all users are hidden",
   "move-swimlane": "Move Swimlane",
-  "moveSwimlanePopup-title": "Move Swimlane"
+  "moveSwimlanePopup-title": "Move Swimlane",
+  "custom-field-stringtemplate": "String Template",
+  "custom-field-stringtemplate-format": "Format"
 }

+ 5 - 0
models/customFields.js

@@ -29,6 +29,7 @@ CustomFields.attachSchema(
         'dropdown',
         'checkbox',
         'currency',
+        'stringtemplate',
       ],
     },
     settings: {
@@ -64,6 +65,10 @@ CustomFields.attachSchema(
         },
       }),
     },
+    'settings.stringtemplateFormat': {
+      type: String,
+      optional: true,
+    },
     showOnCard: {
       /**
        * should we show on the cards this custom field