Rebuild database task now asks for confirmation before rebuilding

Fixed api types build errors
This commit is contained in:
Isaac Abadi
2023-05-21 00:11:48 -06:00
parent a38fb0e2e0
commit 2fcf5364d8
3 changed files with 44 additions and 12 deletions

View File

@@ -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;

View File

@@ -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!`);

View File

@@ -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<SuccessObject>(this.path + 'resetTasks', {}, this.httpOptions);
}
getTask(task_key: string) {
getTask(task_key: TaskType) {
const body: GetTaskRequest = {task_key: task_key};
return this.http.post<GetTaskResponse>(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<SuccessObject>(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<SuccessObject>(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<SuccessObject>(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<SuccessObject>(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<SuccessObject>(this.path + 'updateTaskOptions', body, this.httpOptions);
}