Compare commits
No commits in common. "93b82aedbab9b56b720d1688da0fa8f5ecb454e3" and "26d66397e40200e8c2ab8c8a5fcd51a9463e3700" have entirely different histories.
93b82aedba
...
26d66397e4
19 changed files with 10 additions and 248 deletions
|
|
@ -1,2 +1 @@
|
|||
<app-toast-container aria-live="polite" aria-atomic="true"/>
|
||||
<router-outlet/>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { RouterOutlet } from '@angular/router';
|
||||
import {ToastContainerComponent} from '../components/toast-container/toast-container/toast-container.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
imports: [RouterOutlet, ToastContainerComponent],
|
||||
imports: [RouterOutlet],
|
||||
templateUrl: './app.component.html',
|
||||
styleUrl: './app.component.css'
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
<div class="modal-header">
|
||||
<h4 class="modal-title"> Add new show</h4>
|
||||
<button type="button" class="btn-close" aria-label="Close" (click)="dismiss()"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form [formGroup]="newShowForm" (ngSubmit)="formSubmitted(newShowForm)">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Title</label>
|
||||
<input formControlName="title" type="text" class="form-control"/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Year</label>
|
||||
<input formControlName="year" type="number" class="form-control"/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Seasons</label>
|
||||
<input formControlName="seasons" type="number" class="form-control"/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Description</label>
|
||||
<input formControlName="description" type="text" class="form-control"/>
|
||||
</div>
|
||||
<div class="d-grid justify-content-md-end">
|
||||
<button type="submit" class="btn btn-success" [disabled]="newShowForm.invalid">Submit</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CreateModalComponent } from './create-modal.component';
|
||||
|
||||
describe('CreateModalComponent', () => {
|
||||
let component: CreateModalComponent;
|
||||
let fixture: ComponentFixture<CreateModalComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [CreateModalComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(CreateModalComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
import {Component, inject} from '@angular/core';
|
||||
import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
|
||||
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'app-create-modal',
|
||||
imports: [
|
||||
ReactiveFormsModule
|
||||
],
|
||||
templateUrl: './create-modal.component.html',
|
||||
styleUrl: './create-modal.component.css'
|
||||
})
|
||||
export class CreateModalComponent {
|
||||
private activeModal = inject(NgbActiveModal)
|
||||
protected newShowForm: FormGroup
|
||||
|
||||
constructor() {
|
||||
this.newShowForm = new FormGroup({
|
||||
title: new FormControl("", Validators.required),
|
||||
year: new FormControl("", [Validators.required, Validators.min(1900)]),
|
||||
seasons: new FormControl("", [Validators.required, Validators.min(1)]),
|
||||
description: new FormControl("", Validators.required)
|
||||
})
|
||||
}
|
||||
|
||||
protected dismiss() {
|
||||
this.activeModal.dismiss()
|
||||
}
|
||||
|
||||
protected formSubmitted(form: FormGroup) {
|
||||
let show: {} = {
|
||||
title: form.get("title")?.value,
|
||||
year: form.get("year")?.value,
|
||||
seasons: form.get("seasons")?.value,
|
||||
description: form.get("description")?.value
|
||||
}
|
||||
console.log(show)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
:host {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
margin: 0.5em;
|
||||
z-index: 1200;
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
@for (toast of toastService.toasts; track toast) {
|
||||
<ngb-toast
|
||||
[header]="toast.header || ''" [autohide]="true" [delay]="toast.delay || 5000"
|
||||
(hidden)="toastService.remove(toast)"
|
||||
[animation]="true" [class]="toast.htmlClass"
|
||||
>{{ toast.body }}</ngb-toast>
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ToastContainerComponent } from './toast-container.component';
|
||||
|
||||
describe('ToastContainerComponent', () => {
|
||||
let component: ToastContainerComponent;
|
||||
let fixture: ComponentFixture<ToastContainerComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [ToastContainerComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(ToastContainerComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
import {Component, inject} from '@angular/core';
|
||||
import {ToastService} from '../../../services/toast/toast.service';
|
||||
import {NgbToast} from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
@Component({
|
||||
selector: 'app-toast-container',
|
||||
imports: [
|
||||
NgbToast
|
||||
],
|
||||
templateUrl: './toast-container.component.html',
|
||||
styleUrl: './toast-container.component.css'
|
||||
})
|
||||
export class ToastContainerComponent {
|
||||
toastService: ToastService = inject(ToastService);
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
import {Show} from './show';
|
||||
|
||||
export interface ShowsApiResponse {
|
||||
status: string
|
||||
shows: Show[]
|
||||
totalShows: number
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
export interface Toast {
|
||||
header?: string;
|
||||
body: string;
|
||||
delay?: number;
|
||||
htmlClass?: string;
|
||||
}
|
||||
|
|
@ -1,19 +1 @@
|
|||
<div class="container">
|
||||
<div class="row row-cols-4">
|
||||
@for (show of shows; track show._id) {
|
||||
<div class="card col">
|
||||
<!-- <img src="">-->
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{ show.title }}</h5>
|
||||
<p class="card-text">{{ show.year }}</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="row justify-content-end mt-3">
|
||||
<div class="col-2">
|
||||
<button type="button" class="btn btn-primary" (click)="createNewShow()">Add new show</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>shows works!</p>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,4 @@
|
|||
import {Component, inject} from '@angular/core';
|
||||
import {ShowsApiService} from '../../services/shows/shows-api.service';
|
||||
import {Show} from '../../interfaces/show';
|
||||
import {ShowsApiResponse} from '../../interfaces/shows-api-response';
|
||||
import {Toast} from '../../interfaces/toast';
|
||||
import {ToastService} from '../../services/toast/toast.service';
|
||||
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
|
||||
import {CreateModalComponent} from '../../components/create-modal/create-modal/create-modal.component';
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-shows',
|
||||
|
|
@ -14,31 +7,5 @@ import {CreateModalComponent} from '../../components/create-modal/create-modal/c
|
|||
styleUrl: './shows.component.css'
|
||||
})
|
||||
export class ShowsComponent {
|
||||
private api: ShowsApiService = inject(ShowsApiService);
|
||||
private toastService: ToastService = inject(ToastService);
|
||||
private modalService: NgbModal = inject(NgbModal);
|
||||
|
||||
shows: Show[] = [];
|
||||
|
||||
constructor() {
|
||||
let loadToast: Toast = {body: "Loading shows..."};
|
||||
this.toastService.show(loadToast);
|
||||
this.api.getShows().subscribe({
|
||||
next: (response: ShowsApiResponse) => {
|
||||
this.shows = response.shows;
|
||||
}, error: (err: any) => {
|
||||
console.error("Error: ", err);
|
||||
}, complete: () => {
|
||||
let successToast: Toast = {
|
||||
body: "Shows have been loaded!",
|
||||
htmlClass: "bg-success text-light"
|
||||
}
|
||||
this.toastService.show(successToast);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
createNewShow() {
|
||||
this.modalService.open(CreateModalComponent)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ToastService } from './toast.service';
|
||||
|
||||
describe('ToastService', () => {
|
||||
let service: ToastService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ToastService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {Toast} from '../../interfaces/toast';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ToastService {
|
||||
toasts: Toast[] = [];
|
||||
|
||||
show(toast: Toast) {
|
||||
this.toasts.push(toast);
|
||||
}
|
||||
|
||||
remove(toast: Toast) {
|
||||
this.toasts = this.toasts.filter(t => t != toast);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {ShowsApiResponse} from '../../interfaces/shows-api-response';
|
||||
import {ShowsApiResponse} from './shows-api';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
|
@ -19,8 +19,4 @@ export class ShowsApiService {
|
|||
getShows(): Observable<ShowsApiResponse> {
|
||||
return this.http.get<ShowsApiResponse>(this.showsEndpoint)
|
||||
}
|
||||
|
||||
sendShow(newShow: {}) {
|
||||
return this.http.post(this.showsEndpoint, newShow)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,9 @@
|
|||
export interface ShowsApiResponse {
|
||||
status: string
|
||||
shows: Show[]
|
||||
totalShows: number
|
||||
}
|
||||
|
||||
export interface Show {
|
||||
_id: string
|
||||
title: string
|
||||
Loading…
Add table
Add a link
Reference in a new issue