add custom field "stringtemplate"

This commit is contained in:
tod31 2021-04-07 16:11:19 +02:00
parent 769bb7a55d
commit b8dc7ff18e
8 changed files with 104 additions and 2 deletions

View file

@ -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

View file

@ -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'));

View file

@ -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

View file

@ -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 [
{

View file

@ -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}}")

View file

@ -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')) {

View file

@ -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"
}

View file

@ -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