From 33b157b746a90c067f50df80c0c5bba3166595bf Mon Sep 17 00:00:00 2001 From: tachojelev Date: Thu, 28 Jan 2021 12:11:03 +0200 Subject: [PATCH] Add history requests --- src/api/skaikru-api.ts | 1 + src/app/app-routing.module.ts | 4 ++ src/home/home.component.html | 3 +- src/models/email-record.ts | 6 +++ src/services/mail.service.ts | 6 +++ .../view-history-routing.module.ts | 17 +++++++ src/view-history/view-history.component.html | 32 +++++++++++++ src/view-history/view-history.component.scss | 45 +++++++++++++++++++ .../view-history.component.spec.ts | 25 +++++++++++ src/view-history/view-history.component.ts | 36 +++++++++++++++ src/view-history/view-history.module.ts | 17 +++++++ 11 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 src/models/email-record.ts create mode 100644 src/view-history/view-history-routing.module.ts create mode 100644 src/view-history/view-history.component.html create mode 100644 src/view-history/view-history.component.scss create mode 100644 src/view-history/view-history.component.spec.ts create mode 100644 src/view-history/view-history.component.ts create mode 100644 src/view-history/view-history.module.ts diff --git a/src/api/skaikru-api.ts b/src/api/skaikru-api.ts index 7de85b6..c5aedca 100644 --- a/src/api/skaikru-api.ts +++ b/src/api/skaikru-api.ts @@ -3,6 +3,7 @@ */ export class SkaikruApi { public static readonly HOME: string = 'http://localhost:8080/'; + public static readonly HISTORY: string = 'http://localhost:8080/history'; public static readonly SEND_MAILS: string = 'http://localhost:8080/send-mails'; public static readonly PREVIEW_MAILS: string = 'http://localhost:8080/preview-mails'; public static readonly ADD_TEMPLATE: string = 'http://localhost:8080/add-template'; diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index a0dcea7..4300a05 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -19,6 +19,10 @@ const routes: Routes = [ { path: 'send-mail-template', loadChildren: () => import('../send-mail-template/send-mail-template.module').then(m => m.SendMailTemplateModule) + }, + { + path: 'view-history', + loadChildren: () => import('../view-history/view-history.module').then(m => m.ViewHistoryModule) } ]; diff --git a/src/home/home.component.html b/src/home/home.component.html index fb26cd9..98a857e 100644 --- a/src/home/home.component.html +++ b/src/home/home.component.html @@ -1,9 +1,10 @@
diff --git a/src/models/email-record.ts b/src/models/email-record.ts new file mode 100644 index 0000000..d962680 --- /dev/null +++ b/src/models/email-record.ts @@ -0,0 +1,6 @@ +export class EmailRecord { + email: string; + message: string; + title: string; + successful: boolean; +} diff --git a/src/services/mail.service.ts b/src/services/mail.service.ts index 2735437..ef45442 100644 --- a/src/services/mail.service.ts +++ b/src/services/mail.service.ts @@ -2,6 +2,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { SkaikruApi } from 'src/api/skaikru-api'; +import { EmailRecord } from 'src/models/email-record'; import { EmailTemplate } from 'src/models/email-template'; import { PreviewRecipientEmail } from 'src/models/preview-recipient-email'; import { Recipient } from 'src/models/recipient'; @@ -15,6 +16,11 @@ export class MailService { constructor(private httpClient: HttpClient) { } + getHistory(): Observable> { + const headers = new HttpHeaders().set('content-type', 'application/json'); + return this.httpClient.get>(SkaikruApi.HISTORY, { headers }); + } + sendMail(emailTemplate: EmailTemplate, recipients: Array, html: boolean): Observable { const headers = new HttpHeaders().set('content-type', 'application/json'); const payload = this.buildSendMailRequest(emailTemplate, recipients, html); diff --git a/src/view-history/view-history-routing.module.ts b/src/view-history/view-history-routing.module.ts new file mode 100644 index 0000000..ae55780 --- /dev/null +++ b/src/view-history/view-history-routing.module.ts @@ -0,0 +1,17 @@ + +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; +import { ViewHistoryComponent } from './view-history.component'; + +const routes: Routes = [ + { + path: '', + component: ViewHistoryComponent + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] +}) +export class ViewHistoryRoutingModule { } diff --git a/src/view-history/view-history.component.html b/src/view-history/view-history.component.html new file mode 100644 index 0000000..1f1e3f9 --- /dev/null +++ b/src/view-history/view-history.component.html @@ -0,0 +1,32 @@ +
+

+ History of sent emails +

+ + +
+ + +
+ + {{ emailRecord.successful ? 'check' : 'close' }} + +
+ {{ emailRecord.title }} + {{ emailRecord.email }} +
+ +

+ {{ emailRecord.message }} +

+
+
+
+
+
+ + +

+ - No history for sent emails - +

+
\ No newline at end of file diff --git a/src/view-history/view-history.component.scss b/src/view-history/view-history.component.scss new file mode 100644 index 0000000..3450805 --- /dev/null +++ b/src/view-history/view-history.component.scss @@ -0,0 +1,45 @@ +@import '../shared/_ui-tools.scss'; +@import '../shared/variables'; + +:host { + display: flex; + align-items: center; + flex-direction: column; + height: 100%; + + .container { + @include flex-column-centered(); + padding: 16px; + } + + .heading { + font-size: 36px; + margin: 16px 0; + } + + .title { + font-size: 24px; + margin: 16px 0; + } + + .cards { + display: flex; + flex-wrap: wrap; + flex-direction: column; + + padding: 32px; + overflow: auto; + + .card { + transition: all 150ms ease-in-out; + margin: 8px; + min-height: 100px; + min-width: 500px; + + &:hover { + cursor: pointer; + transform: scale(1.05); + } + } + } +} \ No newline at end of file diff --git a/src/view-history/view-history.component.spec.ts b/src/view-history/view-history.component.spec.ts new file mode 100644 index 0000000..278477f --- /dev/null +++ b/src/view-history/view-history.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ViewHistoryComponent } from './view-history.component'; + +describe('ViewHistoryComponent', () => { + let component: ViewHistoryComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ ViewHistoryComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(ViewHistoryComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/view-history/view-history.component.ts b/src/view-history/view-history.component.ts new file mode 100644 index 0000000..868d7a7 --- /dev/null +++ b/src/view-history/view-history.component.ts @@ -0,0 +1,36 @@ +import { HttpErrorResponse } from '@angular/common/http'; +import { Component, OnInit } from '@angular/core'; +import { EmailRecord } from 'src/models/email-record'; +import { MailService } from 'src/services/mail.service'; + +@Component({ + selector: 'app-view-history', + templateUrl: './view-history.component.html', + styleUrls: ['./view-history.component.scss'] +}) +export class ViewHistoryComponent implements OnInit { + + emailRecords: Array = []; + + constructor(private templateService: MailService) { } + + ngOnInit(): void { + this.fetchHistory(); + } + + fetchHistory(): void { + this.templateService.getHistory().subscribe( + (response: Array) => { this.handleSuccess(response) }, + (response: HttpErrorResponse) => { this.handleFailure(response) } + ); + } + + + private handleSuccess(response: Array): void { + this.emailRecords = response; + } + + private handleFailure(response: HttpErrorResponse): void { + console.error(response); + } +} diff --git a/src/view-history/view-history.module.ts b/src/view-history/view-history.module.ts new file mode 100644 index 0000000..2a8efa6 --- /dev/null +++ b/src/view-history/view-history.module.ts @@ -0,0 +1,17 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { ViewHistoryComponent } from './view-history.component'; +import { ViewHistoryRoutingModule } from './view-history-routing.module'; +import { MatCardModule } from '@angular/material/card'; +import { MatIconModule } from '@angular/material/icon'; + +@NgModule({ + declarations: [ViewHistoryComponent], + imports: [ + CommonModule, + ViewHistoryRoutingModule, + MatCardModule, + MatIconModule + ] +}) +export class ViewHistoryModule { }