fix default tenant locale autocomplete fields

This commit is contained in:
Sofia Papacharalampous 2024-05-22 16:21:13 +03:00
parent 8ceca0a98f
commit 365de9fe5c
2 changed files with 46 additions and 10 deletions

View File

@ -12,7 +12,7 @@ export class DefaultUserLocaleTimezoneLookup extends Lookup {
export class DefaultUserLocaleCultureLookup extends Lookup {
like: string;
selectedItem: CultureInfo;
selectedItem: string;
constructor() {
super();

View File

@ -40,18 +40,42 @@ export class DefaultUserLocaleService {
return timezones;
}
queryCulture(q: DefaultUserLocaleCultureLookup): Observable<CultureInfo[]> {
queryCulture(q: DefaultUserLocaleCultureLookup) {
let cultures = of(this.cultureService.getCultureValues().sort((x, y) => x.displayName.localeCompare(y.displayName)));
if (q.like) {
let likeValue = q.like.toLowerCase();
cultures = cultures.pipe(map((items: CultureInfo[]) => {
let filteredItems = items.filter(i => this.getCultureDisplayFn(i).toLowerCase().includes(likeValue));
let filteredItems = items.filter(i => {
const displayValue = `${i?.displayName} - ${i?.nativeName}`;
if (displayValue.toLowerCase().includes(likeValue)) {
return true;
} else {
return false;
}
});
if (filteredItems != null && filteredItems?.length > 0) return filteredItems;
else return null;
}));
}
if (q.selectedItem) {
let selectedItemValue = q.selectedItem.toLowerCase();
cultures = cultures.pipe(map((items: CultureInfo[]) => {
let selected = items.find(i => {
if (i.name.toLowerCase().includes(selectedItemValue)) {
return true;
} else {
return false;
}
});
if (selected != null) {
return [selected];
}
else return null;
}));
}
return cultures;
}
@ -63,7 +87,7 @@ export class DefaultUserLocaleService {
initialItems: (data?: any) => this.queryTimezone(this.buildTimezoneAutocompleteLookup(null)),
filterFn: (searchQuery: string, data?: any) => this.queryTimezone(this.buildTimezoneAutocompleteLookup(searchQuery)),
getSelectedItem: (selectedItem: string) => this.queryTimezone(this.buildTimezoneAutocompleteLookup(null, selectedItem)),
displayFn: (item: string) => this.timezoneInfoDisplayPipe.transform(item),
displayFn: (item: string) => this.getTimezoneDisplayFn(item),
titleFn: (item: string) => this.timezoneInfoDisplayPipe.transform(item),
valueAssign: (item: string) => item,
};
@ -76,25 +100,37 @@ export class DefaultUserLocaleService {
return lookup;
}
getTimezoneDisplayFn(value: any) {
return Array.isArray(value) ? this.timezoneInfoDisplayPipe.transform(value[0]) : this.timezoneInfoDisplayPipe.transform(value);
}
singleCultureAutocompleteConfiguration: SingleAutoCompleteConfiguration = {
initialItems: (data?: any) => this.queryCulture(this.buildCultureAutocompleteLookup(null)),
filterFn: (searchQuery: string, data?: any) => this.queryCulture(this.buildCultureAutocompleteLookup(searchQuery)),
getSelectedItem: (selectedItem: CultureInfo) => this.queryCulture(this.buildCultureAutocompleteLookup(null, selectedItem)),
displayFn: (item: CultureInfo) => this.getCultureDisplayFn(item),
titleFn: (item: CultureInfo) => this.getCultureDisplayFn(item),
getSelectedItem: (selectedItem: string) =>this.queryCulture(this.buildCultureAutocompleteLookup(null, selectedItem)),
displayFn: (item: any) => this.getCultureDisplayFn(item),
titleFn: (item: CultureInfo) => this.getCultureTitleFn(item),
valueAssign: (item: CultureInfo) => item.name,
};
private buildCultureAutocompleteLookup(like?: string, selectedItem?: CultureInfo): DefaultUserLocaleCultureLookup {
private buildCultureAutocompleteLookup(like?: string, selectedItem?: string): DefaultUserLocaleCultureLookup {
const lookup: DefaultUserLocaleCultureLookup = new DefaultUserLocaleCultureLookup();
lookup.page = { size: 100, offset: 0 };
if (like) { lookup.like = like; }
if (selectedItem) { lookup.selectedItem = selectedItem }
return lookup;
}
private getCultureDisplayFn(culture: CultureInfo): string {
private getCultureTitleFn(culture: any): string {
return `${culture?.displayName} - ${culture?.nativeName}`;
}
private getCultureDisplayFn(culture: any): string {
if (Array.isArray(culture)) {
return this.getCultureTitleFn(culture[0]);
} else {
return this.getCultureTitleFn(culture);
}
}
}