Skip to content

Commit fbf5b3d

Browse files
committed
changed logic implementation for load currencies correctly
1 parent 3bf4155 commit fbf5b3d

File tree

6 files changed

+72
-14
lines changed

6 files changed

+72
-14
lines changed

i4t_web/client/imports/app/web/administrator/administration/establishment/monthly-config/establishment-list/establishment-list.component.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,25 @@ export class EstablishmentListComponent implements OnInit, OnDestroy {
6969
this._establishments = Establishments.find({}).zone();
7070
this.countEstablishments();
7171
this._establishments.subscribe(() => { this.countEstablishments(); });
72+
73+
this._currencySub = MeteorObservable.subscribe('getCurrenciesByUserId', Meteor.userId()).takeUntil(this._ngUnsubscribe).subscribe(() => {
74+
this._ngZone.run(() => {
75+
let _currenciesIds: string[] = [];
76+
Establishments.collection.find({ creation_user: Meteor.userId() }).forEach(function <Establishment>(establishment, index, args) {
77+
_currenciesIds.push(establishment.currencyId);
78+
});
79+
this._currencies = Currencies.find({ _id: { $in: _currenciesIds } }).zone();
80+
});
81+
});
7282
});
7383
});
7484
this._tableSub = MeteorObservable.subscribe('tables', Meteor.userId()).takeUntil(this._ngUnsubscribe).subscribe(() => {
75-
this._tables = this._tables = Tables.find({}).zone();
76-
});
77-
this._currencySub = MeteorObservable.subscribe('getCurrenciesByUserId').takeUntil(this._ngUnsubscribe).subscribe(() => {
78-
this._currencies = Currencies.find({}).zone();
85+
this._ngZone.run(() => {
86+
this._tables = this._tables = Tables.find({}).zone();
87+
});
7988
});
80-
this._countrySub = MeteorObservable.subscribe('countries').takeUntil(this._ngUnsubscribe).subscribe();
8189

90+
this._countrySub = MeteorObservable.subscribe('countries').takeUntil(this._ngUnsubscribe).subscribe();
8291
this._paymentHistorySub = MeteorObservable.subscribe('getHistoryPaymentsByUser', Meteor.userId()).takeUntil(this._ngUnsubscribe).subscribe();
8392
}
8493

