File tree Expand file tree Collapse file tree 3 files changed +27
-28
lines changed Expand file tree Collapse file tree 3 files changed +27
-28
lines changed Original file line number Diff line number Diff line change 38
38
class ="value-label "> </ Label >
39
39
</ StackLayout >
40
40
41
- < StackLayout *ngIf ="state == 'read' "
42
- orientation ="horizontal ">
43
- < Label text ="Budget for a day - "
44
- class ="info-label "> </ Label >
45
- < Label [text] ="budgetService.budgetForDay "
46
- class ="value-label "> </ Label >
47
- </ StackLayout >
48
-
49
41
< StackLayout *ngIf ="state == 'edit' "
50
42
orientation ="vertical ">
51
43
< Label text ="Budget for a mounth: "
Original file line number Diff line number Diff line change @@ -20,6 +20,11 @@ export class BudgetComponent {
20
20
private budgetService : BudgetService
21
21
) { }
22
22
23
+ ngOnInit ( ) {
24
+ console . log ( 'ngOnInit' ) ;
25
+ this . budgetService . getBudget ( ) ;
26
+ }
27
+
23
28
onEditButtonTap ( ) {
24
29
this . state = 'edit' ;
25
30
}
@@ -33,7 +38,7 @@ export class BudgetComponent {
33
38
return ;
34
39
}
35
40
36
- this . budgetService . budget = Number ( textField . text ) ;
41
+ this . budgetService . setBudget ( Number ( textField . text ) ) ;
37
42
this . state = 'read' ;
38
43
}
39
44
Original file line number Diff line number Diff line change 1
1
import { Injectable } from '@angular/core' ;
2
+ import firebase = require( 'nativescript-plugin-firebase' ) ;
3
+
4
+ import { Config } from '../common/config' ;
2
5
3
6
@Injectable ( )
4
7
export class BudgetService {
5
- private _budget : number = 3000 ;
6
- public budgetForDay : number = 0 ;
7
-
8
- private getDayBudget ( ) {
9
- let currentDaysMonth = this . daysInCurrentMonth ( ) ;
10
- this . budgetForDay = Number ( ( this . _budget / currentDaysMonth ) . toFixed ( 2 ) ) ;
11
- }
12
-
13
- private daysInCurrentMonth ( ) {
14
- let dateNow = new Date ( ) ;
15
- return new Date ( dateNow . getFullYear ( ) , dateNow . getMonth ( ) + 1 , 0 ) . getDate ( ) ;
16
- }
17
-
18
- public set budget ( value : number ) {
19
- this . _budget = value ;
20
- this . getDayBudget ( ) ;
21
- }
8
+ public budget : number = 0 ;
22
9
23
- public get budget ( ) : number {
24
- return this . _budget ;
10
+ getBudget ( ) {
11
+ const userid = Config . getUserToken ( ) ;
12
+ firebase . getValue ( `/${ userid } /budget` ) . then ( result => {
13
+ this . budget = result . value . value ;
14
+ } ) ;
25
15
}
26
16
17
+ setBudget ( value : number ) {
18
+ const userid = Config . getUserToken ( ) ;
19
+ firebase . setValue (
20
+ `/${ userid } /budget` ,
21
+ {
22
+ value : value ,
23
+ updateTs : firebase . ServerValue . TIMESTAMP
24
+ }
25
+ ) . then ( result => {
26
+ this . budget = value ;
27
+ } ) ;
28
+ }
27
29
}
You can’t perform that action at this time.
0 commit comments