Skip to content

Commit 4ca9f21

Browse files
committed
feat: add view rules on report component
1 parent 05faab4 commit 4ca9f21

File tree

6 files changed

+167
-90
lines changed

6 files changed

+167
-90
lines changed

src/app/app/budgets/budgets.component.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ <h3 class="card-title" i18n="@@budgets">Budgets</h3>
1212
</a>
1313
</div>
1414
</div>
15-
<div class="card-body p-0">
15+
<div class="card-body p-0 table-responsive">
1616
<table class="table table-striped projects">
1717
<thead>
1818
<tr>
@@ -155,7 +155,7 @@ <h4 class="modal-title pull-left" i18n="@@editBudget">Edit budget</h4>
155155
</div>
156156
</div>
157157
<div class="form-group">
158-
<label for="rules">Rules</label>
158+
<label for="rules" i18n="@@budgetsRules">Rules</label>
159159
<select class="custom-select" class="form-control" style="width: 100%;" formControlName="rules"
160160
id="rules">
161161
<option *ngFor="let item of rules | keyvalue" value="{{ item.key }}">{{ item.value.name }}</option>

src/app/app/projects/list/list-projects.component.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ export class ListProjectsComponent implements OnInit {
117117
var projectCampaigns = data.filter(campaign => campaign.project.id === project.id);
118118
var projectTotalDonations = projectCampaigns.reduce((sum, current) => sum + current.totalDonations, 0);
119119
var projectDonationsRequired = projectCampaigns.reduce((sum, current) => {
120+
console.log(current.status + " : " + current.totalRequired);
120121
if (current.status != CampaignStatus.FAILED) {
121-
return sum + current.donationsRequired
122+
return sum + current.totalRequired
122123
} else {
123124
return sum
124125
}

src/app/app/report/report.component.html

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
<div class="row action-bar" [formGroup]="selectBudgetForm">
2-
<div class="col-2">
2+
<div class="col-md-2">
33
<div class="form-group">
44
<label for="amount" i18n="@@budget">Budget</label>
55
<select class="form-control" style="width: 100%;" formControlName="budget">
66
<option *ngFor="let budget of budgets; index as i" value="{{ budget.id }}">{{ budget.name }}</option>
77
</select>
88
</div>
99
</div>
10-
<div class="col-10">
10+
<div class="col-md-2">
11+
<div class="form-group">
12+
<label for="amount" i18n="@@reportRulesLabel">Rules</label>
13+
<button type="button" class="btn btn-block btn-default" (click)="onViewTermsOfUse(viewRulesModalTemplate)" i18n="@@reportRulesButton">View rules</button>
14+
</div>
15+
</div>
16+
<div class="col-md-8">
1117
<div id="budgetUsage" class="progress-group">
1218
<span class="progress-text" i18n="@@usageOverview">Usage overview</span>
1319
<div class="progress" title="{{ budgetUsage }}">
@@ -54,7 +60,7 @@ <h3 class="card-title" i18n="@@campaigns">Campaigns</h3>
5460
<td><span *ngIf="projects.get(campaign.project.id) !== undefined">{{
5561
getProject(campaign.project.id).peopleGivingTimeRef.length }} / 3</span></td>
5662
<td>{{ campaign.totalDonations.toFixed(2) }} €</td>
57-
<td>{{ campaign.donationsRequired.toFixed(2) }} €</td>
63+
<td>{{ campaign.totalRequired.toFixed(2) }} €</td>
5864
<td>
5965
<span *ngIf="campaign.status === 'IN_PROGRESS'" class="badge bg-yellow"
6066
i18n="@@reportStatusInProgress">In Progress</span>
@@ -191,4 +197,18 @@ <h3 class="card-title" i18n="@@reportAccountsState">Accounts State</h3>
191197
</div>
192198
</div>
193199
</div>
194-
</div>
200+
</div>
201+
202+
<ng-template #viewRulesModalTemplate>
203+
<div class="modal-header">
204+
<h4 class="modal-title pull-left">{{ rules.name }}</h4>
205+
<button type="button" class="close pull-right" aria-label="Close" (click)="viewRulesModal.hide()">
206+
<span aria-hidden="true">&times;</span>
207+
</button>
208+
</div>
209+
<div class="modal-body" [innerHTML]="rules.value">
210+
</div>
211+
<div class="modal-footer">
212+
<button class="btn btn-primary" (click)="viewRulesModal.hide()" i18n="@@close">Close</button>
213+
</div>
214+
</ng-template>

src/app/app/report/report.component.ts

+54-32
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, TemplateRef } from '@angular/core';
22
import { UntypedFormBuilder } from '@angular/forms';
3-
import { Account, Budget, User } from 'src/app/_entities';
3+
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
4+
import { Account, Budget, Content, User } from 'src/app/_entities';
45
import { AccountModel, CampaignModel, DataPage, ProjectModel } from 'src/app/_models';
56
import { Pager } from 'src/app/_models/pagination/pager/pager';
6-
import { AuthenticationService, BudgetService, OrganizationService, PagerService, ProjectService } from 'src/app/_services';
7+
import { AuthenticationService, BudgetService, ContentService, OrganizationService, PagerService, ProjectService } from 'src/app/_services';
78

89
@Component({
910
selector: 'app-report',
@@ -22,6 +23,10 @@ export class ReportComponent implements OnInit {
2223
budget: [0]
2324
});
2425

26+
// Rules Modal
27+
viewRulesModal = new BsModalRef();
28+
rules = new Content();
29+
2530
// Campaigns Box
2631
private rawProjectsResponse = new DataPage<CampaignModel>();
2732
campaignPager = new Pager();
@@ -37,12 +42,14 @@ export class ReportComponent implements OnInit {
3742
accountsSyncStatus = 'idle';
3843

3944
constructor(
45+
private modalService: BsModalService,
46+
private fb: UntypedFormBuilder,
4047
private authenticationService: AuthenticationService,
4148
private budgetService: BudgetService,
49+
private contentService: ContentService,
4250
private organizationService: OrganizationService,
4351
private projectService: ProjectService,
44-
private pagerService: PagerService,
45-
private fb: UntypedFormBuilder) { }
52+
private pagerService: PagerService) { }
4653

4754
ngOnInit() {
4855
this.refresh();
@@ -56,7 +63,7 @@ export class ReportComponent implements OnInit {
5663
});
5764
this.selectBudgetForm.controls['budget'].valueChanges.subscribe(val => {
5865
const budgetFound = this.budgets.find(budget => budget.id === +val);
59-
if(budgetFound !== undefined) {
66+
if (budgetFound !== undefined) {
6067
this.budget = budgetFound;
6168
this.budgetUsage = this.computeNumberPercent(this.budget.totalDonations, this.authenticationService.currentOrganizationValue.membersRef.length * this.budget.amountPerMember) + "%";
6269
this.refreshCampaigns(this.campaignPager.currentPage);
@@ -69,32 +76,39 @@ export class ReportComponent implements OnInit {
6976
if (this.pagerService.canChangePage(this.campaignPager, page)) {
7077
this.campaignsSyncStatus = 'running';
7178
this.budgetService.getCampaigns(this.selectBudgetForm.controls['budget'].value, page - 1, this.campaignsPageSize)
72-
.subscribe(response => {
73-
this.rawProjectsResponse = response;
74-
this.setCampaignsPage(page);
75-
const projectIds: number[] = [];
76-
this.pagedCampaigns.forEach(campaign => {
77-
if(campaign.project.id > 0) {
78-
projectIds.push(campaign.project.id);
79-
}
80-
});
81-
this.projectService.getAllByIds(projectIds)
82-
.subscribe(response => {
83-
response.forEach(prj => this.projects.set(prj.id, prj))
84-
},
85-
error => {
86-
console.log(error);
79+
.subscribe({
80+
next: (response) => {
81+
this.rawProjectsResponse = response;
82+
this.setCampaignsPage(page);
83+
const projectIds: number[] = [];
84+
this.pagedCampaigns.forEach(campaign => {
85+
if (campaign.project.id > 0) {
86+
projectIds.push(campaign.project.id);
87+
}
8788
});
88-
this.campaignsSyncStatus = 'success';
89-
setTimeout(() => {
90-
this.campaignsSyncStatus = 'idle';
91-
}, 1000);
92-
}, error => {
93-
this.campaignsSyncStatus = 'error';
94-
console.log(error);
95-
setTimeout(() => {
96-
this.campaignsSyncStatus = 'idle';
97-
}, 1000);
89+
this.projectService.getAllByIds(projectIds)
90+
.subscribe({
91+
next: (response) => response.forEach(prj => this.projects.set(prj.id, prj)),
92+
complete: () => { },
93+
error: error => {
94+
console.log(error);
95+
}
96+
});
97+
this.campaignsSyncStatus = 'success';
98+
setTimeout(() => {
99+
this.campaignsSyncStatus = 'idle';
100+
}, 1000);
101+
102+
},
103+
complete: () => { },
104+
error: error => {
105+
this.campaignsSyncStatus = 'error';
106+
console.log(error);
107+
setTimeout(() => {
108+
this.campaignsSyncStatus = 'idle';
109+
}, 1000);
110+
111+
}
98112
});
99113
}
100114
}
@@ -147,7 +161,7 @@ export class ReportComponent implements OnInit {
147161

148162
getProject(id: number): ProjectModel {
149163
let entity = this.projects.get(id);
150-
if(entity === undefined) {
164+
if (entity === undefined) {
151165
entity = new ProjectModel();
152166
}
153167
return entity;
@@ -159,4 +173,12 @@ export class ReportComponent implements OnInit {
159173
}
160174
return 100 * number / max;
161175
}
176+
177+
onViewTermsOfUse(template: TemplateRef<string>) {
178+
this.contentService.getById(this.budget.rules.id)
179+
.subscribe(content => {
180+
this.rules = Content.fromModel(content);
181+
this.viewRulesModal = this.modalService.show(template);
182+
});
183+
}
162184
}

src/locale/messages.fr.xlf

+9
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
<trans-unit id="costOfHour" datatype="html">
6969
<target>Coût d'une heure</target>
7070
</trans-unit>
71+
<trans-unit id="budgetsRules" datatype="html">
72+
<target>Règles d'utilisation</target>
73+
</trans-unit>
7174
<trans-unit id="budgetFieldDisabled" datatype="html">
7275
<target> Certains champs ont été désactivés car le budget est déjà distribué entre les membres de l'organisation. </target>
7376
</trans-unit>
@@ -562,6 +565,12 @@
562565
<trans-unit id="userWhantToLeadRealOfIdea" datatype="html">
563566
<target>Je souhaite porter la réalisation de cette idée</target>
564567
</trans-unit>
568+
<trans-unit id="reportRulesLabel" datatype="html">
569+
<target>Règles associées</target>
570+
</trans-unit>
571+
<trans-unit id="reportRulesButton" datatype="html">
572+
<target>Afficher les règles</target>
573+
</trans-unit>
565574
<trans-unit id="usageOverview" datatype="html">
566575
<target>Utilisation</target>
567576
</trans-unit>

0 commit comments

Comments
 (0)