import { RhSycService } from './../../syc.service'; import { DatabaseBackupConfigDto, ConfigGroupDatasDto, ConfigGroupDatasQueryDto } from './../../syc-models'; import { Component, OnInit } from '@angular/core'; import { UntypedFormGroup, UntypedFormBuilder, Validators } from '@angular/forms'; import { DateHelper, FormHelper, MsgHelper, ArrayHelper } from 'rh-base/core'; import { RhSafeAny } from 'rh-base/model'; @Component({ selector: 'rh-database-backup-manage', templateUrl: './database-backup-manage.component.html', styleUrls: ['./database-backup-manage.component.less'] }) export class RhDatabaseBackupManageComponent implements OnInit { databaseBackupConfigDtoForm!: UntypedFormGroup; dataLoading = false; fFormData: DatabaseBackupConfigDto | null = null; submitBusy = false; opSign = 1; // 是否有选中项 isCheckedSome = false; editViewTitle = '新增配置数据'; editViewVisible = false; // 数据展示 dataSetLoading = false; dataSet: ConfigGroupDatasDto[] = []; dataSetDisplay: ConfigGroupDatasDto[] = []; // 选择行控制变量 isAllDisplayDataChecked = false; isIndeterminate = false; mapOfCheckedId: { [key: string]: boolean } = {}; constructor(private fb: UntypedFormBuilder, private dataOperate: RhSycService) { // } ngOnInit() { this.fFormData = this.initDatabaseBackupConfigDto(); this.createDatabaseBackupConfigDtoForm(this.fFormData); this.loadDatabaseBacukupDatas(); } createDatabaseBackupConfigDtoForm(dto: DatabaseBackupConfigDto): void { this.databaseBackupConfigDtoForm = this.fb.group({ ServerIp: [dto.ServerIp, [Validators.required]], UserId: [dto.UserId, [Validators.required]], Password: [dto.Password, [Validators.required]], DatabaseList: [dto.DatabaseList, [Validators.required]], BackupFilePath: [dto.BackupFilePath, [Validators.required]], BackupFileNamedRule: [dto.BackupFileNamedRule, [Validators.required]], IsCreateDircetoryPerDb: [dto.IsCreateDircetoryPerDb, [Validators.required]], FirstBackupTime: [dto.FirstBackupTime, [Validators.required]], BackupTimeInterval: [dto.BackupTimeInterval, [Validators.required]], BackupRetentionPeroid: [dto.BackupRetentionPeroid, [Validators.required]], ClearRedundanceBackup: [dto.ClearRedundanceBackup, [Validators.required]] }); } initDatabaseBackupConfigDto(): DatabaseBackupConfigDto { return new DatabaseBackupConfigDto( '', '', '', [], 'd:\\DataBase\\BackupDB', '{DB}-yyyyMMddHHmmssfff', true, DateHelper.now(), DateHelper.now(), 1, '' ); } submitForm($event: Event): void { $event.preventDefault(); FormHelper.YGSubmitForm(this.fFormData as DatabaseBackupConfigDto, this.databaseBackupConfigDtoForm, (dto) => { this.submitBusy = true; this.dataOperate.StoreDatabaseBackupConfigData(dto as RhSafeAny).subscribe((opresult) => { FormHelper.HandleOpResult(opresult, (r) => { MsgHelper.ShowSuccessModal('数据库备份配置成功!'); this.resetForm($event); this.loadDatabaseBacukupDatas(); this.closeEditView(); }); }); }); } resetForm($event: Event): void { $event.preventDefault(); this.submitBusy = false; this.databaseBackupConfigDtoForm.reset(this.initDatabaseBackupConfigDto()); } loadDatabaseBacukupDatas(): void { const queryDto = new ConfigGroupDatasQueryDto(null, null, null, null, -1, 'PP'); queryDto.GroupKey = 'DatabaeBackup'; this.dataOperate.GetGroupConfigDatas(queryDto).subscribe((dataresult) => { FormHelper.HandleDataResult(dataresult, (r) => { this.dataSet = r.Attach as ConfigGroupDatasDto[]; }); }); } closeEditView(): void { this.editViewVisible = false; } navToEidtView(title: string, opSign: number, formData: DatabaseBackupConfigDto): void { this.editViewVisible = true; this.editViewTitle = title; this.fFormData = formData; this.opSign = opSign; this.databaseBackupConfigDtoForm.reset(this.fFormData); } addNew(): void { this.navToEidtView('新增数据库备份配置数据', 1, this.initDatabaseBackupConfigDto()); } editDto(dto: ConfigGroupDatasDto): void { const editItem: DatabaseBackupConfigDto = JSON.parse(dto.CustomData?.toString() as string); this.navToEidtView('修改配置数据', 2, editItem); } removeDtos(): void { MsgHelper.ShowDeleteConfirm( '删除该配置数据,该配置数据将会彻底删除!', () => { const dtos: ConfigGroupDatasDto[] = this.dataSet.filter((item) => this.mapOfCheckedId[`${item.GroupKey}_${item.Name}`]); if (dtos.length > 0) { this.dataOperate.RemoveConfigGroupDatas(dtos).subscribe((dr) => { FormHelper.HandleOpResult(dr, (r) => { this.dataSet = ArrayHelper.Remove(this.dataSet, (f) => this.mapOfCheckedId[`${f.GroupKey}_${f.Name}`]); }); }); } }, () => { // } ); } // -----------------------table 控制------------------------------------------- currentPageDataChange($event: ConfigGroupDatasDto[]): void { this.dataSetDisplay = $event; this.refreshStatus(); } refreshStatus(): void { this.isAllDisplayDataChecked = this.dataSetDisplay.every((item) => this.mapOfCheckedId[`${item.GroupKey}_${item.Name}`]); this.isIndeterminate = this.dataSetDisplay.some((item) => this.mapOfCheckedId[`${item.GroupKey}_${item.Name}`]) && !this.isAllDisplayDataChecked; this.isCheckedSome = this.dataSet.filter((item) => this.mapOfCheckedId[`${item.GroupKey}_${item.Name}`]).length > 0; } checkAll(value: boolean): void { this.dataSetDisplay.forEach((item) => (this.mapOfCheckedId[`${item.GroupKey}_${item.Name}`] = value)); this.refreshStatus(); } }