@@ -93,8 +102,15 @@ export class EstablishmentListComponent implements OnInit, OnDestroy {
93102
* Remove all subscriptions
94103
*/
95104
removeSubscription(): void {
105+
/**
96106
this._ngUnsubscribe.next();
97107
this._ngUnsubscribe.complete();
108+
*/
109+
if (this._establishmentSub) { this._establishmentSub.unsubscribe(); }
110+
if (this._tableSub) { this._tableSub.unsubscribe(); }
111+
if (this._currencySub) { this._currencySub.unsubscribe(); }
112+
if (this._countrySub) { this._countrySub.unsubscribe(); }
113+
if (this._paymentHistorySub) { this._paymentHistorySub.unsubscribe(); }
98114
}
99115

100116
/**
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
<mat-card>
2-
<mat-card-title>{{'BAGS_PAYMENT.TITLE' | translate }}</mat-card-title>
2+
<mat-card-header>
3+
<mat-card-title>{{'BAGS_PAYMENT.TITLE' | translate }}</mat-card-title>
4+
<mat-card-subtitle>{{'BAGS_PAYMENT.SUBTITLE' | translate}}</mat-card-subtitle>
5+
</mat-card-header>
36

7+
<mat-card-content style="background: #FFF">
8+
9+
10+
</mat-card-content>
11+
12+
<mat-card-actions>
13+
<button mat-button>PAGAR</button>
14+
</mat-card-actions>
415
</mat-card>

i4t_web/client/imports/app/web/administrator/payment/bags-payment/bags-payment.component.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { MeteorObservable } from 'meteor-rxjs';
66
import { TranslateService } from '@ngx-translate/core';
77
import { Observable, Subscription, Subject } from 'rxjs';
88
import { UserLanguageService } from '../../../services/general/user-language.service';
9-
9+
import { Establishment } from '../../../../../../../both/models/establishment/establishment.model';
10+
import { Establishments } from '../../../../../../../both/collections/establishment/establishment.collection';
11+
import { Currency } from '../../../../../../../both/models/general/currency.model';
12+
import { Currencies } from '../../../../../../../both/collections/general/currency.collection';
1013

1114
@Component({
1215
selector: 'bags-payment',
@@ -16,10 +19,19 @@ import { UserLanguageService } from '../../../services/general/user-language.ser
1619

1720
export class BagsPaymentComponent implements OnInit, OnDestroy {
1821

22+
private _user = Meteor.userId();
23+
private _establishments: Observable<Establishment[]>;
24+
private _currencies: Observable<Currency[]>;
25+
26+
private _establishmentSub: Subscription;
27+
private _currencySub: Subscription;
28+
29+
private _ngUnsubscribe: Subject<void> = new Subject<void>();
30+
1931
/**
2032
* MonthlyPaymentComponent Constructor
21-
* @param {Router} router
22-
* @param {FormBuilder} _formBuilder
33+
* @param {Router} router
34+
* @param {NgZone} _ngZone
2335
* @param {TranslateService} translate
2436
* @param {UserLanguageService} _userLanguageService
2537
*/
@@ -32,6 +44,21 @@ export class BagsPaymentComponent implements OnInit, OnDestroy {
3244
}
3345

3446
ngOnInit() {
35-
47+
this.removeSubscriptions();
48+
49+
this._establishmentSub = MeteorObservable.subscribe('establishments', this._user).takeUntil(this._ngUnsubscribe).subscribe(() => {
50+
this._establishments = Establishments.find({ creation_user: this._user }).zone();
51+
});
52+
53+
this._currencySub = MeteorObservable.subscribe('getCurrenciesByUserId').takeUntil(this._ngUnsubscribe).subscribe(() => {
54+
this._currencies = Currencies.find({}).zone();
55+
});
56+
}
57+
58+
/**
59+
* Remove all subscriptions
60+
*/
61+
removeSubscriptions(): void {
62+
3663
}
3764
}

i4t_web/public/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,7 @@
18401840
"LARGE": "A LA CARTÉ"
18411841
},
18421842
"BAGS_PAYMENT": {
1843-
"TITLE": "Purchase of bags"
1843+
"TITLE": "Purchase of bags",
1844+
"SUBTITLE": "Here you can to purchase the bag of points by restaurant that you want"
18441845
}
18451846
}

i4t_web/public/i18n/es.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,7 @@
18401840
"LARGE": "A LA CARTA"
18411841
},
18421842
"BAGS_PAYMENT": {
1843-
"TITLE": "Compra de bolsas"
1843+
"TITLE": "Compra de bolsas",
1844+
"SUBTITLE": "Aquí puedes comprar la bolsa de puntos por restaurante que desees"
18441845
}
18451846
}

i4t_web/server/imports/publications/general/currency.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ Meteor.publish('getCurrenciesByEstablishmentsId', function (_establishmentsId: s
2323
/**
2424
* Meteor publication return currencies by userId
2525
*/
26-
Meteor.publish('getCurrenciesByUserId', function () {
26+
Meteor.publish('getCurrenciesByUserId', function (_userId: string) {
2727
let _currenciesIds: string[] = [];
28-
Establishments.collection.find({ creation_user: this.userId }).forEach(function <Establishment>(establishment, index, args) {
28+
Establishments.collection.find({ creation_user: _userId }).forEach(function <Establishment>(establishment, index, args) {
2929
_currenciesIds.push(establishment.currencyId);
3030
});
3131

32+
console.log('------------------------------');
33+
console.log(_currenciesIds);
3234
return Currencies.find({ _id: { $in: _currenciesIds } });
3335
});
3436

0 commit comments

Comments
 (0)