Files
doneit-web/src/app/services/toast.service.ts
T

118 lines
3.2 KiB
TypeScript
Raw Normal View History

import { Injectable } from '@angular/core';
2021-06-09 10:01:45 +01:00
import { AnimationController, ModalController, ToastController } from '@ionic/angular';
import { BadRequestPage } from '../shared/popover/bad-request/bad-request.page';
import { SuccessMessagePage } from '../shared/popover/success-message/success-message.page';
@Injectable({
providedIn: 'root'
})
export class ToastService {
2021-06-09 10:01:45 +01:00
constructor(
public toastController: ToastController,
private animationController: AnimationController,
private modalController: ModalController,
) { }
async presentToast(infoMessage: string) {
const toast = await this.toastController.create({
message: infoMessage,
duration: 2000
});
toast.present();
}
2021-06-09 16:34:14 +01:00
async successMessage(message?: string, callback?) {
2021-06-09 10:01:45 +01:00
const enterAnimation = (baseEl: any) => {
const backdropAnimation = this.animationController.create()
.addElement(baseEl.querySelector('ion-backdrop')!)
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
const wrapperAnimation = this.animationController.create()
.addElement(baseEl.querySelector('.modal-wrapper')!)
.keyframes([
{ offset: 0, opacity: '1', right: '-100%' },
{ offset: 1, opacity: '1', right: '0px' }
]);
return this.animationController.create()
.addElement(baseEl)
.easing('ease-out')
2021-06-09 10:45:19 +01:00
.duration(500)
2021-06-09 10:01:45 +01:00
.addAnimation([backdropAnimation, wrapperAnimation]);
}
const leaveAnimation = (baseEl: any) => {
return enterAnimation(baseEl).direction('reverse');
}
const modal = await this.modalController.create({
enterAnimation,
leaveAnimation,
component: SuccessMessagePage,
componentProps: {
message: message || 'Processo efetuado' ,
},
cssClass: 'notification-modal'
});
modal.present()
setTimeout(()=>{
2021-06-09 16:34:14 +01:00
if (callback) {
callback()
}
2021-06-09 10:01:45 +01:00
modal.dismiss()
2021-06-09 10:45:19 +01:00
},7000)
2021-06-09 10:01:45 +01:00
}
2021-06-09 16:34:14 +01:00
async badRequest(message?: string, callback?) {
2021-06-09 10:01:45 +01:00
const enterAnimation = (baseEl: any) => {
const backdropAnimation = this.animationController.create()
.addElement(baseEl.querySelector('ion-backdrop')!)
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
const wrapperAnimation = this.animationController.create()
.addElement(baseEl.querySelector('.modal-wrapper')!)
.keyframes([
{ offset: 0, opacity: '1', right: '-100%' },
{ offset: 1, opacity: '1', right: '0px' }
]);
return this.animationController.create()
.addElement(baseEl)
.easing('ease-out')
2021-06-09 13:34:55 +01:00
.duration(500)
2021-06-09 10:01:45 +01:00
.addAnimation([backdropAnimation, wrapperAnimation]);
}
const leaveAnimation = (baseEl: any) => {
return enterAnimation(baseEl).direction('reverse');
}
const modal = await this.modalController.create({
enterAnimation,
leaveAnimation,
component: BadRequestPage,
componentProps: {
message: message || 'Processo efetuado' ,
},
cssClass: 'notification-modal'
});
modal.present()
setTimeout(()=>{
2021-06-09 16:34:14 +01:00
if (callback) {
callback()
}
2021-06-09 10:01:45 +01:00
modal.dismiss()
2021-06-09 13:34:55 +01:00
},7000)
2021-06-09 10:01:45 +01:00
}
}