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

267 lines
6.3 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,
2022-01-13 10:19:14 +01:00
) { }
2021-11-03 15:04:30 +01:00
ngOnInit() {}
2021-07-12 11:13:29 +01:00
async presentToast(infoMessage: string) {
const toast = await this.toastController.create({
message: infoMessage,
duration: 2000
});
toast.present();
}
2021-11-07 20:56:34 +01:00
async _successMessage(message?: any, callback?) {
2022-01-17 13:48:08 +01:00
2021-11-07 20:56:34 +01:00
let notification = document.createElement('div')
notification.className = 'notification'
notification.innerHTML = `
<div class="main-content width-100 pa-20">
<p class="message d-flex align-center success">
<ion-icon slot="end" class="title-icon pr-10" src="/assets/images/nofitication-success.svg"></ion-icon>
<p class="text">{{ message }}</p>
</p>
2022-01-17 13:48:08 +01:00
2021-11-07 20:56:34 +01:00
</div>
`
document.body.append(notification)
notification.querySelector('.text').innerHTML = message || 'Processo efetuado'
setTimeout(()=>{
if (callback) {
callback()
}
notification.style.right = "-100%"
setTimeout(()=>{
notification.remove()
},1000)
},6000)
2022-01-17 13:48:08 +01:00
2021-11-07 20:56:34 +01:00
}
async _badRequest(message?: string, callback?) {
let notification = document.createElement('div')
notification.className = 'notification'
notification.innerHTML = `
<div class="main-content width-100 pa-20">
<p class="message d-flex align-center faild">
<ion-icon slot="end" class="title-icon pr-10" src="/assets/images/notification-error.svg"></ion-icon>
<p class="text">{{ message }}</p>
</p>
2022-01-17 13:48:08 +01:00
2021-11-07 20:56:34 +01:00
</div>
`
notification.style.animationName = 'notification-top'
document.body.append(notification)
notification.querySelector('.text').innerHTML = message || 'Processo não efetuado'
setTimeout(()=>{
if (callback) {
callback()
}
notification.style.right = "-100%"
setTimeout(()=>{
notification.remove()
},1000)
},6000)
}
2022-01-17 13:48:08 +01:00
async _chatMessage(message?: any, sender?:string) {
let notification = document.createElement('div')
notification.className = 'notification'
notification.innerHTML = `
<div class="main-content width-100 pa-20">
<p class="message d-flex align-bottom success">
<ion-icon slot="end" class="title-icon pr-10" src="/assets/images/nofitication-success.svg"></ion-icon>
<p class="text">{{ message.message }}</p>
</p>
<p class="text">{{ message.sender }} </p>
</div>
`
document.body.append(notification)
notification.querySelector('.text').innerHTML = message || 'Processo efetuado'
setTimeout(()=>{
/* if (callback) {
callback()
} */
notification.style.right = "-100%"
setTimeout(()=>{
notification.remove()
},1000)
},6000)
}
2021-06-09 16:38:41 +01:00
async successMessage(message?: any, callback?) {
2022-01-17 13:48:08 +01:00
2021-06-15 14:48:25 +01:00
let notification = document.createElement('div')
2021-06-16 15:58:44 +01:00
notification.className = 'notification'
2021-06-15 14:48:25 +01:00
notification.innerHTML = `
<div class="main-content width-100 pa-20">
2021-07-14 22:10:22 +01:00
<p class="message d-flex align-center success">
2021-06-15 14:48:25 +01:00
<ion-icon slot="end" class="title-icon pr-10" src="/assets/images/nofitication-success.svg"></ion-icon>
<p class="text">{{ message }}</p>
</p>
2022-01-17 13:48:08 +01:00
2021-06-15 14:48:25 +01:00
</div>
`
2021-10-29 14:23:25 +01:00
// document.body.append(notification)
2021-06-15 14:48:25 +01:00
notification.querySelector('.text').innerHTML = message || 'Processo efetuado'
2021-06-09 10:01:45 +01:00
setTimeout(()=>{
2021-06-09 16:34:14 +01:00
if (callback) {
callback()
}
2021-06-16 15:58:44 +01:00
notification.style.right = "-100%"
setTimeout(()=>{
notification.remove()
},1000)
},6000)
2022-01-17 13:48:08 +01:00
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
2021-06-15 14:48:25 +01:00
let notification = document.createElement('div')
2021-06-16 15:58:44 +01:00
notification.className = 'notification'
2021-06-15 14:48:25 +01:00
notification.innerHTML = `
<div class="main-content width-100 pa-20">
2021-07-14 22:10:22 +01:00
<p class="message d-flex align-center faild">
2021-06-15 14:48:25 +01:00
<ion-icon slot="end" class="title-icon pr-10" src="/assets/images/notification-error.svg"></ion-icon>
<p class="text">{{ message }}</p>
</p>
2022-01-17 13:48:08 +01:00
2021-06-15 14:48:25 +01:00
</div>
`
2021-06-18 16:03:34 +01:00
notification.style.animationName = 'notification-top'
2021-10-29 14:23:25 +01:00
// document.body.append(notification)
2021-06-15 14:49:41 +01:00
notification.querySelector('.text').innerHTML = message || 'Processo não efetuado'
2021-06-09 10:01:45 +01:00
setTimeout(()=>{
2021-06-09 16:34:14 +01:00
if (callback) {
callback()
}
2021-06-16 15:58:44 +01:00
notification.style.right = "-100%"
setTimeout(()=>{
notification.remove()
},1000)
},6000)
2021-06-15 14:48:25 +01:00
2021-06-09 10:01:45 +01:00
}
2022-01-17 13:48:08 +01:00
2021-06-21 09:10:45 +01:00
async notificationMessage(message?: any, callback?: any,data?: any) {
2022-01-17 13:48:08 +01:00
2021-06-21 09:10:45 +01:00
let notification = document.createElement('div')
notification.className = 'notificationPush'
notification.innerHTML = `
<div class="main-content width-100 pa-20">
<p class="message d-flex align-left">
<p class="text">{{ message }}</p>
</p>
2022-01-17 13:48:08 +01:00
2021-06-21 09:10:45 +01:00
</div>
`
let funcx = ()=>{
callback(data);
document.body.removeEventListener('click', funcx);
notification.remove();
}
2021-10-29 14:23:25 +01:00
// document.body.append(notification)
2021-06-21 09:10:45 +01:00
document.body.addEventListener('click', funcx);
notification.querySelector('.text').innerHTML = message || 'Processo efetuado'
setTimeout(()=>{
notification.style.top = "-100%"
setTimeout(()=>{
notification.remove()
},1000)
},6000)
2022-01-17 13:48:08 +01:00
2021-06-21 09:10:45 +01:00
}
2021-07-07 16:25:36 +01:00
loading() : HTMLDivElement {
2021-11-16 14:51:21 +01:00
2021-07-07 16:25:36 +01:00
let loader: HTMLDivElement = document.createElement('div')
2021-11-16 14:51:21 +01:00
let theme;
2021-07-07 16:25:36 +01:00
2021-11-16 14:51:21 +01:00
if(document.querySelector('body').className.includes('gov')) {
theme = 'gov'
} else if(document.querySelector('body').className.includes('default')) {
theme = 'blue'
} else if(document.querySelector('body').className.includes('tribunal')) {
theme = 'tribunal'
} else {
theme = 'gov'
}
loader.innerHTML = `
<div class="loading-blocker">
<div class="loading-blocker-container">
<img src="/assets/gif/theme/${theme}/Blocks-loader.svg" />
</div>
</div>
`;
2022-01-17 13:48:08 +01:00
2022-04-28 09:32:27 +01:00
//
2021-10-29 16:41:03 +01:00
document.body.append(loader)
2021-07-07 16:25:36 +01:00
loader.addEventListener('click', ()=>{
// loader.remove()
})
return loader
2022-01-17 13:48:08 +01:00
2021-07-07 16:25:36 +01:00
}
}
2022-01-13 10:19:14 +01:00
2022-01-17 13:48:08 +01:00
export const ToastsService = new ToastService(new ToastController())