You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

blog-create.component.ts 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { Component, OnInit } from '@angular/core';
  2. import {BlogEntry} from "../blog-entry/blog-entry";
  3. import {FormBuilder, Validators} from "@angular/forms";
  4. import {initialEntries} from "../blog-entry/initialEntries";
  5. @Component({
  6. selector: 'app-blog-create',
  7. templateUrl: './blog-create.component.html',
  8. styleUrls: ['./blog-create.component.css']
  9. })
  10. export class BlogCreateComponent implements OnInit {
  11. title = 'Einkaufszettel';
  12. entries: BlogEntry[] = [];
  13. isSubmitted = false;
  14. Kategorien: any = ['Lebensmittel', 'Spielwaren', 'Technik', 'Sonstiges'];
  15. constructor(public fb: FormBuilder) {
  16. this.entries = [];
  17. this.entries = initialEntries;
  18. }
  19. // Getter method to access formcontrols
  20. get kategorieName() {
  21. return this.registrationForm.get('kategorieName');
  22. }
  23. /*########### Form ###########*/
  24. registrationForm = this.fb.group({
  25. kategorieName: ['', [Validators.required]]
  26. });
  27. saveTask(value: any){
  28. console.log(value);
  29. }
  30. createBlogEntry(einkaufsort: string, menge: string, kommentar: string, ) {
  31. if (einkaufsort && kommentar) {
  32. const entry = new BlogEntry();
  33. entry.einkaufsort = einkaufsort;
  34. entry.menge = menge;
  35. entry.kommentar = kommentar;
  36. if(einkaufsort === 'Aldi Süd'){
  37. entry.image = 'https://www.horizont.net/news/media/20/Logo-Aldi-Sd-2017-198042-detailnp.jpeg';
  38. entry.kategorie = 'Lebensmittel';
  39. }
  40. else if (einkaufsort === 'Edeka') {
  41. entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Logo_Edeka.svg/1200px-Logo_Edeka.svg.png';
  42. entry.kategorie = 'Lebensmittel';}
  43. else if (einkaufsort == 'Lidl') {
  44. entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Lidl-Logo.svg/1200px-Lidl-Logo.svg.png';
  45. entry.kategorie = 'Lebensmittel';}
  46. else if (einkaufsort == 'Rewe') {
  47. entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Logo_REWE.svg/1200px-Logo_REWE.svg.png';
  48. entry.kategorie = 'Lebensmittel';}
  49. else if (einkaufsort == 'Netto') {
  50. entry.image = 'https://www.netto-online.de/images/favicons/logo_netto.png';
  51. entry.kategorie = 'Lebensmittel';}
  52. else if (einkaufsort == 'Penny') {
  53. entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Penny-Markt.svg/1200px-Penny-Markt.svg.png';
  54. entry.kategorie = 'Lebensmittel';}
  55. else if (einkaufsort == 'DM') {
  56. entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Dm_Logo.svg/1200px-Dm_Logo.svg.png';
  57. entry.kategorie = 'Drogerie';}
  58. else if (einkaufsort == 'Rossmann') {
  59. entry.image = 'https://www.einkaufsbahnhof.de/wp-content/uploads/2018/03/rossmann_logo_schreibschrift.png';
  60. entry.kategorie = 'Drogerie';}
  61. else if (einkaufsort == 'Müller') {
  62. entry.image = 'https://www.e-einz.de/wp-content/uploads/2017/02/Mueller.png';
  63. entry.kategorie = 'Drogerie';}
  64. else if (einkaufsort == 'OBI') {
  65. entry.image = 'https://media.aubi-plus.com/files/premiumprofil/logo/35d8961-obi.jpg';
  66. entry.kategorie = 'Baumarkt';}
  67. else if (einkaufsort == 'Dehner') {
  68. entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Dehner.svg/1200px-Dehner.svg.png';
  69. entry.kategorie = 'Garten-Center';}
  70. else if (einkaufsort == 'Hornbach') {
  71. 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';
  72. entry.kategorie = 'Baumarkt';}
  73. else if (einkaufsort == 'Anderer') {
  74. entry.image = 'https://previews.123rf.com/images/krisdog/krisdog1312/krisdog131200065/24639132-ein-beispiel-f%C3%BCr-ein-einkaufswagen-oder-einkaufswagen-symbol.jpg';
  75. entry.kategorie = 'Unbekannt';};
  76. this.entries.push(entry);
  77. }
  78. }
  79. deleteAllEntries() {
  80. console.log(this.entries.length);
  81. const index: number = this.entries.length;
  82. if (index !== -1) {
  83. this.entries = this.entries.splice(index, 1);
  84. }
  85. }
  86. deleteLastEntry() {
  87. console.log(this.entries.length);
  88. const index: number = this.entries.length;
  89. if (index !== -1) {
  90. this.entries.splice(index-1, 1);
  91. }
  92. }
  93. // Kategorie mit Drop Down Menu wählen
  94. changeKategorie(e) {
  95. console.log(e.value);
  96. this.kategorieName.setValue(e.target.value, {
  97. onlySelf: true
  98. });
  99. }
  100. /*########### Template Driven Form ###########*/
  101. onSubmit() {
  102. this.isSubmitted = true;
  103. if (!this.registrationForm.valid) {
  104. return false;
  105. } else {
  106. alert(JSON.stringify(this.registrationForm.value));
  107. }
  108. }
  109. ngOnInit(): void {
  110. }
  111. }