1- import { Component , OnInit } from '@angular/core' ;
1+ import { Component , OnInit , TemplateRef } from '@angular/core' ;
22import { 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' ;
45import { AccountModel , CampaignModel , DataPage , ProjectModel } from 'src/app/_models' ;
56import { 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}
0 commit comments