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

243 lines
7.4 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';
import { GroupContactsPage } from '../group-messages/group-contacts/group-contacts.page';
2022-05-27 13:36:37 +01:00
import { ThemeService } from 'src/app/services/theme.service';
2021-10-28 15:40:41 +01:00
import { ChatService } from 'src/app/services/chat.service';
import { ProcessesService } from 'src/app/services/processes.service';
2022-01-26 17:01:50 +01:00
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service';
import { AuthService } from 'src/app/services/auth.service';
import { SessionStore } from 'src/app/store/session.service';
@Component({
selector: 'app-new-group',
templateUrl: './new-group.page.html',
styleUrls: ['./new-group.page.scss'],
})
export class NewGroupPage implements OnInit {
2021-01-21 16:27:04 +01:00
isGroupCreated:boolean;
showLoader: boolean;
2021-01-06 15:28:42 +01:00
displayDuration: any;
showDuration: boolean;
2021-01-06 15:28:42 +01:00
selectedDuration = ['','',''];
2021-10-28 15:40:41 +01:00
thedate:any;
2021-01-21 16:27:04 +01:00
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,
private chatService: ChatService,
private processesService: ProcessesService,
2022-01-26 17:01:50 +01:00
public wsChatMethodsService: WsChatMethodsService,
private authService: AuthService,
2022-05-27 13:36:37 +01:00
) {
2022-01-26 17:01:50 +01:00
this.loggedUserChat = authService.ValidatedUserChat['data'];
2021-01-21 16:27:04 +01:00
this.isGroupCreated = false;
this.groupName = this.navParams.get('name');
this.documents = this.navParams.get('documents');
}
ngOnInit() {
2022-06-10 09:42:41 +01:00
this.chatService.refreshtoken();
2022-06-29 15:51:28 +01:00
// console.log(this.documents)
2022-04-28 09:32:27 +01:00
}
_ionChange(event){
this.showDuration = event.detail.checked;
2021-10-28 15:40:41 +01:00
if(event.detail.checked){
this.thedate = new Date();
}
else{
this.thedate = '';
}
}
close(){
this.modalController.dismiss();
}
2022-01-26 17:01:50 +01:00
async createGroup(){
2022-04-28 09:32:27 +01:00
2021-10-28 15:40:41 +01:00
let name = this.groupName.split(' ').join('-');
//Take out all special characters in string
2021-11-03 15:35:01 +01:00
name = name.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
2022-01-26 17:01:50 +01:00
let customFields = {}
let res:any;
2022-05-27 13:36:37 +01:00
if(this.thedate) {
2022-01-26 17:01:50 +01:00
let customFields = {
2022-05-27 13:36:37 +01:00
"countDownDate": this.thedate
2022-01-26 17:01:50 +01:00
}
2022-04-26 14:34:52 +01:00
res = await this.wsChatMethodsService.createPrivateRoom(name, SessionStore.user.UserName, customFields);
2022-04-28 09:32:27 +01:00
2022-01-26 17:01:50 +01:00
}
else{
2022-04-26 14:34:52 +01:00
res = await this.wsChatMethodsService.createPrivateRoom(name, SessionStore.user.UserName, customFields);
2022-04-28 09:32:27 +01:00
2022-01-26 17:01:50 +01:00
}
this.isGroupCreated = true;
this.addContacts(res.result);
2022-05-27 13:36:37 +01:00
setTimeout(() => {
this.wsChatMethodsService.subscribeToRoomUpdate(res.result.rid, res.result);
}, 10)
2022-01-26 17:01:50 +01:00
2021-10-28 15:40:41 +01:00
}
2022-05-27 13:36:37 +01:00
async addContacts(room) {
2021-01-26 15:18:03 +01:00
this.close();
2021-01-21 16:27:04 +01:00
2021-01-26 15:18:03 +01:00
let name = this.groupName.split(' ').join('-');
2022-04-28 09:32:27 +01:00
2021-10-28 15:40:41 +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: {
2021-10-28 15:40:41 +01:00
room: room,
},
2020-12-22 15:53:30 +01:00
cssClass: 'contacts',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
}
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: [
2021-10-28 15:40:41 +01:00
{
2021-01-06 15:28:42 +01:00
text: 'Cancelar', role: 'cancel', cssClass: 'btn-cancel'
},
2021-10-28 15:40:41 +01:00
{
text: 'Ok',
2021-01-06 15:28:42 +01:00
cssClass: 'btn-cancel',
2022-05-27 13:36:37 +01:00
handler:(value:any) => {
2022-04-28 09:32:27 +01:00
2021-10-28 15:40:41 +01:00
let now = new Date();
this.thedate = 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());
2021-01-06 15:28:42 +01:00
this.selectedDuration = [
value.days.value,
value.hours.value,
value.minutes.value,
]
2022-04-28 09:32:27 +01:00
2021-01-06 15:28:42 +01:00
if(value.days.value != null && value.hours.value != null && value.minutes.value != null){
2022-05-27 13:36:37 +01:00
if(value.days.value > 0) {
if(value.days.value == 1) {
if(value.hours.value == 1) {
2021-10-28 15:40:41 +01:00
this.displayDuration = value.days.value + " day " +
2021-01-06 15:28:42 +01:00
value.hours.value + " hora " +
value.minutes.value + " minutos";
}
else{
2021-10-28 15:40:41 +01:00
this.displayDuration = value.days.value + " days " +
2021-01-06 15:28:42 +01:00
value.hours.value + " horas " +
value.minutes.value + " minutos";
}
}
else{
if(value.hours.value == 1){
2021-10-28 15:40:41 +01:00
this.displayDuration = value.days.value + " days " +
2021-01-06 15:28:42 +01:00
value.hours.value + " hora " +
value.minutes.value + " minutos";
}
else{
2021-10-28 15:40:41 +01:00
this.displayDuration = value.days.value + " days " +
2021-01-06 15:28:42 +01:00
value.hours.value + " horas " +
value.minutes.value + " minutos";
}
}
}
else{
if(value.hours.value == 1){
this.displayDuration = value.hours.value + " hora " +
value.minutes.value + " minutos";
}
else{
this.displayDuration = value.hours.value + " horas " +
value.minutes.value + " minutos";
}
}
2021-10-28 15:40:41 +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: 3,
options: [
{ text: '0', value: 0 },
{ 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();
picker.onDidDismiss().then(async data =>{
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
}