-
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.
- Loading branch information
Showing
8 changed files
with
164 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { setView, applyView, GeneralActions } from './view'; | ||
|
||
export const CustomActions = { | ||
setView, | ||
applyView, | ||
...GeneralActions | ||
}; |
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 { AITableView, AIViewAction, ViewActionName } from '../types/view'; | ||
import { AIViewTable } from '../types/view'; | ||
import { createDraft, finishDraft } from 'immer'; | ||
|
||
export function setView(aiTable: AIViewTable, newView: AITableView, path: [number]) { | ||
const [index] = path; | ||
const view = aiTable.views()[index]; | ||
if (JSON.stringify(view) !== JSON.stringify(newView)) { | ||
const operation = { | ||
type: ViewActionName.setView, | ||
view, | ||
newView, | ||
path | ||
}; | ||
aiTable.viewApply(operation); | ||
} | ||
} | ||
|
||
export const GeneralActions = { | ||
transform(aiTable: AIViewTable, op: AIViewAction): void { | ||
const views = createDraft(aiTable.views()); | ||
applyView(aiTable, views, op); | ||
aiTable.views.update(() => { | ||
return finishDraft(views); | ||
}); | ||
} | ||
}; | ||
|
||
export const applyView = (aiTable: AIViewTable, views: AITableView[], options: AIViewAction) => { | ||
const [viewIndex] = options.path; | ||
views[viewIndex] = options.newView; | ||
return views; | ||
}; | ||
|
||
export const ViewActions = { | ||
setView, | ||
applyView | ||
}; |
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,7 +1,12 @@ | ||
行高: | ||
<thy-select [(ngModel)]="activeView().rowHeight" style="width: 200px" (ngModelChange)="changeRowHeight($event)"> | ||
<thy-option *ngFor="let option of listOfOption" [thyValue]="option.value" [thyLabelText]="option.text"> </thy-option> | ||
</thy-select> | ||
<ai-table-grid | ||
[(aiRecords)]="records" | ||
[(aiFields)]="fields" | ||
(onChange)="onChange($event)" | ||
[aiFieldConfig]="aiFieldConfig" | ||
[aiPlugins]="plugins" | ||
(aiTableInitialized)="aiTableInitialized($event)" | ||
></ai-table-grid> |
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,20 @@ | ||
import { AITable, AITableAction, FLUSHING } from '@ai-table/grid'; | ||
import { CustomActions } from '../action'; | ||
import { AIViewAction, AIViewTable } from '../types/view'; | ||
|
||
export const withCustomApply = (aiTable: AITable) => { | ||
const viewTable = aiTable as AIViewTable; | ||
viewTable.viewApply = (action: AIViewAction) => { | ||
aiTable.actions.push(action as unknown as AITableAction); | ||
CustomActions.transform(viewTable, action); | ||
if (!FLUSHING.get(aiTable)) { | ||
FLUSHING.set(aiTable, true); | ||
Promise.resolve().then(() => { | ||
FLUSHING.set(aiTable, false); | ||
aiTable.onChange(); | ||
aiTable.actions = []; | ||
}); | ||
} | ||
}; | ||
return aiTable; | ||
}; |
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,47 @@ | ||
import { AITable } from '@ai-table/grid'; | ||
import { Direction } from '@angular/cdk/bidi'; | ||
import { Signal, WritableSignal } from '@angular/core'; | ||
|
||
export enum RowHeight { | ||
short = 'short', | ||
medium = 'medium', | ||
tall = 'tall' | ||
} | ||
|
||
export interface AITableView { | ||
id: string; | ||
name: string; | ||
emoji_icon?: string; | ||
isActive?: boolean; | ||
rowHeight?: RowHeight; | ||
sortCondition?: { | ||
keepSort: boolean; | ||
conditions: { | ||
sortBy: string; | ||
direction: Direction; | ||
}[]; | ||
}; | ||
// filterCondition?: { | ||
// fieldKey: string; | ||
// operation: OperationSymbol; | ||
// logical: LogicalOperator; | ||
// value?: SafeAny; | ||
// disabled?: boolean; | ||
// }[]; | ||
} | ||
|
||
export enum ViewActionName { | ||
setView = 'set_view' | ||
} | ||
|
||
export interface AIViewAction { | ||
type: ViewActionName.setView; | ||
view: AITableView; | ||
newView: AITableView; | ||
path: [number]; | ||
} | ||
|
||
export interface AIViewTable extends AITable { | ||
views: WritableSignal<AITableView[]>; | ||
viewApply: (action: AIViewAction) => void; | ||
} |