hello , my pages have been refreshed twice when i use capacitor hardware button to go to accueil.ts component , so my presence.ts component which should go to my accueil without second refresh
import {Component, OnInit, AfterViewInit, OnDestroy} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {StorageService} from '../services/storage/storage.service';
import {UserCrudService} from '../services/user/user-crud.service';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';
import {DataService} from "../services/DataService/data.service.ts.service";
import {Subscription} from "rxjs";
import {AutoUnsubscribe} from "../decorator/auto-unsuscribe.decorator";
import {AuthService} from "../services/AuthService/auth-service.service";
import {JourTravail} from "../entity/JourTravail/JourTravail";
import { App as CapacitorApp } from '@capacitor/app';
import {PluginListenerHandle} from "@capacitor/core";
@Component({
selector: 'app-presence',
templateUrl: './presence.page.html',
styleUrls: ['./presence.page.scss'],
})
export class PresencePage implements OnInit,AfterViewInit ,OnDestroy {
formPresence: FormGroup ;
public date: string;
public username: string;
private parameters: any ;
private selectedDates :Date[];
private token: string ;
private parametres: string;
private receivedParameters: any;
private subscriptions: Subscription[] = [];
private backButtonSubscription: Subscription;
private getParam: Subscription;
private backButtonListener: PluginListenerHandle=null;
constructor(private route: ActivatedRoute, public formBuilder: FormBuilder,private myStorage: StorageService,private router: Router, private userService: UserCrudService, private dataService: DataService, private authService: AuthService) {
this.formPresence= this.formBuilder.group({
presM: false,
presA: false,
typeAbsence: null // Ajout du nouveau contrôle de formulaire
});
//this.subscriptions.push(this.backButtonSubscription);
this.backButtonListener = CapacitorApp.addListener('backButton', async({canGoBack}) => {
if(!canGoBack){
CapacitorApp.exitApp();
} else {
const param=JSON.stringify(this.parameters);
console.log("les paramètres qui cont être envoyés à accueil sont "+param);
await this.router.navigate(['/accueil',{param}]);
}
});
}
ngOnInit() {
registerLocaleData(localeFr);
if (!this.authService.isLoggedIn()) {
this.router.navigate(['login']);
}
// this.parameters= this.dataService.getData();
// console.log(this.route.snapshot.params.param);
try {
this.parameters=JSON.parse(this.route.snapshot.params.param);
}
catch(error: any){
console.log(error.message);
}
console.log(this.parameters);
if (this.parameters) {
console.log(this.parameters);
this.username = this.parameters.username;
this.selectedDates = this.parameters.selectedDates;
}
try {
this.getParam = this.route.params.subscribe(params => {
if (params['param']) {
this.parameters = JSON.parse(params['param']);
console.log(this.parameters.toString());
this.username = this.parameters.username;
this.selectedDates = this.parameters.selectedDates;
console.log('Received Parameters:', this.parameters);
}
});
} catch (error: any) {
console.error(error.toString());
}
//this.subscriptions.push(this.backButtonSubscription);
this.subscriptions.push(this.getParam);
}
ngOnDestroy(): void {
this.backButtonListener.remove;
this.getParam.unsubscribe();
}
ngAfterViewInit(){
}
isPresenceMatin() {
console.log(this.userService.getUsers());
}
isPresenceApresMidi() {
console.log(this.userService.getUsers());
}
onSubmit() {
this.username = this.parameters.username;
let mesJoursDeTravail: JourTravail[] = [];
const userSubscription = this.userService.getUserByUsername(this.username).subscribe(user => {
this.selectedDates.forEach(uneDate => {
console.log(uneDate);
});
const demiDaySubscription = this.userService.putDemiDay(mesJoursDeTravail).subscribe(value => {
console.log(value);
});
});
// this.router.navigate(['/'])
}
listeValidation() {
//this.parameters=JSON.parse(this.route.snapshot.params.parameters);
const parameters :any={
username :this.username,
}
//this.username=this.parameters.username;
//this.selectedDates=this.parameters.selectedDates;
const param= JSON.stringify(parameters);
this.router.navigate(['liste-validation',{param}])
}
returnHome() {
if(localStorage.getItem('token')!=null) {
this.router.navigate(['home']);
}
}
noteDeFrais() {
console.log('username:', this.username);
console.log('mesDates:', this.selectedDates);
if (this.username && this.selectedDates && this.selectedDates.length > 0) {
let parameters:any = {
username: this.username,
selectedDates: Array.isArray(this.selectedDates) ? this.selectedDates : [this.selectedDates]
}
let param = JSON.stringify(parameters);
console.log(param);
this.router.navigate(['payer-note-de-frais', {param}]);
} else {
console.error('username or mesDates is not defined or mesDates is empty');
}
}
}
to
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from "@angular/router";
import {ScreenOrientation} from "@ionic-native/screen-orientation/ngx";
import {NavController, Platform, ToastController} from "@ionic/angular";
import {FormGroup} from "@angular/forms";
import {DataService} from "../services/DataService/data.service.ts.service";
import {AuthService} from "../services/AuthService/auth-service.service";
import {Subscription} from "rxjs";
import {AutoUnsubscribe} from "../decorator/auto-unsuscribe.decorator";
import {App as CapacitorApp} from "@capacitor/app";
import {PluginListenerHandle} from "@capacitor/core";
@Component({
selector: 'app-accueil',
templateUrl: './accueil.page.html',
styleUrls: ['./accueil.page.scss'],
})
export class AccueilPage implements OnInit ,AfterViewInit{
formPresence: FormGroup;
public date: string;
public username: string;
private parameters: any;
private selectedDates: any[];
private token: string;
private parametres: string;
private backButtonSubscription: Subscription ;
private subscriptions : Subscription[] =[];
private getParam: Subscription;
private backButtonListener: PluginListenerHandle=null;
constructor(
private route: ActivatedRoute,
private router: Router,
private screenOrientation: ScreenOrientation,
private toastController: ToastController,
private dataService: DataService,
private authService: AuthService // Retirez le point-virgule
) {
console.log("coucou on est encore bien dans le constructeur")
this.token = localStorage.getItem('token');
this.backButtonListener = CapacitorApp.addListener('backButton', async({canGoBack}) => {
if(!canGoBack){
CapacitorApp.exitApp();
} else {
const param=JSON.stringify(this.parameters);
console.log("les paramètres qui cont être envoyés à accueil sont "+param);
await this.router.navigate(['/accueil',{param}]);
}
});
}
ngAfterViewInit(): void {
try {
this.getParam= this.route.params.subscribe(params => {
console.log("on rentre dans le bout de code qui permet de récupérer les données 13");
if (params['param']) {
try {
this.parameters = JSON.parse(params['param']);
}
catch (error :any){
console.error(error.toString());
}
try {
this.selectedDates = this.parameters.selectedDates;
}
catch (error :any){
console.error(error.toString())
}
console.log('Received Parameters:', this.parameters);
}
});
}catch (error :any){
console.error(error.toString());
}
}
ngOnInit() {
if (this.authService.isLoggedIn()) {
this.token = localStorage.getItem('token');
this.username = localStorage.getItem('username')
/*try {
console.log("les paramètres valent " + this.route.snapshot.params.param);
this.parameters = JSON.parse(this.route.snapshot.params.param);
} catch (error: any) {
console.error(error.toString())
}*/
// console.log(this.parameters);
/*try {
this.username = this.parameters.username;
} catch (error: any) {
console.error(error.toString())
}
try {
this.selectedDates = this.parameters.selectedDates;
} catch (error: any) {
console.error(error.toString())
}
console.log(this.selectedDates);*/
} else {
this.router.navigate(['login']);
}
}
selectionner(){
console.log(this.parameters);
this.parameters={
username:this.username,
selectedDates:this.selectedDates
};
console.log(this.parameters);
const param=JSON.stringify(this.parameters);
console.log(param);
localStorage.setItem('data', param);
try {
if (localStorage.getItem('token') != null) {
console.log("on est dans le if pour accéder à la route ");
//this.dataService.setData(param);
//console.log(this.dataService.getData());
this.router.navigate(['/presence',{param}]);
}
}
catch (error :any){
console.log(error.toString());
}
}
allerPageCompteur(){
this.parameters={
username:this.username,
selectedDates : this.selectedDates
};
console.log(this.parameters);
const param=JSON.stringify(this.parameters);
console.log(param);
if (localStorage.getItem('token') != null) {
this.router.navigate(['/compteurs', {param}])
.then(() => {
// Navigation réussie
// Vous pouvez ajouter du code ici si nécessaire
})
.catch((error) => {
// Erreur lors de la navigation
console.error(error.message);
this.router.navigate(['/liste-validation',{param}]);
});
}
}
listeValidation() {
this.parameters={
username:this.username,
date:this.selectedDates
};
console.log(this.parameters);
const param=JSON.stringify(this.parameters);
console.log(param);
if(localStorage.getItem('token') != null){
this.router.navigate(['/avance-deplacement',{param}])
.then(() => {
// Navigation réussie
// Vous pouvez ajouter du code ici si nécessaire
})
.catch((error) => {
// Erreur lors de la navigation
console.error(error.message);
this.router.navigate(['/liste-validation',{param}]);
});
}
}
allerAvanceDeDeplacement() {
this.parameters={
username:this.username,
date:this.selectedDates
};
console.log(this.parameters);
const param=JSON.stringify(this.parameters);
console.log(param);
if (this.selectedDates.length === 0 ) {
this.showToastNombreDeDates();
if(localStorage.getItem('token') != null){
this.router.navigate(['/liste-validation',{param}])
}
//return; // Cela interrompt la fonction et ne continue pas vers la navigation.
}
if(localStorage.getItem('token') != null){
this.router.navigate(['/avance-deplacement',{param}])
}
}
allerPlanifierDeplacement() {
console.log(this.selectedDates);
this.parameters={
username:this.username,
date:this.selectedDates
};
console.log(this.parameters);
const param=JSON.stringify(this.parameters);
console.log(param);
if (this.selectedDates.length === 0 ) {
this.showToastNombreDeDates();
if(localStorage.getItem('token') != null){
this.router.navigate(['/liste-validation',{param}])
}
//return; // Cela interrompt la fonction et ne continue pas vers la navigation.
}
if(localStorage.getItem('token') != null){
this.router.navigate(['/avance-deplacement',{param}])
}
}
ngOnDestroy() {
// Désabonnement manuel de tous les abonnements
try {
this.getParam.unsubscribe();
}
catch (error : any)
{
console.error(error.toString());
}
}
ordreDeplacement() {
console.log(this.selectedDates);
this.parameters={
username:this.username,
date:this.selectedDates
};
console.log(this.parameters);
const param=JSON.stringify(this.parameters);
console.log(param);
if (this.selectedDates.length === 0) {
this.showToastNombreDeDates();
if(localStorage.getItem('token') != null){
this.router.navigate(['/liste-validation',{param}])
}
return; // Cela interrompt la fonction et ne continue pas vers la navigation.
}
this.router.navigate(['/ordre-de-deplacement',{param}])
.then(() => {
// Navigation réussie
// Vous pouvez ajouter du code ici si nécessaire
})
.catch((error) => {
// Erreur lors de la navigation
console.error(error.message);
this.router.navigate(['/liste-validation',{param}]);
this.showToastNombreDeDates();
});
}
async conges() {
this.parameters={
username:this.username,
date:this.selectedDates
};
console.log(this.parameters);
const param=JSON.stringify(this.parameters);
console.log(param);
try {
await this.router.navigate(['/conges', {param}])
} catch (error) {
console.error("Erreur lors de la navigation :", error.message);
}
}
async functionnalityToast() {
const toast = await this.toastController.create({
message: 'la fonctionnalité n\' est pas encore disponible',
duration: 2000
});
await toast.present();
}
async showToastNombreDeDates() {
const toast = await this.toastController.create({
message: 'il n\'y a qu\'une date ',
duration: 2000
});
await toast.present();
}
}
could you help me ?
video demonstration : WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free