From 8b97e39c2b79ca613e2ef77d7b559885c379f66a Mon Sep 17 00:00:00 2001 From: Dimitris Mytakis Date: Tue, 23 Jun 2020 18:00:00 +0300 Subject: [PATCH] Back Browser Button & Modals --- .../new-member/new-member.component.ts | 2 +- .../new-partner/new-partner.component.ts | 5 +- src/app/app.component.ts | 4 +- src/app/auth/auth.component.ts | 2 +- .../email_verification.component.ts | 2 +- .../forgot_password.component.ts | 2 +- src/app/auth/login/login.component.ts | 2 +- .../need_verification.component.ts | 2 +- .../password_restoration.component.ts | 2 +- .../password_verification.component.ts | 2 +- .../register-partner.component.ts | 5 +- src/app/auth/register/register.component.ts | 2 +- src/app/auth/terms/synergy_terms.component.ts | 2 +- .../create-content.component.ts | 2 +- .../edit-content/edit-content.component.ts | 2 +- src/app/core/config/i18n/el.ts | 2 + src/app/core/config/i18n/en.ts | 4 +- src/app/core/helpers/auth.guard.ts | 6 +- src/app/core/helpers/config.guard.ts | 4 +- src/app/history/history.component.ts | 23 +- src/app/history/loyalty/loyalty.component.ts | 48 +- .../microcredit/microcredit.component.ts | 47 +- .../member-dashboard.component.ts | 198 +++-- .../member-explore.component.scss | 4 +- .../member-explore.component.ts | 211 ++--- .../member-redeem/member-redeem.component.ts | 33 +- .../member-support.component.ts | 107 ++- .../sub-amount-form.component.ts | 13 +- .../sub-final-step.component.ts | 13 +- .../support-microcredit.component.ts | 65 +- .../edit-event/edit-event.component.ts | 2 +- .../new-event/new-event.component.html | 4 +- .../p-events/new-event/new-event.component.ts | 2 +- .../edit-offer/edit-offer.component.ts | 2 +- .../new-offer/new-offer.component.ts | 2 +- .../partner-offers.component.html | 2 +- .../partner-offers.component.scss | 8 +- .../edit-microcredit-campaign.component.ts | 2 +- .../add-support/add-support.component.ts | 24 +- .../new-microcredit-campaign.component.ts | 2 +- .../partner-campaigns.component.ts | 4 +- .../p-posts/edit-post/edit-post.component.ts | 2 +- .../p-posts/new-post/new-post.component.ts | 2 +- src/app/scanner/_scanner.interface.ts | 67 +- src/app/scanner/_scanner.service.ts | 12 +- .../scan-loyalty/scan-loyalty.component.html | 6 + .../scan-loyalty/scan-loyalty.component.scss | 16 + .../scan-loyalty/scan-loyalty.component.ts | 167 ++-- .../scan-microcredit.component.html | 5 +- .../scan-microcredit.component.scss | 16 + .../scan-microcredit.component.ts | 40 +- .../scan-offers/scan-offers.component.html | 5 +- .../scan-offers/scan-offers.component.scss | 16 + .../scan-offers/scan-offers.component.ts | 66 +- src/app/scanner/scanner.component.html | 2 +- src/app/scanner/scanner.component.scss | 3 + src/app/scanner/scanner.component.ts | 178 +++-- src/app/scanner/scanner.module.ts | 3 +- .../sub-final-step.component.html | 11 +- .../sub-final-step.component.ts | 3 + .../sub-microcredit-form.component.html | 2 +- .../sub-offer-form.component.html | 4 +- .../sub-offer-form.component.ts | 2 +- .../personal-information.component.ts | 11 +- .../card-microcredit.component.scss | 9 +- .../card-microcredit.component.ts | 21 +- .../card-partner/card-partner.component.scss | 20 +- .../card-partner/card-partner.component.ts | 7 + .../cards/card-post/card-post.component.scss | 1 + .../cards/card-post/card-post.component.ts | 7 + .../card-support/card-support.component.ts | 7 + .../views/layout/footer/footer.component.ts | 26 +- src/app/views/layout/layout.component.ts | 22 +- .../single-microcredit.component.ts | 18 +- .../single-partner.component.html | 8 +- .../single-partner.component.ts | 162 ++-- .../single-post/single-post.component.ts | 14 +- .../archive-offers.component.ts | 34 +- .../archive-partners.component.ts | 34 +- .../archive-posts/archive-posts.component.ts | 34 +- .../views/pages/qr-code/qr-code.component.ts | 14 +- src/assets/scss/config_assets.scss | 749 +++++++++--------- 82 files changed, 1734 insertions(+), 962 deletions(-) diff --git a/src/app/a-members/new-member/new-member.component.ts b/src/app/a-members/new-member/new-member.component.ts index c803a5e9..e6665635 100644 --- a/src/app/a-members/new-member/new-member.component.ts +++ b/src/app/a-members/new-member/new-member.component.ts @@ -32,7 +32,7 @@ export class NewMemberComponent implements OnInit, OnDestroy { private unsubscribe: Subject; /** - * Component constructor + * Component Constructor * * @param cdRef: ChangeDetectorRef * @param fb: FormBuilder diff --git a/src/app/a-partners/new-partner/new-partner.component.ts b/src/app/a-partners/new-partner/new-partner.component.ts index e3dbf498..cbbe83b5 100644 --- a/src/app/a-partners/new-partner/new-partner.component.ts +++ b/src/app/a-partners/new-partner/new-partner.component.ts @@ -27,6 +27,9 @@ import { PartnerPayment } from 'src/app/core/models/partner_payment.model'; }) export class NewPartnerComponent implements OnInit, OnDestroy { + /** + * Configuration and Static Data + */ public subAccessConfig: Boolean[] = environment.subAccess; public paymentsList: PaymentList[]; @@ -45,7 +48,7 @@ export class NewPartnerComponent implements OnInit, OnDestroy { private unsubscribe: Subject; /** - * Component constructor + * Component Constructor * * @param cdRef: ChangeDetectorRef * @param fb: FormBuilder diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 60da39f3..fd4ebd59 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -27,7 +27,7 @@ export class AppComponent implements OnInit, OnDestroy { // Public properties loader: boolean; - private unsubscribe: Subscription[] = []; + private unsubscribe: Subscription[] = []; // Read more: => https://brianflove.com/2016/12/11/anguar-2-unsubscribe-observables/ language: LanguageFlag; @@ -44,7 +44,7 @@ export class AppComponent implements OnInit, OnDestroy { }, ]; /** - * Component constructor + * Component Constructor * * @param translationService: TranslationService * @param router: Router diff --git a/src/app/auth/auth.component.ts b/src/app/auth/auth.component.ts index 3381daa0..8e0c74f4 100644 --- a/src/app/auth/auth.component.ts +++ b/src/app/auth/auth.component.ts @@ -19,7 +19,7 @@ export class AuthComponent implements OnInit { public version = `${environment.version}`; /** - * Component constructor + * Component Constructor * * @param el: ElementRef * @param renderr: Renderer2 diff --git a/src/app/auth/email_verification/email_verification.component.ts b/src/app/auth/email_verification/email_verification.component.ts index 860ca6ae..7a9ca4ef 100644 --- a/src/app/auth/email_verification/email_verification.component.ts +++ b/src/app/auth/email_verification/email_verification.component.ts @@ -38,7 +38,7 @@ export class EmailVerificationComponent implements OnInit, OnDestroy { // Read more: => https://brianflove.com/2016/12/11/anguar-2-unsubscribe-observables/ /** - * Component constructor + * Component Constructor * * @param router: Router * @param fb: FormBuilder, diff --git a/src/app/auth/forgot_password/forgot_password.component.ts b/src/app/auth/forgot_password/forgot_password.component.ts index da0f8e24..4362889c 100644 --- a/src/app/auth/forgot_password/forgot_password.component.ts +++ b/src/app/auth/forgot_password/forgot_password.component.ts @@ -29,7 +29,7 @@ export class ForgotPasswordComponent implements OnInit, OnDestroy { loading: boolean = false; /** - * Component constructor + * Component Constructor * * @param router: Router * @param fb: FormBuilder, diff --git a/src/app/auth/login/login.component.ts b/src/app/auth/login/login.component.ts index b648aef0..2a77f568 100644 --- a/src/app/auth/login/login.component.ts +++ b/src/app/auth/login/login.component.ts @@ -33,7 +33,7 @@ export class LoginComponent implements OnInit, OnDestroy { // Read more: => https://brianflove.com/2016/12/11/anguar-2-unsubscribe-observables/ /** - * Component constructor + * Component Constructor * * @param router: Router * @param fb: FormBuilder, diff --git a/src/app/auth/need_verification/need_verification.component.ts b/src/app/auth/need_verification/need_verification.component.ts index 4d55e654..29dce87f 100644 --- a/src/app/auth/need_verification/need_verification.component.ts +++ b/src/app/auth/need_verification/need_verification.component.ts @@ -29,7 +29,7 @@ export class NeedVerificationComponent implements OnInit, OnDestroy { loading: boolean = false; /** - * Component constructor + * Component Constructor * * @param router: Router * @param fb: FormBuilder diff --git a/src/app/auth/password_restoration/password_restoration.component.ts b/src/app/auth/password_restoration/password_restoration.component.ts index b818e9c5..084a86bb 100644 --- a/src/app/auth/password_restoration/password_restoration.component.ts +++ b/src/app/auth/password_restoration/password_restoration.component.ts @@ -36,7 +36,7 @@ export class PasswordRestorationComponent implements OnInit, OnDestroy { // Read more: => https://brianflove.com/2016/12/11/anguar-2-unsubscribe-observables/ /** - * Component constructor + * Component Constructor * * @param router: Router * @param fb: FormBuilder diff --git a/src/app/auth/password_verification/password_verification.component.ts b/src/app/auth/password_verification/password_verification.component.ts index 6de33aae..aba31fa6 100644 --- a/src/app/auth/password_verification/password_verification.component.ts +++ b/src/app/auth/password_verification/password_verification.component.ts @@ -33,7 +33,7 @@ export class PasswordVerificationComponent implements OnInit, OnDestroy { loading: boolean = false; /** - * Component constructor + * Component Constructor * * @param router: Router * @param fb: FormBuilder diff --git a/src/app/auth/register-partner/register-partner.component.ts b/src/app/auth/register-partner/register-partner.component.ts index 00ef5294..e98a8dc0 100644 --- a/src/app/auth/register-partner/register-partner.component.ts +++ b/src/app/auth/register-partner/register-partner.component.ts @@ -30,6 +30,9 @@ import { GeneralList } from 'src/app/core/interfaces/general-list.interface'; }) export class RegisterPartnerComponent implements OnInit, OnDestroy { + /** + * Configuration and Static Data + */ public paymentsList: PaymentList[]; public sectorList: GeneralList[]; @@ -47,7 +50,7 @@ export class RegisterPartnerComponent implements OnInit, OnDestroy { loading: boolean = false; /** - * Component constructor + * Component Constructor * * @param router: Router * @param fb: FormBuilder, diff --git a/src/app/auth/register/register.component.ts b/src/app/auth/register/register.component.ts index 02af93d1..b10dfee1 100644 --- a/src/app/auth/register/register.component.ts +++ b/src/app/auth/register/register.component.ts @@ -35,7 +35,7 @@ export class RegisterComponent implements OnInit, OnDestroy { loading: boolean = false; /** - * Component constructor + * Component Constructor * * @param router: Router * @param fb: FormBuilder, diff --git a/src/app/auth/terms/synergy_terms.component.ts b/src/app/auth/terms/synergy_terms.component.ts index 3643665a..53f7ba87 100644 --- a/src/app/auth/terms/synergy_terms.component.ts +++ b/src/app/auth/terms/synergy_terms.component.ts @@ -8,7 +8,7 @@ import { MatDialog } from '@angular/material'; export class TermsComponent implements OnInit, OnDestroy { /** - * Component constructor + * Component Constructor * * @param dialog: MatDialog */ diff --git a/src/app/content/create-content/create-content.component.ts b/src/app/content/create-content/create-content.component.ts index 2d5f55ec..8686213a 100644 --- a/src/app/content/create-content/create-content.component.ts +++ b/src/app/content/create-content/create-content.component.ts @@ -21,7 +21,7 @@ export class CreateContentComponent implements OnInit, OnDestroy { private unsubscribe: Subject; /** - * Component constructor + * Component Constructor * * @param cdRef: ChangeDetectorRef * @param fb: FormBuilder diff --git a/src/app/content/edit-content/edit-content.component.ts b/src/app/content/edit-content/edit-content.component.ts index c970a525..8073d2cf 100644 --- a/src/app/content/edit-content/edit-content.component.ts +++ b/src/app/content/edit-content/edit-content.component.ts @@ -23,7 +23,7 @@ export class EditContentComponent implements OnInit { private unsubscribe: Subject; /** - * Component constructor + * Component Constructor * * @param cdRef: ChangeDetectorRef * @param fb: FormBuilder diff --git a/src/app/core/config/i18n/el.ts b/src/app/core/config/i18n/el.ts index 7308dfc8..3e531e70 100644 --- a/src/app/core/config/i18n/el.ts +++ b/src/app/core/config/i18n/el.ts @@ -824,6 +824,7 @@ export const locale = { SUB_OFFER_FORM: { HEADING_MAIN: 'Λεπτομέρειες Προσφοράς', HEADING: 'Ποσό Συναλλαγής', + OFFER: 'Προσφορά', TITLE: 'Ποσότητα', HINT: 'Παρακαλούμε εισάγετε το ποσό συναλλαγής.', ALERT: 'Δε φτάνουν οι πόντοι.', @@ -845,6 +846,7 @@ export const locale = { }, SUB_MICROCREDIT_FORM: { HEADING: 'Τεμάχια Συναλλαγής', + CAMPAIGN: 'Καμπάνια', CAMPAIGN_ID: 'Ταυτότητα Καμπάνιας', HEADING_2: 'Πόντοι', SUPPORT_ID: 'Ταυτότητα Συναλλαγής', diff --git a/src/app/core/config/i18n/en.ts b/src/app/core/config/i18n/en.ts index 0c659327..8783f457 100644 --- a/src/app/core/config/i18n/en.ts +++ b/src/app/core/config/i18n/en.ts @@ -707,7 +707,7 @@ export const locale = { DRAFT: 'Draft', EXPECTED: 'Is Expected', EXPIRED: 'Expired', - REDEEM_TO: 'Redeem To' + REDEEM_TO: 'redeem until' } }, SUPPORT: { @@ -823,6 +823,7 @@ export const locale = { SUB_OFFER_FORM: { HEADING_MAIN: 'Offer Transaction Details', HEADING: 'Transaction quantity', + OFFER: 'Offer', TITLE: 'Quantity', HINT: 'Please enter transaction quantity.', ALERT: 'Not enough points', @@ -844,6 +845,7 @@ export const locale = { }, SUB_MICROCREDIT_FORM: { HEADING: 'Support items', + CAMPAIGN: 'Campaign', CAMPAIGN_ID: 'Campaign ID', HEADING_2: 'Tokens', SUPPORT_ID: 'Support ID', diff --git a/src/app/core/helpers/auth.guard.ts b/src/app/core/helpers/auth.guard.ts index ff65a551..ec56257f 100644 --- a/src/app/core/helpers/auth.guard.ts +++ b/src/app/core/helpers/auth.guard.ts @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'; import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; import { AuthenticationService } from '../services/authentication.service'; +import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; @Injectable({ providedIn: 'root' }) export class AuthGuard implements CanActivate { @@ -12,10 +13,11 @@ export class AuthGuard implements CanActivate { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { const currentUser = this.authenticationService.currentUserValue; + if (currentUser) { - return true; + return true; } - // not logged in so redirect to login page with the return url + this.router.navigate(['/auth/login']);//, { queryParams: { returnUrl: state.url }}); return false; } diff --git a/src/app/core/helpers/config.guard.ts b/src/app/core/helpers/config.guard.ts index a309ca50..a582d9bb 100644 --- a/src/app/core/helpers/config.guard.ts +++ b/src/app/core/helpers/config.guard.ts @@ -3,6 +3,7 @@ import { Router, CanActivate, ActivatedRouteSnapshot } from '@angular/router'; import { AuthenticationService } from '../services/authentication.service'; import { environment } from '../../../environments/environment'; +import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; @Injectable({ providedIn: 'root' }) export class ConfigGuard implements CanActivate { @@ -15,10 +16,11 @@ export class ConfigGuard implements CanActivate { // on the data property const accessIndex = route.data.accessIndex; - console.log(route.data.redirectURL) + if (environment.access[accessIndex] === true) { return true; } + this.router.navigate([route.data.redirectURL || '/']); return false; diff --git a/src/app/history/history.component.ts b/src/app/history/history.component.ts index be81a157..307170e5 100644 --- a/src/app/history/history.component.ts +++ b/src/app/history/history.component.ts @@ -3,11 +3,12 @@ import { NavigationEnd, Router } from '@angular/router'; import { filter } from 'rxjs/operators'; import { StaticDataService } from '../core/services/static-data.service'; -interface Menu { - title?: string, - link?: string, - icon?: string -} +import { Menu } from '../core/interfaces/menu.interface'; +// interface Menu { +// title?: string, +// link?: string, +// icon?: string +// } @Component({ selector: 'app-history', @@ -18,14 +19,24 @@ export class HistoryComponent implements OnInit { currentRouteUrl: string = ''; public menu: Menu[]; + /** + * Component Constructor + * + * @param cdRef: ChangeDetectorRef + * @param router: Router + * @param staticDataService: StaticDataService + */ constructor( - private router: Router, private cdr: ChangeDetectorRef, + private router: Router, private staticDataService: StaticDataService ) { this.menu = this.staticDataService.getHistorySubMenu; } + /** + * On Init + */ ngOnInit() { this.currentRouteUrl = this.router.url.split(/[?#]/)[0]; this.router.events diff --git a/src/app/history/loyalty/loyalty.component.ts b/src/app/history/loyalty/loyalty.component.ts index f0febb9e..1f972e59 100644 --- a/src/app/history/loyalty/loyalty.component.ts +++ b/src/app/history/loyalty/loyalty.component.ts @@ -1,10 +1,16 @@ import { Component, OnInit, OnDestroy, ChangeDetectorRef } from '@angular/core'; import { tap, takeUntil, finalize } from 'rxjs/operators'; import { Subject } from 'rxjs'; -// Services + +/** + * Services + */ import { AuthenticationService } from 'src/app/core/services/authentication.service'; import { LoyaltyService } from '../../core/services/loyalty.service'; -// Models + +/** + * Models & Interfaces + */ import { LoyaltyTransaction } from '../../core/models/loyalty_transaction.model'; @Component({ @@ -14,12 +20,24 @@ import { LoyaltyTransaction } from '../../core/models/loyalty_transaction.model' }) export class LoyaltyHistoryComponent implements OnInit, OnDestroy { - access: string = ''; + /** + * Content Variables + */ public transactions: LoyaltyTransaction[]; + + access: string = ''; + p: number = 1; loading: boolean = false; private unsubscribe: Subject; + /** + * Component Constructor + * + * @param cdRef: ChangeDetectorRef + * @param authenticationService: AuthenticationService + * @param loyaltyService: LoyaltyService + */ constructor( private cdRef: ChangeDetectorRef, private authenticationService: AuthenticationService, @@ -28,9 +46,27 @@ export class LoyaltyHistoryComponent implements OnInit, OnDestroy { this.unsubscribe = new Subject(); } + /** + * On Init + */ ngOnInit() { this.access = this.authenticationService.currentUserValue.user["access"]; + this.fetchTransactions(); + } + /** + * On Destroy + */ + ngOnDestroy() { + this.unsubscribe.next(); + this.unsubscribe.complete(); + this.loading = false; + } + + /** + * Fetch Transactions List (for One User) + */ + fetchTransactions() { this.loyaltyService.readTransactions('0-0-0') .pipe( tap( @@ -50,9 +86,5 @@ export class LoyaltyHistoryComponent implements OnInit, OnDestroy { .subscribe(); } - ngOnDestroy() { - this.unsubscribe.next(); - this.unsubscribe.complete(); - this.loading = false; - } + } diff --git a/src/app/history/microcredit/microcredit.component.ts b/src/app/history/microcredit/microcredit.component.ts index 3ff8e549..12f27af8 100644 --- a/src/app/history/microcredit/microcredit.component.ts +++ b/src/app/history/microcredit/microcredit.component.ts @@ -1,10 +1,16 @@ import { Component, OnInit, OnDestroy, ChangeDetectorRef } from '@angular/core'; import { tap, takeUntil, finalize } from 'rxjs/operators'; import { Subject } from 'rxjs'; -// Services + +/** + * Services + */ import { AuthenticationService } from 'src/app/core/services/authentication.service'; import { MicrocreditService } from '../../core/services/microcredit.service'; -// Models + +/** + * Models & Interfaces + */ import { MicrocreditTransaction } from '../../core/models/microcredit_transaction.model'; @Component({ @@ -14,13 +20,24 @@ import { MicrocreditTransaction } from '../../core/models/microcredit_transactio }) export class MicrocreditHistoryComponent implements OnInit, OnDestroy { - access: string = ''; + /** + * Content Variables + */ public transactions: MicrocreditTransaction[]; + + access: string = ''; p: number = 1; loading: boolean = false; private unsubscribe: Subject; + /** + * Component Constructor + * + * @param cdRef: ChangeDetectorRef + * @param authenticationService: AuthenticationService + * @param microcreditService: MicrocreditService + */ constructor( private cdRef: ChangeDetectorRef, private authenticationService: AuthenticationService, @@ -29,9 +46,27 @@ export class MicrocreditHistoryComponent implements OnInit, OnDestroy { this.unsubscribe = new Subject(); } + /** + * On Init + */ ngOnInit() { this.access = this.authenticationService.currentUserValue.user["access"]; + this.fetchTransactions() + } + + /** + * On Destroy + */ + ngOnDestroy() { + this.unsubscribe.next(); + this.unsubscribe.complete(); + this.loading = false; + } + /** + * Fetch Transactions List (for One User) + */ + fetchTransactions() { this.microcreditService.readTransactions('0-0-0') .pipe( tap( @@ -49,10 +84,4 @@ export class MicrocreditHistoryComponent implements OnInit, OnDestroy { ) .subscribe(); } - - ngOnDestroy() { - this.unsubscribe.next(); - this.unsubscribe.complete(); - this.loading = false; - } } diff --git a/src/app/member-dashboard/member-dashboard.component.ts b/src/app/member-dashboard/member-dashboard.component.ts index c06e3c56..87f4f42f 100644 --- a/src/app/member-dashboard/member-dashboard.component.ts +++ b/src/app/member-dashboard/member-dashboard.component.ts @@ -1,25 +1,29 @@ //Import Basic Services -import { Component, OnInit, OnDestroy, ChangeDetectorRef, ViewChild } from '@angular/core'; -import { first, tap, finalize, takeUntil } from 'rxjs/operators'; -import { Subject, Subscriber } from 'rxjs'; -import { NgbModal, NgbActiveModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap'; -//Import System Services - -import { MicrocreditSupport } from '../core/models/microcredit_support.model'; -import { AuthenticationService } from '../core/services/authentication.service'; -import { StaticContentService } from '../core/services/staticcontent.service'; -import { ItemsService } from '../core/services/items.service'; -import { LoyaltyService } from '../core/services/loyalty.service'; -import { MicrocreditService } from 'src/app/core/services/microcredit.service'; -import { ContentService } from 'src/app/core/services/content.service'; +import { Component, OnInit, OnDestroy, ChangeDetectorRef, ViewChild, HostListener } from '@angular/core'; +import { tap, finalize, takeUntil } from 'rxjs/operators'; +import { Subject } from 'rxjs'; +import { NgbModal, NgbActiveModal, ModalDismissReasons, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; import { TranslateService } from '@ngx-translate/core'; + +/** + * Environment + */ import { environment } from '../../environments/environment'; + +/** + * Services + */ import { StaticDataService } from '../core/services/static-data.service'; +import { ContentService } from 'src/app/core/services/content.service'; +import { LoyaltyService } from '../core/services/loyalty.service'; +import { MicrocreditService } from 'src/app/core/services/microcredit.service'; -import { Offer } from '../core/models/offer.model'; +/** + * Models & Interfaces + */ import { Activity } from '../core/models/activity.model'; import { Balance } from '../core/interfaces/balance.interface'; - +import { MicrocreditSupport } from '../core/models/microcredit_support.model'; import { PaymentList } from '../core/interfaces/payment-list.interface'; @Component({ @@ -29,9 +33,18 @@ import { PaymentList } from '../core/interfaces/payment-list.interface'; }) export class MemberDashboardComponent implements OnInit, OnDestroy { + /** + * Children Modals + */ + @ViewChild('qrcodeModal', { static: false }) qrcodeModal: NgbModalRef; + @ViewChild('walletModal', { static: false }) walletModal: NgbModalRef; + @ViewChild('supportsModal', { static: false }) supportsModal: NgbModalRef; + + /** + * Configuration and Static Data + */ public configAccess: Boolean[] = environment.access; public paymentsList: PaymentList[]; - //Set Basic Variables loading: boolean = false; private unsubscribe: Subject; @@ -43,9 +56,9 @@ export class MemberDashboardComponent implements OnInit, OnDestroy { //Set Content Variables Text: any; //Static Text for QR Code Modal - supportsList: MicrocreditSupport[]; //The microcredits the member supports - supportItem: MicrocreditSupport; //Currently Selected microcredit Support - offers: Offer[]; //Available Offers + public supportsList: MicrocreditSupport[]; //The microcredits the member supports + public supportItem: MicrocreditSupport; //Currently Selected microcredit Support + //offers: Offer[]; //Available Offers p: number = 1; @@ -56,51 +69,42 @@ export class MemberDashboardComponent implements OnInit, OnDestroy { one_of_us: '../../../assets/media/images/ranking-3.png', }; - //Set Child Modals - @ViewChild('qrcodeModal', { static: false }) qrcodeModal; - @ViewChild('walletModal', { static: false }) walletModal; - @ViewChild('supportsModal', { static: false }) supportsModal; - /** - * Component constructor - * - * @param cdRef: ChangeDetectorRef - * @param authenticationService: AuthenticationService - * @param loyaltyService: LoyaltyService - */ + * Component Constructor + * + * @param cdRef: ChangeDetectorRef + * @param modalService: NgbModal + * @param translate: TranslateService + * @param staticDataService: StaticDataService + * @param loyaltyService: LoyaltyService + * @param microcreditService: MicrocreditService + * @param contentService: ContentService + */ constructor( private cdRef: ChangeDetectorRef, - private authenticationService: AuthenticationService, private modalService: NgbModal, - private loyaltyService: LoyaltyService, - private staticContentService: StaticContentService, public translate: TranslateService, - private itemsService: ItemsService, + private staticDataService: StaticDataService, + private loyaltyService: LoyaltyService, private microcreditService: MicrocreditService, - private contentService: ContentService, - private staticDataService: StaticDataService + private contentService: ContentService ) { this.paymentsList = this.staticDataService.getPaymentsList; this.unsubscribe = new Subject(); } /** - * On Init - */ + * On Init + */ ngOnInit() { - //Get Badge this.fetchLoyaltyBadgeData(); this.fetchMicrocreditBadgeData(); - //Get Wallet Data this.fetchBalanceData(); this.fetchSupportsData(); - //Get Offers Data - // this.fetchOffersData(); } - /** - * On destroy + * On Destroy */ ngOnDestroy(): void { this.unsubscribe.next(); @@ -109,10 +113,33 @@ export class MemberDashboardComponent implements OnInit, OnDestroy { } /** - * Assets Function On Init - */ + * Close Modal on Browser Back Button + */ + controlModalState(state: boolean) { + if (state) { + const modalState = { + modal: true, + desc: 'MemberDashboardModals' + }; + history.pushState(modalState, null); + } else { + if (window.history.state.modal) { + history.back(); + } + } + } - //Get the Badge of the Member + @HostListener('window:popstate', ['$event']) + dismissModal() { + if (this.modalService.hasOpenModals()) { + this.modalService.dismissAll(); + this.controlModalState(false); + } + } + + /** + * Fetch Loyalty Badge + */ fetchLoyaltyBadgeData() { this.loyaltyService.readBadge() .pipe( @@ -171,6 +198,9 @@ export class MemberDashboardComponent implements OnInit, OnDestroy { .subscribe(); } + /** + * Fetch Microcredit Badge + */ fetchMicrocreditBadgeData() { this.microcreditService.readBadge() .pipe( @@ -191,7 +221,9 @@ export class MemberDashboardComponent implements OnInit, OnDestroy { .subscribe(); } - //Get the Balance of the Member + /** + * Fetch Loyalty Balance + */ fetchBalanceData() { this.loyaltyService.readBalance() .pipe( @@ -231,27 +263,9 @@ export class MemberDashboardComponent implements OnInit, OnDestroy { .subscribe(); } - //Get the Offers - // fetchOffersData() { - // this.itemsService.readAllOffers('0-0-0') - // .pipe( - // tap( - // data => { - // this.offers = data; - // }, - // error => { - // console.log(error); - // }), - // takeUntil(this.unsubscribe), - // finalize(() => { - // this.loading = false; - // this.cdRef.markForCheck(); - // }) - // ) - // .subscribe(); - // } - - //Get the Mircoredit the Member supports + /** + * Fetch Supports History + */ fetchSupportsData() { this.microcreditService.readAllBackerSupports('0-0-1') .pipe( @@ -272,18 +286,18 @@ export class MemberDashboardComponent implements OnInit, OnDestroy { } /** - * Modal Functions - */ + * Open QR Modal + */ openQrcode() { //Open the QR code Modal - this.modalService.open(this.qrcodeModal).result.then((result) => { - console.log('closed'); - }, (reason) => { - console.log('dismissed'); - }); + this.controlModalState(true); + this.modalService.open(this.qrcodeModal) + .result.then( + (result) => { this.controlModalState(false); console.log('closed'); }, + (reason) => { this.controlModalState(false); console.log('dismissed'); }); + //Get static content of Balance Points this.contentService.readContentById('QR Code') - //this.staticContentService.readText('23') .pipe( tap( data => { @@ -299,15 +313,22 @@ export class MemberDashboardComponent implements OnInit, OnDestroy { this.cdRef.markForCheck(); }) ).subscribe(); - } + + /** + * Open Wallet Modal + */ openWallet() { - this.modalService.open(this.walletModal).result.then((result) => { - console.log('closed'); - }, (reason) => { - console.log('dismissed'); - }); + this.controlModalState(true); + this.modalService.open(this.walletModal) + .result.then( + (result) => { this.controlModalState(false); console.log('closed'); }, + (reason) => { this.controlModalState(false); console.log('dismissed'); }); } + + /** + * Open Support Modal + */ openSupportItem(supportItemTemp) { this.supportItem = { @@ -322,10 +343,11 @@ export class MemberDashboardComponent implements OnInit, OnDestroy { })[0].value } }; - this.modalService.open(this.supportsModal).result.then((result) => { - console.log('closed'); - }, (reason) => { - console.log('dismissed'); - }); + + this.controlModalState(true); + this.modalService.open(this.supportsModal) + .result.then( + (result) => { this.controlModalState(false); console.log('closed'); }, + (reason) => { this.controlModalState(false); console.log('dismissed'); }); } } \ No newline at end of file diff --git a/src/app/member-explore/member-explore.component.scss b/src/app/member-explore/member-explore.component.scss index 68c115d6..ed6ef993 100644 --- a/src/app/member-explore/member-explore.component.scss +++ b/src/app/member-explore/member-explore.component.scss @@ -1,5 +1,5 @@ .explore { - .section-list{ + .section-list { margin-bottom: 65px; } -} \ No newline at end of file +} diff --git a/src/app/member-explore/member-explore.component.ts b/src/app/member-explore/member-explore.component.ts index 8e0d25f0..0d508824 100644 --- a/src/app/member-explore/member-explore.component.ts +++ b/src/app/member-explore/member-explore.component.ts @@ -1,18 +1,29 @@ -import { Component, OnInit, OnDestroy, ChangeDetectorRef, ViewChild, ElementRef } from '@angular/core'; +import { Component, OnInit, OnDestroy, ChangeDetectorRef, ViewChild, ElementRef, HostListener } from '@angular/core'; import { Subject } from 'rxjs'; +import { tap, takeUntil, finalize } from 'rxjs/operators'; +import { NgbModal, NgbActiveModal, ModalDismissReasons, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; +import { TranslateService } from '@ngx-translate/core'; +import { OwlOptions } from 'ngx-owl-carousel-o'; + +/** + * Environment + */ +import { environment } from '../../environments/environment'; +/** + * Services + */ +import { StaticDataService } from '../core/services/static-data.service'; import { PartnersService } from '../core/services/partners.service'; import { ItemsService } from '../core/services/items.service'; -import { tap, takeUntil, finalize } from 'rxjs/operators'; -import { NgbModal, NgbActiveModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap'; -import { OwlOptions } from 'ngx-owl-carousel-o'; -import { environment } from '../../environments/environment'; +/** + * Models & Interfaces + */ import { Partner } from '../core/models/partner.model'; import { Offer } from '../core/models/offer.model'; import { PostEvent } from '../core/models/post_event.model'; import { MicrocreditCampaign } from '../core/models/microcredit_campaign.model'; -import { StaticDataService } from '../core/services/static-data.service'; @Component({ selector: 'app-member-explore', @@ -21,50 +32,74 @@ import { StaticDataService } from '../core/services/static-data.service'; }) export class MemberExploreComponent implements OnInit, OnDestroy { - public configAccess: Boolean[] = environment.access; + /** + * Children Modals + */ + @ViewChild('partnerModal', { static: false }) partnerModal: NgbModal; + @ViewChild('postModal', { static: false }) postModal: NgbModal; - //Set Basic Variables - moved; - private unsubscribe: Subject; - loading: boolean = false; + /** + * Configuration and Static Data + */ + public configAccess: Boolean[] = environment.access; - //Set Content Variables - partners: Partner[]; - posts: PostEvent[]; - offers: Offer[]; - //events: Event[]; + /** + * Carousel Variables + */ + customOptions: OwlOptions; + moved: boolean; - singleOffers: Offer; - singleMicrocredit: MicrocreditCampaign; + /** + * Content Variables + */ + public partners: Partner[]; + public posts: PostEvent[]; singlePartner: Partner; singlePost: PostEvent; + //offers: Offer[]; + //events: Event[]; + //currentOpenModal: NgbModalRef; - //Set Child Modals - @ViewChild('partnerModal', { static: false }) partnerModal; - @ViewChild('postModal', { static: false }) postModal; + //singleOffers: Offer; + //singleMicrocredit: MicrocreditCampaign; - //Slider Options - customOptions: OwlOptions; + private unsubscribe: Subject; + loading: boolean = false; + /** + * Component Constructor + * + * @param cdRef: ChangeDetectorRef + * @param modalService: NgbModal + * @param translate: TranslateService + * @param staticDataService: StaticDataService + * @param loyaltyService: LoyaltyService + * @param microcreditService: MicrocreditService + * @param contentService: ContentService + */ constructor( private cdRef: ChangeDetectorRef, + private modalService: NgbModal, + public translate: TranslateService, + private staticDataService: StaticDataService, private partnersService: PartnersService, private itemsService: ItemsService, - private staticDataService: StaticDataService, - private modalService: NgbModal, - private elRef: ElementRef ) { this.customOptions = this.staticDataService.getOwlOptionsThree; this.unsubscribe = new Subject(); } + /** + * On Init + */ ngOnInit() { - //Get Lists Data this.fetchPartnersData(); - // this.fetchOffersData(); this.fetchPostsEventsData(); } + /** + * On Destory + */ ngOnDestroy() { this.unsubscribe.next(); this.unsubscribe.complete(); @@ -72,17 +107,34 @@ export class MemberExploreComponent implements OnInit, OnDestroy { } /** - * Randomize + * Close Modal on Browser Back Button */ - shuffle(array: Partner[]) { - return array.sort(() => Math.random() - 0.5); + controlModalState(state: boolean) { + if (state) { + const modalState = { + modal: true, + desc: 'MemberExploreModals' + }; + history.pushState(modalState, null); + } else { + if (window.history.state.modal) { + history.back(); + } + } } - /** - * Assets Function On Init - */ + @HostListener('window:popstate', ['$event']) + dismissModal() { + if (this.modalService.hasOpenModals()) { + this.modalService.dismissAll(); + this.controlModalState(false); + } + + } - //Get Partners + /** + * Fetch Partners List + */ fetchPartnersData() { this.partnersService.readPartners('0-0-0') .pipe( @@ -103,7 +155,9 @@ export class MemberExploreComponent implements OnInit, OnDestroy { } - //Get Posts & Events + /** + * Fetch Post & Events List + */ fetchPostsEventsData() { this.itemsService.readAllPrivatePostsEvents('0-0-0') .pipe( @@ -128,38 +182,19 @@ export class MemberExploreComponent implements OnInit, OnDestroy { .subscribe(); } - //Get Offers - fetchOffersData() { - this.itemsService.readAllOffers('0-0-0') - .pipe( - tap( - data => { - this.offers = data; - if (this.offers.length < 3) { - this.offers.push(this.offers[0]); - this.offers.push(this.offers[0]); - } - }, - error => { - console.log(error); - }), - takeUntil(this.unsubscribe), - finalize(() => { - this.loading = false; - this.cdRef.markForCheck(); - }) - ) - .subscribe(); + /** + * Randomize Data + */ + shuffle(array: Partner[]) { + return array.sort(() => Math.random() - 0.5); } - - /* - / Modals - */ - - //Open Coop + /** + * Open Partner Modal + */ openPartner(partner: Partner) { this.singlePartner = partner; + this.controlModalState(true); this.modalService.open( this.partnerModal, { @@ -169,17 +204,18 @@ export class MemberExploreComponent implements OnInit, OnDestroy { //backdrop: 'static', windowClass: 'fullscreen-modal', } - ).result.then((result) => { - console.log('closed'); - }, (reason) => { - console.log('dismissed'); - }); + ) + .result.then( + (result) => { this.controlModalState(false); console.log('closed'); }, + (reason) => { this.controlModalState(false); console.log('dismissed'); }); } - - //Open Post + /** + * Open PostEvent Modal + */ openPost(post: PostEvent) { this.singlePost = post; + this.controlModalState(true); this.modalService.open( this.postModal, { @@ -189,33 +225,26 @@ export class MemberExploreComponent implements OnInit, OnDestroy { //backdrop: 'static', windowClass: 'fullscreen-modal', } - ).result.then((result) => { - console.log('closed'); - }, (reason) => { - console.log('dismissed'); - }); + ) + .result.then( + (result) => { this.controlModalState(false); console.log('closed'); }, + (reason) => { this.controlModalState(false); console.log('dismissed'); }); } - //Actions to Open Modals from Carousel - mousedown() { - this.moved = false; - } - mousemove() { - this.moved = true; - } - mouseup(data, type) { - if (this.moved) { - //Do nothings - } else { + /** + * Actions to Open Modals from Carousel + */ + mousedown() { this.moved = false; } + mousemove() { this.moved = true; } + mouseup(data: any, type: string) { + if (this.moved) { } + else { if (type == 'partner') { this.openPartner(data); } else if (type == 'post') { this.openPost(data); - } else { - //Do nothing - } + } else { } } this.moved = false; } - } \ No newline at end of file diff --git a/src/app/member-redeem/member-redeem.component.ts b/src/app/member-redeem/member-redeem.component.ts index cd921498..c8ef55b3 100644 --- a/src/app/member-redeem/member-redeem.component.ts +++ b/src/app/member-redeem/member-redeem.component.ts @@ -2,12 +2,19 @@ import { Component, OnInit, OnDestroy, ChangeDetectorRef, ViewChild } from '@angular/core'; import { first, tap, finalize, takeUntil } from 'rxjs/operators'; import { Subject, Subscriber } from 'rxjs'; -import { TranslateService } from '@ngx-translate/core'; import { OwlOptions } from 'ngx-owl-carousel-o'; +import { TranslateService } from '@ngx-translate/core'; +/** + * Services + */ +import { StaticDataService } from '../core/services/static-data.service'; import { ItemsService } from '../core/services/items.service'; + +/** + * Models & Interfaces + */ import { Offer } from '../core/models/offer.model'; -import { StaticDataService } from '../core/services/static-data.service'; @Component({ selector: 'app-member-redeem', @@ -16,24 +23,31 @@ import { StaticDataService } from '../core/services/static-data.service'; }) export class MemberRedeemComponent implements OnInit, OnDestroy { + /** + * Content Variables + */ public offers: Offer[] = []; - // customOptions: OwlOptions; - counter: number = 0; loading: boolean = false; private unsubscribe: Subject; + /** + * Component Constructor + * + * @param cdRef: ChangeDetectorRef + * @param translate: TranslateService + * @param itemsService: ItemsService + */ constructor( private cdRef: ChangeDetectorRef, public translate: TranslateService, private itemsService: ItemsService, - private staticDataService: StaticDataService, ) { - // this.customOptions = staticDataService.getOwlOptionsThree; this.unsubscribe = new Subject(); } + /** * On Init */ @@ -50,7 +64,9 @@ export class MemberRedeemComponent implements OnInit, OnDestroy { this.loading = false; } - // Get the Offers + /** + * Fetch Offers List + */ fetchOffersData(counter: number) { this.itemsService.readAllOffers(`6-${counter.toString()}-1`) .pipe( @@ -72,6 +88,9 @@ export class MemberRedeemComponent implements OnInit, OnDestroy { .subscribe(); } + /** + * On Scroll + */ onScroll() { this.counter = this.counter + 1; this.fetchOffersData(this.counter); diff --git a/src/app/member-support/member-support.component.ts b/src/app/member-support/member-support.component.ts index 5eb5f714..d403fb55 100644 --- a/src/app/member-support/member-support.component.ts +++ b/src/app/member-support/member-support.component.ts @@ -1,11 +1,21 @@ -import { Component, OnInit, OnDestroy, ChangeDetectorRef, ViewChild } from '@angular/core'; -import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog'; -import { NgbModal, NgbActiveModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap'; +import { Component, OnInit, OnDestroy, ChangeDetectorRef, ViewChild, HostListener } from '@angular/core'; import { Subject, Subscription } from 'rxjs'; -import { tap, takeUntil, finalize } from 'rxjs/operators'; +import { tap, takeUntil, finalize } from 'rxjs/operators'; import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog'; +import { NgbModal, NgbActiveModal, ModalDismissReasons, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; +/** + * Services + */ import { ItemsService } from '../core/services/items.service'; + +/** + * Models & Interfaces + */ import { MicrocreditCampaign } from '../core/models/microcredit_campaign.model'; + +/** + * Local Services & Interfaces + */ import { SupportService } from './_support.service'; @Component({ @@ -14,24 +24,36 @@ import { SupportService } from './_support.service'; styleUrls: ['./member-support.component.scss'] }) export class MemberSupportComponent implements OnInit, OnDestroy { - //Set Child Modals - @ViewChild('campaignModal', { static: false }) campaignModal; - //Set Content Variables + /** + * Children Modals + */ + @ViewChild('campaignModal', { static: false }) campaignModal: NgbModalRef; + + /** + * Content Variables + */ public campaigns: MicrocreditCampaign[] = []; singleMicrocredit: MicrocreditCampaign; counter: number = 0; - //Set Basic Variables loading: boolean = false; private unsubscribe: Subject; - // private subscription: Subscription = new Subscription; + /** + * Component Constructor + * + * @param cdRef: ChangeDetectorRef + * @param modalService: NgbModal + * @param matDialog: MatDialog + * @param itemsService: ItemsService + * @param supportService: SupportService + */ constructor( - public matDialog: MatDialog, - private modalService: NgbModal, private cdRef: ChangeDetectorRef, + private modalService: NgbModal, + public matDialog: MatDialog, private itemsService: ItemsService, private supportService: SupportService ) { @@ -47,7 +69,7 @@ export class MemberSupportComponent implements OnInit, OnDestroy { } /** - * On destroy + * On Destroy */ ngOnDestroy() { this.unsubscribe.next(); @@ -56,18 +78,34 @@ export class MemberSupportComponent implements OnInit, OnDestroy { this.loading = false; } - /** - * Randomize - */ - shuffle(array: MicrocreditCampaign[]) { - return array.sort(() => Math.random() - 0.5); + /** + * Close Modal on Browser Back Button + */ + controlModalState(state: boolean) { + if (state) { + const modalState = { + modal: true, + desc: 'MemberDashboardModals' + }; + history.pushState(modalState, null); + } else { + if (window.history.state.modal) { + history.back(); + } + } } - /** - * Assets Function On Init - */ + @HostListener('window:popstate', ['$event']) + dismissModal() { + if (this.modalService.hasOpenModals()) { + this.modalService.dismissAll(); + this.controlModalState(false); + } + } - //Get Microcredit Campaigns + /** + * Fetch Microcredit Campaigns List + */ fetchMicrocreditData(counter: number) { this.itemsService.readAllPrivateMicrocreditCampaigns(`6-${counter.toString()}-1`) .pipe( @@ -88,6 +126,9 @@ export class MemberSupportComponent implements OnInit, OnDestroy { .subscribe(); } + /** + * On Scroll + */ onScroll() { this.counter = this.counter + 1; this.fetchMicrocreditData(this.counter); @@ -96,13 +137,19 @@ export class MemberSupportComponent implements OnInit, OnDestroy { this.cdRef.markForCheck(); } - /* - / Modals - */ + /** + * Randomize Data + */ + shuffle(array: MicrocreditCampaign[]) { + return array.sort(() => Math.random() - 0.5); + } - //Open Microcredit + /** + * Open Microcredit Campaign Modal + */ openMicrocredit(campaign: MicrocreditCampaign) { this.singleMicrocredit = campaign; + this.controlModalState(true); this.modalService.open( this.campaignModal, { ariaLabelledBy: 'modal-basic-title', @@ -110,11 +157,9 @@ export class MemberSupportComponent implements OnInit, OnDestroy { backdropClass: 'fullscrenn-backdrop', //backdrop: 'static', windowClass: 'fullscreen-modal', - }).result.then((result) => { - console.log('closed'); - }, (reason) => { - console.log('dismissed'); - }); + }) + .result.then( + (result) => { this.controlModalState(false); console.log('closed'); }, + (reason) => { this.controlModalState(false); console.log('dismissed'); }); } - } diff --git a/src/app/member-support/sub-amount-form/sub-amount-form.component.ts b/src/app/member-support/sub-amount-form/sub-amount-form.component.ts index 0329ce4f..fa659000 100644 --- a/src/app/member-support/sub-amount-form/sub-amount-form.component.ts +++ b/src/app/member-support/sub-amount-form/sub-amount-form.component.ts @@ -17,19 +17,30 @@ import { PaymentList } from 'src/app/core/interfaces/payment-list.interface'; }) export class SubAmountFormComponent implements OnInit { + /** + * Event Emitter + */ @Output() add_amount: EventEmitter = new EventEmitter(); + /** + * Configuration and Static Data + */ public paymentsList: PaymentList[]; + /** + * Content Variables + */ public support: MicrocreditSupport; public campaign: MicrocreditCampaign; - //campaignType: any; tempAmount: number; showAddStep: boolean = true; showSubStep: boolean = false; + /** + * Forms + */ submitForm: FormGroup; submitted: boolean = false; diff --git a/src/app/member-support/sub-final-step/sub-final-step.component.ts b/src/app/member-support/sub-final-step/sub-final-step.component.ts index 17abb135..1d7304ee 100644 --- a/src/app/member-support/sub-final-step/sub-final-step.component.ts +++ b/src/app/member-support/sub-final-step/sub-final-step.component.ts @@ -10,12 +10,22 @@ import { SupportService } from '../_support.service'; }) export class SubFinalStepComponent implements OnInit { + /** + * Imported Variables + */ @Input() type: number; + + /** + * Event Emitter + */ @Output() finalize: EventEmitter = new EventEmitter(); - support: SupportInterface["MicrocreditSupport"]; + /** + * Content Variables + */ + public support: SupportInterface["MicrocreditSupport"]; constructor( private supportService: SupportService @@ -35,5 +45,4 @@ export class SubFinalStepComponent implements OnInit { onNextStep() { this.finalize.emit(true); } - } diff --git a/src/app/member-support/support-microcredit/support-microcredit.component.ts b/src/app/member-support/support-microcredit/support-microcredit.component.ts index e4b1d2f2..3b22dd70 100644 --- a/src/app/member-support/support-microcredit/support-microcredit.component.ts +++ b/src/app/member-support/support-microcredit/support-microcredit.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, OnDestroy, Inject, ViewChild, ChangeDetectorRef } from '@angular/core'; +import { Component, OnInit, OnDestroy, Inject, ViewChild, ChangeDetectorRef, HostListener } from '@angular/core'; import { Subject, Subscription } from 'rxjs'; import { takeUntil, finalize, tap } from 'rxjs/operators'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; @@ -13,6 +13,7 @@ import { SupportService } from '../_support.service'; import { SupportInterface } from '../_support.interface'; import { StaticDataService } from 'src/app/core/services/static-data.service'; import { PaymentList } from 'src/app/core/interfaces/payment-list.interface'; +import { PlatformLocation } from '@angular/common'; @Component({ selector: 'app-support-microcredit', @@ -21,10 +22,23 @@ import { PaymentList } from 'src/app/core/interfaces/payment-list.interface'; }) export class SupportMicrocreditComponent implements OnInit, OnDestroy { + /** + * Wizard Component + */ @ViewChild(WizardComponent, { static: true }) public wizard: WizardComponent; + + /** + * Configuration and Static Data + */ public paymentsList: PaymentList[]; + /** + * Content Variables + */ + public campaign: SupportInterface["MicrocreditCampaign"]; + public support: SupportInterface["MicrocreditSupport"]; + // campaign_id: string; // partner_id: string; @@ -32,19 +46,26 @@ export class SupportMicrocreditComponent implements OnInit, OnDestroy { private unsubscribe: Subject; private subscription: Subscription = new Subscription; - //public campaigns: SupportInterface["MicrocreditCampaign"][]; - public campaign: SupportInterface["MicrocreditCampaign"]; - public support: SupportInterface["MicrocreditSupport"]; - + /** + * Component Constructor + * + * @param cdr: ChangeDetectorRef + * @param translate: TranslateService, + * @param supportNoticeService: MessageNoticeService + * @param staticDataService: StaticDataService + * @param microcreditService: MicrocreditService + * @param supportService: SupportService + * @param dialogRef: MatDialogRef + * @param data: any (@Inject(MAT_DIALOG_DATA)) + */ constructor( private cdRef: ChangeDetectorRef, private translate: TranslateService, private supportNoticeService: MessageNoticeService, - private itemsService: ItemsService, + private staticDataService: StaticDataService, private microcreditService: MicrocreditService, private supportService: SupportService, public dialogRef: MatDialogRef, - private staticDataService: StaticDataService, @Inject(MAT_DIALOG_DATA) public data: any ) { console.log("HEREE", this.data) @@ -60,6 +81,7 @@ export class SupportMicrocreditComponent implements OnInit, OnDestroy { * On destroy */ ngOnInit() { + // this.controlModalState(true); this.initializeCurrentCampaignData(); } @@ -67,6 +89,9 @@ export class SupportMicrocreditComponent implements OnInit, OnDestroy { * On destroy */ ngOnDestroy() { + //console.log("On Destory Support Dialog") + //this.controlModalState(false); + this.supportNoticeService.setNotice(null); this.subscription.unsubscribe(); this.unsubscribe.next(); @@ -74,6 +99,31 @@ export class SupportMicrocreditComponent implements OnInit, OnDestroy { this.loading = false; } + // controlModalState(state: boolean) { + // if (state) { + // const modalState = { + // modal: true, + // desc: 'Dialog' + // }; + // console.log("Add Fake State") + // history.pushState(modalState, null); + // console.log(history.state['desc']) + // } else {// if (window.history.state.modal) { + // console.log("State in Support Dialog") + // console.log(window.history.state) + // if (window.history.state['desc'] == "Dialog") { + // console.log("I am in Support Dialog - Back()") + // //window.history.back(); + // } + // } + // } + + // @HostListener('window:popstate', ['$event']) + // dismissModal() { + // this.controlModalState(false); + // this.dialogRef.close(); + // } + initializeCurrentCampaignData() { // const currentCampaign = this.campaigns[this.campaigns.map(function (e) { return e.campaign_id; }).indexOf(this.campaign_id)]; this.campaign = this.data.campaign; @@ -135,5 +185,6 @@ export class SupportMicrocreditComponent implements OnInit, OnDestroy { onFinalStep(event = null) { this.dialogRef.close(); + // this.controlModalState(false); } } diff --git a/src/app/p-events/edit-event/edit-event.component.ts b/src/app/p-events/edit-event/edit-event.component.ts index 9b888dd8..29cb8155 100644 --- a/src/app/p-events/edit-event/edit-event.component.ts +++ b/src/app/p-events/edit-event/edit-event.component.ts @@ -65,7 +65,7 @@ export class EditEventComponent implements OnInit { private unsubscribe: Subject; /** - * Component constructor + * Component Constructor * * @param router: Router * @param fb: FormBuilder diff --git a/src/app/p-events/new-event/new-event.component.html b/src/app/p-events/new-event/new-event.component.html index 0487b6fd..2eb5a3fd 100644 --- a/src/app/p-events/new-event/new-event.component.html +++ b/src/app/p-events/new-event/new-event.component.html @@ -8,7 +8,7 @@
- + {{'FIELDS.EVENT.TITLE.TITLE' | translate}} @@ -143,4 +143,4 @@ -
+
\ No newline at end of file diff --git a/src/app/p-events/new-event/new-event.component.ts b/src/app/p-events/new-event/new-event.component.ts index 3822db7a..b9f23087 100644 --- a/src/app/p-events/new-event/new-event.component.ts +++ b/src/app/p-events/new-event/new-event.component.ts @@ -50,7 +50,7 @@ export class NewEventComponent implements OnInit, OnDestroy { private unsubscribe: Subject; /** - * Component constructor + * Component Constructor * * @param cdRef: ChangeDetectorRef * @param itemsService: ItemsService diff --git a/src/app/p-loyalty/edit-offer/edit-offer.component.ts b/src/app/p-loyalty/edit-offer/edit-offer.component.ts index 2938bec9..a9e16d08 100644 --- a/src/app/p-loyalty/edit-offer/edit-offer.component.ts +++ b/src/app/p-loyalty/edit-offer/edit-offer.component.ts @@ -43,7 +43,7 @@ export class EditOfferComponent implements OnInit, OnDestroy { private unsubscribe: Subject; /** - * Component constructor + * Component Constructor * * @param router: Router * @param fb: FormBuilder diff --git a/src/app/p-loyalty/new-offer/new-offer.component.ts b/src/app/p-loyalty/new-offer/new-offer.component.ts index 42fe7387..389be088 100644 --- a/src/app/p-loyalty/new-offer/new-offer.component.ts +++ b/src/app/p-loyalty/new-offer/new-offer.component.ts @@ -36,7 +36,7 @@ export class NewOfferComponent implements OnInit, OnDestroy { private unsubscribe: Subject; /** - * Component constructor + * Component Constructor * * @param fb: FormBuilder * @param cdRef: ChangeDetectorRef diff --git a/src/app/p-loyalty/partner-offers/partner-offers.component.html b/src/app/p-loyalty/partner-offers/partner-offers.component.html index 50d9103a..63273d7a 100644 --- a/src/app/p-loyalty/partner-offers/partner-offers.component.html +++ b/src/app/p-loyalty/partner-offers/partner-offers.component.html @@ -13,7 +13,7 @@

{{'OFFER.PLURAL' | translate}}

- + +
+ +
@@ -57,6 +60,9 @@

{{ 'PARTNER.WIZARD.SCAN_LOYALTY.HEADING' | translate }}

+
+ +
diff --git a/src/app/scanner/scan-loyalty/scan-loyalty.component.scss b/src/app/scanner/scan-loyalty/scan-loyalty.component.scss index e69de29b..ac93441f 100644 --- a/src/app/scanner/scan-loyalty/scan-loyalty.component.scss +++ b/src/app/scanner/scan-loyalty/scan-loyalty.component.scss @@ -0,0 +1,16 @@ +@import "../../../variables.scss"; + +.scan-modal-container { + .spinner-overlay { + position: fixed; + width: 100%; + height: 100%; + top: 0; + left: 0; + background-color: rgba(255, 255, 255, 0.7); + display: flex; + justify-content: center; + align-items: center; + z-index: 200; + } +} diff --git a/src/app/scanner/scan-loyalty/scan-loyalty.component.ts b/src/app/scanner/scan-loyalty/scan-loyalty.component.ts index cb7eb0d2..41cbc34a 100644 --- a/src/app/scanner/scan-loyalty/scan-loyalty.component.ts +++ b/src/app/scanner/scan-loyalty/scan-loyalty.component.ts @@ -1,24 +1,30 @@ -import { Component, OnInit, OnDestroy, ViewChild, ChangeDetectorRef, Inject } from '@angular/core'; +import { Component, OnInit, OnDestroy, ViewChild, ChangeDetectorRef, Inject, HostListener } from '@angular/core'; +import { tap, takeUntil, finalize } from 'rxjs/operators'; +import { Subject, Subscription } from 'rxjs'; import { FormControl, FormBuilder, FormGroup, Validators } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; - -// Translate +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; import { TranslateService } from '@ngx-translate/core'; +import { WizardComponent } from "angular-archwizard"; -// Services +/** + * Services + */ import { MessageNoticeService } from '../../core/helpers/message-notice/message-notice.service'; import { AuthenticationService } from '../../core/services/authentication.service'; import { LoyaltyService } from '../../core/services/loyalty.service'; -import { WizardComponent } from "angular-archwizard"; -import { tap, takeUntil, finalize } from 'rxjs/operators'; -import { Subject, Subscription } from 'rxjs'; - +/** + * Components + */ import { SubDiscountFormComponent } from "../sub-discount-form/sub-discount-form.component"; import { ScannerService } from "../_scanner.service"; + +/** + * Local Services & Interfaces + */ import { ScannerInterface } from "../_scanner.interface"; -import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; @Component({ selector: 'app-scan-loyalty', @@ -27,24 +33,34 @@ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; // providers: [LoyaltyLocalService] }) export class ScanLoyaltyComponent implements OnInit, OnDestroy { - + /** + * Imported Component + */ @ViewChild(SubDiscountFormComponent, { static: true }) public discountForm: SubDiscountFormComponent; + + /** + * Wizard Component + */ @ViewChild(WizardComponent, { static: true }) public wizard: WizardComponent; + /** + * Content Variables + */ + public user: ScannerInterface["User"]; + public transaction: ScannerInterface["PointsTransaction"]; + public actions: ScannerInterface["Actions"]; + showIdentifierForm: boolean = false; showEmailForm: boolean = false; + conversionRatiο = 0.01; + loading: boolean = false; private unsubscribe: Subject; private subscription: Subscription = new Subscription; - public user: ScannerInterface["User"]; - public transaction: ScannerInterface["PointsTransaction"]; - public actions: ScannerInterface["Actions"]; - conversionRatiο = 0.01; - constructor( private cdRef: ChangeDetectorRef, private translate: TranslateService, @@ -64,12 +80,15 @@ export class ScanLoyaltyComponent implements OnInit, OnDestroy { * On Init */ ngOnInit() { + // this.controlModalState(true); } /** * On destroy */ ngOnDestroy() { + // this.controlModalState(false); + this.scannerNoticeService.setNotice(null); this.subscription.unsubscribe(); this.unsubscribe.next(); @@ -77,6 +96,24 @@ export class ScanLoyaltyComponent implements OnInit, OnDestroy { this.loading = false; } + // controlModalState(state: boolean) { + // if (state) { + // const modalState = { + // modal: true, + // desc: 'fake state for our modal' + // }; + // history.pushState(modalState, null); + // } else if (window.history.state.modal) { + // history.back(); + // } + // } + + // @HostListener('window:popstate', ['$event']) + // dismissModal() { + // this.controlModalState(false); + // this.dialogRef.close(); + // } + checkRegistrationOnIdentifier(status: string) { let action: string = 'xxxx'; let type: string = '', message: string = ''; @@ -290,7 +327,7 @@ export class ScanLoyaltyComponent implements OnInit, OnDestroy { break; } default: { - this.fetchBalanceData(); + this.fetchBalanceData(false); //this.onNextStep(); break; } @@ -303,27 +340,9 @@ export class ScanLoyaltyComponent implements OnInit, OnDestroy { // => link an email } - fetchBalanceData() { - this.loyaltyService.readBalanceByPartner(((this.user.identifier_scan || this.user.identifier_form)).toLowerCase()) - .pipe( - tap( - data => { - this.transaction.points = parseInt(data.points, 16); - this.scannerService.changePointsTransaction(this.transaction); - this.initializeDiscountAmount(); - }, - error => { - console.log(error); - }), - takeUntil(this.unsubscribe), - finalize(() => { - this.loading = false; - this.cdRef.markForCheck(); - }) - ) - .subscribe(); - } - + /** + * Slip Floor + */ slipFloor(num: number) { let f = Math.floor(num); if (num - f < 0.5) { @@ -370,17 +389,19 @@ export class ScanLoyaltyComponent implements OnInit, OnDestroy { console.log("Redeem: " + this.actions.redeem); this.earnPoints(this.user.identifier_form || this.user.identifier_scan); - this.onNextStep(); + // this.onNextStep(); } actionRegistration(notice: { type: string, message: string }, email: string, card: string) { - console.log('Reg', email + card) + + this.loading = true; + this.authenticationService.register_member(email, card) .pipe( tap( data => { console.log(data); - this.fetchBalanceData(); + this.fetchBalanceData(false); }, error => { this.scannerNoticeService.setNotice(this.translate.instant('WIZARD_MESSAGES.ERROR_REGISTRATION') + '
' + @@ -397,12 +418,14 @@ export class ScanLoyaltyComponent implements OnInit, OnDestroy { actionLinkCard(notice: { type: string, message: string }, email: string, card: string) { console.log('Card', email + card) + this.loading = true; + this.authenticationService.linkCard(email, card) .pipe( tap( data => { console.log(data); - this.fetchBalanceData(); + this.fetchBalanceData(false); }, error => { this.scannerNoticeService.setNotice(this.translate.instant('WIZARD_MESSAGES.ERROR_LINK_CARD') + '
' + @@ -419,12 +442,14 @@ export class ScanLoyaltyComponent implements OnInit, OnDestroy { actionLinkEmail(notice: { type: string, message: string }, email: string, card: string) { console.log('Email', email + card); + this.loading = true; + this.authenticationService.linkEmail(email, card) .pipe( tap( data => { console.log(data); - this.fetchBalanceData(); + this.fetchBalanceData(false); }, error => { this.scannerNoticeService.setNotice(this.translate.instant('WIZARD_MESSAGES.ERROR_LINK_EMAIL') + '
' + @@ -439,6 +464,36 @@ export class ScanLoyaltyComponent implements OnInit, OnDestroy { .subscribe(); } + fetchBalanceData(final: boolean) { + this.loyaltyService.readBalanceByPartner(((this.user.identifier_scan || this.user.identifier_form)).toLowerCase()) + .pipe( + tap( + data => { + if (final) { + this.transaction.final_points = parseInt(data.points, 16); + console.log("Balance Points ", this.transaction.final_points); + this.scannerService.changePointsTransaction(this.transaction); + this.scannerNoticeService.setNotice(this.translate.instant('WIZARD_MESSAGES.SUCCESS_TRANSACTION'), 'success'); + this.onNextStep(); + } else { + this.transaction.points = parseInt(data.points, 16); + console.log("Balance Points ", this.transaction.points); + this.scannerService.changePointsTransaction(this.transaction); + this.initializeDiscountAmount(); + } + }, + error => { + console.log(error); + }), + takeUntil(this.unsubscribe), + finalize(() => { + this.loading = false; + this.cdRef.markForCheck(); + }) + ) + .subscribe(); + } + earnPoints(_to: string) { let earnPoints = { @@ -447,6 +502,8 @@ export class ScanLoyaltyComponent implements OnInit, OnDestroy { _amount: this.transaction.final_amount }; + this.loading = true; + this.loyaltyService.earnPoints(earnPoints._to, earnPoints.password, earnPoints._amount) .pipe( tap( @@ -457,16 +514,12 @@ export class ScanLoyaltyComponent implements OnInit, OnDestroy { this.redeemPoints(_to); } else { console.log("Will Not Redeem"); - this.scannerNoticeService.setNotice(this.translate.instant('WIZARD_MESSAGES.SUCCESS_TRANSACTION'), 'success'); - - this.transaction.previous_points = this.transaction.points; - this.scannerService.changePointsTransaction(this.transaction); - this.fetchBalanceData(); - - this.onNextStep(); + // this.scannerNoticeService.setNotice(this.translate.instant('WIZARD_MESSAGES.SUCCESS_TRANSACTION'), 'success'); + this.fetchBalanceData(true); } }, error => { + this.loading = false; console.log(error) this.scannerNoticeService.setNotice( this.translate.instant('WIZARD_MESSAGES.ERROR_EARN_POINTS') + '
' + @@ -474,7 +527,7 @@ export class ScanLoyaltyComponent implements OnInit, OnDestroy { }), takeUntil(this.unsubscribe), finalize(() => { - this.loading = false; + // this.loading = false; this.cdRef.markForCheck(); }) ) @@ -494,22 +547,19 @@ export class ScanLoyaltyComponent implements OnInit, OnDestroy { .pipe( tap( data => { - this.scannerNoticeService.setNotice(this.translate.instant('WIZARD_MESSAGES.SUCCESS_TRANSACTION'), 'success'); - - this.transaction.previous_points = this.transaction.points; - this.scannerService.changePointsTransaction(this.transaction); - this.fetchBalanceData(); - - this.onNextStep(); + console.log("Redeem ", data) + // this.scannerNoticeService.setNotice(this.translate.instant('WIZARD_MESSAGES.SUCCESS_TRANSACTION'), 'success'); + this.fetchBalanceData(true); }, error => { + this.loading = false; this.scannerNoticeService.setNotice( this.translate.instant('WIZARD_MESSAGES.ERROR_REDEEM_POINTS') + '
' + this.translate.instant(error), 'danger'); }), takeUntil(this.unsubscribe), finalize(() => { - this.loading = false; + // this.loading = false; this.cdRef.markForCheck(); }) ) @@ -541,6 +591,7 @@ export class ScanLoyaltyComponent implements OnInit, OnDestroy { onFinalStep(event: boolean) { this.dialogRef.close(); + // this.controlModalState(false); } } diff --git a/src/app/scanner/scan-microcredit/scan-microcredit.component.html b/src/app/scanner/scan-microcredit/scan-microcredit.component.html index 2852b3ff..054e4a33 100644 --- a/src/app/scanner/scan-microcredit/scan-microcredit.component.html +++ b/src/app/scanner/scan-microcredit/scan-microcredit.component.html @@ -31,6 +31,9 @@ +
+ +
@@ -50,4 +53,4 @@ -
+
\ No newline at end of file diff --git a/src/app/scanner/scan-microcredit/scan-microcredit.component.scss b/src/app/scanner/scan-microcredit/scan-microcredit.component.scss index e69de29b..ac93441f 100644 --- a/src/app/scanner/scan-microcredit/scan-microcredit.component.scss +++ b/src/app/scanner/scan-microcredit/scan-microcredit.component.scss @@ -0,0 +1,16 @@ +@import "../../../variables.scss"; + +.scan-modal-container { + .spinner-overlay { + position: fixed; + width: 100%; + height: 100%; + top: 0; + left: 0; + background-color: rgba(255, 255, 255, 0.7); + display: flex; + justify-content: center; + align-items: center; + z-index: 200; + } +} diff --git a/src/app/scanner/scan-microcredit/scan-microcredit.component.ts b/src/app/scanner/scan-microcredit/scan-microcredit.component.ts index 5ebd1646..685ea482 100644 --- a/src/app/scanner/scan-microcredit/scan-microcredit.component.ts +++ b/src/app/scanner/scan-microcredit/scan-microcredit.component.ts @@ -1,17 +1,21 @@ -import { Component, OnInit, OnDestroy, ViewChild, ChangeDetectorRef, Inject } from '@angular/core'; -import { Router, ActivatedRoute, Params } from '@angular/router'; -import { MatDialog, MatDialogConfig, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { Component, OnInit, OnDestroy, ViewChild, ChangeDetectorRef, Inject, HostListener } from '@angular/core'; import { Subject, Observable, Subscription } from 'rxjs'; import { tap, takeUntil, finalize } from 'rxjs/operators'; +import { Router, ActivatedRoute, Params } from '@angular/router'; +import { MatDialog, MatDialogConfig, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { TranslateService } from '@ngx-translate/core'; import { WizardComponent } from 'angular-archwizard'; -// Global Services +/** + * Services + */ import { MessageNoticeService } from 'src/app/core/helpers/message-notice/message-notice.service'; import { AuthenticationService } from '../../core/services/authentication.service'; import { MicrocreditService } from '../../core/services/microcredit.service'; -// Local Services & Models/Interfaces +/** + * Local Services & Interfaces + */ import { ScannerService } from '../_scanner.service'; import { ScannerInterface } from '../_scanner.interface'; @@ -58,6 +62,7 @@ export class ScanMicrocreditComponent implements OnInit, OnDestroy { * On Init */ ngOnInit() { + // this.controlModalState(true); this.initializeCampaignData(); } @@ -65,6 +70,8 @@ export class ScanMicrocreditComponent implements OnInit, OnDestroy { * On destroy */ ngOnDestroy() { + // this.controlModalState(false); + this.scannerNoticeService.setNotice(null); this.subscription.unsubscribe(); this.unsubscribe.next(); @@ -72,9 +79,29 @@ export class ScanMicrocreditComponent implements OnInit, OnDestroy { this.loading = false; } + // controlModalState(state: boolean) { + // if (state) { + // const modalState = { + // modal: true, + // desc: 'fake state for our modal' + // }; + // history.pushState(modalState, null); + // } else if (window.history.state.modal) { + // history.back(); + // } + // } + + // @HostListener('window:popstate', ['$event']) + // dismissModal() { + // this.dialogRef.close(); + // } + + initializeCampaignData() { const currentCampaign = this.campaigns[this.campaigns.map(function (e) { return e.campaign_id; }).indexOf(this.campaign_id)]; this.transaction.campaign_id = currentCampaign.campaign_id; + console.log(currentCampaign) + this.transaction.campaign_title = currentCampaign.title; this.scannerService.changeMicrocreditTransaction(this.transaction); } @@ -131,6 +158,8 @@ export class ScanMicrocreditComponent implements OnInit, OnDestroy { support_id: this.transaction.support_id }; + this.loading = true; + this.microcreditService.redeemTokens(this.authenticationService.currentUserValue.user["_id"], this.campaign_id, redeemTokens._to, redeemTokens._tokens, redeemTokens.password, redeemTokens.support_id) .pipe( tap( @@ -167,5 +196,6 @@ export class ScanMicrocreditComponent implements OnInit, OnDestroy { onFinalStep(event = null) { this.dialogRef.close(); + // this.controlModalState(false); } } diff --git a/src/app/scanner/scan-offers/scan-offers.component.html b/src/app/scanner/scan-offers/scan-offers.component.html index 99996c73..9eef76de 100644 --- a/src/app/scanner/scan-offers/scan-offers.component.html +++ b/src/app/scanner/scan-offers/scan-offers.component.html @@ -31,6 +31,9 @@ +
+ +
@@ -49,4 +52,4 @@ -
+
\ No newline at end of file diff --git a/src/app/scanner/scan-offers/scan-offers.component.scss b/src/app/scanner/scan-offers/scan-offers.component.scss index e69de29b..ac93441f 100644 --- a/src/app/scanner/scan-offers/scan-offers.component.scss +++ b/src/app/scanner/scan-offers/scan-offers.component.scss @@ -0,0 +1,16 @@ +@import "../../../variables.scss"; + +.scan-modal-container { + .spinner-overlay { + position: fixed; + width: 100%; + height: 100%; + top: 0; + left: 0; + background-color: rgba(255, 255, 255, 0.7); + display: flex; + justify-content: center; + align-items: center; + z-index: 200; + } +} diff --git a/src/app/scanner/scan-offers/scan-offers.component.ts b/src/app/scanner/scan-offers/scan-offers.component.ts index 2d62ffdf..49565430 100644 --- a/src/app/scanner/scan-offers/scan-offers.component.ts +++ b/src/app/scanner/scan-offers/scan-offers.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, OnDestroy, ViewChild, ChangeDetectorRef, Inject } from '@angular/core'; +import { Component, OnInit, OnDestroy, ViewChild, ChangeDetectorRef, Inject, HostListener } from '@angular/core'; import { Router, ActivatedRoute, Params } from '@angular/router'; import { MatDialog, MatDialogConfig } from '@angular/material/dialog'; @@ -62,6 +62,8 @@ export class ScanOffersComponent implements OnInit, OnDestroy { * On Init */ ngOnInit() { + // this.controlModalState(true); + this.initializeOfferData(); } @@ -69,6 +71,8 @@ export class ScanOffersComponent implements OnInit, OnDestroy { * On destroy */ ngOnDestroy() { + // this.controlModalState(false); + this.scannerNoticeService.setNotice(null); this.subscription.unsubscribe(); this.unsubscribe.next(); @@ -76,27 +80,57 @@ export class ScanOffersComponent implements OnInit, OnDestroy { this.loading = false; } + // controlModalState(state: boolean) { + // if (state) { + // const modalState = { + // modal: true, + // desc: 'fake state for our modal' + // }; + // history.pushState(modalState, null); + // } else if (window.history.state.modal) { + // history.back(); + // } + // } + + // @HostListener('window:popstate', ['$event']) + // dismissModal() { + // this.dialogRef.close(); + // } + + initializeOfferData() { const currentOffer = this.offers[this.offers.map(function (e) { return e.offer_id; }).indexOf(this.offer_id)]; this.transaction.offer_id = currentOffer.offer_id; + this.transaction.offer_title = currentOffer.title; this.transaction.cost = currentOffer.cost; this.scannerService.changeOfferTransaction(this.transaction); } - fetchBalanceData() { + fetchBalanceData(final: boolean) { const identifier = this.user.identifier_scan || this.user.identifier_form; this.loyaltyService.readBalanceByPartner((identifier).toLowerCase()) .pipe( tap( data => { - console.log(parseInt(data.points, 16)); - this.transaction.points = parseInt(data.points, 16); - this.transaction.possible_quantity = Math.floor(this.transaction.points / this.transaction.cost); - if (!this.transaction.possible_quantity) { - this.scannerNoticeService.setNotice(this.translate.instant('WIZARD_MESSAGES.NOT_ENOUGH_POINTS'), 'danger'); + console.log(data); + + if (final) { + this.transaction.final_points = parseInt(data.points, 16); + this.scannerService.changeOfferTransaction(this.transaction); + + this.scannerNoticeService.setNotice(this.translate.instant('WIZARD_MESSAGES.SUCCESS_TRANSACTION'), 'success'); + this.onNextStep(); + } else { + console.log(parseInt(data.points, 16)); + this.transaction.points = parseInt(data.points, 16); + this.transaction.possible_quantity = Math.floor(this.transaction.points / this.transaction.cost); + this.scannerService.changeOfferTransaction(this.transaction); + this.onNextStep(); + + if (!this.transaction.possible_quantity) { + this.scannerNoticeService.setNotice(this.translate.instant('WIZARD_MESSAGES.NOT_ENOUGH_POINTS'), 'danger'); + } } - this.scannerService.changeOfferTransaction(this.transaction); - this.onNextStep(); }, error => { this.scannerNoticeService.setNotice(this.translate.instant(error), 'danger'); @@ -112,11 +146,11 @@ export class ScanOffersComponent implements OnInit, OnDestroy { } onSuccessScanIdentifier(event: string) { - this.fetchBalanceData(); + this.fetchBalanceData(false); } onSubmitIdentifierForm(event: string) { - this.fetchBalanceData(); + this.fetchBalanceData(false); } onSubmitOfferForm(event: number) { @@ -129,22 +163,23 @@ export class ScanOffersComponent implements OnInit, OnDestroy { quanitive: this.transaction.quantity }; + this.loading = true; + this.loyaltyService.redeemOffer(this.authenticationService.currentUserValue.user["_id"], redeemOffer.offer_id, redeemOffer._to, redeemOffer.password, redeemOffer._points, redeemOffer.quanitive) .pipe( tap( data => { - this.scannerNoticeService.setNotice(this.translate.instant('WIZARD_MESSAGES.SUCCESS_TRANSACTION'), 'success'); - this.onNextStep(); - console.log(data); + this.fetchBalanceData(true); }, error => { this.scannerNoticeService.setNotice( this.translate.instant('WIZARD_MESSAGES.ERROR_REDEEM_OFFER') + '
' + this.translate.instant(error), 'danger'); + this.loading = false; }), takeUntil(this.unsubscribe), finalize(() => { - this.loading = false; + // this.loading = false; this.cdRef.markForCheck(); }) ) @@ -173,5 +208,6 @@ export class ScanOffersComponent implements OnInit, OnDestroy { onFinalStep(event = null) { this.dialogRef.close(); + // this.controlModalState(false); } } diff --git a/src/app/scanner/scanner.component.html b/src/app/scanner/scanner.component.html index 12ff182f..e96806a7 100644 --- a/src/app/scanner/scanner.component.html +++ b/src/app/scanner/scanner.component.html @@ -21,7 +21,7 @@

- + +

{{'CAMPAIGN.PLURAL' | translate }}

@@ -54,7 +54,7 @@

{{'CAMPAIGN.PLURAL' | translate }}

- +

{{ 'OFFER.PLURAL' | translate }}

@@ -66,7 +66,7 @@

{{ 'OFFER.PLURAL' | translate }}

- +

{{ 'POST_EVENT.PLURAL' | translate }}

@@ -85,7 +85,7 @@

{{ 'POST_EVENT.PLURAL' | translate }}

- +