Skip to content

Commit 428f765

Browse files
Merge pull request #4 from apanashchenko/patrons-list-view
Add Patrons list view
2 parents 6a55479 + 89425e6 commit 428f765

File tree

12 files changed

+132
-8
lines changed

12 files changed

+132
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ testem.log
3737
# System Files
3838
.DS_Store
3939
Thumbs.db
40+
*.iml

src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { LinkifyPipe } from './pipes/linkify.pipe';
2222
import { JwtInterceptor } from './jwt.interceptor';
2323
import { UserManagementComponent } from './user-management/user-management.component';
2424
import { AddUserComponent } from './add-user/add-user.component';
25+
import { PatronsListComponent } from './patrons-list/patrons-list.component';
2526

2627

2728
@NgModule({
@@ -36,7 +37,8 @@ import { AddUserComponent } from './add-user/add-user.component';
3637
LoginComponent,
3738
LinkThemesComponent,
3839
UserManagementComponent,
39-
AddUserComponent
40+
AddUserComponent,
41+
PatronsListComponent
4042
],
4143
imports: [
4244
BrowserModule,

src/app/app.routing.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { LoginComponent } from './login/login.component';
1010
import { LinkThemesComponent } from './link-themes/link-themes.component';
1111
import { UserManagementComponent } from './user-management/user-management.component';
1212
import { AddUserComponent } from './add-user/add-user.component';
13+
import {PatronsListComponent} from "./patrons-list/patrons-list.component";
1314

1415
const routes: Routes = [
1516
{ path: "add-user", component: AddUserComponent, canActivate: [AuthGuard] },
@@ -19,6 +20,7 @@ const routes: Routes = [
1920
{ path: 'list', component: EpisodeListComponent, canActivate: [AuthGuard] },
2021
{ path: 'link-themes/:id', component: LinkThemesComponent, canActivate: [AuthGuard] },
2122
{ path: 'episode-details/:id', component: EpisodeDetailsComponent, canActivate: [AuthGuard] },
23+
{ path: 'patrons-list', component: PatronsListComponent, canActivate: [AuthGuard] },
2224
{ path: '**', component: LoginComponent }
2325
]
2426

src/app/model/patron.list.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {Patron} from "./patron";
2+
3+
export class PatronList {
4+
totalAmount: Number
5+
patrons: Patron[]
6+
}
7+

src/app/model/patron.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export class Patron {
2+
id: Number
3+
fullName: string
4+
amount: Number
5+
email: boolean
6+
active: boolean
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.not-read {
2+
background-color: #e9ecef;
3+
border-color: #dee2e6;
4+
}
5+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<div class="row pb-3 pr-3">
2+
<div class="col">
3+
<h4><strong>Total: </strong>{{patronList?.totalAmount}}</h4>
4+
</div>
5+
<button type="button" class="btn btn-warning pull-right" (click)="clearPatronsCaches()">Reset Patron cache</button>
6+
</div>
7+
8+
9+
<div class="row">
10+
<div class="col">
11+
<div class="table-responsive">
12+
<table class="table table-hover">
13+
<thead class="thead-light">
14+
<tr>
15+
<th class="hidden"></th>
16+
<th class="hidden">Full Name</th>
17+
<th class="hidden">Amount</th>
18+
<th class="hidden">Email</th>
19+
</tr>
20+
</thead>
21+
<tbody>
22+
<ng-container *ngFor="let patron of patronList?.patrons; index as i">
23+
<tr [ngClass]="{'not-read' : !isShow(patron.amount)}">
24+
<td>{{i + 1}}</td>
25+
<td>{{ patron.fullName }}</td>
26+
<td>{{ transformPrice(patron.amount) | currency:' ':false:'1.1'}} $</td>
27+
<td>{{ patron.email }}</td>
28+
</tr>
29+
</ng-container>
30+
</tbody>
31+
</table>
32+
</div>
33+
</div>
34+
</div>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import {PatronList} from "../model/patron.list";
3+
import {PatronService} from "../service/patron.service";
4+
import {Router} from "@angular/router";
5+
6+
@Component({
7+
selector: 'app-patrons-list',
8+
templateUrl: './patrons-list.component.html',
9+
styleUrls: ['./patrons-list.component.css']
10+
})
11+
export class PatronsListComponent implements OnInit {
12+
13+
patronList: PatronList;
14+
15+
constructor(private patronService: PatronService, private router: Router) { }
16+
17+
ngOnInit() {
18+
this.patronService.getPatronList().subscribe(data => {
19+
this.patronList = data;
20+
});
21+
}
22+
23+
transformPrice(val: number): number {
24+
return val/100;
25+
}
26+
27+
isShow(val: number): boolean {
28+
return val >= 500
29+
}
30+
31+
clearPatronsCaches() {
32+
this.patronService.clearPatronsCaches()
33+
window.location.reload();
34+
}
35+
36+
}

src/app/service/patron.service.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Injectable } from '@angular/core';
2+
import { HttpClient } from '@angular/common/http';
3+
import { environment } from '../../environments/environment';
4+
import { Observable } from 'rxjs';
5+
import {PatronList} from "../model/patron.list";
6+
7+
@Injectable({
8+
providedIn: 'root'
9+
})
10+
export class PatronService {
11+
constructor(private http: HttpClient) { }
12+
baseUrl: string = `${environment.apiUrl}`
13+
14+
getPatronList(): Observable<PatronList> {
15+
return this.http.get<PatronList>(`${this.baseUrl}/patrons`)
16+
}
17+
18+
clearPatronsCaches() {
19+
this.http.get<PatronList>(`${this.baseUrl}/clearPatronsCaches`)
20+
}
21+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<nav class="navbar navbar-dark bg-dark mt-5 fixed-bottom">
2-
<div class="navbar-expand m-auto navbar-text">
3-
Made with <i class="fa fa-heart"></i> by <a href="https://github.com/SergeyPirogov">Sergey Pirogov</a>
4-
</div>
5-
</nav>
2+
<!--<div class="navbar-expand m-auto navbar-text">-->
3+
<!--Made with <i class="fa fa-heart"></i> by <a href="https://github.com/SergeyPirogov">Sergey Pirogov</a>-->
4+
<!--</div>-->
5+
</nav>

0 commit comments

Comments
 (0)