Skip to content

Commit

Permalink
#8 pdf download button
Browse files Browse the repository at this point in the history
  • Loading branch information
djuerges committed Apr 5, 2020
1 parent f238f59 commit a8597d6
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 56 deletions.
3 changes: 3 additions & 0 deletions src/app/places/invitation-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface InvitationLink {
link: string;
}
5 changes: 5 additions & 0 deletions src/app/places/place.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {InvitationLink} from './invitation-link';
import { Place } from './place';
import { Observable, of } from 'rxjs';

Expand All @@ -21,4 +22,8 @@ export class PlaceService {
block(place: Place): Observable<Place> {
return this.http.put<Place>(`/api/admin/places/${place.id}/block`, place);
}

getInvitationLink(place: Place): Observable<InvitationLink> {
return this.http.get<InvitationLink>(`/api/admin/places/${place.id}/invitation`);
}
}
10 changes: 10 additions & 0 deletions src/app/places/places-list/places-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@
</mat-cell>
</ng-container>

<!-- PDF -->
<ng-container matColumnDef="pdf">
<mat-header-cell *matHeaderCellDef>Invitation</mat-header-cell>
<mat-cell *matCellDef="let row">
<a (click)="downloadPdf(row)" target="_blank" *ngIf="hasPdf(row.status)">
<button mat-stroked-button color="accent">download</button>
</a>
</mat-cell>
</ng-container>

<!-- Header and Row Declarations -->
<mat-header-row *matHeaderRowDef="columns"></mat-header-row>
<mat-row class="table-row" *matRowDef="let row; columns: columns"></mat-row>
Expand Down
4 changes: 4 additions & 0 deletions src/app/places/places-list/places-list.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
margin-right: 1em;
color: map-get($purple-palette, 500);
}

