Skip to content

Commit

Permalink
fix: adjust code
Browse files Browse the repository at this point in the history
  • Loading branch information
huanhuanwa committed Aug 5, 2024
1 parent 2f4c16c commit e4a44ec
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 292 deletions.
22 changes: 5 additions & 17 deletions src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
import { Routes } from '@angular/router';
import { BasicComponent } from './component/basic/basic.component';
import { ShareComponent } from './component/share/share.component';
import { TableComponent } from './component/basic/table/table.component';
import { ShareTableComponent } from './component/share/table/table.component';
import { DemoTableContent } from './component/common/content/content.component';
import { DemoTable } from './component/table.component';

export const routes: Routes = [
{
path: 'share',
component: ShareComponent,
children:[
{
path: ':viewId',
component: ShareTableComponent,
}
]
},
{
path: '',
component: BasicComponent,
component: DemoTable,
children:[
{
path: ':viewId',
component: TableComponent,
component: DemoTableContent,
}
]
},
}

];
9 changes: 0 additions & 9 deletions src/app/component/basic/basic.component.html

This file was deleted.

35 changes: 0 additions & 35 deletions src/app/component/basic/basic.component.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/app/component/basic/table/table.component.html

This file was deleted.

15 changes: 0 additions & 15 deletions src/app/component/basic/table/table.component.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<a thyAction class="mb-2" thyIcon="move" href="javascript:;" (click)="moveRecord()">移动选中行到第三行</a>
<a thyAction class="mb-2" thyIcon="move" href="javascript:;" (click)="moveField()">移动选中列到第三列</a>
</div>

<ai-table-grid
[(aiRecords)]="tableService.records"
[(aiFields)]="tableService.fields"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
import { AfterViewInit, Component, OnInit, Signal, signal, WritableSignal, inject } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { RouterOutlet } from '@angular/router';
import {
AITableGrid,
AITableField,
AITable,
AIFieldConfig,
EditFieldPropertyItem,
DividerMenuItem,
RemoveFieldItem,
Actions,
AIFieldConfig,
AIFieldPath,
AIRecordPath,
AITable,
AITableChangeOptions,
AITableField,
AITableGrid,
AITableQueries,
AITableRecord,
AITableChangeOptions,
AITableAction
DividerMenuItem,
EditFieldPropertyItem,
RemoveFieldItem
} from '@ai-table/grid';
import { ThyIconRegistry } from 'ngx-tethys/icon';
import { ThyPopoverModule } from 'ngx-tethys/popover';
import { withCustomApply } from '../../plugins/custom-action.plugin';
import { AIViewTable } from '../../types/view';
import { FieldPropertyEditor } from './field-property-editor/field-property-editor.component';
import { Component, inject, Signal, WritableSignal } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { ThyAction } from 'ngx-tethys/action';
import { DemoAIField, DemoAIRecord, UpdateFieldTypes, UpdateRecordTypes } from '../../types';
import { getDefaultValue, getSortFieldsAndRecordsByPositions, setActiveViewPositions } from '../../utils/utils';
import { TableService } from '../../service/table.service';
import { ThyPopoverModule } from 'ngx-tethys/popover';
import { FormsModule } from '@angular/forms';
import { ThyInputDirective } from 'ngx-tethys/input';
import { DomSanitizer } from '@angular/platform-browser';
import { ThyIconRegistry } from 'ngx-tethys/icon';
import { withCustomApply } from '../../../plugins/custom-action.plugin';
import { TableService } from '../../../service/table.service';
import applyActionOps from '../../../share/apply-to-yjs';
import { YjsAITable } from '../../../share/yjs-table';
import { AIViewTable } from '../../../types/view';
import { getDefaultValue } from '../../../utils/utils';
import { FieldPropertyEditor } from '../field-property-editor/field-property-editor.component';

@Component({
selector: 'common-ai-table',
selector: 'demo-table-content',
standalone: true,
imports: [RouterOutlet, AITableGrid, ThyPopoverModule, FieldPropertyEditor, ThyAction],
template: ''
imports: [RouterOutlet, AITableGrid, ThyPopoverModule, FieldPropertyEditor, ThyAction, FormsModule, ThyInputDirective],
templateUrl: './content.component.html'
})
export class CommonTableComponent implements OnInit, AfterViewInit {
records!: WritableSignal<DemoAIRecord[]>;

fields!: WritableSignal<DemoAIField[]>;

export class DemoTableContent {
aiTable!: AITable;

plugins = [withCustomApply];
Expand Down Expand Up @@ -86,10 +84,14 @@ export class CommonTableComponent implements OnInit, AfterViewInit {
}

ngOnInit(): void {
const value = getDefaultValue();
const { records, fields } = getSortFieldsAndRecordsByPositions(value.records, value.fields, this.tableService.activeView().id);
this.records = signal(records);
this.fields = signal(fields);
if (this.tableService.sharedType) {
this.tableService.buildRenderRecords();
this.tableService.buildRenderFields();
} else {
const value = getDefaultValue();
this.tableService.buildRenderRecords(value.records);
this.tableService.buildRenderFields(value.fields);
}
console.time('render');
}

Expand All @@ -102,7 +104,14 @@ export class CommonTableComponent implements OnInit, AfterViewInit {
}

onChange(data: AITableChangeOptions) {
this.setPositions(data.actions);
// TODO:获取当前的 view 和 path,转换为 sharedType 中原数据的 path
if (this.tableService.sharedType) {
if (!YjsAITable.isRemote(this.aiTable) && !YjsAITable.isUndo(this.aiTable)) {
YjsAITable.asLocal(this.aiTable, () => {
applyActionOps(this.tableService.sharedType!, data.actions, this.aiTable);
});
}
}
}

prevent(event: Event) {
Expand All @@ -113,17 +122,7 @@ export class CommonTableComponent implements OnInit, AfterViewInit {
aiTableInitialized(aiTable: AITable) {
this.aiTable = aiTable;
(this.aiTable as AIViewTable).views = this.tableService.views;
}

setPositions(actions: AITableAction[]) {
if (actions.some((item) => UpdateRecordTypes.includes(item.type))) {
const records = setActiveViewPositions(this.records(), this.tableService.activeView().id) as DemoAIRecord[];
this.records.set(records);
}
if (actions.some((item) => UpdateFieldTypes.includes(item.type))) {
const fields = setActiveViewPositions(this.fields(), this.tableService.activeView().id) as DemoAIField[];
this.fields.set(fields);
}
this.tableService.setAITable(aiTable);
}

removeRecord() {
Expand Down
69 changes: 0 additions & 69 deletions src/app/component/share/table/table.component.ts

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,38 @@ import { AITableGrid } from '@ai-table/grid';
import { FormsModule } from '@angular/forms';
import { ThyPopoverModule } from 'ngx-tethys/popover';
import { ThyTabs, ThyTab } from 'ngx-tethys/tabs';
import { DemoAIRecord, DemoAIField } from '../../types';
import { ThyInputDirective } from 'ngx-tethys/input';
import { getDefaultValue } from '../../utils/utils';
import { TableService } from '../../service/table.service';
import { TableService } from '../service/table.service';

const initViews = [
{ id: 'view1', name: '表格视图1', isActive: true },
{ id: 'view2', name: '表格视图2' }
];

@Component({
selector: 'ai-table-share',
selector: 'demo-ai-table',
standalone: true,
imports: [RouterOutlet, AITableGrid, ThyAction, ThyTabs, ThyTab, ThyPopoverModule, FormsModule, ThyInputDirective],
templateUrl: './share.component.html',
templateUrl: './table.component.html',
providers: [TableService]
})
export class ShareComponent implements OnInit, OnDestroy {
export class DemoTable implements OnInit, OnDestroy {
provider!: WebsocketProvider | null;

room = 'share-room-1';

records!: WritableSignal<DemoAIRecord[]>;

fields!: WritableSignal<DemoAIField[]>;
room = 'share-room-2';

router = inject(Router);

tableService = inject(TableService);

ngOnInit(): void {
this.router.navigate(['/share/view1']);
this.tableService.initViews(initViews);
const value = getDefaultValue();
this.tableService.initRecordsAndFields(value.records, value.fields);
this.router.navigate(['/view1']);
this.tableService.initData(initViews);
}

activeTabChange(data: any) {
this.tableService.updateActiveView(data);
this.router.navigateByUrl(`/share/${this.tableService.activeView().id}`);
this.router.navigateByUrl(`/${this.tableService.activeView().id}`);
}

handleShared() {
Expand Down
Loading

0 comments on commit e4a44ec

Please sign in to comment.