From 4ca9f21f7d04d2f4e302430d609c77e2777c95bb Mon Sep 17 00:00:00 2001 From: Thomah <5090230+Thomah@users.noreply.github.com> Date: Sat, 28 Oct 2023 18:25:32 +0200 Subject: [PATCH] feat: add view rules on report component --- src/app/app/budgets/budgets.component.html | 4 +- .../projects/list/list-projects.component.ts | 3 +- src/app/app/report/report.component.html | 28 +++- src/app/app/report/report.component.ts | 86 +++++++----- src/locale/messages.fr.xlf | 9 ++ src/locale/messages.xlf | 127 +++++++++++------- 6 files changed, 167 insertions(+), 90 deletions(-) diff --git a/src/app/app/budgets/budgets.component.html b/src/app/app/budgets/budgets.component.html index 4f6833f..2246823 100644 --- a/src/app/app/budgets/budgets.component.html +++ b/src/app/app/budgets/budgets.component.html @@ -12,7 +12,7 @@

Budgets

-
+
@@ -155,7 +155,7 @@
- + @@ -7,7 +7,13 @@
-
+
+
+ + +
+
+
Usage overview
@@ -54,7 +60,7 @@

Campaigns

- +
{{ getProject(campaign.project.id).peopleGivingTimeRef.length }} / 3 {{ campaign.totalDonations.toFixed(2) }} €{{ campaign.donationsRequired.toFixed(2) }} €{{ campaign.totalRequired.toFixed(2) }} € In Progress @@ -191,4 +197,18 @@

Accounts State

