123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- import { Component, OnInit } from '@angular/core';
- import {BlogEntry} from "../blog-entry/blog-entry";
- import {FormBuilder, Validators} from "@angular/forms";
- import {initialEntries} from "../blog-entry/initialEntries";
-
- @Component({
- selector: 'app-blog-create',
- templateUrl: './blog-create.component.html',
- styleUrls: ['./blog-create.component.css']
- })
- export class BlogCreateComponent implements OnInit {
- title = 'Einkaufszettel';
- entries: BlogEntry[] = [];
- isSubmitted = false;
- Kategorien: any = ['Lebensmittel', 'Spielwaren', 'Technik', 'Sonstiges'];
-
- constructor(public fb: FormBuilder) {
- this.entries = [];
- this.entries = initialEntries;
- }
-
- // Getter method to access formcontrols
- get kategorieName() {
- return this.registrationForm.get('kategorieName');
- }
-
- /*########### Form ###########*/
- registrationForm = this.fb.group({
- kategorieName: ['', [Validators.required]]
- });
- saveTask(value: any){
- console.log(value);
- }
-
- createBlogEntry(einkaufsort: string, menge: string, kommentar: string, ) {
- if (einkaufsort && kommentar) {
- const entry = new BlogEntry();
- entry.einkaufsort = einkaufsort;
- entry.menge = menge;
- entry.kommentar = kommentar;
-
- if(einkaufsort === 'Aldi Süd'){
- entry.image = 'https://www.horizont.net/news/media/20/Logo-Aldi-Sd-2017-198042-detailnp.jpeg';
- entry.kategorie = 'Lebensmittel';
- }
- else if (einkaufsort === 'Edeka') {
- entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Logo_Edeka.svg/1200px-Logo_Edeka.svg.png';
- entry.kategorie = 'Lebensmittel';}
- else if (einkaufsort == 'Lidl') {
- entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Lidl-Logo.svg/1200px-Lidl-Logo.svg.png';
- entry.kategorie = 'Lebensmittel';}
- else if (einkaufsort == 'Rewe') {
- entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Logo_REWE.svg/1200px-Logo_REWE.svg.png';
- entry.kategorie = 'Lebensmittel';}
- else if (einkaufsort == 'Netto') {
- entry.image = 'https://www.netto-online.de/images/favicons/logo_netto.png';
- entry.kategorie = 'Lebensmittel';}
- else if (einkaufsort == 'Penny') {
- entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Penny-Markt.svg/1200px-Penny-Markt.svg.png';
- entry.kategorie = 'Lebensmittel';}
- else if (einkaufsort == 'DM') {
- entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Dm_Logo.svg/1200px-Dm_Logo.svg.png';
- entry.kategorie = 'Drogerie';}
- else if (einkaufsort == 'Rossmann') {
- entry.image = 'https://www.einkaufsbahnhof.de/wp-content/uploads/2018/03/rossmann_logo_schreibschrift.png';
- entry.kategorie = 'Drogerie';}
- else if (einkaufsort == 'Müller') {
- entry.image = 'https://www.e-einz.de/wp-content/uploads/2017/02/Mueller.png';
- entry.kategorie = 'Drogerie';}
- else if (einkaufsort == 'OBI') {
- entry.image = 'https://media.aubi-plus.com/files/premiumprofil/logo/35d8961-obi.jpg';
- entry.kategorie = 'Baumarkt';}
- else if (einkaufsort == 'Dehner') {
- entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Dehner.svg/1200px-Dehner.svg.png';
- entry.kategorie = 'Garten-Center';}
- else if (einkaufsort == 'Hornbach') {
- entry.image = 'https://www.luvshopping.de/-/media/images/b2c/germany/lubeck/logo-stores/hornbach.jpg?h=442&la=de-DE&mw=650&w=650&hash=C6C36C2C1536745108FF620D3B9CD7E4864A9308';
- entry.kategorie = 'Baumarkt';}
- else if (einkaufsort == 'Anderer') {
- entry.image = 'https://previews.123rf.com/images/krisdog/krisdog1312/krisdog131200065/24639132-ein-beispiel-f%C3%BCr-ein-einkaufswagen-oder-einkaufswagen-symbol.jpg';
- entry.kategorie = 'Unbekannt';};
-
- this.entries.push(entry);
- }
- }
-
-
- deleteAllEntries() {
- console.log(this.entries.length);
- const index: number = this.entries.length;
- if (index !== -1) {
- this.entries = this.entries.splice(index, 1);
- }
- }
- deleteLastEntry() {
- console.log(this.entries.length);
- const index: number = this.entries.length;
- if (index !== -1) {
- this.entries.splice(index-1, 1);
- }
- }
-
- // Kategorie mit Drop Down Menu wählen
- changeKategorie(e) {
- console.log(e.value);
- this.kategorieName.setValue(e.target.value, {
- onlySelf: true
- });
- }
-
- /*########### Template Driven Form ###########*/
- onSubmit() {
- this.isSubmitted = true;
- if (!this.registrationForm.valid) {
- return false;
- } else {
- alert(JSON.stringify(this.registrationForm.value));
- }
-
- }
-
- ngOnInit(): void {
- }
-
- }
|