mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-10-08 14:51:32 +00:00
[ADF-2914] support for number range patterns (#3282)
* support for number range patterns * fix memory leak for tag actions
This commit is contained in:
committed by
Eugenio Romano
parent
f63614e964
commit
3a3acd23ff
@@ -41,7 +41,16 @@ export class SearchNumberRangeComponent implements SearchWidget, OnInit {
|
||||
settings?: SearchWidgetSettings;
|
||||
context?: SearchQueryBuilderService;
|
||||
|
||||
field: string;
|
||||
format = '[{FROM} TO {TO}]';
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
if (this.settings) {
|
||||
this.field = this.settings.field;
|
||||
this.format = this.settings.format || '[{FROM} TO {TO}]';
|
||||
}
|
||||
|
||||
const validators = Validators.compose([
|
||||
Validators.required,
|
||||
Validators.pattern(/^-?(0|[1-9]\d*)?$/)
|
||||
@@ -57,12 +66,30 @@ export class SearchNumberRangeComponent implements SearchWidget, OnInit {
|
||||
}
|
||||
|
||||
apply(model: { from: string, to: string }, isValid: boolean) {
|
||||
if (isValid && this.id && this.context && this.settings && this.settings.field) {
|
||||
this.context.queryFragments[this.id] = `${this.settings.field}:[${model.from} TO ${model.to}]`;
|
||||
if (isValid && this.id && this.context && this.field) {
|
||||
const map = new Map<string, string>();
|
||||
map.set('FROM', model.from);
|
||||
map.set('TO', model.to);
|
||||
|
||||
const value = this.formatString(this.format, map);
|
||||
const query = `${this.field}:${value}`;
|
||||
|
||||
this.context.queryFragments[this.id] = query;
|
||||
this.context.update();
|
||||
}
|
||||
}
|
||||
|
||||
private formatString(str: string, map: Map<string, string>): string {
|
||||
let result = str;
|
||||
|
||||
map.forEach((value, key) => {
|
||||
const expr = new RegExp('{' + key + '}', 'gm');
|
||||
result = result.replace(expr, value);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.form.reset({
|
||||
from: '',
|
||||
|
Reference in New Issue
Block a user