mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
327 lines
10 KiB
TypeScript
327 lines
10 KiB
TypeScript
import { Component, EventEmitter, Input, OnInit, Output,ViewContainerRef } from '@angular/core';
|
|
import { PickerController, PopoverController } from '@ionic/angular';
|
|
// import { ChatSystemService } from 'src/app/services/chat/chat-system.service';
|
|
import { DataService } from 'src/app/services/data.service';
|
|
import { GroupDurationPage } from 'src/app/shared/popover/group-duration/group-duration.page';
|
|
import { SessionStore } from 'src/app/store/session.service';
|
|
import { ThemeService } from 'src/app/services/theme.service';
|
|
import { RouteService } from 'src/app/services/route.service';
|
|
import { HttpErrorResponse } from '@angular/common/http';
|
|
|
|
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service'
|
|
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service'
|
|
import { UDate } from 'src/app/utils/date';
|
|
import { ToastService } from 'src/app/services/toast.service';
|
|
|
|
@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;
|
|
expirationDate:Date = null;
|
|
_day:any;
|
|
selectedDuration = ['','',''];
|
|
countDownTime:any;
|
|
task:any;
|
|
event: any
|
|
link = ''
|
|
documents: any;
|
|
loggedUserChat: any;
|
|
contact: {
|
|
Email: string
|
|
DisplayName: string
|
|
}[]
|
|
|
|
@Input() roomId: string;
|
|
|
|
@Input() groupName:string;
|
|
@Output() addGroupMessage:EventEmitter<any> = new EventEmitter<any>();
|
|
@Output() closeAllDesktopComponents:EventEmitter<any> = new EventEmitter<any>();
|
|
@Output() backToChat:EventEmitter<any> = new EventEmitter<any>();
|
|
|
|
|
|
constructor(
|
|
private pickerController: PickerController,
|
|
private popoverController: PopoverController,
|
|
private dataService:DataService,
|
|
// public ChatSystemService: ChatSystemService,
|
|
public ThemeService: ThemeService,
|
|
private RouteService: RouteService,
|
|
private viewContainerRef: ViewContainerRef,
|
|
private httpErrorHandle: HttpErrorHandle,
|
|
private ChatServiceService: ChatServiceService,
|
|
private toastService: ToastService,
|
|
)
|
|
{
|
|
this.loggedUserChat = SessionStore.user.ChatData['data'];
|
|
this.isGroupCreated = false;
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
this.task = this.dataService.get("task");
|
|
this.event = this.dataService.get("event");
|
|
|
|
if(this.task && this.dataService.get("newGroup")) {
|
|
this.link = this.dataService.get("link");
|
|
this.groupName = this.task.Folio;
|
|
this.documents = this.dataService.get("documents");
|
|
this.dataService.set("newGroup", false);
|
|
this.dataService.set("link", false);
|
|
} else if (this.event && this.dataService.get("newGroup")) {
|
|
//
|
|
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);
|
|
|
|
} else {
|
|
this.dataService.clear();
|
|
}
|
|
|
|
}
|
|
|
|
onDateExpirationChange(event) {
|
|
|
|
this.showDuration = event.detail.checked;
|
|
|
|
if(event.detail.checked) {
|
|
this.expirationDate = new Date();
|
|
}
|
|
else {
|
|
this.expirationDate = null;
|
|
}
|
|
}
|
|
|
|
close() {
|
|
if(this.link) {
|
|
this.viewContainerRef.clear();
|
|
this.RouteService.goBack();
|
|
this.dataService.set("link", false);
|
|
} else {
|
|
if(this.roomId) {
|
|
this.backToChat.emit({roomId: this.roomId});
|
|
this.viewContainerRef.clear();
|
|
} else {
|
|
this.viewContainerRef.clear();
|
|
this.closeAllDesktopComponents.emit();
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
async createGroup() {
|
|
this.createGroup1()
|
|
}
|
|
|
|
async createGroup1() {
|
|
const result = await this.ChatServiceService.createRoom({
|
|
roomName: this.groupName,
|
|
createdBy: SessionStore.user.UserId,
|
|
roomType: 0,
|
|
expirationDate: this.expirationDate?.toISOString() ? UDate.GetDateWithTimeZone(this.expirationDate) : null,
|
|
members: []
|
|
})
|
|
|
|
if(result.isOk()) {
|
|
await this.ChatServiceService.getRoomById(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.');
|
|
}
|
|
|
|
}
|
|
|
|
createGroupWithAttachmentsCath(res: any) {
|
|
// if(!this.ChatSystemService.getGroupRoom(res.result.rid)) {
|
|
// setTimeout(() => {
|
|
// this.createGroupWithAttachmentsCath(res)
|
|
// }, 1500)
|
|
// } else {
|
|
// this.createGroupWithAttachments(res)
|
|
// }
|
|
}
|
|
|
|
createGroupWithAttachments(res: any) {
|
|
// this.ChatSystemService.getGroupRoom(res.result.rid).hasLoadHistory = true;
|
|
|
|
// 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
|
|
// }
|
|
// }
|
|
// },
|
|
// 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",
|
|
// }],
|
|
// })
|
|
// });
|
|
// }
|
|
|
|
|
|
// this.ChatSystemService.getAllRooms();
|
|
|
|
// setTimeout(() => {
|
|
// this.groupName = ""
|
|
// }, 150);
|
|
}
|
|
|
|
|
|
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: [
|
|
{
|
|
text: 'Cancelar', role: 'cancel', cssClass: 'btn-cancel'
|
|
},
|
|
{
|
|
text: 'Ok',
|
|
cssClass: 'btn-cancel',
|
|
handler:(value:any)=>{
|
|
|
|
let now = new Date();
|
|
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())
|
|
|
|
this.selectedDuration = [
|
|
value.days.value,
|
|
value.hours.value,
|
|
value.minutes.value,
|
|
]
|
|
|
|
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";
|
|
}
|
|
else{
|
|
this.displayDuration = value.days.value + " days " +
|
|
value.hours.value + " horas " +
|
|
value.minutes.value + " minutos";
|
|
}
|
|
}
|
|
else{
|
|
if(value.hours.value == 1){
|
|
this.displayDuration = value.days.value + " days " +
|
|
value.hours.value + " hora " +
|
|
value.minutes.value + " minutos";
|
|
}
|
|
else{
|
|
this.displayDuration = value.days.value + " days " +
|
|
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";
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
],
|
|
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 },
|
|
{ text: '5', value: 5 },
|
|
{ text: '6', value: 6 },
|
|
]
|
|
},
|
|
{
|
|
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,
|
|
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();
|
|
picker.onDidDismiss().then(async data => {
|
|
let day = await picker.getColumn('days');
|
|
let hour = await picker.getColumn('hours');
|
|
let minutes = await picker.getColumn('minutes');
|
|
});
|
|
|
|
}
|
|
|
|
}
|