-
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
d23082c
commit 22385ad
Showing
10 changed files
with
118 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,82 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { AITable, AITableField, AITableFieldType, AITableQueries } from '../core'; | ||
import { AITableReferences, AITableSelectField } from '../types'; | ||
import { transformCellValue } 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 fieldType = field.type; | ||
|
||
let cellText: string[] = []; | ||
|
||
switch (fieldType) { | ||
case AITableFieldType.link: | ||
if (transformValue?.text) { | ||
cellText.push(transformValue.text); | ||
} | ||
break; | ||
case AITableFieldType.select: | ||
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); | ||
} | ||
}); | ||
} | ||
break; | ||
case AITableFieldType.progress: | ||
cellText.push(`${transformValue}%`); | ||
break; | ||
case AITableFieldType.number: | ||
case AITableFieldType.rate: | ||
cellText.push(String(transformValue)); | ||
break; | ||
case AITableFieldType.member: | ||
case AITableFieldType.createdBy: | ||
case AITableFieldType.updatedBy: | ||
if (cellValue?.length && references) { | ||
for (let index = 0; index < cellValue.length; index++) { | ||
const userInfo = references?.members[cellValue[index]]; | ||
if (!userInfo) { | ||
continue; | ||
} | ||
if (userInfo.display_name) { | ||
cellText.push(userInfo.display_name); | ||
} | ||
} | ||
} | ||
break; | ||
default: | ||
if (transformValue) { | ||
cellText.push(transformValue); | ||
} | ||
} | ||
try { | ||
return keywords && cellText.length && cellText.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