-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding own implementation for flashed messages. Also adding product C…
…SV import. It still needs some polishing, but should work fine.
- Loading branch information
1 parent
109d6bb
commit 4e15bce
Showing
17 changed files
with
259 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Component, Input, OnInit } from "@angular/core"; | ||
import { FlashMessage, FlashMessageService } from "app/services" | ||
|
||
@Component({ | ||
selector: 'flash-messages', | ||
templateUrl: '../templates/flash-messages.html', | ||
providers: [] | ||
}) | ||
export class FlashMessageComponent implements OnInit{ | ||
flashMessages: FlashMessage[]; | ||
|
||
constructor(private flashMessageService: FlashMessageService) {} | ||
|
||
ngOnInit() { | ||
this.flashMessages = this.flashMessageService.getFlashMessages(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Component, OnInit } from "@angular/core"; | ||
import { Product, Tag, Identifier, Pricing } from "app/models"; | ||
import { BackendService } from "app/services/backend.service"; | ||
import { Parser } from "csv-parse"; | ||
|
||
@Component({ | ||
selector: 'product-import', | ||
templateUrl: '../templates/product-import.html', | ||
providers: [] | ||
}) | ||
export class ProductImportComponent implements OnInit{ | ||
|
||
fileReader: FileReader; | ||
fileParser: Parser; | ||
importableProducts: Product[]; | ||
importProgress: number; | ||
|
||
constructor( | ||
private backendService: BackendService | ||
) { } | ||
|
||
ngOnInit() { | ||
this.fileReader = new FileReader(); | ||
this.fileReader.onloadend = () => { this.onFileRead() }; | ||
|
||
this.fileParser = new Parser({delimiter: ","}); | ||
this.fileParser.on("readable", () => { this.onFileReadable() }); | ||
|
||
this.importableProducts = []; | ||
|
||
this.importProgress = 0; | ||
} | ||
|
||
fileEventListener(event: any) { | ||
this.fileReader.readAsText(event.target.files[0]); | ||
} | ||
|
||
onFileRead(){ | ||
this.fileParser.write(this.fileReader.result); | ||
} | ||
|
||
onFileReadable(){ | ||
let record:String[]; | ||
while(record = this.fileParser.read()){ | ||
let product: Product = new Product( | ||
null, | ||
<string> record[0], | ||
Tag.getTagArrayFromStringArray(record[2].split(" ")), | ||
[new Identifier(<string> record[3])], | ||
[new Pricing(null, Number(record[1]), 999999)] | ||
); | ||
this.importableProducts.push(product); | ||
} | ||
} | ||
|
||
confirmImport(){ | ||
let importCount = 0; | ||
for(let item of this.importableProducts){ | ||
this.backendService.saveProduct(item) | ||
.subscribe( | ||
product => { | ||
(item as any).import_success = true; | ||
importCount++; | ||
this.importProgress = importCount / this.importableProducts.length * 100; | ||
}, | ||
error => { | ||
(item as any).import_fail = true; | ||
console.log(error); | ||
importCount++; | ||
this.importProgress = importCount / this.importableProducts.length * 100; | ||
} | ||
); | ||
} | ||
} | ||
|
||
abortImport(){ | ||
this.importableProducts = []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.