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

364 lines
10 KiB
TypeScript
Raw Normal View History

2023-06-22 12:53:35 +01:00
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2022-10-12 17:01:09 +01:00
import { ModalController, PickerController, PopoverController } from '@ionic/angular';
2022-09-30 15:13:36 +01:00
import { ChatSystemService } from 'src/app/services/chat/chat-system.service';
2021-12-01 15:11:54 +01:00
import { DataService } from 'src/app/services/data.service';
2021-03-04 18:50:26 +01:00
import { GroupDurationPage } from 'src/app/shared/popover/group-duration/group-duration.page';
2022-04-24 19:45:20 +01:00
import { SessionStore } from 'src/app/store/session.service';
2021-03-04 18:50:26 +01:00
import { GroupContactsPage } from '../group-messages/group-contacts/group-contacts.page';
2022-05-27 13:36:37 +01:00
import { ToastService } from 'src/app/services/toast.service';
2022-09-28 16:54:24 +01:00
import { ThemeService } from 'src/app/services/theme.service';
2022-10-11 13:56:56 +01:00
import { RouteService } from 'src/app/services/route.service';
2021-03-04 18:50:26 +01:00
@Component({
selector: 'app-new-group',
templateUrl: './new-group.page.html',
styleUrls: ['./new-group.page.scss'],
})
2021-12-01 15:11:54 +01:00
export class NewGroupPage implements OnInit{
2021-03-04 18:50:26 +01:00
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-12-01 15:11:54 +01:00
task:any;
2023-06-22 12:53:35 +01:00
event: any
2022-10-11 13:56:56 +01:00
link = ''
documents: any;
2022-01-26 16:37:59 +01:00
loggedUserChat: any;
2023-06-22 12:53:35 +01:00
contact: {
Email: string
DisplayName: string
}[]
2022-10-11 14:18:55 +01:00
@Input() roomId: string;
2021-03-15 18:09:41 +01:00
@Input() groupName:string;
2021-03-17 09:06:42 +01:00
@Output() addGroupMessage:EventEmitter<any> = new EventEmitter<any>();
2022-07-27 16:12:46 +01:00
@Output() closeAllDesktopComponents:EventEmitter<any> = new EventEmitter<any>();
2022-10-11 14:18:55 +01:00
@Output() backToChat:EventEmitter<any> = new EventEmitter<any>();
2022-07-27 16:12:46 +01:00
2021-03-04 18:50:26 +01:00
constructor(
private pickerController: PickerController,
private popoverController: PopoverController,
private modalController: ModalController,
2021-12-01 15:11:54 +01:00
private dataService:DataService,
2022-09-30 15:13:36 +01:00
public ChatSystemService: ChatSystemService,
2022-05-27 13:36:37 +01:00
private toastService: ToastService,
2022-10-11 13:56:56 +01:00
public ThemeService: ThemeService,
private RouteService: RouteService,
2021-10-27 08:45:37 +01:00
)
{
2022-10-12 17:01:09 +01:00
this.loggedUserChat = SessionStore.user.ChatData['data'];
2021-03-04 18:50:26 +01:00
this.isGroupCreated = false;
}
ngOnInit() {
2022-09-28 16:33:13 +01:00
this.task = this.dataService.get("task");
2023-06-22 12:53:35 +01:00
this.event = this.dataService.get("event");
2022-09-30 16:55:09 +01:00
if(this.task) {
2022-10-11 13:56:56 +01:00
this.link = this.dataService.get("link");
2022-09-30 16:55:09 +01:00
this.groupName = this.task.Folio;
this.documents = this.dataService.get("documents");
this.dataService.set("newGroup", false);
2022-10-11 13:56:56 +01:00
this.dataService.set("link", false);
2023-06-22 12:53:35 +01:00
} else if (this.event) {
//
this.link = this.dataService.get("link");
this.groupName = this.event.Subject;
this.documents = this.dataService.get("documents");
this.contact = this.dataService.get("contacts");
//
this.dataService.set("newGroup", false);
this.dataService.set("link", false);
2022-09-30 16:55:09 +01:00
}
2021-03-04 18:50:26 +01:00
}
2022-09-28 16:33:13 +01:00
_ionChange(event) {
2022-04-28 09:32:27 +01:00
this.showDuration = event.detail.checked;
2021-10-27 08:45:37 +01:00
2022-10-11 14:53:48 +01:00
if(event.detail.checked) {
2021-10-28 15:40:41 +01:00
this.thedate = new Date();
}
2022-10-11 14:53:48 +01:00
else {
2021-10-28 15:40:41 +01:00
this.thedate = '';
}
2021-03-04 18:50:26 +01:00
}
2021-10-28 15:40:41 +01:00
2022-07-26 16:37:05 +01:00
close() {
2022-10-11 13:56:56 +01:00
if(this.link) {
this.RouteService.goBack();
this.dataService.set("link", false);
} else {
2022-10-13 14:37:03 +01:00
if(this.roomId) {
this.backToChat.emit({roomId: this.roomId});
} else {
this.closeAllDesktopComponents.emit();
}
2022-10-11 13:56:56 +01:00
}
2021-03-16 14:33:36 +01:00
}
2021-10-27 08:45:37 +01:00
2022-05-27 13:36:37 +01:00
async createGroup() {
2022-04-28 09:32:27 +01:00
2021-03-16 14:33:36 +01:00
let name = this.groupName.split(' ').join('-');
2021-12-10 11:41:24 +01:00
//Take out all special characters in string
name = name.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
2022-01-26 16:37:59 +01:00
let customFields = {}
let res:any;
2022-07-26 17:48:33 +01:00
const loader = this.toastService.loading();
2022-05-27 13:36:37 +01:00
if(this.thedate) {
2022-01-26 16:37:59 +01:00
let customFields = {
"countDownDate":this.thedate
}
2022-09-30 15:13:36 +01:00
res = await this.ChatSystemService.createPrivateRoom(name, SessionStore.user.UserName, customFields);
2022-01-26 16:37:59 +01:00
}
2022-05-27 13:36:37 +01:00
else {
2022-09-30 15:13:36 +01:00
res = await this.ChatSystemService.createPrivateRoom(name, SessionStore.user.UserName, customFields);
2022-05-27 13:36:37 +01:00
}
2022-07-26 17:48:33 +01:00
loader.remove();
2022-05-27 13:36:37 +01:00
// FsId
// DocId
if(res?.result?.rid) {
this.addGroupMessage.emit(res.result.rid);
2022-09-30 15:13:36 +01:00
await this.ChatSystemService.getAllRooms();
2022-05-27 13:36:37 +01:00
2022-09-30 15:13:36 +01:00
if(!this.ChatSystemService.getGroupRoom(res.result.rid)) {
2022-07-26 16:54:21 +01:00
this.createGroupWithAttachmentsCath(res)
2022-07-26 16:37:05 +01:00
} else {
setTimeout(()=> {
2022-07-26 17:18:52 +01:00
2022-07-26 16:54:21 +01:00
this.createGroupWithAttachments(res)
2022-07-26 16:37:05 +01:00
}, 500)
}
2022-04-28 09:32:27 +01:00
2022-05-27 13:36:37 +01:00
} else {
this.toastService._badRequest('Existe um grupo com este nome!');
2022-01-26 16:37:59 +01:00
}
2021-03-04 18:50:26 +01:00
}
2022-07-26 16:54:21 +01:00
createGroupWithAttachmentsCath(res: any) {
2022-09-30 15:13:36 +01:00
if(!this.ChatSystemService.getGroupRoom(res.result.rid)) {
2022-07-26 16:54:21 +01:00
setTimeout(()=>{
this.createGroupWithAttachmentsCath(res)
}, 1500)
} else {
this.createGroupWithAttachments(res)
}
}
createGroupWithAttachments(res: any) {
2022-09-30 15:13:36 +01:00
this.ChatSystemService.getGroupRoom(res.result.rid).hasLoadHistory = true;
2022-07-26 17:18:52 +01:00
2022-10-12 11:38:04 +01:00
if(this.documents) {
this.documents.forEach(element => {
this.ChatSystemService.getGroupRoom(res.result.rid).send({
file: {
"name": element.Assunto,
"type": "application/webtrix",
"ApplicationId": element.ApplicationId,
"DocId": element.DocId,
"Assunto": element.Assunto,
},
temporaryData: {
data: {
selected: {
Id: element.DocId,
ApplicationType: element.ApplicationId
}
2022-07-26 16:54:21 +01:00
}
2022-10-12 11:38:04 +01:00
},
attachments: [{
"title": element.Assunto,
"description": element.Assunto,
"title_link_download": true,
"type": "webtrix",
"text": element.Assunto,
"thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png",
}],
})
});
}
2022-07-27 15:11:34 +01:00
2022-10-03 11:02:32 +01:00
this.ChatSystemService.getAllRooms();
2022-07-27 15:11:34 +01:00
setTimeout(() => {
this.groupName = ""
}, 150);
2022-07-26 16:54:21 +01:00
}
2023-06-22 12:53:35 +01:00
async addContacts() {
2021-03-04 18:50:26 +01:00
this.close();
let name = this.groupName.split(' ').join('-');
2022-04-28 09:32:27 +01:00
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
});
2023-07-15 11:01:09 +01:00
2021-03-04 18:50:26 +01:00
modal.onDidDismiss();
2023-07-15 11:01:09 +01:00
await modal.present();
2021-03-04 18:50:26 +01:00
}
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();
}
2023-06-22 12:53:35 +01:00
async showPicker() {
2021-03-04 18:50:26 +01:00
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)=>{
2022-04-28 09:32:27 +01:00
2021-10-27 08:45:37 +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-03-04 18:50:26 +01:00
this.selectedDuration = [
value.days.value,
value.hours.value,
value.minutes.value,
]
2022-04-28 09:32:27 +01:00
2021-03-04 18:50:26 +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-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();
2022-05-27 13:36:37 +01:00
picker.onDidDismiss().then(async data => {
2021-03-04 18:50:26 +01:00
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');
});
}
}