.mat-column-pdf {
justify-content: center;
}
21 changes: 18 additions & 3 deletions src/app/places/places-list/places-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Observable } from 'rxjs';
})
export class PlacesListComponent implements OnInit {

readonly columns: string[] = ['status-color', 'company', 'address', 'id', 'status'];
readonly columns: string[] = ['status-color', 'company', 'address', 'id', 'status', 'pdf'];

data$: Observable<Place[]>;

Expand All @@ -24,7 +24,7 @@ export class PlacesListComponent implements OnInit {

changeStatus(event: MatSelectChange, place: Place) {
const newStatus = event.value;
if (this.isApprove(newStatus)) {
if (this.isContacted(newStatus)) {
this.placeService.approve(place).subscribe(approvedPlace => {
place = approvedPlace;
});
Expand All @@ -35,10 +35,25 @@ export class PlacesListComponent implements OnInit {
}
}

private isApprove(status: string): boolean {
downloadPdf(place: Place) {
this.placeService.getInvitationLink(place).subscribe(invitationLink => {
const url = invitationLink.link;
window.open(url.startsWith('http') ? url : 'http://localhost:4572/cofund/' + url);
});
}

hasPdf(status: string): boolean {
return this.isActive(status) || this.isContacted(status);
}

private isContacted(status: string): boolean {
return status === 'CONTACTED';
}

private isActive(status: string): boolean {
return status === 'ACTIVE';
}

private isBlocked(status: string): boolean {
return status === 'BLOCKED';
}
Expand Down
4 changes: 3 additions & 1 deletion src/app/places/places.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {MatIconModule} from '@angular/material/icon';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatSelectModule } from '@angular/material/select';
import { MatTableModule } from '@angular/material/table';
import { SharedModule } from '../shared/shared.module';
Expand All @@ -13,6 +14,7 @@ import { PlaceLinkPipe } from './place-link.pipe';
imports: [
CommonModule,
HttpClientModule,
MatButtonModule,
MatIconModule,
MatSelectModule,
MatTableModule,
Expand Down
10 changes: 5 additions & 5 deletions src/app/statistic/statistic.component.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div class="statistic-container">
<div class="statistic-row">
<div class="statistic-entry">
{{ sum$ | async }}€
<div class="statistic-entry" *ngIf="transactionsSum$">
{{ transactionsSum$ | async }}€
</div>
<div class="statistic-entry">
{{ donorCount$ | async }} Spender
<div class="statistic-entry" *ngIf="transactionsCount$">
{{ transactionsCount$ | async }} Spender
</div>
<div class="statistic-entry">
<div class="statistic-entry" *ngIf="placeCount$">
{{ placeCount$ | async }} Unternehmen
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/app/statistic/statistic.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import {StatisticService} from './statistic.service';
})
export class StatisticComponent implements OnInit {

sum$: Observable<number>;
donorCount$: Observable<number>;
placeCount$: Observable<number>;
transactionsCount$: Observable<number>;
transactionsSum$: Observable<number>;

constructor(private statisticService: StatisticService) { }

ngOnInit(): void {
this.sum$ = this.statisticService.getSum();
this.donorCount$ = this.statisticService.getDonorCount();
this.placeCount$ = this.statisticService.getPlaceCount();
this.placeCount$ = this.statisticService.getPlacesCount();
this.transactionsCount$ = this.statisticService.getTransactionsCount();
this.transactionsSum$ = this.statisticService.getTransactionsSum();
}
}
15 changes: 6 additions & 9 deletions src/app/statistic/statistic.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ export class StatisticService {

constructor(private http: HttpClient) { }

getSum(): Observable<number> {
return of(10786);
// return this.http.get<number>('/api/admin/transactions/sum');
getPlacesCount(): Observable<number> {
return this.http.get<number>('/api/admin/statistics/places/count');
}

getDonorCount(): Observable<number> {
return of(231);
// return this.http.get<number>('/api/admin/transactions/donorcount');
getTransactionsCount(): Observable<number> {
return this.http.get<number>('/api/admin/statistics/transactions/count');
}

getPlaceCount(): Observable<number> {
return of(89);
// return this.http.get<number>('/api/admin/transactions/placecount');
getTransactionsSum(): Observable<number> {
return this.http.get<number>('/api/admin/statistics/transactions/sum');
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<mat-table [dataSource]="data$ | async">

<!-- Status Indicator -->
<ng-container matColumnDef="status-color">
<mat-header-cell class="status-color-cell" *matHeaderCellDef></mat-header-cell>
<mat-cell class="status-color-cell" *matCellDef="let row">
<cofund-status-indicator [status]="row.status.toLowerCase()" *ngIf="row.status"></cofund-status-indicator>
</mat-cell>
</ng-container>

<ng-container matColumnDef="id">
<mat-header-cell *matHeaderCellDef>Zahlungs-ID</mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.id}} </mat-cell>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core';
import {MatSelectChange} from '@angular/material/select';
import {Observable} from 'rxjs';
import {Transaction} from '../transaction';
import {TransactionService} from '../transaction.service';
Expand All @@ -12,7 +11,7 @@ import {TransactionService} from '../transaction.service';
})
export class TransactionListComponent implements OnInit {

readonly columns: string[] = ['status-color', 'id', 'place', 'amount', 'status'];
readonly columns: string[] = ['id', 'place', 'amount', 'status'];

data$: Observable<Transaction[]>;

Expand All @@ -21,25 +20,4 @@ export class TransactionListComponent implements OnInit {
ngOnInit(): void {
this.data$ = this.transactionService.getAll();
}

changeStatus(event: MatSelectChange, transaction: Transaction) {
const newStatus = event.value;
if (this.isAccepted(newStatus)) {
this.transactionService.accept(transaction).subscribe(acceptedTransaction => {
transaction = acceptedTransaction;
});
} else if (this.isDeclined(newStatus)) {
this.transactionService.decline(transaction).subscribe(declinedTransaction => {
transaction = declinedTransaction;
});
}
}

private isAccepted(status: string): boolean {
return status === 'ACCEPTED';
}

private isDeclined(status: string): boolean {
return status === 'DECLINED';
}
}
2 changes: 0 additions & 2 deletions src/app/transaction/transaction.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {CommonModule} from '@angular/common';
import {HttpClientModule} from '@angular/common/http';
import {NgModule} from '@angular/core';
import {MatSelectModule} from '@angular/material/select';
import {MatTableModule} from '@angular/material/table';
import {SharedModule} from '../shared/shared.module';
import {TransactionListComponent} from './transaction-list/transaction-list.component';
Expand All @@ -12,7 +11,6 @@ import {TransactionListComponent} from './transaction-list/transaction-list.comp
CommonModule,
HttpClientModule,
MatTableModule,
MatSelectModule,
SharedModule
]
})
Expand Down

0 comments on commit a8597d6

Please sign in to comment.