fix default tenant locale autocomplete fields
This commit is contained in:
parent
8ceca0a98f
commit
365de9fe5c
|
@ -12,7 +12,7 @@ export class DefaultUserLocaleTimezoneLookup extends Lookup {
|
||||||
|
|
||||||
export class DefaultUserLocaleCultureLookup extends Lookup {
|
export class DefaultUserLocaleCultureLookup extends Lookup {
|
||||||
like: string;
|
like: string;
|
||||||
selectedItem: CultureInfo;
|
selectedItem: string;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
|
@ -40,18 +40,42 @@ export class DefaultUserLocaleService {
|
||||||
return timezones;
|
return timezones;
|
||||||
}
|
}
|
||||||
|
|
||||||
queryCulture(q: DefaultUserLocaleCultureLookup): Observable<CultureInfo[]> {
|
queryCulture(q: DefaultUserLocaleCultureLookup) {
|
||||||
let cultures = of(this.cultureService.getCultureValues().sort((x, y) => x.displayName.localeCompare(y.displayName)));
|
let cultures = of(this.cultureService.getCultureValues().sort((x, y) => x.displayName.localeCompare(y.displayName)));
|
||||||
|
|
||||||
if (q.like) {
|
if (q.like) {
|
||||||
let likeValue = q.like.toLowerCase();
|
let likeValue = q.like.toLowerCase();
|
||||||
cultures = cultures.pipe(map((items: CultureInfo[]) => {
|
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;
|
if (filteredItems != null && filteredItems?.length > 0) return filteredItems;
|
||||||
else return null;
|
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;
|
return cultures;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +87,7 @@ export class DefaultUserLocaleService {
|
||||||
initialItems: (data?: any) => this.queryTimezone(this.buildTimezoneAutocompleteLookup(null)),
|
initialItems: (data?: any) => this.queryTimezone(this.buildTimezoneAutocompleteLookup(null)),
|
||||||
filterFn: (searchQuery: string, data?: any) => this.queryTimezone(this.buildTimezoneAutocompleteLookup(searchQuery)),
|
filterFn: (searchQuery: string, data?: any) => this.queryTimezone(this.buildTimezoneAutocompleteLookup(searchQuery)),
|
||||||
getSelectedItem: (selectedItem: string) => this.queryTimezone(this.buildTimezoneAutocompleteLookup(null, selectedItem)),
|
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),
|
titleFn: (item: string) => this.timezoneInfoDisplayPipe.transform(item),
|
||||||
valueAssign: (item: string) => item,
|
valueAssign: (item: string) => item,
|
||||||
};
|
};
|
||||||
|
@ -76,17 +100,21 @@ export class DefaultUserLocaleService {
|
||||||
return lookup;
|
return lookup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTimezoneDisplayFn(value: any) {
|
||||||
|
return Array.isArray(value) ? this.timezoneInfoDisplayPipe.transform(value[0]) : this.timezoneInfoDisplayPipe.transform(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
singleCultureAutocompleteConfiguration: SingleAutoCompleteConfiguration = {
|
singleCultureAutocompleteConfiguration: SingleAutoCompleteConfiguration = {
|
||||||
initialItems: (data?: any) => this.queryCulture(this.buildCultureAutocompleteLookup(null)),
|
initialItems: (data?: any) => this.queryCulture(this.buildCultureAutocompleteLookup(null)),
|
||||||
filterFn: (searchQuery: string, data?: any) => this.queryCulture(this.buildCultureAutocompleteLookup(searchQuery)),
|
filterFn: (searchQuery: string, data?: any) => this.queryCulture(this.buildCultureAutocompleteLookup(searchQuery)),
|
||||||
getSelectedItem: (selectedItem: CultureInfo) => this.queryCulture(this.buildCultureAutocompleteLookup(null, selectedItem)),
|
getSelectedItem: (selectedItem: string) =>this.queryCulture(this.buildCultureAutocompleteLookup(null, selectedItem)),
|
||||||
displayFn: (item: CultureInfo) => this.getCultureDisplayFn(item),
|
displayFn: (item: any) => this.getCultureDisplayFn(item),
|
||||||
titleFn: (item: CultureInfo) => this.getCultureDisplayFn(item),
|
titleFn: (item: CultureInfo) => this.getCultureTitleFn(item),
|
||||||
valueAssign: (item: CultureInfo) => item.name,
|
valueAssign: (item: CultureInfo) => item.name,
|
||||||
};
|
};
|
||||||
|
|
||||||
private buildCultureAutocompleteLookup(like?: string, selectedItem?: CultureInfo): DefaultUserLocaleCultureLookup {
|
private buildCultureAutocompleteLookup(like?: string, selectedItem?: string): DefaultUserLocaleCultureLookup {
|
||||||
const lookup: DefaultUserLocaleCultureLookup = new DefaultUserLocaleCultureLookup();
|
const lookup: DefaultUserLocaleCultureLookup = new DefaultUserLocaleCultureLookup();
|
||||||
lookup.page = { size: 100, offset: 0 };
|
lookup.page = { size: 100, offset: 0 };
|
||||||
if (like) { lookup.like = like; }
|
if (like) { lookup.like = like; }
|
||||||
|
@ -94,7 +122,15 @@ export class DefaultUserLocaleService {
|
||||||
return lookup;
|
return lookup;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getCultureDisplayFn(culture: CultureInfo): string {
|
private getCultureTitleFn(culture: any): string {
|
||||||
return `${culture?.displayName} - ${culture?.nativeName}`;
|
return `${culture?.displayName} - ${culture?.nativeName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getCultureDisplayFn(culture: any): string {
|
||||||
|
if (Array.isArray(culture)) {
|
||||||
|
return this.getCultureTitleFn(culture[0]);
|
||||||
|
} else {
|
||||||
|
return this.getCultureTitleFn(culture);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue