-
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.
refactor(grid): merge field model from state to grid
- Loading branch information
1 parent
bc5d894
commit 4127696
Showing
30 changed files
with
374 additions
and
461 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Id } from 'ngx-tethys/types'; | ||
|
||
export enum AITableFilterOperation { | ||
eq = 'eq', | ||
gte = 'gte', | ||
lte = 'lte', | ||
gt = 'gt', | ||
lt = 'lt', | ||
in = 'in', | ||
contain = 'contain', | ||
ne = 'ne', | ||
nin = 'nin', | ||
between = 'between', | ||
besides = 'besides', | ||
empty = 'empty', | ||
exists = 'exists', | ||
notContain = 'not_contain' | ||
} | ||
|
||
export interface AITableFilterCondition<TValue = unknown> { | ||
field_id: Id; | ||
operation: AITableFilterOperation; | ||
value: TValue; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,44 @@ | ||
import { AITableFilterCondition, AITableFilterOperation, AITableReferences } from '../../../types'; | ||
import { AITableField, FieldValue } from '../../../core'; | ||
import { isEmpty } from '../../common'; | ||
|
||
export abstract class Field { | ||
// 排序 | ||
abstract compare(cellValue1: FieldValue, cellValue2: FieldValue, field: AITableField, references?: AITableReferences): number; | ||
|
||
// 筛选 | ||
isMeetFilter(condition: AITableFilterCondition, cellValue: FieldValue) { | ||
switch (condition.operation) { | ||
case AITableFilterOperation.empty: | ||
case AITableFilterOperation.exists: { | ||
return this.isEmptyOrNot(condition.operation, cellValue); | ||
} | ||
default: { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
// 查找 | ||
cellFullText(transformValue: any, field: AITableField, references?: AITableReferences): string[] { | ||
let fullText: string[] = []; | ||
if (!isEmpty(transformValue)) { | ||
fullText.push(String(transformValue)); | ||
} | ||
return fullText; | ||
} | ||
|
||
isEmptyOrNot(operation: AITableFilterOperation.empty | AITableFilterOperation.exists, cellValue: FieldValue) { | ||
switch (operation) { | ||
case AITableFilterOperation.empty: { | ||
return isEmpty(cellValue); | ||
} | ||
case AITableFilterOperation.exists: { | ||
return !isEmpty(cellValue); | ||
} | ||
default: { | ||
throw new Error('compare operator type error'); | ||
} | ||
} | ||
} | ||
} |
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,37 @@ | ||
import { FieldValue, LinkFieldValue } from '../../../core'; | ||
import { AITableFilterCondition, AITableFilterOperation } from '../../../types'; | ||
import { isEmpty } from '../../common'; | ||
import { compareString, stringInclude } from '../operate'; | ||
import { Field } from './field'; | ||
|
||
export class LinkField extends Field { | ||
override isMeetFilter(condition: AITableFilterCondition<string>, cellValue: FieldValue) { | ||
const cellTextValue = cellValue?.text; | ||
switch (condition.operation) { | ||
case AITableFilterOperation.empty: | ||
return isEmpty(cellTextValue); | ||
case AITableFilterOperation.exists: | ||
return !isEmpty(cellTextValue); | ||
case AITableFilterOperation.contain: | ||
return !isEmpty(cellTextValue) && stringInclude(cellTextValue, condition.value); | ||
default: | ||
return super.isMeetFilter(condition, cellTextValue); | ||
} | ||
} | ||
|
||
override compare(cellValue1: FieldValue, cellValue2: FieldValue): number { | ||
return compareString(cellValueToSortValue(cellValue1), cellValueToSortValue(cellValue2)); | ||
} | ||
|
||
override cellFullText(transformValue: LinkFieldValue): string[] { | ||
let texts: string[] = []; | ||
if (!isEmpty(transformValue?.text)) { | ||
texts.push(transformValue.text); | ||
} | ||
return texts; | ||
} | ||
} | ||
|
||
function cellValueToSortValue(cellValue: LinkFieldValue): string | null { | ||
return (cellValue && cellValue.text && cellValue.text.trim()) || null; | ||
} |
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,60 @@ | ||
import { AITableField, FieldValue, MemberFieldValue } from '../../../core'; | ||
import { AITableFilterCondition, AITableFilterOperation, AITableReferences } from '../../../types'; | ||
import { isEmpty } from '../../common'; | ||
import { compareString, hasIntersect } from '../operate'; | ||
import { Field } from './field'; | ||
|
||
export class MemberField extends Field { | ||
override isMeetFilter(condition: AITableFilterCondition<string>, cellValue: MemberFieldValue) { | ||
switch (condition.operation) { | ||
case AITableFilterOperation.empty: | ||
return isEmpty(cellValue); | ||
case AITableFilterOperation.exists: | ||
return !isEmpty(cellValue); | ||
case AITableFilterOperation.in: | ||
return Array.isArray(condition.value) && hasIntersect(cellValue, condition.value); | ||
case AITableFilterOperation.nin: | ||
return Array.isArray(condition.value) && !hasIntersect(cellValue, condition.value); | ||
default: | ||
return super.isMeetFilter(condition, cellValue); | ||
} | ||
} | ||
|
||
override compare(cellValue1: FieldValue, cellValue2: FieldValue, field: AITableField, references: AITableReferences): number { | ||
const value1 = cellValueToSortValue(cellValue1, field, references); | ||
const value2 = cellValueToSortValue(cellValue2, field, references); | ||
return compareString(value1, value2); | ||
} | ||
|
||
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; | ||
} | ||
} | ||
|
||
function cellValueToSortValue(cellValue: MemberFieldValue, field: AITableField, references: AITableReferences): string | null { | ||
let names: string[] = []; | ||
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_pinyin) { | ||
names.push(userInfo.display_name_pinyin); | ||
} | ||
} | ||
} | ||
return names && names.length ? names.join(', ') : null; | ||
} |
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
Oops, something went wrong.