-
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: support add and extend field #WIK-16038 (#10)
- Loading branch information
1 parent
195aae5
commit 74edbbb
Showing
31 changed files
with
349 additions
and
99 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
10 changes: 10 additions & 0 deletions
10
packages/grid/src/components/field-menu/field-menu.component.html
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,10 @@ | ||
@for (menu of fieldMenus; track index; let index = $index) { | ||
@if (menu.id === 'divider') { | ||
<thy-divider [thyStyle]="'solid'"></thy-divider> | ||
} @else { | ||
<a thyDropdownMenuItem href="javascript:;" (click)="execute(menu)"> | ||
<thy-icon [thyIconName]="menu.icon!"></thy-icon> | ||
<span>{{ menu.name! }}</span> | ||
</a> | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
packages/grid/src/components/field-menu/field-menu.component.ts
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,40 @@ | ||
import { Component, ChangeDetectionStrategy, Input, ElementRef, signal } from '@angular/core'; | ||
import { AITableFieldMenu } from '../../types/field'; | ||
import { AITableField, AITable } from '../../core'; | ||
import { | ||
ThyDropdownMenuItemDirective, | ||
ThyDropdownMenuItemNameDirective, | ||
ThyDropdownMenuItemIconDirective, | ||
ThyDropdownMenuComponent | ||
} from 'ngx-tethys/dropdown'; | ||
import { ThyIcon } from 'ngx-tethys/icon'; | ||
import { ThyDivider } from 'ngx-tethys/divider'; | ||
|
||
@Component({ | ||
selector: 'field-menu', | ||
templateUrl: './field-menu.component.html', | ||
standalone: true, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
imports: [ | ||
ThyIcon, | ||
ThyDivider, | ||
ThyDropdownMenuComponent, | ||
ThyDropdownMenuItemDirective, | ||
ThyDropdownMenuItemNameDirective, | ||
ThyDropdownMenuItemIconDirective | ||
] | ||
}) | ||
export class FieldMenu { | ||
@Input({ required: true }) field!: AITableField; | ||
|
||
@Input({ required: true }) aiTable!: AITable; | ||
|
||
@Input({ required: true }) fieldMenus!: AITableFieldMenu[]; | ||
|
||
@Input() origin!: HTMLElement | ElementRef<any>; | ||
|
||
execute(menu: AITableFieldMenu) { | ||
const field = signal({ ...this.field }); | ||
menu.exec && menu.exec(this.aiTable, field, this.origin); | ||
} | ||
} |
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 @@ | ||
export * from './field-property-editor/field-property-editor.component' |
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, AITableField } from '../core'; | ||
import { AITableFieldMenu } from '../types/field'; | ||
import { AI_TABLE_GRID_FIELD_SERVICE_MAP } from '../services/field.service'; | ||
import { ElementRef, WritableSignal } from '@angular/core'; | ||
|
||
export const DividerMenuItem = { | ||
id: 'divider' | ||
}; | ||
|
||
export const EditFieldPropertyItem = { | ||
id: 'editFieldProperty', | ||
name: '编辑列', | ||
icon: 'edit', | ||
exec: (aiTable: AITable, field: WritableSignal<AITableField>, origin?: HTMLElement | ElementRef<any>) => { | ||
const fieldService = AI_TABLE_GRID_FIELD_SERVICE_MAP.get(aiTable); | ||
origin && fieldService?.editFieldProperty(origin, aiTable, field, true); | ||
} | ||
}; | ||
|
||
export const DefaultFieldMenus: AITableFieldMenu[] = [EditFieldPropertyItem]; |
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 +1,2 @@ | ||
export * from './grid'; | ||
export * from './field'; |
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 './types'; | ||
export * from './action'; | ||
export * from './utils'; | ||
export * from './constants/field'; |
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,5 +1,17 @@ | ||
import { AITableFieldType } from '../types'; | ||
import { FieldsMap } from '../constants/field'; | ||
import { AITable, AITableFieldType } from '../types'; | ||
import { idCreator } from './id-creator'; | ||
|
||
export function getDefaultFieldValue(type: AITableFieldType) { | ||
return ''; | ||
} | ||
|
||
export function createDefaultFieldName(aiTable: AITable, type: AITableFieldType = AITableFieldType.Text) { | ||
const fields = aiTable.fields(); | ||
const count = fields.filter((item) => item.type === type).length; | ||
return count === 0 ? FieldsMap[type].name : FieldsMap[type].name + count; | ||
} | ||
|
||
export function createDefaultField(aiTable: AITable, type: AITableFieldType = AITableFieldType.Text) { | ||
return { id: idCreator(), type, name: createDefaultFieldName(aiTable, type) }; | ||
} |
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.