Files
doneit-web/src/app/ui/chat/modal/new-group/new-group.page.ts
T

242 lines
7.3 KiB
TypeScript
Raw Normal View History

import { Component, OnInit } from '@angular/core';
2021-01-21 16:27:04 +01:00
import { ModalController, NavParams, PickerController, PopoverController } from '@ionic/angular';
2021-01-06 15:28:42 +01:00
import { GroupDurationPage } from 'src/app/shared/popover/group-duration/group-duration.page';
2022-05-27 13:36:37 +01:00
import { ThemeService } from 'src/app/services/theme.service';
import { SessionStore } from 'src/app/store/session.service';
2023-08-21 12:22:19 +01:00
import { ToastService } from 'src/app/services/toast.service';
2024-03-03 18:14:33 +01:00
import { catchError } from 'rxjs/operators';
2024-09-19 09:16:14 +01:00
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service'
import { UDate } from 'src/app/utils/date';
import { HttpErrorResponse } from '@angular/common/http';
2024-09-19 23:36:59 +01:00
import { z } from 'zod';
2024-10-07 13:27:49 +01:00
import { GroupContactsPage, IGroupContactsPageOutPutSchema } from '../group-contacts/group-contacts.page';
2024-09-19 09:16:14 +01:00
2024-09-19 23:36:59 +01:00
const NewGroupModalOutPutSchema = z.object({
roomId: z.string().optional()
})
export type INewGroupModalOutPut = z.infer<typeof NewGroupModalOutPutSchema>
@Component({
selector: 'app-new-group',
templateUrl: './new-group.page.html',
styleUrls: ['./new-group.page.scss'],
})
export class NewGroupPage implements OnInit {
2023-10-11 17:41:05 +01:00
isGroupCreated: boolean;
showLoader: boolean;
2024-10-07 13:27:49 +01:00
expirationDate: Date = null;
displayDuration = ''
showDuration: boolean;
2023-10-11 17:41:05 +01:00
selectedDuration = ['', '', ''];
thedate: any;
groupName: string;
documents: any;
2022-01-26 17:01:50 +01:00
loggedUserChat: any;
constructor(
2021-01-06 15:28:42 +01:00
private pickerController: PickerController,
private popoverController: PopoverController,
2021-01-21 16:27:04 +01:00
private modalController: ModalController,
private navParams: NavParams,
2021-10-28 15:40:41 +01:00
public ThemeService: ThemeService,
2024-09-19 09:16:14 +01:00
public chatSystemService: ChatServiceService,
2023-08-21 12:22:19 +01:00
private toastService: ToastService,
2022-05-27 13:36:37 +01:00
) {
2022-10-12 17:01:09 +01:00
this.loggedUserChat = SessionStore.user.ChatData['data'];
2021-01-21 16:27:04 +01:00
this.isGroupCreated = false;
this.groupName = this.navParams.get('name');
this.documents = this.navParams.get('documents');
}
2024-09-19 09:16:14 +01:00
ngOnInit() {}
2023-09-19 10:21:23 +01:00
_ionChange(event) {
this.showDuration = event.detail.checked;
2021-10-28 15:40:41 +01:00
2023-10-11 17:41:05 +01:00
if (event.detail.checked) {
2021-10-28 15:40:41 +01:00
this.thedate = new Date();
}
2023-09-19 10:21:23 +01:00
else {
2021-10-28 15:40:41 +01:00
this.thedate = '';
}
}
2023-09-19 10:21:23 +01:00
close() {
this.modalController.dismiss();
}
2023-10-11 17:41:05 +01:00
async createGroup() {
2023-09-19 10:21:23 +01:00
2024-09-19 09:16:14 +01:00
const result = await this.chatSystemService.createRoom({
roomName: this.groupName,
createdBy: SessionStore.user.UserId,
roomType: 0,
2024-10-07 13:27:49 +01:00
expirationDate: this.expirationDate?.toISOString() ? UDate.GetDateWithTimeZone(this.expirationDate) : null,
2024-09-19 09:16:14 +01:00
members: []
})
if(result.isOk()) {
await this.chatSystemService.getRoomById(result.value.id)
this.addContacts(result.value.id)
//this.addGroupMessage.emit(result.value.id);
} else if(result.error instanceof HttpErrorResponse) {
// this.httpErrorHandle.httpStatusHandle(result.error)
} else {
this.toastService._badRequest('Por favor, contacta um administrador.');
}
2023-08-21 12:22:19 +01:00
}
2021-10-28 15:40:41 +01:00
2024-09-19 23:36:59 +01:00
async addContacts(roomId:string) {
2021-01-21 16:27:04 +01:00
2021-01-26 15:18:03 +01:00
let name = this.groupName.split(' ').join('-');
2023-09-19 10:21:23 +01:00
2020-12-22 15:53:30 +01:00
const modal = await this.modalController.create({
component: GroupContactsPage,
2021-01-21 16:27:04 +01:00
componentProps: {
2024-09-19 09:16:14 +01:00
roomId: roomId,
2021-10-28 15:40:41 +01:00
},
2020-12-22 15:53:30 +01:00
cssClass: 'contacts',
backdropDismiss: false
});
2023-07-15 11:01:09 +01:00
2024-09-19 23:36:59 +01:00
modal.onDidDismiss<IGroupContactsPageOutPutSchema>().then(result => {
this.modalController.dismiss({roomId})
});
2023-07-15 11:01:09 +01:00
await modal.present();
2020-12-22 15:53:30 +01:00
}
2021-10-28 15:40:41 +01:00
2021-01-06 15:28:42 +01:00
async setDuration(ev: any) {
const popover = await this.popoverController.create({
component: GroupDurationPage,
cssClass: 'group-duration',
event: ev,
translucent: true
});
return await popover.present();
}
2022-05-30 16:06:28 +01:00
async showPicker() {
2021-01-06 15:28:42 +01:00
const picker = await this.pickerController.create({
cssClass: '',
buttons: [
2023-10-11 17:41:05 +01:00
{
text: 'Cancelar', role: 'cancel', cssClass: 'btn-cancel'
},
{
text: 'Ok',
cssClass: 'btn-cancel',
2024-10-07 13:27:49 +01:00
handler:(value:any)=>{
2023-10-11 17:41:05 +01:00
let now = new Date();
2024-10-07 13:27:49 +01:00
this.expirationDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() + value.days.value, now.getHours() + value.hours.value, now.getMinutes() + value.minutes.value, now.getSeconds(), now.getMilliseconds())
2023-10-11 17:41:05 +01:00
this.selectedDuration = [
value.days.value,
value.hours.value,
value.minutes.value,
]
2024-10-07 13:27:49 +01:00
if(value.days.value != null && value.hours.value != null && value.minutes.value != null){
if(value.days.value > 0){
if(value.days.value == 1){
if(value.hours.value == 1){
this.displayDuration = value.days.value + " day " +
value.hours.value + " hora " +
value.minutes.value + " minutos";
2023-10-11 17:41:05 +01:00
}
2024-10-07 13:27:49 +01:00
else{
this.displayDuration = value.days.value + " days " +
value.hours.value + " horas " +
value.minutes.value + " minutos";
2021-01-06 15:28:42 +01:00
}
2023-10-11 17:41:05 +01:00
}
2024-10-07 13:27:49 +01:00
else{
if(value.hours.value == 1){
this.displayDuration = value.days.value + " days " +
value.hours.value + " hora " +
value.minutes.value + " minutos";
2023-10-11 17:41:05 +01:00
}
2024-10-07 13:27:49 +01:00
else{
this.displayDuration = value.days.value + " days " +
value.hours.value + " horas " +
value.minutes.value + " minutos";
2021-01-06 15:28:42 +01:00
}
}
2023-10-11 17:41:05 +01:00
}
2024-10-07 13:27:49 +01:00
else{
if(value.hours.value == 1){
2023-10-11 17:41:05 +01:00
this.displayDuration = value.hours.value + " hora " +
2024-10-07 13:27:49 +01:00
value.minutes.value + " minutos";
2023-10-11 17:41:05 +01:00
}
2024-10-07 13:27:49 +01:00
else{
2023-10-11 17:41:05 +01:00
this.displayDuration = value.hours.value + " horas " +
2024-10-07 13:27:49 +01:00
value.minutes.value + " minutos";
2021-01-06 15:28:42 +01:00
}
2021-10-28 15:40:41 +01:00
}
2023-10-11 17:41:05 +01:00
}
},
2021-01-06 15:28:42 +01:00
},
],
columns: [
{
name: 'days',
prefix: 'Dias',
options: [
{ text: '0', value: 0 },
{ text: '1', value: 1 },
{ text: '2', value: 2 },
{ text: '3', value: 3 },
{ text: '4', value: 4 },
]
},
{
name: 'hours',
prefix: 'Horas',
options: [
{ text: '0', value: 0 },
{ text: '1', value: 1 },
{ text: '2', value: 2 },
{ text: '3', value: 3 },
{ text: '4', value: 4 },
{ text: '5', value: 5 },
{ text: '6', value: 6 },
{ text: '7', value: 7 },
{ text: '8', value: 8 },
]
},
{
name: 'minutes',
prefix: 'Minutos',
selectedIndex: 0,
2021-01-06 15:28:42 +01:00
options: [
{ text: '5', value: 5 },
{ text: '10', value: 10 },
{ text: '15', value: 15 },
{ text: '20', value: 20 },
{ text: '25', value: 25 },
{ text: '30', value: 30 },
{ text: '35', value: 35 },
{ text: '45', value: 45 },
{ text: '50', value: 50 },
{ text: '55', value: 55 },
]
}
]
});
await picker.present();
2023-10-11 17:41:05 +01:00
picker.onDidDismiss().then(async data => {
2021-01-06 15:28:42 +01:00
let day = await picker.getColumn('days');
2021-10-28 15:40:41 +01:00
let hour = await picker.getColumn('hours');
2021-01-06 15:28:42 +01:00
let minutes = await picker.getColumn('minutes');
});
}
2020-12-22 15:53:30 +01:00
}