Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { IDeal } from './../../interfaces/IDeal';
- import { SocialSharing } from '@ionic-native/social-sharing/ngx';
- import { DealService } from '../../services/deal.service';
- import { Component, OnInit , ViewChild } from '@angular/core';
- import { Clipboard } from '@ionic-native/clipboard/ngx';
- import { IonInfiniteScroll, IonContent, Platform } from '@ionic/angular';
- import { AlertController, IonSearchbar } from '@ionic/angular';
- import * as moment from 'moment';
- import { Keyboard } from '@ionic-native/keyboard/ngx';
- import { IImagesSlides } from '../../interfaces/IImageSlides';
- import { Storage } from '@ionic/storage';
- import { Plugins } from '@capacitor/core';
- const { SplashScreen } = Plugins;
- @Component({
- selector: 'app-deals-list',
- templateUrl: './deals-list.page.html',
- styleUrls: ['./deals-list.page.scss'],
- })
- export class DealsListPage implements OnInit {
- showNotFound = false;
- public today : string = moment().format('YYYY-MM-DD');
- public totalDeals : IDeal[];
- public dealsListAll : IDeal[];
- public dealsListAllNoChange : IDeal[];
- public dealsListOnlyDiscountCode : IDeal[];
- public dealsListOnlyOffer : IDeal[];
- public dealsListOnly20: IDeal[];
- public dealsListOnly20_50 : IDeal[];
- public dealsListOnly50_100 : IDeal[];
- public dealsListOnly100 : IDeal[];
- public dealsMinimiStorici : IDeal[];
- public deals : IDeal[] = [];
- public deals_copy : IDeal[];
- public i = 0;
- public page = 1;
- public isShow: boolean = false;
- public isShowBK: boolean = false;
- public flagSearch : boolean = false;
- public filterNumber : number = 0;
- imageSlides : IImagesSlides[];
- @ViewChild(IonInfiniteScroll) infiniteScroll: IonInfiniteScroll;
- @ViewChild(IonContent) ionContent: IonContent;
- @ViewChild('mySearchbar') searchbar: IonSearchbar;
- slideOptsOne = {
- initialSlide: 0,
- loop: true,
- //slidesPerView: 1,
- speed: 1000,
- autoplay:true
- };
- ngOnInit() {
- }
- constructor(private ds: DealService, private clipboard: Clipboard, private socialShareing : SocialSharing, private platform : Platform,private alertController: AlertController,
- private keyboard: Keyboard, private storage: Storage) {
- this.ds.imagesListForSlides$().subscribe( (imagesSlieds) => {
- this.imageSlides = imagesSlieds as IImagesSlides[];
- });
- this.loadDeals();
- this.platform.backButton.subscribe( () => {
- this.ionContent.scrollToTop(500);
- }).unsubscribe;
- this.platform.pause.subscribe(async () => {
- this.storage.set('lastDatePause', Date.now());
- });
- this.platform.resume.subscribe(async () => {
- this.storage.get('lastDatePause').then((date) => {
- if (Date.now() - date >= 36000000) { // 10*60*60*1000
- SplashScreen.show({
- autoHide: true
- });
- location.reload();
- }
- })
- });
- }
- loadDeals(){
- //this.ds.dealsListFromDB$().subscribe( (deals) => {
- this.ds.dealsList$.subscribe((deals)=> {
- this.totalDeals = deals as IDeal[];
- this.storage.get("myFavoritesList").then((deals)=> {
- let totalFavoritesDeals = deals as IDeal[];
- this.ds.syncFavoritesListWithAllDeals(this.totalDeals,totalFavoritesDeals);
- });
- this.dealsListAllNoChange = deals.filter(deal => deal.priorityLevel != 3) as IDeal[];
- this.dealsListAll = deals.filter(deal => deal.priorityLevel != 3) as IDeal[];
- while(this.i<this.page*10 && this.i<this.dealsListAll.length){
- this.deals.push(this.dealsListAll[this.i]);
- this.i++;
- }
- this.dealsListOnlyDiscountCode = this.dealsListAll.filter(deal => deal.discountCodeSingle);
- this.dealsListOnlyOffer = this.dealsListAll.filter(deal => !deal.discountCodeSingle);
- this.dealsListOnly20 = this.dealsListAll.filter(deal => this.formatPriceToNumber(deal.finalPrice,1));
- this.dealsListOnly20_50 = this.dealsListAll.filter(deal => this.formatPriceToNumber(deal.finalPrice,2));
- this.dealsListOnly50_100 = this.dealsListAll.filter(deal => this.formatPriceToNumber(deal.finalPrice,3));
- this.dealsListOnly100 = this.dealsListAll.filter(deal => this.formatPriceToNumber(deal.finalPrice,4));
- this.dealsMinimiStorici = this.dealsListAll.filter(deal => deal.priorityLevel.toString() == '2');
- this.deals_copy = this.deals;
- this.page++;
- }
- );
- }
- public getScrollPos(pos: number) {
- if(this.deals.length>2){
- this.isShow = pos > this.platform.height()/4 ? true : false;
- if(this.isShowBK != this.isShow){
- this.ds.valueOfFlagScroll(!this.isShow);
- this.isShowBK = this.isShow;
- }
- }
- }
- scrollContent(scroll) {
- if (scroll === 'top') {
- this.ionContent.scrollToTop(500); //300 for animate the scroll effect.
- } else {
- this.ionContent.scrollToBottom(); //300 for animate the scroll effect.
- }
- }
- toggleInfiniteScroll() {
- this.infiniteScroll.disabled = !this.infiniteScroll.disabled;
- }
- formatPriceToNumber(string : String,number : Number) : Boolean {
- string = string.replace(".","");
- string = string.replace("€","");
- let price = Number(string.replace(",","."));
- switch(number){
- case 1:
- return (price <= 20.00);
- case 2:
- return (price >= 20.00 && price<=50.00);
- case 3:
- return (price >= 50.00 && price<=100.00);
- case 4:
- return (price >= 100.00);
- }
- }
- loadMore(event){
- this.page++;
- while(this.i<this.page*10 && this.i<this.dealsListAll.length){
- this.deals.push(this.dealsListAll[this.i]);
- this.i++;
- }
- this.deals_copy = this.deals;
- event.target.complete();
- if (this.deals.length == this.dealsListAll.length) {
- event.target.disabled = true;
- }
- }
- CopyText(coupon : string){
- this.clipboard.copy(coupon).then(()=>{
- this._showAlert();
- }
- )
- }
- async _showAlert() {
- const alert = await this.alertController.create({
- header: '✅CODICE COPIATO',
- //subHeader: 'PREFERITI',
- message: 'Ricorda di incollare il codice in fase di pagamento!',
- buttons: ['OK']
- });
- await alert.present();
- }
- shareDeal(deal : IDeal){
- let messaggio = '';
- if(deal.textExtra){
- if(deal.discountCodeSingle) {
- messaggio = 'Ho trovato questo prodotto in offerta sull\'app di GosuMania a soli ' + deal.finalPrice
- + '\n' + 'usando il Codice Sconto [ ' + deal.discountCodeSingle + ' ]'
- + '\n❗️' + deal.textExtra
- + '\n' + deal.productLink5
- + '\n\n' + 'Scarica anche tu l\'app � https://gosumania.it/download-app-gosumania';
- } else {
- messaggio = 'Ho trovato questo prodotto in offerta sull\'app di GosuMania a soli ' + deal.finalPrice
- + '\n❗️' + deal.textExtra
- + '\n' + deal.productLink5
- + '\n\n' + 'Scarica anche tu l\'app � https://gosumania.it/download-app-gosumania';
- }
- } else {
- if(deal.discountCodeSingle) {
- messaggio = 'Ho trovato questo prodotto in offerta sull\'app di GosuMania a soli ' + deal.finalPrice
- + '\n' + 'usando il Codice Sconto [ ' + deal.discountCodeSingle + ' ]'
- + '\n' + deal.productLink5
- + '\n\n' + 'Scarica anche tu l\'app � https://gosumania.it/download-app-gosumania';
- } else {
- messaggio = 'Ho trovato questo prodotto in offerta sull\'app di GosuMania a soli ' + deal.finalPrice
- + '\n' + deal.productLink5
- + '\n\n' + 'Scarica anche tu l\'app � https://gosumania.it/download-app-gosumania';
- }
- }
- this.socialShareing.share(messaggio).then(()=>{
- //alert("Success");
- }).catch(e => {
- alert("Abilita i permessi nelle impostazioni del tuo Smartphone!");
- });
- }
- searchProduct(e){
- let value : string = e.detail.value;
- if(value.length == 0){
- this.showNotFound = false;
- this.flagSearch = false;
- this.showOnlyDeals(this.filterNumber);
- this.ionContent.scrollToTop();
- this.ds.valueOfFlagSearch(false);
- }else {
- this.flagSearch = true;
- this.ds.valueOfFlagSearch(true);
- this.showOnlyDeals(this.filterNumber);
- value = value.toLocaleUpperCase();
- this.dealsListAll = this.dealsListAll.filter(deal => deal.productName.toLocaleUpperCase().match(value));
- this.deals = [];
- this.i = 0;
- this.page=1;
- if(this.dealsListAll.length === 0) {
- this.showNotFound = true;
- } else {
- this.showNotFound = false;
- }
- while(this.i<this.page*10 && this.i<this.dealsListAll.length){
- this.deals.push(this.dealsListAll[this.i]);
- this.i++;
- }
- this.ionContent.scrollToTop();
- }
- }
- filterDeal(value : Number){
- this.searchbar.value = '';
- this.showOnlyDeals(value);
- }
- showOnlyDeals(value: Number){
- switch(Number(value)){
- case 1:
- this.dealsListAll = this.dealsListOnlyDiscountCode;
- this.deals = [];
- this.i = 0;
- this.page=1;
- while(this.i<this.page*10 && this.i<this.dealsListAll.length){
- this.deals.push(this.dealsListAll[this.i]);
- this.i++;
- }
- break;
- case 2:
- this.dealsListAll = this.dealsListOnlyOffer;
- this.deals = [];
- this.i = 0;
- this.page=1;
- while(this.i<this.page*10 && this.i<this.dealsListAll.length){
- this.deals.push(this.dealsListAll[this.i]);
- this.i++;
- }
- break;
- case 3:
- this.dealsListAll = this.dealsMinimiStorici;
- this.deals = [];
- this.i = 0;
- this.page=1;
- while(this.i<this.page*10 && this.i<this.dealsListAll.length){
- this.deals.push(this.dealsListAll[this.i]);
- this.i++;
- }
- break;
- case 4:
- this.dealsListAll = this.dealsListOnly20;
- this.deals = [];
- this.i = 0;
- this.page=1;
- while(this.i<this.page*10 && this.i<this.dealsListAll.length){
- this.deals.push(this.dealsListAll[this.i]);
- this.i++;
- }
- break;
- case 5:
- this.dealsListAll = this.dealsListOnly20_50;
- this.deals = [];
- this.i = 0;
- this.page=1;
- while(this.i<this.page*10 && this.i<this.dealsListAll.length){
- this.deals.push(this.dealsListAll[this.i]);
- this.i++;
- }
- break;
- case 6:
- this.dealsListAll = this.dealsListOnly50_100;
- this.deals = [];
- this.i = 0;
- this.page=1;
- while(this.i<this.page*10 && this.i<this.dealsListAll.length){
- this.deals.push(this.dealsListAll[this.i]);
- this.i++;
- }
- break;
- case 7:
- this.dealsListAll = this.dealsListOnly100;
- this.deals = [];
- this.i = 0;
- this.page=1;
- while(this.i<this.page*10 && this.i<this.dealsListAll.length){
- this.deals.push(this.dealsListAll[this.i]);
- this.i++;
- }
- break;
- default:
- this.dealsListAll = this.dealsListAllNoChange;
- this.deals = [];
- this.i = 0;
- this.page=1;
- while(this.i<this.page*10 && this.i<this.dealsListAll.length){
- this.deals.push(this.dealsListAll[this.i]);
- this.i++;
- }
- }
- this.filterNumber = Number(value);
- }
- doRefresh(event) {
- this.ds.dealsListFromDB$().subscribe((deals) => {
- this.ds.valueOfDealsList(deals as IDeal[]);
- this.filterDeal(this.filterNumber);
- event.target.complete();
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement