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. constructor(public fb: FormBuilder) {
  14. this.entries = [];
  15. this.entries = initialEntries;
  16. }
  17. saveTask(value: any){
  18. console.log(value);
  19. }
  20. createBlogEntry(einkaufsort: string, kategorie: string, menge: string, kommentar: string, position: string) {
  21. if (einkaufsort && kommentar) {
  22. const entry = new BlogEntry();
  23. entry.einkaufsort = einkaufsort;
  24. entry.menge = menge;
  25. entry.kommentar = kommentar;
  26. if(einkaufsort === 'Aldi Süd'){
  27. entry.image = 'https://www.horizont.net/news/media/20/Logo-Aldi-Sd-2017-198042-detailnp.jpeg';
  28. entry.kategorie = 'Lebensmittel';
  29. }
  30. else if (einkaufsort === 'Edeka') {
  31. entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Logo_Edeka.svg/1200px-Logo_Edeka.svg.png';
  32. entry.kategorie = 'Lebensmittel';}
  33. else if (einkaufsort == 'Lidl') {
  34. entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Lidl-Logo.svg/1200px-Lidl-Logo.svg.png';
  35. entry.kategorie = 'Lebensmittel';}
  36. else if (einkaufsort == 'Rewe') {
  37. entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Logo_REWE.svg/1200px-Logo_REWE.svg.png';
  38. entry.kategorie = 'Lebensmittel';}
  39. else if (einkaufsort == 'Netto') {
  40. entry.image = 'https://www.netto-online.de/images/favicons/logo_netto.png';
  41. entry.kategorie = 'Lebensmittel';}
  42. else if (einkaufsort == 'Penny') {
  43. entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Penny-Markt.svg/1200px-Penny-Markt.svg.png';
  44. entry.kategorie = 'Lebensmittel';}
  45. else if (einkaufsort == 'DM') {
  46. entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Dm_Logo.svg/1200px-Dm_Logo.svg.png';
  47. entry.kategorie = 'Drogerie';}
  48. else if (einkaufsort == 'Rossmann') {
  49. entry.image = 'https://www.einkaufsbahnhof.de/wp-content/uploads/2018/03/rossmann_logo_schreibschrift.png';
  50. entry.kategorie = 'Drogerie';}
  51. else if (einkaufsort == 'Müller') {
  52. entry.image = 'https://www.e-einz.de/wp-content/uploads/2017/02/Mueller.png';
  53. entry.kategorie = 'Drogerie';}
  54. else if (einkaufsort == 'OBI') {
  55. entry.image = 'https://media.aubi-plus.com/files/premiumprofil/logo/35d8961-obi.jpg';
  56. entry.kategorie = 'Baumarkt';}
  57. else if (einkaufsort == 'Dehner') {
  58. entry.image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Dehner.svg/1200px-Dehner.svg.png';
  59. entry.kategorie = 'Garten-Center';}
  60. else if (einkaufsort == 'Hornbach') {
  61. 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';
  62. entry.kategorie = 'Baumarkt';}
  63. else {
  64. entry.image = 'https://previews.123rf.com/images/krisdog/krisdog1312/krisdog131200065/24639132-ein-beispiel-f%C3%BCr-ein-einkaufswagen-oder-einkaufswagen-symbol.jpg';
  65. if(kategorie === '')
  66. entry.kategorie = 'Unbekannt';
  67. else {
  68. entry.kategorie = kategorie;
  69. }
  70. };
  71. if (position == '' || Number(position) >= this.entries.length){
  72. entry.position = this.entries.length;
  73. this.entries.push(entry);
  74. }
  75. else {
  76. entry.position = Number(position)-1;
  77. this.entries.splice(Number(position)-1, 0, entry);
  78. this.entries.forEach(function(part,index,theArray) {
  79. theArray[index].position = index;
  80. })
  81. }
  82. }
  83. }
  84. deleteAllEntries() {
  85. console.log(this.entries.length);
  86. const index: number = this.entries.length;
  87. if (index !== -1) {
  88. this.entries = this.entries.splice(index, 1);
  89. }
  90. }
  91. deleteLastEntry() {
  92. console.log(this.entries.length);
  93. const index: number = this.entries.length;
  94. if (index !== -1) {
  95. this.entries.splice(index-1, 1);
  96. }
  97. }
  98. deleteEntry(str: string)
  99. {
  100. const index = Number(str) - 1;
  101. this.entries.splice(index,1)
  102. this.entries.forEach(function(part,index,theArray) {
  103. theArray[index].position = index;
  104. })
  105. }
  106. ngOnInit(): void {
  107. }
  108. }