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

248 lines
7.7 KiB
TypeScript
Raw Normal View History

2021-03-04 18:50:26 +01:00
import { analyzeAndValidateNgModules } from '@angular/compiler';
2021-03-16 14:33:36 +01:00
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2021-03-04 18:50:26 +01:00
import { ModalController, NavParams, PickerController, PopoverController } from '@ionic/angular';
2021-03-16 14:33:36 +01:00
import { ChatService } from 'src/app/services/chat.service';
2021-03-04 18:50:26 +01:00
import { GroupDurationPage } from 'src/app/shared/popover/group-duration/group-duration.page';
import { GroupContactsPage } from '../group-messages/group-contacts/group-contacts.page';
@Component({
selector: 'app-new-group',
templateUrl: './new-group.page.html',
styleUrls: ['./new-group.page.scss'],
})
export class NewGroupPage implements OnInit {
isGroupCreated:boolean;
showLoader: boolean;
displayDuration: any;
showDuration: boolean;
2021-10-27 08:45:37 +01:00
thedate:any;
_day:any;
2021-03-04 18:50:26 +01:00
selectedDuration = ['','',''];
2021-10-27 08:45:37 +01:00
countDownTime:any;
2021-03-15 18:09:41 +01:00
//groupName:string;
@Input() groupName:string;
2021-03-17 09:06:42 +01:00
@Output() addGroupMessage:EventEmitter<any> = new EventEmitter<any>();
2021-03-04 18:50:26 +01:00
constructor(
private pickerController: PickerController,
private popoverController: PopoverController,
private modalController: ModalController,
2021-03-16 14:33:36 +01:00
private chatService: ChatService,
2021-03-15 18:09:41 +01:00
//private navParams: NavParams,
2021-10-27 08:45:37 +01:00
)
{
2021-03-04 18:50:26 +01:00
this.isGroupCreated = false;
2021-03-15 18:09:41 +01:00
//this.groupName = this.navParams.get('name');
2021-03-04 18:50:26 +01:00
}
ngOnInit() {
}
_ionChange(event){
2021-10-27 08:45:37 +01:00
console.log(event);
console.log(event.detail.checked);
2021-03-04 18:50:26 +01:00
this.showDuration = event.detail.checked;
2021-10-27 08:45:37 +01:00
//this.thedate = new Date(2021, 10, 1, 10, 33, 30, 0);
this.thedate = new Date();
2021-03-04 18:50:26 +01:00
}
close(){
2021-03-16 14:33:36 +01:00
//this.modalController.dismiss();
console.log('close');
2021-03-17 09:06:42 +01:00
this.addGroupMessage.emit();
2021-03-16 14:33:36 +01:00
}
2021-10-27 08:45:37 +01:00
2021-03-16 14:33:36 +01:00
createGroup(){
let name = this.groupName.split(' ').join('-');
let body = { "name":name, }
this.chatService.addGroup(body).subscribe(res=>{
console.log('group created');
console.log(res['group']);
2021-10-27 08:45:37 +01:00
2021-03-17 09:06:42 +01:00
this.addGroupMessage.emit(res['group']._id);
2021-10-27 08:45:37 +01:00
let countDownBody = {
"roomId": res['group']._id,
"customFields":{"countDownDate":this.thedate}
}
this.chatService.setGroupCustomFields(countDownBody).subscribe(res=>{
console.log(res);
});
2021-03-16 14:33:36 +01:00
});
2021-03-04 18:50:26 +01:00
}
async addContacts(){
this.close();
let name = this.groupName.split(' ').join('-');
console.log(name);
2021-10-27 08:45:37 +01:00
2021-03-04 18:50:26 +01:00
const modal = await this.modalController.create({
component: GroupContactsPage,
componentProps: {
isCreated:this.isGroupCreated,
name: name,
duration:'',
2021-10-27 08:45:37 +01:00
},
2021-03-04 18:50:26 +01:00
cssClass: 'contacts',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
}
2021-10-27 08:45:37 +01:00
2021-03-04 18:50:26 +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();
}
async showPicker(){
const picker = await this.pickerController.create({
cssClass: '',
buttons: [
2021-10-27 08:45:37 +01:00
{
2021-03-04 18:50:26 +01:00
text: 'Cancelar', role: 'cancel', cssClass: 'btn-cancel'
},
2021-10-27 08:45:37 +01:00
{
text: 'Ok',
2021-03-04 18:50:26 +01:00
cssClass: 'btn-cancel',
handler:(value:any)=>{
console.log('button done pressed');
2021-10-27 08:45:37 +01:00
console.log(value);
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());
/* let timer = setInterval(() =>{
console.log('Show TIMER');
let difference = this.thedate.getTime() - new Date().getTime();
this._day = Math.floor(difference/(1000*60*60*24));
let c_day = Math.floor(difference/(1000*60*60*24));
let c_hours = Math.floor((difference % (1000*60*60*24)) / (1000*60*60));
let c_minutes = Math.floor((difference % (1000*60*60)) / (1000*60));
let c_seconds = Math.floor((difference % (1000*60)) / 1000);
this.countDownTime = c_day + ":" + c_hours + ":" + c_minutes + ":" + c_seconds ;
if(difference < 0){
clearInterval(timer);
this.countDownTime = "Expired";
}
}) */
2021-03-04 18:50:26 +01:00
this.selectedDuration = [
value.days.value,
value.hours.value,
value.minutes.value,
]
console.log(this.selectedDuration);
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){
2021-10-27 08:45:37 +01:00
this.displayDuration = value.days.value + " day " +
2021-03-04 18:50:26 +01:00
value.hours.value + " hora " +
value.minutes.value + " minutos";
}
else{
2021-10-27 08:45:37 +01:00
this.displayDuration = value.days.value + " days " +
2021-03-04 18:50:26 +01:00
value.hours.value + " horas " +
value.minutes.value + " minutos";
}
}
else{
if(value.hours.value == 1){
2021-10-27 08:45:37 +01:00
this.displayDuration = value.days.value + " days " +
2021-03-04 18:50:26 +01:00
value.hours.value + " hora " +
value.minutes.value + " minutos";
}
else{
2021-10-27 08:45:37 +01:00
this.displayDuration = value.days.value + " days " +
2021-03-04 18:50:26 +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-27 08:45:37 +01:00
}
2021-03-04 18:50:26 +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 },
2021-10-27 08:45:37 +01:00
{ text: '5', value: 5 },
{ text: '6', value: 6 },
2021-03-04 18:50:26 +01:00
]
},
{
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-27 08:45:37 +01:00
let hour = await picker.getColumn('hours');
2021-03-04 18:50:26 +01:00
let minutes = await picker.getColumn('minutes');
});
}
}