Confirm dialog can now optionally use warn colors (used for deletion or breaking changes)

Category re-ordering is fixed

Category deletion in settings is now functional
categories
Isaac Abadi 4 years ago
parent 6f089491a5
commit d4e5082039

@ -61,7 +61,8 @@ export class LogsViewerComponent implements OnInit {
data: { data: {
dialogTitle: 'Clear logs', dialogTitle: 'Clear logs',
dialogText: 'Would you like to clear your logs? This will delete all your current logs, permanently.', dialogText: 'Would you like to clear your logs? This will delete all your current logs, permanently.',
submitText: 'Clear' submitText: 'Clear',
warnSubmitColor: true
} }
}); });
dialogRef.afterClosed().subscribe(confirmed => { dialogRef.afterClosed().subscribe(confirmed => {

@ -6,7 +6,7 @@
</mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions> <mat-dialog-actions>
<!-- The mat-dialog-close directive optionally accepts a value as a result for the dialog. --> <!-- The mat-dialog-close directive optionally accepts a value as a result for the dialog. -->
<button color="primary" mat-flat-button type="submit" (click)="confirmClicked()">{{submitText}}</button> <button [color]="warnSubmitColor ? 'warn' : 'primary'" mat-flat-button type="submit" (click)="confirmClicked()">{{submitText}}</button>
<div class="mat-spinner" *ngIf="submitClicked"> <div class="mat-spinner" *ngIf="submitClicked">
<mat-spinner [diameter]="25"></mat-spinner> <mat-spinner [diameter]="25"></mat-spinner>
</div> </div>

@ -15,12 +15,14 @@ export class ConfirmDialogComponent implements OnInit {
doneEmitter: EventEmitter<any> = null; doneEmitter: EventEmitter<any> = null;
onlyEmitOnDone = false; onlyEmitOnDone = false;
warnSubmitColor = false;
constructor(@Inject(MAT_DIALOG_DATA) public data: any, public dialogRef: MatDialogRef<ConfirmDialogComponent>) { constructor(@Inject(MAT_DIALOG_DATA) public data: any, public dialogRef: MatDialogRef<ConfirmDialogComponent>) {
if (this.data.dialogTitle) { this.dialogTitle = this.data.dialogTitle }; if (this.data.dialogTitle) { this.dialogTitle = this.data.dialogTitle };
if (this.data.dialogText) { this.dialogText = this.data.dialogText }; if (this.data.dialogText) { this.dialogText = this.data.dialogText };
if (this.data.submitText) { this.submitText = this.data.submitText }; if (this.data.submitText) { this.submitText = this.data.submitText };
if (this.data.warnSubmitColor) { this.warnSubmitColor = this.data.warnSubmitColor };
// checks if emitter exists, if so don't autoclose as it should be handled by caller // checks if emitter exists, if so don't autoclose as it should be handled by caller
if (this.data.doneEmitter) { if (this.data.doneEmitter) {

@ -135,7 +135,7 @@
{{category['name']}} {{category['name']}}
<span style="float: right"> <span style="float: right">
<button mat-icon-button (click)="openEditCategoryDialog(category)"><mat-icon>edit</mat-icon></button> <button mat-icon-button (click)="openEditCategoryDialog(category)"><mat-icon>edit</mat-icon></button>
<button mat-icon-button><mat-icon>cancel</mat-icon></button> <button mat-icon-button (click)="deleteCategory(category)"><mat-icon>cancel</mat-icon></button>
</span> </span>
</div> </div>
</div> </div>

@ -82,7 +82,11 @@ export class SettingsComponent implements OnInit {
dropCategory(event: CdkDragDrop<string[]>) { dropCategory(event: CdkDragDrop<string[]>) {
moveItemInArray(this.postsService.categories, event.previousIndex, event.currentIndex); moveItemInArray(this.postsService.categories, event.previousIndex, event.currentIndex);
this.postsService.updateCategories(this.postsService.categories); this.postsService.updateCategories(this.postsService.categories).subscribe(res => {
}, err => {
this.postsService.openSnackBar('Failed to update categories!');
});
} }
openAddCategoryDialog() { openAddCategoryDialog() {
@ -113,6 +117,29 @@ export class SettingsComponent implements OnInit {
}); });
} }
deleteCategory(category) {
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
data: {
dialogTitle: 'Delete category',
dialogText: `Would you like to delete ${category['name']}?`,
submitText: 'Delete',
warnSubmitColor: true
}
});
dialogRef.afterClosed().subscribe(confirmed => {
if (confirmed) {
this.postsService.deleteCategory(category['uid']).subscribe(res => {
if (res['success']) {
this.postsService.openSnackBar(`Successfully deleted ${category['name']}!`);
this.postsService.reloadCategories();
}
}, err => {
this.postsService.openSnackBar(`Failed to delete ${category['name']}!`);
});
}
});
}
openEditCategoryDialog(category) { openEditCategoryDialog(category) {
this.dialog.open(EditCategoryDialogComponent, { this.dialog.open(EditCategoryDialogComponent, {
data: { data: {
@ -206,7 +233,8 @@ export class SettingsComponent implements OnInit {
dialogTitle: 'Kill downloads', dialogTitle: 'Kill downloads',
dialogText: 'Are you sure you want to kill all downloads? Any subscription and non-subscription downloads will end immediately, though this operation may take a minute or so to complete.', dialogText: 'Are you sure you want to kill all downloads? Any subscription and non-subscription downloads will end immediately, though this operation may take a minute or so to complete.',
submitText: 'Kill all downloads', submitText: 'Kill all downloads',
doneEmitter: done doneEmitter: done,
warnSubmitColor: true
} }
}); });
done.subscribe(confirmed => { done.subscribe(confirmed => {

Loading…
Cancel
Save