|
@@ -0,0 +1,100 @@
|
|
|
|
+import { CommonModule } from '@angular/common';
|
|
|
|
+import { Component, Inject } from '@angular/core';
|
|
|
|
+import { FormControl, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
|
|
|
|
+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";
|
|
|
|
+
|
|
|
|
+@Component({
|
|
|
|
+ selector: 'app-comp-edit-object',
|
|
|
|
+ standalone:true,
|
|
|
|
+ imports:[
|
|
|
|
+ CommonModule,
|
|
|
|
+ FormsModule,
|
|
|
|
+ MatFormFieldModule,
|
|
|
|
+ ReactiveFormsModule,
|
|
|
|
+ MatInputModule,
|
|
|
|
+ MatButtonModule,
|
|
|
|
+ MatDialogModule,
|
|
|
|
+ TranslateModule,
|
|
|
|
+ ],
|
|
|
|
+ templateUrl: './comp-edit-object.component.html',
|
|
|
|
+ styleUrls: ['./comp-edit-object.component.scss']
|
|
|
|
+})
|
|
|
|
+export class CompEditObjectComponent {
|
|
|
|
+ jsonData:any = {}
|
|
|
|
+ MinerCluster = Parse.Object.extend("MinerCluster")
|
|
|
|
+
|
|
|
|
+ formControlMap:any = {}
|
|
|
|
+ constructor(
|
|
|
|
+ public dialogRef: MatDialogRef<CompEditObjectComponent>,
|
|
|
|
+ @Inject(MAT_DIALOG_DATA) public data: {
|
|
|
|
+ cluster:Parse.Object|null|undefined,
|
|
|
|
+ center:Parse.Object|null|undefined,
|
|
|
|
+ fieldsArray:Array<any>|null,
|
|
|
|
+ title:string|null,
|
|
|
|
+ default?:any
|
|
|
|
+ },
|
|
|
|
+ ){
|
|
|
|
+ // 设置数据校验
|
|
|
|
+ this.data?.fieldsArray?.forEach(field=>{
|
|
|
|
+ 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?.cluster?.id){
|
|
|
|
+ this.data.cluster = new this.MinerCluster()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ngOnInit(){
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 保存与取消
|
|
|
|
+ */
|
|
|
|
+ close(){
|
|
|
|
+ this.dialogRef.close();
|
|
|
|
+ }
|
|
|
|
+ isSaving:boolean = false;
|
|
|
|
+ requiredErrorMap:any = {}
|
|
|
|
+ async save() {
|
|
|
|
+ if(this.isSaving) return;
|
|
|
|
+ this.isSaving = true
|
|
|
|
+ // 检查必填项
|
|
|
|
+ this.requiredErrorMap = {}
|
|
|
|
+ this.data?.fieldsArray?.forEach(field=>{
|
|
|
|
+ if(field?.require && typeof this.jsonData[field?.key] == "undefined"){
|
|
|
|
+ this.requiredErrorMap[field?.key] = true
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ if(Object.keys(this.requiredErrorMap)?.length>=1){
|
|
|
|
+ this.isSaving = false
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 设置编辑结果
|
|
|
|
+ delete this.jsonData.objectId
|
|
|
|
+ delete this.jsonData.updatedAt
|
|
|
|
+ delete this.jsonData.createdAt
|
|
|
|
+ delete this.jsonData.ACL
|
|
|
|
+ this.data?.cluster?.set(this.jsonData);
|
|
|
|
+
|
|
|
|
+ // 设置默认值
|
|
|
|
+ if(this.data?.default){
|
|
|
|
+ this.data?.cluster?.set(this.data?.default)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 保存并返回
|
|
|
|
+ this.data.cluster = await this.data?.cluster?.save();
|
|
|
|
+ this.dialogRef.close(this.data?.cluster);
|
|
|
|
+ this.isSaving = false
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|