BETTERZON-42: Refactoring components and creating product detail component

This commit is contained in:
2020-12-07 21:37:12 +01:00
parent 4f3a755f78
commit ad1e758325
25 changed files with 72 additions and 11 deletions
@@ -0,0 +1,17 @@
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: dimgrey;
color: white;
text-align: center;
}
.icon-3d {
padding: 10px;
color: #fff;
}
@@ -0,0 +1,14 @@
<!--- footer --->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<footer class="footer">
<div class='wrap'>
<div class="icons">
<a href="https://github.com/Mueller-Patrick/Betterzon" class="fa fa-github fa-4x icon-3d"></a>
<a href="https://twitter.com/elonmusk" class="fa fa-twitter fa-4x icon-3d"></a>
<a href="https://www.facebook.com/TheElonmusk/" class="fa fa-facebook fa-4x icon-3d"></a>
</div>
<div class = "blocks" id="copyright">© COPYRIGHT 2020 </div>
</div>
</footer>
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FooterComponent } from './footer.component';
describe('FooterComponent', () => {
let component: FooterComponent;
let fixture: ComponentFixture<FooterComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ FooterComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(FooterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-footer',
templateUrl: './footer.component.html',
styleUrls: ['./footer.component.css']
})
export class FooterComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
@@ -0,0 +1,2 @@
<app-product-list numberOfProducts="20" showProductPicture="true"></app-product-list>
<app-footer></app-footer>
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LandingpageComponent } from './landingpage.component';
describe('LandingpageComponent', () => {
let component: LandingpageComponent;
let fixture: ComponentFixture<LandingpageComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ LandingpageComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(LandingpageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-landingpage',
templateUrl: './landingpage.component.html',
styleUrls: ['./landingpage.component.css']
})
export class LandingpageComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
@@ -0,0 +1 @@
<p>product-detail-page works!</p>
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ProductDetailPageComponent } from './product-detail-page.component';
describe('ProductDetailPageComponent', () => {
let component: ProductDetailPageComponent;
let fixture: ComponentFixture<ProductDetailPageComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ProductDetailPageComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(ProductDetailPageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-product-detail-page',
templateUrl: './product-detail-page.component.html',
styleUrls: ['./product-detail-page.component.css']
})
export class ProductDetailPageComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
@@ -0,0 +1 @@
<p>product-details works!</p>
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ProductDetailsComponent } from './product-details.component';
describe('ProductDetailsComponent', () => {
let component: ProductDetailsComponent;
let fixture: ComponentFixture<ProductDetailsComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ProductDetailsComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(ProductDetailsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-product-details',
templateUrl: './product-details.component.html',
styleUrls: ['./product-details.component.css']
})
export class ProductDetailsComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
@@ -0,0 +1,6 @@
.productItem {
border-style: solid;
border-color: dimgrey;
border-radius: .5em;
padding: .25em;
}
@@ -0,0 +1,7 @@
<meta charset="UTF-8">
<p class="productItem" *ngFor="let product of products" (click)="clickedProduct(product)">
{{product.name}}
</p>
<div *ngIf="showProductPicture">
Test
</div>
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ProductListComponent } from './product-list.component';
describe('ProductListComponent', () => {
let component: ProductListComponent;
let fixture: ComponentFixture<ProductListComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ProductListComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(ProductListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,41 @@
import {Component, Input, OnInit} from '@angular/core';
import {ApiService} from '../../services/api.service';
import {Product} from '../../models/product';
import {Router} from '@angular/router';
@Component({
selector: 'app-product-list',
templateUrl: './product-list.component.html',
styleUrls: ['./product-list.component.css']
})
export class ProductListComponent implements OnInit {
products: Product[];
@Input() numberOfProducts: number;
@Input() showProductPicture: boolean;
constructor(
private apiService: ApiService,
private router: Router
) {
}
ngOnInit(): void {
this.getProducts();
if (!this.numberOfProducts) {
this.numberOfProducts = 10;
}
if (!this.showProductPicture) {
this.showProductPicture = false;
}
}
getProducts(): void {
this.apiService.getProducts().subscribe(products => this.products = products);
}
clickedProduct(product: Product): void {
this.router.navigate([('/helloworld/' + product.product_id)]);
}
}