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

204 lines
6.0 KiB
TypeScript
Raw Normal View History

2022-10-12 17:01:09 +01:00
2021-04-14 14:10:17 +01:00
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2021-04-16 11:25:10 +01:00
import { ModalController, PickerController } from '@ionic/angular';
2021-04-14 13:56:38 +01:00
import { ChatService } from 'src/app/services/chat.service';
2021-10-25 13:21:48 +01:00
import { ThemeService } from 'src/app/services/theme.service'
2022-10-12 17:01:09 +01:00
import { SessionStore } from 'src/app/store/session.service';
2021-04-14 13:56:38 +01:00
@Component({
selector: 'app-edit-group',
templateUrl: './edit-group.page.html',
styleUrls: ['./edit-group.page.scss'],
})
export class EditGroupPage implements OnInit {
showLoader: boolean;
displayDuration: any;
showDuration: boolean;
selectedDuration = ['','',''];
groupName:string;
room:any;
2021-07-23 14:43:51 +01:00
loggedUser: any;
2021-04-14 13:56:38 +01:00
@Input() roomId:string;
2021-04-14 14:10:17 +01:00
@Output() openGroupContacts:EventEmitter<any> = new EventEmitter<any>();
2021-04-16 11:25:10 +01:00
@Output() openGroupMessage:EventEmitter<any> = new EventEmitter<any>();
@Output() closeAllDesktopComponents:EventEmitter<any> = new EventEmitter<any>();
2021-04-14 13:56:38 +01:00
constructor(
private modalController: ModalController,
private pickerController: PickerController,
private chatService: ChatService,
2021-10-25 13:21:48 +01:00
public ThemeService: ThemeService
2021-04-14 13:56:38 +01:00
) {
2022-10-12 17:01:09 +01:00
this.loggedUser = SessionStore.user.ChatData['data'];
2021-04-14 13:56:38 +01:00
}
ngOnInit() {
2022-10-11 13:56:56 +01:00
// this.chatService.refreshtoken();
2021-04-14 13:56:38 +01:00
this.getRoomInfo();
}
getRoomInfo(){
this.chatService.getRoomInfo(this.roomId).subscribe(room=>{
this.room = room['room'];
2022-04-28 09:32:27 +01:00
2022-10-04 16:50:55 +01:00
try {
this.groupName = this.room.name.split('-').join(' ');
} catch (error) {
this.groupName = this.room.name;
}
2021-04-14 13:56:38 +01:00
});
}
close(){
2021-04-16 11:25:10 +01:00
//this.modalController.dismiss();
this.closeAllDesktopComponents.emit();
this.openGroupMessage.emit(this.roomId);
2021-04-14 13:56:38 +01:00
}
changeGroupName(){
if(this.groupName.trim().length > 1){
let name = this.groupName.split(' ').join('-');
let body = {
"roomId": this.room._id,
"name": name,
}
this.chatService.renameGroup(body).subscribe(res=>{
this.modalController.dismiss(res['group']);
});
}
else{
2022-04-28 09:32:27 +01:00
2021-04-16 11:25:10 +01:00
}
2021-09-07 15:19:56 +01:00
this.updateGroup();
}
updateGroup(){
this.showLoader = true;
this.chatService.getRoomInfo(this.roomId).subscribe(room=>{
this.room = room['room'];
this.showLoader = false;
this.openGroupMessage.emit(this.room._id);
});
2021-04-14 13:56:38 +01:00
}
2021-04-16 11:25:10 +01:00
2021-04-14 13:56:38 +01:00
_ionChange(event){
this.showDuration = event.detail.checked;
}
async showPicker(){
const picker = await this.pickerController.create({
cssClass: '',
buttons: [
2021-07-23 14:43:51 +01:00
{
2021-04-14 13:56:38 +01:00
text: 'Cancelar', role: 'cancel', cssClass: 'btn-cancel'
},
2021-07-23 14:43:51 +01:00
{
text: 'Ok',
2021-04-14 13:56:38 +01:00
cssClass: 'btn-cancel',
handler:(value:any)=>{
2022-04-28 09:32:27 +01:00
2021-04-14 13:56:38 +01:00
this.selectedDuration = [
value.days.value,
value.hours.value,
value.minutes.value,
]
2022-04-28 09:32:27 +01:00
2021-04-14 13:56:38 +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){
2021-07-23 14:43:51 +01:00
this.displayDuration = value.days.value + " day " +
2021-04-14 13:56:38 +01:00
value.hours.value + " hora " +
value.minutes.value + " minutos";
}
else{
2021-07-23 14:43:51 +01:00
this.displayDuration = value.days.value + " days " +
2021-04-14 13:56:38 +01:00
value.hours.value + " horas " +
value.minutes.value + " minutos";
}
}
else{
if(value.hours.value == 1){
2021-07-23 14:43:51 +01:00
this.displayDuration = value.days.value + " days " +
2021-04-14 13:56:38 +01:00
value.hours.value + " hora " +
value.minutes.value + " minutos";
}
else{
2021-07-23 14:43:51 +01:00
this.displayDuration = value.days.value + " days " +
2021-04-14 13:56:38 +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-07-23 14:43:51 +01:00
}
2021-04-14 13:56:38 +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-07-23 14:43:51 +01:00
let hour = await picker.getColumn('hours');
2021-04-14 13:56:38 +01:00
let minutes = await picker.getColumn('minutes');
});
}
}