Added category delete (Fixes #8)

This commit is contained in:
Zakary Timson 2018-07-15 13:31:58 -04:00
parent 4d6bfc5f4d
commit 20979dd4b1
5 changed files with 38 additions and 2 deletions

View File

@ -21,6 +21,7 @@ import {BreadcrumbService} from './store/breadcrumb.service';
import {LoginComponent} from './login/login.component'; import {LoginComponent} from './login/login.component';
import {AngularFireAuthModule} from 'angularfire2/auth'; import {AngularFireAuthModule} from 'angularfire2/auth';
import {NewCategoryComponent} from './store/newCategory/newCategory.component'; import {NewCategoryComponent} from './store/newCategory/newCategory.component';
import {DeleteCategoryComponent} from './store/deleteCategory/deleteCategory.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -28,6 +29,7 @@ import {NewCategoryComponent} from './store/newCategory/newCategory.component';
CategoriesComponent, CategoriesComponent,
ConvertFromGPipe, ConvertFromGPipe,
ConvertToGPipe, ConvertToGPipe,
DeleteCategoryComponent,
FormulaManagerComponent, FormulaManagerComponent,
HomeComponent, HomeComponent,
LoginComponent, LoginComponent,
@ -56,7 +58,7 @@ import {NewCategoryComponent} from './store/newCategory/newCategory.component';
ServiceWorkerModule.register('/ngsw-worker.js', {enabled: environment.production}) ServiceWorkerModule.register('/ngsw-worker.js', {enabled: environment.production})
], ],
providers: [BreadcrumbService], providers: [BreadcrumbService],
entryComponents: [LoginComponent, NewCategoryComponent], entryComponents: [DeleteCategoryComponent, LoginComponent, NewCategoryComponent],
bootstrap: [AppComponent] bootstrap: [AppComponent]
}) })
export class AppModule { export class AppModule {

View File

@ -29,7 +29,7 @@
<button mat-raised-button (click)="create(c)"> <button mat-raised-button (click)="create(c)">
<mat-icon>edit</mat-icon> <mat-icon>edit</mat-icon>
</button> </button>
<button mat-raised-button class="ml-3"> <button mat-raised-button class="ml-3" (click)="delete(c)">
<mat-icon>delete</mat-icon> <mat-icon>delete</mat-icon>
</button> </button>
</mat-card-actions> </mat-card-actions>

View File

@ -8,6 +8,7 @@ import {MatDialog} from '../../../node_modules/@angular/material';
import {NewCategoryComponent} from './newCategory/newCategory.component'; import {NewCategoryComponent} from './newCategory/newCategory.component';
import {AppComponent} from '../app.component'; import {AppComponent} from '../app.component';
import {DomSanitizer} from '../../../node_modules/@angular/platform-browser'; import {DomSanitizer} from '../../../node_modules/@angular/platform-browser';
import {DeleteCategoryComponent} from './deleteCategory/deleteCategory.component';
@Component({ @Component({
selector: 'store', selector: 'store',
@ -61,4 +62,8 @@ export class CategoriesComponent {
create(category) { create(category) {
this.dialog.open(NewCategoryComponent, {data: {category: category, currentCategory: this.category}}); this.dialog.open(NewCategoryComponent, {data: {category: category, currentCategory: this.category}});
} }
delete(category) {
this.dialog.open(DeleteCategoryComponent, {data: category});
}
} }

View File

@ -0,0 +1,13 @@
<mat-dialog-content>
<h3 mat-dialog-title>Delete {{data.name}}</h3>
<p>You are about to delete a category, any items attached to it will be lost.
<br>Edit the items and change their category to prevent this, once ready,
<br>please re-enter
<span style="background-color: #ffff00">{{data.name}}</span> bellow to awknoledge your action.</p>
<mat-form-field>
<input matInput placeholder="Confirm" [(ngModel)]="confirm">
</mat-form-field>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-raised-button color="primary" (click)="delete()" [disabled]="confirm.toLowerCase() != data.name.toLowerCase()">Delete</button>
</mat-dialog-actions>

View File

@ -0,0 +1,16 @@
import {Component, Inject} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef} from '../../../../node_modules/@angular/material';
@Component({
selector: 'delete-category',
templateUrl: 'deleteCategory.component.html'
})
export class DeleteCategoryComponent {
confirm = '';
constructor(private dialogRef: MatDialogRef<DeleteCategoryComponent>, @Inject(MAT_DIALOG_DATA) public data) {}
delete() {
this.data.ref.delete().then(() => this.dialogRef.close());
}
}