HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/pwa.sports-crowd.com/src/app/pages/change-direction/change-direction.ts
import { Component, OnInit } from "@angular/core";
import { TranslateService } from "@ngx-translate/core";
import { ModalController, AlertController } from "@ionic/angular";
import { StorageService } from '../../services/storage.service';
import { Router } from "@angular/router";

import { UserService } from "../../services/user.service";
import { CityService } from "../../services/city.service";
import { SucursalService } from "../../services/sucursal.service";
import { UtilsService } from "../../services/utils.service";

@Component({
  selector: "page-change-direction",
  templateUrl: "change-direction.html",
  styleUrls: ["./change-direction.scss"],
})
export class ChangeDirectionPage implements OnInit {
  infoUser: any;
  listCities: any;
  cityConnection: any;
  messageText: any;
  listSucursals: any;
  sucursalSelected: any;
  constructor(
    public userProvider: UserService,
    public cityProvider: CityService,
    private storage: StorageService,
    public modalCtrl: ModalController,
    public alertCtrl: AlertController,
    private translateService: TranslateService,
    public sucursalProvider: SucursalService,
    public utilsService: UtilsService,
    private router: Router
  ) {
    // traduccion textos
    this.translateService.get(["TITLE_CONFIRM_CHANGE_LOCATION", "TEXT_CONFIRM_CHANGE_LOCATION"]).subscribe((values) => {
      this.messageText = {
        titleConfirmChangeLocation: values.TITLE_CONFIRM_CHANGE_LOCATION,
        textConfirmChangeLocation: values.TEXT_CONFIRM_CHANGE_LOCATION,
      };
    });
  }

  ngOnInit() {
  }

  ionViewWillEnter() {
    this.storage.get("infoUser").then((infoUser) => {
      if (infoUser) {
        this.infoUser = infoUser;
      }
    });

    this.storage.get("listCities").then((listCities) => {
      if (listCities) {
        this.listCities = listCities;
      }
    });

    this.storage.get("infoHost").then((infoHost) => {
      this.cityConnection = infoHost;
    });

    this.storage.get("listSucursals").then((listSucursals) => {
      if (listSucursals) {
        this.listSucursals = listSucursals;
      }
    });

    this.storage.get("sucursalSelected").then((sucursalSelected) => {
      if (sucursalSelected) {
        this.sucursalSelected = sucursalSelected;
      }
    });
  }

  addNewAddress() {
    this.cancel(false);
    setTimeout(() => {
      this.router.navigate(["/address/addressListCreate/true"]);
    }, 500);
  }

  cancel(status, origin = "") {
    this.modalCtrl.dismiss({ status, origin });
  }

  changeAddressUser(id, last_used) {
    if (!last_used) {
      this.utilsService.presentLoading(this.translateService.instant("all.loading")).then(() => {
        this.userProvider.updateLastUsedAddress(id);
        setTimeout(() => {
          this.storage.get("infoUser").then((infoUser) => {
            if (infoUser) {
              this.infoUser = infoUser;
              this.utilsService.dismissLoading();
            }
          });
        }, 500);
      });
    }
  }

  async changeCity(city) {
    if (this.cityConnection.id != city.id) {
      const confirm = await this.alertCtrl.create({
        header: this.messageText.titleConfirmChangeLocation,
        message: this.messageText.textConfirmChangeLocation,
        buttons: [
          {
            text: "No",
            handler: () => {
              console.log("Disagree clicked");
            },
          },
          {
            text: "Si",
            handler: () => {
              this.utilsService.presentLoading(this.translateService.instant("all.loading")).then(() => {
                this.storage.set("infoHost", city);
                setTimeout(() => {
                  this.utilsService.dismissLoading();
                  this.cityProvider.getInfoHost();
                  this.cancel(true);
                }, 500);
              });
            },
          },
        ],
      });
      await confirm.present();
    }
  }

  changeSucursal(sucursal) {
    if (this.sucursalSelected.id != sucursal.id) {
      this.storage.get("token").then((token) => {
        if (token) {
          this.utilsService.presentLoading(this.translateService.instant("all.loading")).then(async () => {
            (await this.sucursalProvider.updateSucursalUser(sucursal.id, token.access_token)).subscribe(
              (resp) => {
                this.utilsService.dismissLoading();
                if (resp["status"] == "success") {
                  this.storage.set("sucursalSelected", sucursal);
                  this.sucursalSelected = sucursal;
                  this.cancel(false, "changeSucursal");
                }
              },
              (error) => {
                console.log("changeSucursal: ", error);
                this.utilsService.dismissLoading();
              }
            );
          });
        }
      });
    }
  }
}