@@ -2,9 +2,9 @@ import { Component, OnInit, TemplateRef } from '@angular/core';
22import { FormBuilder , FormGroup , Validators } from '@angular/forms' ;
33import { ActivatedRoute } from '@angular/router' ;
44import { BsModalService , BsModalRef } from 'ngx-bootstrap/modal' ;
5- import { Account , Budget , Campaign , Content , News , Project , User } from 'src/app/_entities' ;
6- import { BudgetModel , CampaignModel , DonationModel , GenericModel , NewsModel } from 'src/app/_models' ;
7- import { AuthenticationService , BudgetService , CampaignService , ContentService , DonationService , OrganizationService , PagerService , ProjectService , UserService } from 'src/app/_services' ;
5+ import { Budget , Campaign , Content , Project , User } from 'src/app/_entities' ;
6+ import { AccountModel , CampaignModel , DonationModel , GenericModel , NewsModel } from 'src/app/_models' ;
7+ import { AccountService , AuthenticationService , BudgetService , CampaignService , ContentService , DonationService , OrganizationService , PagerService , ProjectService , UserService } from 'src/app/_services' ;
88
99@Component ( {
1010 selector : 'app-view-project' ,
@@ -13,25 +13,27 @@ import { AuthenticationService, BudgetService, CampaignService, ContentService,
1313} )
1414export class ViewProjectComponent implements OnInit {
1515
16+ // Data
1617 id : number = 0 ;
1718 userLoggedIn : User = new User ( ) ;
1819 project : Project = new Project ( ) ;
1920 leader : User = new User ( ) ;
21+
22+ // Informations Card
2023 isUserInTeam : boolean = false ;
2124
22- // Campaigns Box
25+ // Campaigns Card
2326 campaigns : Campaign [ ] = [ ] ;
2427 campaignsSyncStatus : string = 'idle' ;
2528 campaignsBudgets : any = { } ;
2629
2730 // Contributing Modal
2831 selectedCampaign : Campaign = new Campaign ( ) ;
32+ account : AccountModel = new AccountModel ( ) ;
2933 contributeFinanciallyModalRef : BsModalRef = new BsModalRef ( ) ;
3034 donationForm : FormGroup = this . formBuilder . group ( {
31- budget : [ 0 ] ,
3235 amount : [ 10 , [ Validators . min ( 0 ) , Validators . max ( 0 ) ] ]
3336 } ) ;
34- accounts : Account [ ] = [ ] ;
3537
3638 // Funding Modal
3739 private campaign : CampaignModel = new CampaignModel ( ) ;
@@ -73,6 +75,7 @@ export class ViewProjectComponent implements OnInit {
7375 private formBuilder : FormBuilder ,
7476 private pagerService : PagerService ,
7577 private authenticationService : AuthenticationService ,
78+ private accountService : AccountService ,
7679 private budgetService : BudgetService ,
7780 private campaignService : CampaignService ,
7881 private contentService : ContentService ,
@@ -97,7 +100,6 @@ export class ViewProjectComponent implements OnInit {
97100 this . refreshMembers ( ) ;
98101 this . refreshCampaigns ( ) ;
99102 this . refreshNews ( ) ;
100- this . refreshAccounts ( ) ;
101103 } ) ;
102104 }
103105
@@ -116,7 +118,6 @@ export class ViewProjectComponent implements OnInit {
116118 this . members = User . fromModels ( members ) ;
117119 this . members . forEach ( member => {
118120 member . hasLeftTheOrganization = ! this . authenticationService . currentOrganizationValue . membersRef . some ( orgMemberId => orgMemberId == member . id ) ;
119- console . log ( member . hasLeftTheOrganization ) ;
120121 } ) ;
121122 this . isUserInTeam = this . members . find ( user => {
122123 return this . userLoggedIn . id === user . id ;
@@ -125,6 +126,7 @@ export class ViewProjectComponent implements OnInit {
125126 this . membersSyncStatus = 'idle' ;
126127 } , 1000 ) ;
127128 } , error => {
129+ console . log ( error ) ;
128130 this . membersSyncStatus = 'error' ;
129131 setTimeout ( ( ) => {
130132 this . membersSyncStatus = 'idle' ;
@@ -198,23 +200,15 @@ export class ViewProjectComponent implements OnInit {
198200 }
199201 }
200202
201- refreshAccounts ( ) {
202- this . userService . getAccounts ( this . userLoggedIn . id )
203- . subscribe ( accounts => {
204- this . accounts = Account . fromModels ( accounts ) ;
205- } )
206- }
207-
208203 openContributingModal ( template : TemplateRef < any > , campaign : Campaign ) {
209204 this . selectedCampaign = campaign ;
210- this . donationForm . controls [ 'amount' ] . setValidators ( [ Validators . required , Validators . min ( 0.01 ) , Validators . max (
211- + ( this . min ( this . accounts [ this . donationForm . controls [ 'budget' ] . value ] . amount , campaign . donationsRequired - campaign . totalDonations ) ) . toFixed ( 2 ) ) ] ) ;
212- this . contributeFinanciallyModalRef = this . modalService . show ( template ) ;
213- }
214-
215- onAccountSelectionChange ( ) {
216- this . donationForm . controls [ 'amount' ] . setValidators ( [ Validators . required , Validators . min ( 0.01 ) , Validators . max (
217- + ( this . min ( this . accounts [ this . donationForm . controls [ 'budget' ] . value ] . amount , this . selectedCampaign . donationsRequired - this . selectedCampaign . totalDonations ) ) . toFixed ( 2 ) ) ] ) ;
205+ this . accountService . getByBudgetAndUser ( this . selectedCampaign . budget . id , this . userLoggedIn . id )
206+ . subscribe ( account => {
207+ this . account = account ;
208+ this . donationForm . controls [ 'amount' ] . setValidators ( [ Validators . required , Validators . min ( 0.01 ) , Validators . max (
209+ + ( this . min ( account . amount , campaign . donationsRequired - campaign . totalDonations ) ) . toFixed ( 2 ) ) ] ) ;
210+ this . contributeFinanciallyModalRef = this . modalService . show ( template ) ;
211+ } ) ;
218212 }
219213
220214 onSubmitDonation ( ) {
@@ -225,8 +219,8 @@ export class ViewProjectComponent implements OnInit {
225219 this . contributeFinanciallyModalRef . hide ( ) ;
226220 var donation = new DonationModel ( ) ;
227221 donation . amount = this . donationForm . controls [ 'amount' ] . value ;
228- donation . account = GenericModel . valueOf ( this . accounts [ this . donationForm . controls [ 'budget' ] . value ] . id ) ;
229222 donation . campaign = GenericModel . valueOf ( this . selectedCampaign . id ) ;
223+ donation . account = this . account ;
230224
231225 this . donationService . create ( donation )
232226 . subscribe (
@@ -373,8 +367,5 @@ export class ViewProjectComponent implements OnInit {
373367 }
374368 }
375369
376- get filterByCampaignBudgets ( ) {
377- return this . accounts . filter ( a => this . selectedCampaign . budget . id == a . budget . id ) ;
378- }
379370}
380371
0 commit comments