-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grid): support highlight the cell which match the keywords
- Loading branch information
1 parent
e6e9dd0
commit b317ca0
Showing
19 changed files
with
186 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './event.service'; | ||
export * from './field.service'; | ||
export * from './selection.service'; | ||
export * from './match-cell.service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { AITable, AITableField, AITableQueries } from '../core'; | ||
import { AITableReferences } from '../types'; | ||
import { transformCellValue, ViewOperationMap } from '../utils'; | ||
|
||
@Injectable() | ||
export class AITableGridMatchCellService { | ||
aiTable!: AITable; | ||
|
||
initialize(aiTable: AITable) { | ||
this.aiTable = aiTable; | ||
} | ||
|
||
findMatchedCells(keywords: string, references: AITableReferences) { | ||
let matchedCells: string[] = []; | ||
this.aiTable.records().forEach((record) => { | ||
this.aiTable.fields().forEach((field) => { | ||
if (this.isCellMatchKeywords(this.aiTable, field, record._id, keywords, references)) { | ||
matchedCells.push(`${record._id}-${field._id}`); | ||
} | ||
}); | ||
}); | ||
this.aiTable.matchedCells.set([...matchedCells]); | ||
} | ||
|
||
private isCellMatchKeywords(aiTable: AITable, field: AITableField, recordId: string, keywords: string, references: AITableReferences) { | ||
const cellValue = AITableQueries.getFieldValue(aiTable, [recordId, field._id]); | ||
const transformValue = transformCellValue(aiTable, field, cellValue); | ||
const fieldMethod = ViewOperationMap[field.type]; | ||
let cellFullText: string[] = fieldMethod.cellFullText(transformValue, field, references); | ||
|
||
try { | ||
return keywords && cellFullText.length && cellFullText.some((item) => item.toLowerCase().includes(keywords.toLowerCase())); | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { AITableField, AITableReferences } from '../../index'; | ||
|
||
export abstract class Field { | ||
abstract cellFullText(transformValue: any, field: AITableField, references?: AITableReferences): string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { AITableFieldType } from '../../index'; | ||
import { Field } from './field'; | ||
import { LinkField } from './link'; | ||
import { MemberField } from './member'; | ||
import { SelectField } from './select'; | ||
import { TextField } from './text'; | ||
|
||
export const ViewOperationMap: Record<AITableFieldType, Field> = { | ||
[AITableFieldType.text]: new TextField(), | ||
[AITableFieldType.richText]: new TextField(), | ||
[AITableFieldType.select]: new SelectField(), | ||
[AITableFieldType.date]: new TextField(), | ||
[AITableFieldType.createdAt]: new TextField(), | ||
[AITableFieldType.updatedAt]: new TextField(), | ||
[AITableFieldType.number]: new TextField(), | ||
[AITableFieldType.rate]: new TextField(), | ||
[AITableFieldType.link]: new LinkField(), | ||
[AITableFieldType.member]: new MemberField(), | ||
[AITableFieldType.progress]: new TextField(), | ||
[AITableFieldType.createdBy]: new MemberField(), | ||
[AITableFieldType.updatedBy]: new MemberField() | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { AITableField, LinkFieldValue } from '../../index'; | ||
import { Field } from './field'; | ||
import { isEmpty } from '../common'; | ||
|
||
export class LinkField extends Field { | ||
override cellFullText(transformValue: LinkFieldValue, field: AITableField): string[] { | ||
let fullText: string[] = []; | ||
if (!isEmpty(transformValue?.text)) { | ||
fullText.push(transformValue.text); | ||
} | ||
return fullText; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { AITableField, AITableReferences } from '../../index'; | ||
import { Field } from './field'; | ||
|
||
export class MemberField extends Field { | ||
override cellFullText(transformValue: string[], field: AITableField, references?: AITableReferences): string[] { | ||
let fullText: string[] = []; | ||
if (transformValue?.length && references) { | ||
for (let index = 0; index < transformValue.length; index++) { | ||
const userInfo = references?.members[transformValue[index]]; | ||
if (!userInfo) { | ||
continue; | ||
} | ||
if (userInfo.display_name) { | ||
fullText.push(userInfo.display_name); | ||
} | ||
} | ||
} | ||
return fullText; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { AITableField } from '../../index'; | ||
import { Field } from './field'; | ||
|
||
export class ProgressField extends Field { | ||
override cellFullText(transformValue: number, field: AITableField): string[] { | ||
const fullText = `${transformValue}%`; | ||
return [fullText]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Field } from './field'; | ||
import { AITableField, AITableSelectField } from '../../index'; | ||
|
||
export class SelectField extends Field { | ||
override cellFullText(transformValue: string[], field: AITableField): string[] { | ||
let cellText: string[] = []; | ||
if (transformValue && Array.isArray(transformValue) && transformValue.length) { | ||
transformValue.forEach((optionId) => { | ||
const item = (field as AITableSelectField).settings?.options?.find((option) => option._id === optionId); | ||
if (item?.text) { | ||
cellText.push(item.text); | ||
} | ||
}); | ||
} | ||
return cellText; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { AITableField, AITableReferences, isEmpty } from '../../index'; | ||
import { Field } from './field'; | ||
|
||
export class TextField extends Field { | ||
override cellFullText(transformValue: any, field: AITableField, references?: AITableReferences): string[] { | ||
let fullText: string[] = []; | ||
if (!isEmpty(transformValue)) { | ||
fullText.push(String(transformValue)); | ||
} | ||
return fullText; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters