-
-
diff --git a/src/app/store/categories.component.ts b/src/app/store/categories.component.ts
index 5c42b9d..a1579ac 100644
--- a/src/app/store/categories.component.ts
+++ b/src/app/store/categories.component.ts
@@ -32,17 +32,20 @@ export class CategoriesComponent {
this.category = params['category'];
if (!this.category) this.breadcrumb.clear();
+ if (this.category && this.breadcrumb.breadcrumb.length == 0) this.breadcrumb.add(this.category);
this.categories = this.db
.collection('categories', ref => ref.orderBy('name'))
- .valueChanges()
+ .snapshotChanges()
.pipe(
map(rows =>
rows
+ .map((row: any) =>
+ Object.assign({id: row.payload.doc.id, ref: row.payload.doc.ref}, row.payload.doc.data())
+ )
.filter((row: any) => (!this.category && !row.parent) || (this.category && row.parent == this.category))
.map((row: any) => {
row.image = this.domSanitizer.bypassSecurityTrustUrl(row.image);
- console.log(row);
return row;
})
)
@@ -55,7 +58,7 @@ export class CategoriesComponent {
this.router.navigate(['/store', category]);
}
- create() {
- this.dialog.open(NewCategoryComponent);
+ create(category) {
+ this.dialog.open(NewCategoryComponent, {data: {category: category, currentCategory: this.category}});
}
}
diff --git a/src/app/store/newCategory/newCategory.component.html b/src/app/store/newCategory/newCategory.component.html
index 1bfe7e9..7acb167 100644
--- a/src/app/store/newCategory/newCategory.component.html
+++ b/src/app/store/newCategory/newCategory.component.html
@@ -9,6 +9,7 @@
root
+ {{c.name}}
diff --git a/src/app/store/newCategory/newCategory.component.ts b/src/app/store/newCategory/newCategory.component.ts
index 477b67a..2670e6f 100644
--- a/src/app/store/newCategory/newCategory.component.ts
+++ b/src/app/store/newCategory/newCategory.component.ts
@@ -9,6 +9,7 @@ import {MAT_DIALOG_DATA, MatDialogRef} from '../../../../node_modules/@angular/m
export class NewCategoryComponent {
@ViewChild('fileInput') fileInput;
+ categories;
parent: string = 'root';
name: string;
image: string;
@@ -17,7 +18,15 @@ export class NewCategoryComponent {
private dialogRef: MatDialogRef
,
private db: AngularFirestore,
@Inject(MAT_DIALOG_DATA) public data
- ) {}
+ ) {
+ this.categories = this.db.collection('categories').valueChanges();
+ if (data.currentCategory) this.parent = data.currentCategory;
+
+ if (data.category) {
+ this.name = data.category.name;
+ this.parent = data.category.parent == null ? 'root' : data.category.parent;
+ }
+ }
imageChanged() {
let reader = new FileReader();
@@ -26,11 +35,16 @@ export class NewCategoryComponent {
}
submit() {
- if (!this.data) {
+ let newCategory = {name: this.name, parent: this.parent == 'root' ? null : this.parent};
+ if (this.image) newCategory['image'] = this.image;
+
+ if (!this.data.category) {
this.db
.collection('categories')
- .add({name: this.name, image: this.image, parent: this.parent == 'root' ? null : this.parent})
+ .add(newCategory)
.then(data => this.dialogRef.close());
+ } else {
+ this.data.category.ref.update(newCategory).then(data => this.dialogRef.close());
}
}
}