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'
}
];
View File
+3
View File
@@ -0,0 +1,3 @@
export const environment = {
production: true
};
+16
View File
@@ -0,0 +1,16 @@
// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.
export const environment = {
production: false
};
/*
* For easier debugging in development mode, you can import the following file
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
*
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 948 B

+13
View File
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Einkaufszettel</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
+12
View File
@@ -0,0 +1,12 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));
+63
View File
@@ -0,0 +1,63 @@
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/guide/browser-support
*/
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run `npm install --save classlist.js`.
/**
* Web Animations `@angular/platform-browser/animations`
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
*/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/**
* By default, zone.js will patch all possible macroTask and DomEvents
* user can disable parts of macroTask/DomEvents patch by setting following flags
* because those flags need to be set before `zone.js` being loaded, and webpack
* will put import in the top of bundle, so user need to create a separate file
* in this directory (for example: zone-flags.ts), and put the following flags
* into that file, and then add the following code before importing zone.js.
* import './zone-flags';
*
* The flags allowed in zone-flags.ts are listed here.
*
* The following flags will work for all browsers.
*
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
*
* (window as any).__Zone_enable_cross_context_check = true;
*
*/
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/
+65
View File
@@ -0,0 +1,65 @@
body {
font-family: Helvetica;
padding-left: 15px;
}
.form {
background-color: #eee;
width: 580px; /* Breite des Formulars */
padding: 20px;
border: 1px solid #8c8c8c;
position: absolute;
margin-bottom: 25px;
}
.control {
display: flex;
}
label {
width: 100px;
cursor: pointer;
}
input,
textarea {
width: 550px;
border: 1px solid #8c8c8c;
margin-bottom: 1em;
}
span.title {
font-size: x-large;
}
.clear-fix {
clear: both;
}
.blog-entry {
width: 600px;
display: flex;
padding-bottom: 30px;
}
button {
float: right;
padding-right: 20px;
}
.blog-image {
width: 30%;
}
img {
max-width: 90%;
max-height: 100px;
}
.blog-summary {
width: 70%;
}
textarea {
height: 7em;
}
+25
View File
@@ -0,0 +1,25 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: {
context(path: string, deep?: boolean, filter?: RegExp): {
keys(): string[];
<T>(id: string): T;
};
};
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);