- \ No newline at end of file + + + + + + + \ No newline at end of file diff --git a/src/app/app/report/report.component.ts b/src/app/app/report/report.component.ts index d8c1053..a1c487c 100644 --- a/src/app/app/report/report.component.ts +++ b/src/app/app/report/report.component.ts @@ -1,9 +1,10 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, TemplateRef } from '@angular/core'; import { UntypedFormBuilder } from '@angular/forms'; -import { Account, Budget, User } from 'src/app/_entities'; +import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; +import { Account, Budget, Content, User } from 'src/app/_entities'; import { AccountModel, CampaignModel, DataPage, ProjectModel } from 'src/app/_models'; import { Pager } from 'src/app/_models/pagination/pager/pager'; -import { AuthenticationService, BudgetService, OrganizationService, PagerService, ProjectService } from 'src/app/_services'; +import { AuthenticationService, BudgetService, ContentService, OrganizationService, PagerService, ProjectService } from 'src/app/_services'; @Component({ selector: 'app-report', @@ -22,6 +23,10 @@ export class ReportComponent implements OnInit { budget: [0] }); + // Rules Modal + viewRulesModal = new BsModalRef(); + rules = new Content(); + // Campaigns Box private rawProjectsResponse = new DataPage(); campaignPager = new Pager(); @@ -37,12 +42,14 @@ export class ReportComponent implements OnInit { accountsSyncStatus = 'idle'; constructor( + private modalService: BsModalService, + private fb: UntypedFormBuilder, private authenticationService: AuthenticationService, private budgetService: BudgetService, + private contentService: ContentService, private organizationService: OrganizationService, private projectService: ProjectService, - private pagerService: PagerService, - private fb: UntypedFormBuilder) { } + private pagerService: PagerService) { } ngOnInit() { this.refresh(); @@ -56,7 +63,7 @@ export class ReportComponent implements OnInit { }); this.selectBudgetForm.controls['budget'].valueChanges.subscribe(val => { const budgetFound = this.budgets.find(budget => budget.id === +val); - if(budgetFound !== undefined) { + if (budgetFound !== undefined) { this.budget = budgetFound; this.budgetUsage = this.computeNumberPercent(this.budget.totalDonations, this.authenticationService.currentOrganizationValue.membersRef.length * this.budget.amountPerMember) + "%"; this.refreshCampaigns(this.campaignPager.currentPage); @@ -69,32 +76,39 @@ export class ReportComponent implements OnInit { if (this.pagerService.canChangePage(this.campaignPager, page)) { this.campaignsSyncStatus = 'running'; this.budgetService.getCampaigns(this.selectBudgetForm.controls['budget'].value, page - 1, this.campaignsPageSize) - .subscribe(response => { - this.rawProjectsResponse = response; - this.setCampaignsPage(page); - const projectIds: number[] = []; - this.pagedCampaigns.forEach(campaign => { - if(campaign.project.id > 0) { - projectIds.push(campaign.project.id); - } - }); - this.projectService.getAllByIds(projectIds) - .subscribe(response => { - response.forEach(prj => this.projects.set(prj.id, prj)) - }, - error => { - console.log(error); + .subscribe({ + next: (response) => { + this.rawProjectsResponse = response; + this.setCampaignsPage(page); + const projectIds: number[] = []; + this.pagedCampaigns.forEach(campaign => { + if (campaign.project.id > 0) { + projectIds.push(campaign.project.id); + } }); - this.campaignsSyncStatus = 'success'; - setTimeout(() => { - this.campaignsSyncStatus = 'idle'; - }, 1000); - }, error => { - this.campaignsSyncStatus = 'error'; - console.log(error); - setTimeout(() => { - this.campaignsSyncStatus = 'idle'; - }, 1000); + this.projectService.getAllByIds(projectIds) + .subscribe({ + next: (response) => response.forEach(prj => this.projects.set(prj.id, prj)), + complete: () => { }, + error: error => { + console.log(error); + } + }); + this.campaignsSyncStatus = 'success'; + setTimeout(() => { + this.campaignsSyncStatus = 'idle'; + }, 1000); + + }, + complete: () => { }, + error: error => { + this.campaignsSyncStatus = 'error'; + console.log(error); + setTimeout(() => { + this.campaignsSyncStatus = 'idle'; + }, 1000); + + } }); } } @@ -147,7 +161,7 @@ export class ReportComponent implements OnInit { getProject(id: number): ProjectModel { let entity = this.projects.get(id); - if(entity === undefined) { + if (entity === undefined) { entity = new ProjectModel(); } return entity; @@ -159,4 +173,12 @@ export class ReportComponent implements OnInit { } return 100 * number / max; } + + onViewTermsOfUse(template: TemplateRef) { + this.contentService.getById(this.budget.rules.id) + .subscribe(content => { + this.rules = Content.fromModel(content); + this.viewRulesModal = this.modalService.show(template); + }); + } } diff --git a/src/locale/messages.fr.xlf b/src/locale/messages.fr.xlf index e790c6b..db345cc 100644 --- a/src/locale/messages.fr.xlf +++ b/src/locale/messages.fr.xlf @@ -68,6 +68,9 @@ Coût d'une heure + + Règles d'utilisation + Certains champs ont été désactivés car le budget est déjà distribué entre les membres de l'organisation. @@ -562,6 +565,12 @@ Je souhaite porter la réalisation de cette idée + + Règles associées + + + Afficher les règles + Utilisation diff --git a/src/locale/messages.xlf b/src/locale/messages.xlf index d91bf97..ee5df89 100644 --- a/src/locale/messages.xlf +++ b/src/locale/messages.xlf @@ -110,7 +110,7 @@ src/app/app/profile/profile.component.html - 53 + 52 src/app/app/projects/view/view-project.component.html @@ -209,6 +209,13 @@ 127 + + Rules + + src/app/app/budgets/budgets.component.html + 158 + + Some field have been disabled because budget is already distributed between organization members. @@ -224,12 +231,16 @@ src/app/app/profile/profile.component.html - 157 + 156 src/app/app/projects/view/view-project.component.html 536 + + src/app/app/report/report.component.html + 212 + Save @@ -251,7 +262,7 @@ src/app/app/profile/profile.component.html - 119 + 118 src/app/app/projects/edit/edit-project.component.html @@ -299,7 +310,7 @@ src/app/app/profile/profile.component.html - 51 + 50 src/app/app/projects/edit/edit-project.component.html @@ -419,11 +430,11 @@ src/app/app/profile/profile.component.html - 100 + 99 src/app/app/profile/profile.component.html - 101 + 100 src/app/app/users/users.component.html @@ -487,11 +498,11 @@ src/app/app/report/report.component.html - 78 + 84 src/app/app/report/report.component.html - 158 + 164 src/app/app/users/users.component.html @@ -522,11 +533,11 @@ src/app/app/report/report.component.html - 80 + 86 src/app/app/report/report.component.html - 160 + 166 src/app/app/users/users.component.html @@ -557,11 +568,11 @@ src/app/app/report/report.component.html - 82 + 88 src/app/app/report/report.component.html - 162 + 168 src/app/app/users/users.component.html @@ -592,11 +603,11 @@ src/app/app/report/report.component.html - 84 + 90 src/app/app/report/report.component.html - 164 + 170 src/app/app/users/users.component.html @@ -819,14 +830,14 @@ Projects src/app/app/profile/profile.component.html - 47 + 46 Short Description src/app/app/profile/profile.component.html - 52 + 51 src/app/app/projects/edit/edit-project.component.html @@ -841,49 +852,49 @@ Draft src/app/app/profile/profile.component.html - 61 + 60 Idea src/app/app/profile/profile.component.html - 62 + 61 In Progress src/app/app/profile/profile.component.html - 63 + 62 On Pause src/app/app/profile/profile.component.html - 64 + 63 Finished src/app/app/profile/profile.component.html - 65 + 64 Contributions src/app/app/profile/profile.component.html - 71 + 70 Budget src/app/app/profile/profile.component.html - 75 + 74 src/app/app/projects/view/view-project.component.html @@ -906,7 +917,7 @@ Date src/app/app/profile/profile.component.html - 76 + 75 src/app/app/projects/view/view-project.component.html @@ -917,14 +928,14 @@ Project src/app/app/profile/profile.component.html - 77 + 76 Amount src/app/app/profile/profile.component.html - 78 + 77 src/app/app/projects/view/view-project.component.html @@ -939,14 +950,14 @@ Settings src/app/app/profile/profile.component.html - 97 + 96 Password src/app/app/profile/profile.component.html - 104 + 103 src/app/app/users/users.component.html @@ -961,7 +972,7 @@ Password - Keep empty to leave it unchanged src/app/app/profile/profile.component.html - 105 + 104 src/app/app/users/users.component.html @@ -972,11 +983,11 @@ Firstname src/app/app/profile/profile.component.html - 108 + 107 src/app/app/profile/profile.component.html - 109 + 108 src/app/app/users/users.component.html @@ -991,11 +1002,11 @@ Lastname src/app/app/profile/profile.component.html - 112 + 111 src/app/app/profile/profile.component.html - 113 + 112 src/app/app/users/users.component.html @@ -1010,11 +1021,11 @@ Avatar URL src/app/app/profile/profile.component.html - 116 + 115 src/app/app/profile/profile.component.html - 117 + 116 src/app/app/users/users.component.html @@ -1029,21 +1040,21 @@ Developper src/app/app/profile/profile.component.html - 122 + 121 Generate src/app/app/profile/profile.component.html - 143 + 142 Your new API Token src/app/app/profile/profile.component.html - 148 + 147 @@ -1612,95 +1623,109 @@ 576 + + Rules + + src/app/app/report/report.component.html + 12 + + + + View rules + + src/app/app/report/report.component.html + 13 + + Usage overview src/app/app/report/report.component.html - 12 + 18 Campaigns src/app/app/report/report.component.html - 24 + 30 Title src/app/app/report/report.component.html - 37 + 43 Created at src/app/app/report/report.component.html - 38 + 44 Description src/app/app/report/report.component.html - 39 + 45 Team Members src/app/app/report/report.component.html - 40 + 46 Donations src/app/app/report/report.component.html - 41 + 47 Donations required src/app/app/report/report.component.html - 42 + 48 Status src/app/app/report/report.component.html - 43 + 49 In Progress src/app/app/report/report.component.html - 60 + 66 Failed src/app/app/report/report.component.html - 62 + 68 Successful src/app/app/report/report.component.html - 64 + 70 Accounts State src/app/app/report/report.component.html - 121 + 127