1
- import { Component , OnInit } from '@angular/core' ;
1
+ import { Component , OnInit , TemplateRef } from '@angular/core' ;
2
2
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' ;
4
5
import { AccountModel , CampaignModel , DataPage , ProjectModel } from 'src/app/_models' ;
5
6
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' ;
7
8
8
9
@Component ( {
9
10
selector : 'app-report' ,
@@ -22,6 +23,10 @@ export class ReportComponent implements OnInit {
22
23
budget : [ 0 ]
23
24
} ) ;
24
25
26
+ // Rules Modal
27
+ viewRulesModal = new BsModalRef ( ) ;
28
+ rules = new Content ( ) ;
29
+
25
30
// Campaigns Box
26
31
private rawProjectsResponse = new DataPage < CampaignModel > ( ) ;
27
32
campaignPager = new Pager ( ) ;
@@ -37,12 +42,14 @@ export class ReportComponent implements OnInit {
37
42
accountsSyncStatus = 'idle' ;
38
43
39
44
constructor (
45
+ private modalService : BsModalService ,
46
+ private fb : UntypedFormBuilder ,
40
47
private authenticationService : AuthenticationService ,
41
48
private budgetService : BudgetService ,
49
+ private contentService : ContentService ,
42
50
private organizationService : OrganizationService ,
43
51
private projectService : ProjectService ,
44
- private pagerService : PagerService ,
45
- private fb : UntypedFormBuilder ) { }
52
+ private pagerService : PagerService ) { }
46
53
47
54
ngOnInit ( ) {
48
55
this . refresh ( ) ;
@@ -56,7 +63,7 @@ export class ReportComponent implements OnInit {
56
63
} ) ;
57
64
this . selectBudgetForm . controls [ 'budget' ] . valueChanges . subscribe ( val => {
58
65
const budgetFound = this . budgets . find ( budget => budget . id === + val ) ;
59
- if ( budgetFound !== undefined ) {
66
+ if ( budgetFound !== undefined ) {
60
67
this . budget = budgetFound ;
61
68
this . budgetUsage = this . computeNumberPercent ( this . budget . totalDonations , this . authenticationService . currentOrganizationValue . membersRef . length * this . budget . amountPerMember ) + "%" ;
62
69
this . refreshCampaigns ( this . campaignPager . currentPage ) ;
@@ -69,32 +76,39 @@ export class ReportComponent implements OnInit {
69
76
if ( this . pagerService . canChangePage ( this . campaignPager , page ) ) {
70
77
this . campaignsSyncStatus = 'running' ;
71
78
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
+ }
87
88
} ) ;
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
+ }
98
112
} ) ;
99
113
}
100
114
}
@@ -147,7 +161,7 @@ export class ReportComponent implements OnInit {
147
161
148
162
getProject ( id : number ) : ProjectModel {
149
163
let entity = this . projects . get ( id ) ;
150
- if ( entity === undefined ) {
164
+ if ( entity === undefined ) {
151
165
entity = new ProjectModel ( ) ;
152
166
}
153
167
return entity ;
@@ -159,4 +173,12 @@ export class ReportComponent implements OnInit {
159
173
}
160
174
return 100 * number / max ;
161
175
}
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
+ }
162
184
}
0 commit comments