mirror of
https://github.com/wekan/wekan.git
synced 2025-12-19 17:00:13 +01:00
CustomFieldStringTemplate regular expressions now on minicard too
This commit is contained in:
parent
d7f451a7d9
commit
53bfa967c6
3 changed files with 47 additions and 31 deletions
|
|
@ -2,6 +2,7 @@ import moment from 'moment/min/moment-with-locales';
|
||||||
import { TAPi18n } from '/imports/i18n';
|
import { TAPi18n } from '/imports/i18n';
|
||||||
import { DatePicker } from '/client/lib/datepicker';
|
import { DatePicker } from '/client/lib/datepicker';
|
||||||
import Cards from '/models/cards';
|
import Cards from '/models/cards';
|
||||||
|
import { CustomFieldStringTemplate } from '/client/lib/customFields'
|
||||||
|
|
||||||
Template.cardCustomFieldsPopup.helpers({
|
Template.cardCustomFieldsPopup.helpers({
|
||||||
hasCustomField() {
|
hasCustomField() {
|
||||||
|
|
@ -245,38 +246,17 @@ CardCustomField.register('cardCustomField');
|
||||||
}.register('cardCustomField-dropdown'));
|
}.register('cardCustomField-dropdown'));
|
||||||
|
|
||||||
// cardCustomField-stringtemplate
|
// cardCustomField-stringtemplate
|
||||||
(class extends CardCustomField {
|
class CardCustomFieldStringTemplate extends CardCustomField {
|
||||||
onCreated() {
|
onCreated() {
|
||||||
super.onCreated();
|
super.onCreated();
|
||||||
|
|
||||||
this.stringtemplateFormat = this.data().definition.settings.stringtemplateFormat;
|
this.customField = new CustomFieldStringTemplate(this.data().definition);
|
||||||
this.stringtemplateSeparator = this.data().definition.settings.stringtemplateSeparator;
|
|
||||||
|
|
||||||
this.stringtemplateItems = new ReactiveVar(this.data().value ?? []);
|
this.stringtemplateItems = new ReactiveVar(this.data().value ?? []);
|
||||||
}
|
}
|
||||||
|
|
||||||
formattedValue() {
|
formattedValue() {
|
||||||
const ret = (this.data().value ?? [])
|
const ret = this.customField.getFormattedValue(this.data().value);
|
||||||
.filter(value => !!value.trim())
|
|
||||||
.map(value => {
|
|
||||||
let _ret = this.stringtemplateFormat.replace(/[%$]\{.+?\}/g, function(_match) {
|
|
||||||
let __ret;
|
|
||||||
if (_match.match(/%\{value\}/i)) {
|
|
||||||
__ret = value;
|
|
||||||
} else {
|
|
||||||
_match = _match.replace(/^\$/, "");
|
|
||||||
try {
|
|
||||||
const _json = JSON.parse(_match);
|
|
||||||
__ret = value.replace(new RegExp(_json.regex, _json.flags), _json.replace);
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return __ret;
|
|
||||||
});
|
|
||||||
return _ret;
|
|
||||||
})
|
|
||||||
.join(this.stringtemplateSeparator ?? '');
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -348,4 +328,5 @@ CardCustomField.register('cardCustomField');
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}.register('cardCustomField-stringtemplate'));
|
}
|
||||||
|
CardCustomFieldStringTemplate.register('cardCustomField-stringtemplate');
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { TAPi18n } from '/imports/i18n';
|
import { TAPi18n } from '/imports/i18n';
|
||||||
|
import { CustomFieldStringTemplate } from '/client/lib/customFields'
|
||||||
|
|
||||||
// Template.cards.events({
|
// Template.cards.events({
|
||||||
// 'click .member': Popup.open('cardMember')
|
// 'click .member': Popup.open('cardMember')
|
||||||
|
|
@ -31,12 +32,8 @@ BlazeComponent.extendComponent({
|
||||||
const customFieldTrueValue =
|
const customFieldTrueValue =
|
||||||
customField && customField.trueValue ? customField.trueValue : [];
|
customField && customField.trueValue ? customField.trueValue : [];
|
||||||
|
|
||||||
return customFieldTrueValue
|
const ret = new CustomFieldStringTemplate(definition).getFormattedValue(customFieldTrueValue);
|
||||||
.filter(value => !!value.trim())
|
return ret;
|
||||||
.map(value =>
|
|
||||||
definition.settings.stringtemplateFormat.replace(/%\{value\}/gi, value),
|
|
||||||
)
|
|
||||||
.join(definition.settings.stringtemplateSeparator ?? '');
|
|
||||||
},
|
},
|
||||||
|
|
||||||
showCreator() {
|
showCreator() {
|
||||||
|
|
|
||||||
38
client/lib/customFields.js
Normal file
38
client/lib/customFields.js
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
class CustomField {
|
||||||
|
constructor(definition) {
|
||||||
|
this.definition = definition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CustomFieldStringTemplate extends CustomField {
|
||||||
|
constructor(definition) {
|
||||||
|
super(definition);
|
||||||
|
this.format = definition.settings.stringtemplateFormat;
|
||||||
|
this.separator = definition.settings.stringtemplateSeparator;
|
||||||
|
}
|
||||||
|
|
||||||
|
getFormattedValue(rawValue) {
|
||||||
|
const ret = (rawValue ?? [])
|
||||||
|
.filter(value => !!value.trim())
|
||||||
|
.map(value => {
|
||||||
|
let _ret = this.format.replace(/[%$]\{.+?\}/g, function(_match) {
|
||||||
|
let __ret;
|
||||||
|
if (_match.match(/%\{value\}/i)) {
|
||||||
|
__ret = value;
|
||||||
|
} else {
|
||||||
|
_match = _match.replace(/^\$/, "");
|
||||||
|
try {
|
||||||
|
const _json = JSON.parse(_match);
|
||||||
|
__ret = value.replace(new RegExp(_json.regex, _json.flags), _json.replace);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return __ret;
|
||||||
|
});
|
||||||
|
return _ret;
|
||||||
|
})
|
||||||
|
.join(this.separator ?? '');
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue