Browse Source

feat: new comp edit object

ryanemax 9 months ago
parent
commit
4523a6a24b

+ 8 - 0
projects/textbook/src/app/comp-comfirm-dialog/comp-comfirm-dialog.component.html

@@ -0,0 +1,8 @@
+<h1 mat-dialog-title>{{data.title}}</h1>
+<div mat-dialog-content *ngIf="data?.message">
+  <p>{{data?.message}}</p>
+</div>
+<div mat-dialog-actions>
+  <button mat-button (click)="confirm(false)" >{{'取消'|translate}}</button>
+  <button mat-button (click)="confirm(true)" >{{'确认'|translate}}</button>
+</div>

+ 0 - 0
projects/textbook/src/app/comp-comfirm-dialog/comp-comfirm-dialog.component.scss


+ 23 - 0
projects/textbook/src/app/comp-comfirm-dialog/comp-comfirm-dialog.component.spec.ts

@@ -0,0 +1,23 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { CompComfirmDialogComponent } from './comp-comfirm-dialog.component';
+
+describe('CompComfirmDialogComponent', () => {
+  let component: CompComfirmDialogComponent;
+  let fixture: ComponentFixture<CompComfirmDialogComponent>;
+
+  beforeEach(async () => {
+    await TestBed.configureTestingModule({
+      declarations: [ CompComfirmDialogComponent ]
+    })
+    .compileComponents();
+
+    fixture = TestBed.createComponent(CompComfirmDialogComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 32 - 0
projects/textbook/src/app/comp-comfirm-dialog/comp-comfirm-dialog.component.ts

@@ -0,0 +1,32 @@
+import { CommonModule } from '@angular/common';
+import { Component, Inject } from '@angular/core';
+import { MatButtonModule } from '@angular/material/button';
+import { MatDialogModule, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
+import { TranslateModule } from '@ngx-translate/core';
+
+@Component({
+  selector: 'app-comp-comfirm-dialog',
+  standalone:true,
+  imports:[ 
+    CommonModule,
+    MatButtonModule,
+    MatDialogModule,
+    TranslateModule,
+  ],
+  templateUrl: './comp-comfirm-dialog.component.html',
+  styleUrls: ['./comp-comfirm-dialog.component.scss']
+})
+export class CompComfirmDialogComponent {
+  constructor(
+    public dialogRef: MatDialogRef<CompComfirmDialogComponent>,
+    @Inject(MAT_DIALOG_DATA) public data: {
+      title:string|null,
+      message:string|null,
+    },
+  ){
+  }
+  confirm(result:any){
+    this.dialogRef.close(result)
+  }
+
+}

+ 9 - 8
projects/textbook/src/app/comp-table/comp-edit-object/comp-edit-object.component.html

@@ -1,19 +1,20 @@
-<h1 mat-dialog-title *ngIf="data?.cluster?.id">{{"编辑" | translate}}-{{data?.cluster?.get("name") | translate}}</h1>
-<h1 mat-dialog-title *ngIf="!data?.cluster?.id">{{"创建新" | translate}}{{data?.title}}</h1>
+<h1 mat-dialog-title *ngIf="data?.object?.id">{{"编辑"}}-{{data?.object?.get("name")}}</h1>
+<h1 mat-dialog-title *ngIf="!data?.object?.id">{{"创建新"}}{{data?.title}}</h1>
 <div mat-dialog-content>
-    <form>
+    <form *ngIf="isFormShow">
         <ng-container *ngFor="let field of data?.fieldsArray">
             <mat-form-field>
-                <mat-label translate>{{field?.name}}</mat-label>
-                <input matInput [(ngModel)]="jsonData[field?.key]" [formControl]="formControlMap[field?.key]" [errorState]="requiredErrorMap[field?.key]">
+                <mat-label >{{field?.name}}</mat-label>
+                <!-- [errorState]="requiredErrorMap[field?.key]" -->
+                <input matInput [(ngModel)]="jsonData[field?.key]" [formControl]="formControlMap[field?.key]||null" >
                 <mat-error *ngIf="requiredErrorMap[field?.key]">
-                    {{field?.name | translate}}<strong translate>必填</strong>
+                    {{field?.name}}<strong >必填</strong>
                 </mat-error>
             </mat-form-field>
         </ng-container>
     </form>
 </div>
 <div mat-dialog-actions>
-  <button mat-button [disabled]="isSaving" (click)="close()" >{{"取消" | translate}}</button>
-  <button mat-button [disabled]="isSaving" (click)="save()" >{{"保存" | translate}}</button>
+  <button mat-button [disabled]="isSaving" (click)="close()" >{{"取消"}}</button>
+  <button mat-button [disabled]="isSaving" (click)="save()" >{{"保存"}}</button>
 </div>

+ 4 - 0
projects/textbook/src/app/comp-table/comp-edit-object/comp-edit-object.component.scss

@@ -0,0 +1,4 @@
+form{
+    display: flex;
+    flex-direction: column;
+}

+ 21 - 16
projects/textbook/src/app/comp-table/comp-edit-object/comp-edit-object.component.ts

@@ -5,8 +5,8 @@ import { MatButtonModule } from '@angular/material/button';
 import { MatDialogModule, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
 import { MatFormFieldModule } from '@angular/material/form-field';
 import { MatInputModule } from '@angular/material/input';
-import { TranslateModule } from '@ngx-translate/core';
 import Parse from "parse";
+import { ParseSchema } from '../../../schemas/func-parse';
 
 @Component({
   selector: 'app-comp-edit-object',
@@ -14,26 +14,25 @@ import Parse from "parse";
   imports:[ 
     CommonModule,
     FormsModule,
-    MatFormFieldModule,
     ReactiveFormsModule,
+    MatFormFieldModule,
     MatInputModule,
     MatButtonModule,
     MatDialogModule,
-    TranslateModule,
+    // MatFormFieldModule,
   ],
   templateUrl: './comp-edit-object.component.html',
   styleUrls: ['./comp-edit-object.component.scss']
 })
 export class CompEditObjectComponent {
   jsonData:any = {}
-  MinerCluster = Parse.Object.extend("MinerCluster")
-
   formControlMap:any = {}
+  isFormShow:boolean = false;
   constructor(
     public dialogRef: MatDialogRef<CompEditObjectComponent>,
     @Inject(MAT_DIALOG_DATA) public data: {
-      cluster:Parse.Object|null|undefined,
-      center:Parse.Object|null|undefined,
+      schema:ParseSchema|undefined,
+      object:Parse.Object|null|undefined,
       fieldsArray:Array<any>|null,
       title:string|null,
       default?:any
@@ -41,19 +40,25 @@ export class CompEditObjectComponent {
   ){
     // 设置数据校验
     this.data?.fieldsArray?.forEach(field=>{
+      this.formControlMap[field?.key] = new FormControl(field?.key)
       if(field?.require){
         this.formControlMap[field?.key] = new FormControl(field?.key, [Validators.required]);
       }
     })
-    if(this.data.cluster?.toJSON()){
-      this.jsonData = this.data?.cluster?.toJSON();
+    if(this.data.object?.toJSON()){
+      this.jsonData = this.data?.object?.toJSON();
+      console.log(this.jsonData)
     }
-    if(!this.data?.cluster?.id){
-      this.data.cluster = new this.MinerCluster()
+    if(!this.data?.object?.id){
+      let className:any = this.data?.object?.className || this.data.schema?.className
+      let SchemaContructor =  Parse.Object.extend(className)
+      this.data.object = new SchemaContructor()
     }
   }
   ngOnInit(){
-
+    setTimeout(() => {
+      this.isFormShow = true
+    }, 200);
   }
   /**
    * 保存与取消
@@ -83,16 +88,16 @@ export class CompEditObjectComponent {
     delete this.jsonData.updatedAt
     delete this.jsonData.createdAt
     delete this.jsonData.ACL
-    this.data?.cluster?.set(this.jsonData);
+    this.data?.object?.set(this.jsonData);
 
     // 设置默认值
     if(this.data?.default){
-      this.data?.cluster?.set(this.data?.default)
+      this.data?.object?.set(this.data?.default)
     }
 
     // 保存并返回
-    this.data.cluster = await this.data?.cluster?.save();
-    this.dialogRef.close(this.data?.cluster);
+    this.data.object = await this.data?.object?.save();
+    this.dialogRef.close(this.data?.object);
     this.isSaving = false
 
   }

+ 3 - 1
projects/textbook/src/schemas/EduTextbook.ts

@@ -1,7 +1,9 @@
 import { MatDialog } from "@angular/material/dialog";
 import Parse from "parse";
+import { ParseSchema } from "./func-parse";
 
-export const EduTextbook = {
+export const EduTextbook:ParseSchema = {
+    title:"教材",
     className:"EduTextbook",
     include:["user"],
     buttons:[

+ 7 - 4
projects/textbook/src/schemas/_Role.ts

@@ -1,6 +1,9 @@
+import { MatDialog } from "@angular/material/dialog";
+import { openObjectEditDialog, ParseSchema } from "./func-parse";
 
 
-    const _Role = {
+    const _Role:ParseSchema = {
+        "title":"用户组",
         "className": "_Role",
         "fieldsArray": [
             {
@@ -34,9 +37,9 @@
                 show:(options:{object:Parse.Object})=>{
                     return true
                 },
-                // handle:(options:{clusterServ:ClusterService,dialog:MatDialog,object:Parse.Object})=>{
-                //     options?.clusterServ?.openMinerDialog(options?.dialog,options?.object)
-                // }
+                handle:(options:{dialog:MatDialog,object:Parse.Object})=>{
+                    openObjectEditDialog(options?.dialog,_Role,options?.object)
+                }
             },
         ]
       };

+ 62 - 0
projects/textbook/src/schemas/func-parse.ts

@@ -0,0 +1,62 @@
+import { MatDialog } from "@angular/material/dialog";
+import { CompComfirmDialogComponent } from "../app/comp-comfirm-dialog/comp-comfirm-dialog.component";
+import { CompEditObjectComponent } from "../app/comp-table/comp-edit-object/comp-edit-object.component";
+
+export interface ParseField{
+    key:string
+    name:string
+    type:string
+    className?:string
+    showName?:string
+    isHeader?:boolean
+}
+export interface ParseSchema{
+    title:string
+    className:string,
+    fieldsArray:Array<ParseField>
+    include?:Array<string>,
+    buttons?:Array<any>,
+}
+
+/**
+   * 创建集装箱
+   * @param dialog 
+   * @param cluster 
+   * @param afterClosed 
+   */
+ export function openObjectEditDialog(dialog: MatDialog,schema:ParseSchema, object?: Parse.Object, afterClosed?: Function): void {
+    let dialogRef = dialog.open(CompEditObjectComponent, {
+      data: {
+        title: schema?.title,
+        fieldsArray: schema?.fieldsArray,
+        default: {
+        //   center: this.center?.toPointer(),
+        //   type: "cluster",
+        //   isOnline: true,
+        },
+        schema:schema,
+        object: object,
+      },
+    });
+
+    dialogRef.afterClosed().subscribe(result => {
+      console.log('The dialog was closed', result);
+      afterClosed && afterClosed(result)
+    });
+  }
+  export function confirmDialog(dialog:MatDialog, options: {
+    title: string,
+    message?: string,
+    handleOK?: Function
+  }) {
+    let dialogRef = dialog.open(CompComfirmDialogComponent, {
+      data: {
+        title: options?.title,
+        message: options?.message,
+      },
+    });
+
+    dialogRef.afterClosed().subscribe(isOK => {
+      isOK && options?.handleOK && options?.handleOK()
+    });
+  }

+ 3 - 2
server/db/data/init-data.sql

@@ -18,11 +18,12 @@ SET
 "updatedAt"=excluded."updatedAt";
 
 -- 初始化超级管理员角色
-INSERT INTO "_Role" ("objectId", "name", "_rperm", "_wperm", "company", "createdAt", "updatedAt")
+INSERT INTO "_Role" ("objectId","title", "name", "_rperm", "_wperm", "company", "createdAt", "updatedAt")
 VALUES
-('ZQOwyoDteL', 'superadmin','{*,BOOKADMINI}','{BOOKADMINI}','RbIKpmuaMC','2024-06-16 12:00:00','2024-06-16 12:00:00')
+('ZQOwyoDteL','超级管理员', 'superadmin','{*,BOOKADMINI}','{BOOKADMINI}','RbIKpmuaMC','2024-06-16 12:00:00','2024-06-16 12:00:00')
 ON conflict("objectId") DO UPDATE
 SET 
+"title" = excluded."title",
 "name" = excluded."name",
 "company" = excluded."company",
 "createdAt"=excluded."createdAt";

+ 3 - 0
server/db/schemas/_Role.js

@@ -1,6 +1,9 @@
 const _Role = {
     "className": "_Role",
     "fields": {
+        "title": {
+            "type": "String"
+        },
         "name": {
             "type": "String"
         },