UI: Improve page link default search function
This commit is contained in:
		
							parent
							
								
									4832f85f5d
								
							
						
					
					
						commit
						88ff9f4d19
					
				@ -21,25 +21,43 @@ import { SortDirection } from '@angular/material/sort';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export const MAX_SAFE_PAGE_SIZE = 2147483647;
 | 
					export const MAX_SAFE_PAGE_SIZE = 2147483647;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type PageLinkSearchFunction<T> = (entity: T, textSearch: string) => boolean;
 | 
					export type PageLinkSearchFunction<T> = (entity: T, textSearch: string, searchProperty?: string) => boolean;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const defaultPageLinkSearchFunction: PageLinkSearchFunction<any> =
 | 
					export function defaultPageLinkSearchFunction(searchProperty?: string): PageLinkSearchFunction<any> {
 | 
				
			||||||
  (entity: any, textSearch: string) => {
 | 
					  return (entity, textSearch) => defaultPageLinkSearch(entity, textSearch, searchProperty);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const defaultPageLinkSearch: PageLinkSearchFunction<any> =
 | 
				
			||||||
 | 
					  (entity: any, textSearch: string, searchProperty?: string) => {
 | 
				
			||||||
    if (textSearch === null || !textSearch.length) {
 | 
					    if (textSearch === null || !textSearch.length) {
 | 
				
			||||||
      return true;
 | 
					      return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    const expected = ('' + textSearch).toLowerCase();
 | 
					    const expected = ('' + textSearch).toLowerCase();
 | 
				
			||||||
    for (const key of Object.keys(entity)) {
 | 
					    if (searchProperty && searchProperty.length) {
 | 
				
			||||||
      const val = entity[key];
 | 
					      if (Object.prototype.hasOwnProperty.call(entity, searchProperty)) {
 | 
				
			||||||
      if (val !== null) {
 | 
					        const val = entity[searchProperty];
 | 
				
			||||||
        if (val !== Object(val)) {
 | 
					        if (val !== null) {
 | 
				
			||||||
          const actual = ('' + val).toLowerCase();
 | 
					          if (val !== Object(val)) {
 | 
				
			||||||
          if (actual.indexOf(expected) !== -1) {
 | 
					            const actual = ('' + val).toLowerCase();
 | 
				
			||||||
            return true;
 | 
					            if (actual.indexOf(expected) !== -1) {
 | 
				
			||||||
 | 
					              return true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        } else if (isObject(val)) {
 | 
					        }
 | 
				
			||||||
          if (defaultPageLinkSearchFunction(val, textSearch)) {
 | 
					      }
 | 
				
			||||||
            return true;
 | 
					    } else {
 | 
				
			||||||
 | 
					      for (const key of Object.keys(entity)) {
 | 
				
			||||||
 | 
					        const val = entity[key];
 | 
				
			||||||
 | 
					        if (val !== null) {
 | 
				
			||||||
 | 
					          if (val !== Object(val)) {
 | 
				
			||||||
 | 
					            const actual = ('' + val).toLowerCase();
 | 
				
			||||||
 | 
					            if (actual.indexOf(expected) !== -1) {
 | 
				
			||||||
 | 
					              return true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          } else if (isObject(val)) {
 | 
				
			||||||
 | 
					            if (defaultPageLinkSearch(val, textSearch)) {
 | 
				
			||||||
 | 
					              return true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@ -103,7 +121,7 @@ export class PageLink {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public filterData<T>(data: Array<T>,
 | 
					  public filterData<T>(data: Array<T>,
 | 
				
			||||||
                       searchFunction: PageLinkSearchFunction<T> = defaultPageLinkSearchFunction): PageData<T> {
 | 
					                       searchFunction: PageLinkSearchFunction<T> = defaultPageLinkSearchFunction()): PageData<T> {
 | 
				
			||||||
    const pageData = emptyPageData<T>();
 | 
					    const pageData = emptyPageData<T>();
 | 
				
			||||||
    pageData.data = [...data];
 | 
					    pageData.data = [...data];
 | 
				
			||||||
    if (this.textSearch && this.textSearch.length) {
 | 
					    if (this.textSearch && this.textSearch.length) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user