V0.1b Test zweiter Push

This commit is contained in:
2020-05-19 15:07:27 +02:00
commit a4c43386f4
34 changed files with 14079 additions and 0 deletions
View File
+54
View File
@@ -0,0 +1,54 @@
<h1>Einkaufszettel</h1>
<app-blog-entry *ngFor="let entry of entries" [entry]="entry"></app-blog-entry>
<h2>Neuen Einkaufszettel Eintrag anlegen:</h2>
<div class="form">
<div class="control">
<label for="title">Titel:</label>
<input type="text" id="title" #title/>
</div>
<div class="control">
<label for="title">Bild-URL:</label>
<input type="text" id="image" #image/>
</div>
<div class="container">
<div class="row custom-wrapper">
<div class="col-md-12">
<!-- Form starts -->
<form [formGroup]="registrationForm" (ngSubmit)="onSubmit()">
<div class="group-gap">
<div class="d-block my-3">
<div class="mb-3">
<select class="custom-select" (change)="changeKategorie($event)" formControlName="kategorieName">
<option value="">Wählen sie eine Kategorie</option>
<option *ngFor="let kategorie of Kategorien" [ngValue]="kategorie">{{kategorie}}</option>
</select>
<!-- error block -->
<div class="invalid-feedback" *ngIf="isSubmitted && kategorieName.errors?.required">
<sup>*</sup>Bitte geben sie eine Kategorie ein!
</div>
</div>
</div>
</div>
<!-- Submit Button -->
<button type="submit" class="btn btn-danger btn-lg btn-block">Speichern</button>
</form><!-- Form ends -->
</div>
</div>
</div>
<div class="control">
<label for="title">Kategorie:</label>
<input type="text" id="kategorie" #kategorie/>
</div>
<div class="control">
<label for="text">Text:</label>
<textarea id="text" cols="20" rows="3" #text>
</textarea>
</div>
<div>
<button (click)="createBlogEntry(title.value, image.value, kategorie.value, text.value)">
Blog-Eintrag anlegen
</button>
</div>
</div>
+31
View File
@@ -0,0 +1,31 @@
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
}));
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
it(`should have as title 'Einkaufszettel'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('Einkaufszettel');
});
it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement;
expect(compiled.querySelector('.content span').textContent).toContain('Einkaufszettel app is running!');
});
});
+61
View File
@@ -0,0 +1,61 @@
import {Component} from '@angular/core';
import {initialEntries} from './initialEntries';
import {BlogEntry} from './blog-entry';
import {FormBuilder, Validators} from '@angular/forms';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html'
})
export class AppComponent {
constructor(public fb: FormBuilder) {
this.entries = [];
this.entries = initialEntries;
}
// Getter method to access formcontrols
get kategorieName() {
return this.registrationForm.get('kategorieName');
}
title = 'Einkaufszettel';
entries: BlogEntry[] = [];
isSubmitted = false;
// Kategorien
Kategorien: any = ['Lebensmittel', 'Spielwaren', 'Technik', 'Sonstiges'];
/*########### Form ###########*/
registrationForm = this.fb.group({
kategorieName: ['', [Validators.required]]
});
createBlogEntry(title: string, image: string, kategorie: string, text: string, ) {
if (title && image && text && kategorie) {
const entry = new BlogEntry();
entry.title = title;
entry.image = image;
entry.text = text;
entry.kategorie = kategorie;
this.entries.push(entry);
}
}
// 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));
}
}
}
+20
View File
@@ -0,0 +1,20 @@
import { BlogEntryComponent } from './blog-entry.component';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import {ReactiveFormsModule} from '@angular/forms';
@NgModule({
declarations: [
AppComponent,
BlogEntryComponent
],
imports: [
BrowserModule,
ReactiveFormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
+10
View File
@@ -0,0 +1,10 @@
<div class="blog-entry">
<div class="blog-image">
<img [src]="entry.image" [alt]="entry.title"/>
</div>
<div class="blog-summary">
<span class="title">{{entry.title}}</span>
<p> {{entry.kategorie}}</p>
<p> {{entry.text}}</p>
</div>
</div>
+10
View File
@@ -0,0 +1,10 @@
import {Component, Input} from '@angular/core';
import {BlogEntry} from './blog-entry';
@Component({
selector: 'app-blog-entry',
templateUrl: 'blog-entry.component.html'
})
export class BlogEntryComponent {
@Input() entry: BlogEntry;
}
+6
View File
@@ -0,0 +1,6 @@
export class BlogEntry {
title: string;
image: string;
kategorie: string;
text: string;
}
+14
View File
@@ -0,0 +1,14 @@
export const initialEntries = [
{
title: 'Edeka',
image: 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Logo_Edeka.svg/1200px-Logo_Edeka.svg.png',
kategorie: 'Lebensmittel',
text: 'Hier könnten ihre benötigten Einkäufe stehen'
},
{
title: 'Aldi Süd',
image: 'https://www.horizont.net/news/media/20/Logo-Aldi-Sd-2017-198042-detailnp.jpeg',
kategorie: 'Lebensmittel',
text: 'Hier könnten ihre benötigten Einkäufe stehen'
}
];