Skip to content

Commit

Permalink
Add history requests
Browse files Browse the repository at this point in the history
  • Loading branch information
tachojelev committed Jan 28, 2021
1 parent 62fae41 commit 33b157b
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/api/skaikru-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 4 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
];

Expand Down
3 changes: 2 additions & 1 deletion src/home/home.component.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<section class="main-section">
<div class="banner-section">
<h1 class="mat-h1">Skaikru mail</h1>
<h2>Get started by sending an email or view your templates!</h2>
<h2>Get started by sending an email or view your templates and history!</h2>
<div>
<button mat-raised-button routerLink="/view-templates" class="action-button">View templates</button>
<button mat-raised-button routerLink="/view-history" class="action-button">View history</button>
<button mat-raised-button routerLink="/send-mail-template">Send email</button>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/models/email-record.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class EmailRecord {
email: string;
message: string;
title: string;
successful: boolean;
}
6 changes: 6 additions & 0 deletions src/services/mail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -15,6 +16,11 @@ export class MailService {

constructor(private httpClient: HttpClient) { }

getHistory(): Observable<Array<EmailRecord>> {
const headers = new HttpHeaders().set('content-type', 'application/json');
return this.httpClient.get<Array<EmailRecord>>(SkaikruApi.HISTORY, { headers });
}

sendMail(emailTemplate: EmailTemplate, recipients: Array<Recipient>, html: boolean): Observable<number> {
const headers = new HttpHeaders().set('content-type', 'application/json');
const payload = this.buildSendMailRequest(emailTemplate, recipients, html);
Expand Down
17 changes: 17 additions & 0 deletions src/view-history/view-history-routing.module.ts
Original file line number Diff line number Diff line change
@@ -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 { }
32 changes: 32 additions & 0 deletions src/view-history/view-history.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="container">
<h1 class="mat-h1 heading">
History of sent emails
</h1>

<ng-container *ngIf="emailRecords!.length else empty">
<div class="cards">
<mat-card class="card" *ngFor="let emailRecord of emailRecords">
<mat-card-header>
<div mat-card-avatar>
<mat-icon>
{{ emailRecord.successful ? 'check' : 'close' }}
</mat-icon>
</div>
<mat-card-title>{{ emailRecord.title }}</mat-card-title>
<mat-card-subtitle>{{ emailRecord.email }}</mat-card-subtitle>
</mat-card-header>
<mat-card-content>
<p>
{{ emailRecord.message }}
</p>
</mat-card-content>
</mat-card>
</div>
</ng-container>
</div>

<ng-template #empty>
<h4 class="mat-h2 title">
- No history for sent emails -
</h4>
</ng-template>
45 changes: 45 additions & 0 deletions src/view-history/view-history.component.scss
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
25 changes: 25 additions & 0 deletions src/view-history/view-history.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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<ViewHistoryComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ViewHistoryComponent ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(ViewHistoryComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
36 changes: 36 additions & 0 deletions src/view-history/view-history.component.ts
Original file line number Diff line number Diff line change
@@ -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<EmailRecord> = [];

constructor(private templateService: MailService) { }

ngOnInit(): void {
this.fetchHistory();
}

fetchHistory(): void {
this.templateService.getHistory().subscribe(
(response: Array<EmailRecord>) => { this.handleSuccess(response) },
(response: HttpErrorResponse) => { this.handleFailure(response) }
);
}


private handleSuccess(response: Array<EmailRecord>): void {
this.emailRecords = response;
}

private handleFailure(response: HttpErrorResponse): void {
console.error(response);
}
}
17 changes: 17 additions & 0 deletions src/view-history/view-history.module.ts
Original file line number Diff line number Diff line change
@@ -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 { }

0 comments on commit 33b157b

Please sign in to comment.