Skip to content

Commit

Permalink
Merge pull request #320 from mild-blue/show-slots-number
Browse files Browse the repository at this point in the history
Show slots number
  • Loading branch information
LukasForst authored Jun 16, 2021
2 parents f1535e1 + 246f410 commit 7904efb
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"local": {
"url": "http://localhost:8080/api"
"url": "http://localhost:8080/api",
"email": "[email protected]",
"password": "bluemild"
},
"staging": {
"url": "https://covid-vaxx.stg.mild.blue/api",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Content-Type: application/json

{
"credentials": {
"email": "{{user}}",
"email": "{{email}}",
"password": "{{password}}"
},
"vaccineSerialNumber": "test",
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { QuestionService } from '@app/services/question/question.service';
import { AlertService } from '@app/services/alert/alert.service';
import { StatisticsService } from '@app/services/statistics/statistics.service';

@Component({
selector: 'app-root',
Expand All @@ -10,12 +11,14 @@ import { AlertService } from '@app/services/alert/alert.service';
export class AppComponent implements OnInit {

constructor(private _questionService: QuestionService,
private _statisticsService: StatisticsService,
private _alertService: AlertService) {
}

async ngOnInit(): Promise<void> {
// Reload questions from BE on every app load (page refresh as well)
await this._initQuestions();
await this._initStatistics();
}

private async _initQuestions(): Promise<void> {
Expand All @@ -25,4 +28,12 @@ export class AppComponent implements OnInit {
this._alertService.error(e.message);
}
}

private async _initStatistics(): Promise<void> {
try {
await this._statisticsService.loadStatistics();
} catch (e) {
this._alertService.error(e.message);
}
}
}
113 changes: 53 additions & 60 deletions frontend/src/app/generated/api/default.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -948,66 +948,6 @@ export class DefaultService {
);
}

/**
* @param from Date FROM which should system provide statistics.
* @param to Date TO which should system provide statistics.
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public apiAdminStatisticsGet(from?: string, to?: string, observe?: 'body', reportProgress?: boolean, options?: { httpHeaderAccept?: 'application/json' }): Observable<SystemStatisticsDtoOut>;
public apiAdminStatisticsGet(from?: string, to?: string, observe?: 'response', reportProgress?: boolean, options?: { httpHeaderAccept?: 'application/json' }): Observable<HttpResponse<SystemStatisticsDtoOut>>;
public apiAdminStatisticsGet(from?: string, to?: string, observe?: 'events', reportProgress?: boolean, options?: { httpHeaderAccept?: 'application/json' }): Observable<HttpEvent<SystemStatisticsDtoOut>>;
public apiAdminStatisticsGet(from?: string, to?: string, observe: any = 'body', reportProgress: boolean = false, options?: { httpHeaderAccept?: 'application/json' }): Observable<any> {

let queryParameters = new HttpParams({ encoder: this.encoder });
if (from !== undefined && from !== null) {
queryParameters = this.addToHttpParams(queryParameters,
<any>from, 'from');
}
if (to !== undefined && to !== null) {
queryParameters = this.addToHttpParams(queryParameters,
<any>to, 'to');
}

let headers = this.defaultHeaders;

let credential: string | undefined;
// authentication (jwtAuth) required
credential = this.configuration.lookupCredential('jwtAuth');
if (credential) {
headers = headers.set('Authorization', 'Bearer ' + credential);
}

let httpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
if (httpHeaderAcceptSelected === undefined) {
// to determine the Accept header
const httpHeaderAccepts: string[] = [
'application/json'
];
httpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
}
if (httpHeaderAcceptSelected !== undefined) {
headers = headers.set('Accept', httpHeaderAcceptSelected);
}


let responseType: 'text' | 'json' = 'json';
if (httpHeaderAcceptSelected && httpHeaderAcceptSelected.startsWith('text')) {
responseType = 'text';
}

return this.httpClient.get<SystemStatisticsDtoOut>(`${this.configuration.basePath}/api/admin/statistics`,
{
params: queryParameters,
responseType: <any>responseType,
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress
}
);
}

/**
* Get vaccination detail for given patient ID.
* @param id Patients ID
Expand Down Expand Up @@ -1549,6 +1489,59 @@ export class DefaultService {
);
}

/**
* @param from Date FROM which should system provide statistics.
* @param to Date TO which should system provide statistics.
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public apiStatisticsGet(from?: string, to?: string, observe?: 'body', reportProgress?: boolean, options?: { httpHeaderAccept?: 'application/json' }): Observable<SystemStatisticsDtoOut>;
public apiStatisticsGet(from?: string, to?: string, observe?: 'response', reportProgress?: boolean, options?: { httpHeaderAccept?: 'application/json' }): Observable<HttpResponse<SystemStatisticsDtoOut>>;
public apiStatisticsGet(from?: string, to?: string, observe?: 'events', reportProgress?: boolean, options?: { httpHeaderAccept?: 'application/json' }): Observable<HttpEvent<SystemStatisticsDtoOut>>;
public apiStatisticsGet(from?: string, to?: string, observe: any = 'body', reportProgress: boolean = false, options?: { httpHeaderAccept?: 'application/json' }): Observable<any> {

let queryParameters = new HttpParams({ encoder: this.encoder });
if (from !== undefined && from !== null) {
queryParameters = this.addToHttpParams(queryParameters,
<any>from, 'from');
}
if (to !== undefined && to !== null) {
queryParameters = this.addToHttpParams(queryParameters,
<any>to, 'to');
}

let headers = this.defaultHeaders;

let httpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
if (httpHeaderAcceptSelected === undefined) {
// to determine the Accept header
const httpHeaderAccepts: string[] = [
'application/json'
];
httpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
}
if (httpHeaderAcceptSelected !== undefined) {
headers = headers.set('Accept', httpHeaderAcceptSelected);
}


let responseType: 'text' | 'json' = 'json';
if (httpHeaderAcceptSelected && httpHeaderAcceptSelected.startsWith('text')) {
responseType = 'text';
}

return this.httpClient.get<SystemStatisticsDtoOut>(`${this.configuration.basePath}/api/statistics`,
{
params: queryParameters,
responseType: <any>responseType,
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress
}
);
}

/**
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/app/model/Statistics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface Statistics {
availableSlots: number;
bookedSlots: number;
emailsSentCount: number;
patientsDataVerifiedCount: number;
registrationsCount: number;
vaccinatedPatientsCount: number;
}
29 changes: 24 additions & 5 deletions frontend/src/app/pages/info/info.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
<img src="assets/vaccine-icon.svg" alt="Vaccine icon">
<p>
Sedmička a Poliklinika Prahy 7 pro vás zajistily možnost očkování proti nemoci COVID-19 vakcínou Comirnaty od společnosti
<strong>Pfizer/BioNTech</strong>.
<strong>Pfizer/BioNTech</strong>. <br>

<ng-container *ngIf="statistics">
<ng-container *ngIf="statistics.availableSlots > 0">
Zbývá <strong>{{statistics.availableSlots}} volných termínů</strong>.
</ng-container>
<ng-container *ngIf="statistics.availableSlots == 0">
Bohužel už není <strong>žádný volný termín</strong>.
</ng-container>
</ng-container>
</p>
</div>
<div class="welcome__item">
Expand Down Expand Up @@ -58,10 +67,20 @@ <h3>
<mat-icon>favorite_border</mat-icon>
</h3>

<button class="mt-30" color="primary" mat-raised-button routerLink="/registration">
Registrovat se k očkování
<mat-icon>arrow_forward</mat-icon>
</button>
<ng-container *ngIf="statistics !== undefined">
<ng-container *ngIf="statistics.availableSlots > 0 else content">
<button class="mt-30" color="primary" mat-raised-button routerLink="/registration">
Registrovat se k očkování
<mat-icon>arrow_forward</mat-icon>
</button>
</ng-container>

<ng-template #content>
<button class="mt-30" color="primary" mat-raised-button routerLink="/registration" [disabled]="true">
Bohužel už není žádný volný termín
</button>
</ng-template>
</ng-container>
</app-container>

</main>
8 changes: 7 additions & 1 deletion frontend/src/app/pages/info/info.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { Component } from '@angular/core';
import { StatisticsService } from '@app/services/statistics/statistics.service';
import { Statistics } from '@app/model/Statistics';

@Component({
selector: 'app-info',
templateUrl: './info.component.html',
styleUrls: ['./info.component.scss']
})
export class InfoComponent {
public statistics?: Statistics;

constructor() {
constructor(private _statisticsService: StatisticsService) {
this._statisticsService.statistics.subscribe(statistics => {
this.statistics = statistics;
});
}

}
8 changes: 8 additions & 0 deletions frontend/src/app/parsers/statistics.parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { SystemStatisticsDtoOut } from '@app/generated';
import { Statistics } from '@app/model/Statistics';

export const parseStatistics = (data: SystemStatisticsDtoOut): Statistics => {
return {
...data
};
};
16 changes: 16 additions & 0 deletions frontend/src/app/services/statistics/statistics.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { StatisticsService } from './statistics.service';

describe('StatisticsService', () => {
let service: StatisticsService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(StatisticsService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
43 changes: 43 additions & 0 deletions frontend/src/app/services/statistics/statistics.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { SystemStatisticsDtoOut } from '@app/generated';
import { environment } from '@environments/environment';
import { map } from 'rxjs/operators';
import { Statistics } from '@app/model/Statistics';
import { parseStatistics } from '@app/parsers/statistics.parser';
import { BehaviorSubject, Observable } from 'rxjs';

@Injectable({
providedIn: 'root'
})
export class StatisticsService {

private _statisticsnKey = 'questions';
private _statisticsSubject: BehaviorSubject<Statistics | undefined> = new BehaviorSubject<Statistics | undefined>(undefined);
public statistics: Observable<Statistics | undefined> = this._statisticsSubject.asObservable();

constructor(private _http: HttpClient) {
this._initStatistics();
}

public async loadStatistics(): Promise<Statistics> {
return this._http.get<SystemStatisticsDtoOut>(
`${environment.apiUrl}/statistics`
).pipe(
map(response => {
const statistics = parseStatistics(response);

this._statisticsSubject.next(statistics);
localStorage.setItem(this._statisticsnKey, JSON.stringify(statistics));

return statistics;
})
).toPromise();
}

private _initStatistics(): void {
const value = localStorage.getItem(this._statisticsnKey);
const savedStatistics = value ? JSON.parse(value) : undefined;
this._statisticsSubject.next(savedStatistics);
}
}

0 comments on commit 7904efb

Please sign in to comment.