From 2fcf5364d810c8e00c9845f7e499e52722fa641d Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Sun, 21 May 2023 00:11:48 -0600 Subject: [PATCH] Rebuild database task now asks for confirmation before rebuilding Fixed api types build errors --- .../task-settings/task-settings.component.ts | 4 +- src/app/components/tasks/tasks.component.ts | 37 +++++++++++++++++-- src/app/posts.services.ts | 15 ++++---- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/app/components/task-settings/task-settings.component.ts b/src/app/components/task-settings/task-settings.component.ts index f96b57e..c616177 100644 --- a/src/app/components/task-settings/task-settings.component.ts +++ b/src/app/components/task-settings/task-settings.component.ts @@ -1,6 +1,6 @@ import { Component, Inject } from '@angular/core'; import { MAT_DIALOG_DATA } from '@angular/material/dialog'; -import { Task } from 'api-types'; +import { Task, TaskType } from 'api-types'; import { PostsService } from 'app/posts.services'; @Component({ @@ -9,7 +9,7 @@ import { PostsService } from 'app/posts.services'; styleUrls: ['./task-settings.component.scss'] }) export class TaskSettingsComponent { - task_key: string; + task_key: TaskType; new_options = {}; task: Task = null; diff --git a/src/app/components/tasks/tasks.component.ts b/src/app/components/tasks/tasks.component.ts index d462429..3627c5a 100644 --- a/src/app/components/tasks/tasks.component.ts +++ b/src/app/components/tasks/tasks.component.ts @@ -7,7 +7,7 @@ import { ConfirmDialogComponent } from 'app/dialogs/confirm-dialog/confirm-dialo import { RestoreDbDialogComponent } from 'app/dialogs/restore-db-dialog/restore-db-dialog.component'; import { UpdateTaskScheduleDialogComponent } from 'app/dialogs/update-task-schedule-dialog/update-task-schedule-dialog.component'; import { PostsService } from 'app/posts.services'; -import { Task } from 'api-types'; +import { Task, TaskType } from 'api-types'; import { TaskSettingsComponent } from '../task-settings/task-settings.component'; import { Clipboard } from '@angular/cdk/clipboard'; @@ -28,6 +28,15 @@ export class TasksComponent implements OnInit { db_backups = []; + TASKS_TO_REQUIRE_DIALOG: { [key in TaskType]? : {dialogTitle: string, dialogText: string, submitText: string, warnSubmitColor: boolean}} = { + [TaskType.REBUILD_DATABASE]: { + dialogTitle: $localize`Rebuild database`, + dialogText: $localize`Are you sure you want to rebuild the database? All missing users, subscriptions, and files will be reimported. Note that if missing users are detected, they will be created with the password: 'password'. A backup of your current database will be created.`, + submitText: $localize`Rebuild database`, + warnSubmitColor: false + } + } + @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; @@ -79,7 +88,29 @@ export class TasksComponent implements OnInit { }); } - runTask(task_key: string): void { + runTask(task_key: TaskType): void { + const taskToRequireDialog = this.TASKS_TO_REQUIRE_DIALOG[task_key]; + if (taskToRequireDialog) { + const dialogRef = this.dialog.open(ConfirmDialogComponent, { + data: { + dialogTitle: taskToRequireDialog['dialogTitle'], + dialogText: taskToRequireDialog['dialogText'], + submitText: taskToRequireDialog['submitText'], + warnSubmitColor: taskToRequireDialog['warnSubmitColor'] + } + }); + dialogRef.afterClosed().subscribe(confirmed => { + if (confirmed) { + this._runTask(task_key); + } + }); + return; + } + + this._runTask(task_key); + } + + _runTask(task_key: TaskType): void { this.postsService.runTask(task_key).subscribe(res => { this.getTasks(); this.getDBBackups(); @@ -91,7 +122,7 @@ export class TasksComponent implements OnInit { }); } - confirmTask(task_key: string): void { + confirmTask(task_key: TaskType): void { this.postsService.confirmTask(task_key).subscribe(res => { this.getTasks(); if (res['success']) this.postsService.openSnackBar($localize`Successfully confirmed task!`); diff --git a/src/app/posts.services.ts b/src/app/posts.services.ts index 0183bcf..59a0be3 100644 --- a/src/app/posts.services.ts +++ b/src/app/posts.services.ts @@ -112,7 +112,8 @@ import { ImportArchiveRequest, Archive, Subscription, - RestartDownloadResponse + RestartDownloadResponse, + TaskType } from '../api-types'; import { isoLangs } from './settings/locales_list'; import { Title } from '@angular/platform-browser'; @@ -640,32 +641,32 @@ export class PostsService implements CanActivate { return this.http.post(this.path + 'resetTasks', {}, this.httpOptions); } - getTask(task_key: string) { + getTask(task_key: TaskType) { const body: GetTaskRequest = {task_key: task_key}; return this.http.post(this.path + 'getTask', body, this.httpOptions); } - runTask(task_key: string) { + runTask(task_key: TaskType) { const body: GetTaskRequest = {task_key: task_key}; return this.http.post(this.path + 'runTask', body, this.httpOptions); } - confirmTask(task_key: string) { + confirmTask(task_key: TaskType) { const body: GetTaskRequest = {task_key: task_key}; return this.http.post(this.path + 'confirmTask', body, this.httpOptions); } - updateTaskSchedule(task_key: string, schedule: Schedule) { + updateTaskSchedule(task_key: TaskType, schedule: Schedule) { const body: UpdateTaskScheduleRequest = {task_key: task_key, new_schedule: schedule}; return this.http.post(this.path + 'updateTaskSchedule', body, this.httpOptions); } - updateTaskData(task_key: string, data: any) { + updateTaskData(task_key: TaskType, data: any) { const body: UpdateTaskDataRequest = {task_key: task_key, new_data: data}; return this.http.post(this.path + 'updateTaskData', body, this.httpOptions); } - updateTaskOptions(task_key: string, options: any) { + updateTaskOptions(task_key: TaskType, options: any) { const body: UpdateTaskOptionsRequest = {task_key: task_key, new_options: options}; return this.http.post(this.path + 'updateTaskOptions', body, this.httpOptions); }