diff --git a/src/app/app.store.ts b/src/app/app.store.ts index 3925282..fd996ff 100644 --- a/src/app/app.store.ts +++ b/src/app/app.store.ts @@ -39,7 +39,6 @@ export class AppStore { map(rows => rows.map((row: any) => { let temp = Object.assign({ id: row.payload.doc.id, ref: row.payload.doc.ref }, row.payload.doc.data()); - temp.created = temp.created.toDate(); return temp; }) ), @@ -53,13 +52,7 @@ export class AppStore { map(data => data[0].map(row => { let temp = Object.assign({ id: row.payload.doc.id, ref: row.payload.doc.ref }, row.payload.doc.data()); - temp.created = temp.created.toDate(); - - temp.components = temp.components.map(row => { - let component = data[1].filter(c => c.id == row.component.id)[0]; - return { component: component, quantity: row.quantity }; - }); - + temp.components = temp.components.map(row => ({component: data[1].find(c => c.id == row.component), quantity: row.quantity})); return temp; }) ), diff --git a/src/app/formulaManager/formulaManager.component.html b/src/app/formulaManager/formulaManager.component.html index e929d60..1daa84b 100644 --- a/src/app/formulaManager/formulaManager.component.html +++ b/src/app/formulaManager/formulaManager.component.html @@ -51,7 +51,7 @@

{{formula.name}}

- {{formula.created | date}} + {{formula.createdOn.seconds * 1000 | date}}

Approved: check_circle @@ -72,7 +72,7 @@ {{c.component?.name}} {{c.quantity | scale: formula.total : _newTotal | convertFromG: unit}} {{unit}} - {{c.quantity | scale: formula.total : _newTotal / 1000 * c.component.cost | currency}} + {{c.quantity | scale: formula.total : _newTotal / 1000 * c.component.price | currency}}
diff --git a/src/app/formulaManager/formulaManager.component.ts b/src/app/formulaManager/formulaManager.component.ts index 9eb74a5..75dde58 100644 --- a/src/app/formulaManager/formulaManager.component.ts +++ b/src/app/formulaManager/formulaManager.component.ts @@ -52,7 +52,7 @@ export class FormulaManagerComponent { cost() { let cost = 0; this.formula.components.forEach( - row => (cost += (((row.quantity / this.formula.total) * this._newTotal) / 1000) * row.component.cost) + row => (cost += (((row.quantity / this.formula.total) * this._newTotal) / 1000) * row.component.price) ); return cost; } diff --git a/src/app/formulaManager/newComponent/newComponent.component.html b/src/app/formulaManager/newComponent/newComponent.component.html index 37c449f..a9bc530 100644 --- a/src/app/formulaManager/newComponent/newComponent.component.html +++ b/src/app/formulaManager/newComponent/newComponent.component.html @@ -10,15 +10,16 @@ - + - - \ No newline at end of file + + diff --git a/src/app/formulaManager/newComponent/newComponent.component.ts b/src/app/formulaManager/newComponent/newComponent.component.ts index 6492d5c..b42a53a 100644 --- a/src/app/formulaManager/newComponent/newComponent.component.ts +++ b/src/app/formulaManager/newComponent/newComponent.component.ts @@ -1,6 +1,7 @@ -import {Component, ViewChild, Inject} from '@angular/core'; +import {Component, Inject} from '@angular/core'; import {AngularFirestore} from 'angularfire2/firestore'; -import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material'; +import {MAT_DIALOG_DATA, MatDialog, MatDialogRef} from '@angular/material'; +import {DeleteComponent} from '../../delete/delete.component'; @Component({ selector: 'new-component', @@ -9,31 +10,36 @@ import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material'; export class NewComponentComponent { name: string; description: string; - cost: number; + price: number; constructor( private dialogRef: MatDialogRef, + private dialog: MatDialog, private db: AngularFirestore, @Inject(MAT_DIALOG_DATA) public data ) { if (data) { this.name = data.name; this.description = data.description; - this.cost = data.cost; + this.price = data.price; } } + delete() { + this.dialog.open(DeleteComponent, {data: this.data}).afterClosed().subscribe(() => this.dialogRef.close()); + } + submit() { - let newComponent = {name: this.name, description: this.description, cost: Number(this.cost)}; + let newComponent = {name: this.name, description: this.description, price: Number(this.price), createdOn: new Date()}; if (!this.data) { newComponent['created'] = new Date(); this.db .collection('components') - .add(newComponent) - .then(data => this.dialogRef.close()); + .doc(newComponent.name).set(newComponent) + .then(ignore => this.dialogRef.close()); } else { - this.data.ref.update(newComponent).then(data => this.dialogRef.close()); + this.data.ref.update(newComponent).then(ignore => this.dialogRef.close()); } } } diff --git a/src/app/formulaManager/newFormula/newFormula.component.html b/src/app/formulaManager/newFormula/newFormula.component.html index 58de9f9..6bf8751 100644 --- a/src/app/formulaManager/newFormula/newFormula.component.html +++ b/src/app/formulaManager/newFormula/newFormula.component.html @@ -42,7 +42,7 @@ - {{c.name}} + {{c.component.name}} {{c.quantity | convertFromG: unit}} {{unit}} - \ No newline at end of file + diff --git a/src/app/formulaManager/newFormula/newFormula.component.ts b/src/app/formulaManager/newFormula/newFormula.component.ts index 5611c0f..fedf00e 100644 --- a/src/app/formulaManager/newFormula/newFormula.component.ts +++ b/src/app/formulaManager/newFormula/newFormula.component.ts @@ -14,7 +14,7 @@ export class NewFormulaComponent { amount: number; approved: boolean = false; component: string; - components: { component: string; name: string; quantity: number }[] = []; + components: { component: Component; quantity: number }[] = []; componentsList = []; @LocalStorage({ defaultValue: 'kg', fieldName: 'newFormulaUnit' }) unit; @@ -30,17 +30,14 @@ export class NewFormulaComponent { if (this.data) { this.name = this.data.name; this.approved = this.data.approved; - this.components = this.data.components.map(row => { - return { component: row.component.id, name: row.component.name, quantity: row.quantity }; - }); + this.components = this.data.components; } } add() { - let id = this.componentsList.filter(row => row.name == this.component)[0].id; - console.log(id); + let component = this.componentsList.find(row => row.name == this.component); let amount = new ConvertToGPipe().transform(Number(this.amount), this.unit); - this.components.push({ component: id, name: this.component, quantity: amount }); + this.components.push({ component: component, quantity: amount }); this.component = null; this.amount = null; } @@ -53,19 +50,14 @@ export class NewFormulaComponent { let newFormula = { name: this.name, approved: this.approved, - components: this.components.map((row: any) => { - return { component: this.db.collection('components').doc(row.component).ref, quantity: row.quantity }; - }) + components: this.components.map((row: any) => ({component: row.component.id, quantity: row.quantity})), + createdOn: new Date() }; if (!this.data) { - newFormula['created'] = new Date(); - this.db - .collection('formulas') - .add(newFormula) - .then(data => this.dialogRef.close()); + this.db.collection('formulas').doc(this.name).set(newFormula).then(ignore => this.dialogRef.close()); } else { - this.data.ref.update(newFormula).then(data => this.dialogRef.close()); + this.data.ref.update(newFormula).then(ignore => this.dialogRef.close()); } } diff --git a/src/app/formulaManager/viewComponents/viewComponents.component.html b/src/app/formulaManager/viewComponents/viewComponents.component.html index f9af927..1b05394 100644 --- a/src/app/formulaManager/viewComponents/viewComponents.component.html +++ b/src/app/formulaManager/viewComponents/viewComponents.component.html @@ -1,37 +1,17 @@ -
- -
-
- - - - - - - - - - - - - - - - - - - - - -
NameDescriptionCreatedCost Per Kg
{{c.name}}{{c.description}}{{c.created | date}}{{c.cost | currency}} - - - -
+
+
+
Name
+
Description
+
Created
+
$/Kg
+
+ +
+ +
{{c.description}}
+
{{c.createdOn.seconds * 1000 | date}}
+
{{c.price | currency}}
+