added jitsi api + improvements
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
import {Component, OnInit, ViewChild, Inject} from '@angular/core';
|
||||
import {MatSnackBar} from '@angular/material/snack-bar';
|
||||
import {Sort} from '@angular/material/sort';
|
||||
import {FormBuilder, FormGroup, Validators, NgForm} from '@angular/forms';
|
||||
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
|
||||
|
||||
import {QuotaService} from '../../services/quota.service';
|
||||
import {JitsiService} from '../../services/jitsi.service';
|
||||
import {ConfirmDialog} from '../../ui/confirm/confirm.component';
|
||||
import {I18nService} from './../../services/i18n.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-account-jitsi',
|
||||
templateUrl: './jitsi.component.html',
|
||||
styleUrls: ['./jitsi.component.scss']
|
||||
})
|
||||
export class JitsiComponent implements OnInit {
|
||||
|
||||
form: FormGroup;
|
||||
@ViewChild('formDirective') private formDirective: NgForm;
|
||||
jitsiRoomsQuota: number = 0;
|
||||
jitsiRooms: any[] = [];
|
||||
jitsiRoom: any = {};
|
||||
success: boolean;
|
||||
working: boolean;
|
||||
datetimeformat: String;
|
||||
|
||||
jitsiRoomsColumns = ["room", "starts", "expires", "moderationUrl", "delete"];
|
||||
|
||||
constructor(
|
||||
private quotaService: QuotaService,
|
||||
private formBuilder: FormBuilder,
|
||||
private jitsiService: JitsiService,
|
||||
private i18n: I18nService,
|
||||
public dialog: MatDialog) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.datetimeformat = this.i18n.get('format.datetime', []);
|
||||
|
||||
this.form = this.formBuilder.group({
|
||||
room: ['', Validators.required],
|
||||
starts: ['', Validators.nullValidator],
|
||||
expires: ['', Validators.required],
|
||||
});
|
||||
|
||||
this.update();
|
||||
}
|
||||
|
||||
create(): void {
|
||||
this.working = true;
|
||||
this.jitsiService.create(this.jitsiRoom).subscribe(response => {
|
||||
this.update();
|
||||
this.formDirective.resetForm();
|
||||
this.jitsiRoom = {};
|
||||
this.working = false;
|
||||
}, (error) => {
|
||||
this.working = false;
|
||||
if(error.status == 409) {
|
||||
let errors = {};
|
||||
for(let code of error.error) {
|
||||
errors[code.field] = errors[code.field] || {};
|
||||
errors[code.field][code.code] = true;
|
||||
}
|
||||
|
||||
for(let code in errors) {
|
||||
this.form.get(code).setErrors(errors[code]);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
update() {
|
||||
this.jitsiRoomsQuota = 0;
|
||||
this.quotaService.quotas().subscribe((data: any) => {
|
||||
for(let quota of data) {
|
||||
if(quota.name == "jitsi") {
|
||||
this.jitsiRoomsQuota = quota.value;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.jitsiService.get().subscribe((data: any) => {
|
||||
this.jitsiRooms = data;
|
||||
})
|
||||
}
|
||||
|
||||
confirmDelete(jitsiRoom) {
|
||||
const dialogRef = this.dialog.open(ConfirmDialog, {
|
||||
data: {
|
||||
'label': 'jitsi.rooms.confirmDelete',
|
||||
'args': [jitsiRoom.room]
|
||||
}
|
||||
})
|
||||
|
||||
dialogRef.afterClosed().subscribe(result => {
|
||||
if(result) {
|
||||
this.jitsiService.delete(jitsiRoom.id).subscribe((result: any) => {
|
||||
this.update();
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
sortData(sort: Sort) {
|
||||
const data = this.jitsiRooms.slice();
|
||||
if(!sort.active || sort.direction === '') {
|
||||
this.jitsiRooms = data;
|
||||
return;
|
||||
}
|
||||
|
||||
this.jitsiRooms = data.sort((a, b) => {
|
||||
const isAsc = sort.direction === 'asc';
|
||||
switch(sort.active) {
|
||||
case 'room': return this.compare(a.room, b.room, isAsc);
|
||||
case 'starts': return this.compare(a.room, b.room, isAsc);
|
||||
case 'expires': return this.compare(a.room, b.room, isAsc);
|
||||
default: return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
compare(a: number | string | String, b: number | string | String, isAsc: boolean) {
|
||||
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
|
||||
}
|
||||
|
||||
share(jitsiRoom) {
|
||||
const dialogRef = this.dialog.open(JitsiShareDialog, {
|
||||
data: jitsiRoom,
|
||||
minWidth: '300px',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-jitsi-share-dialog',
|
||||
templateUrl: 'jitsi.share.html',
|
||||
styleUrls: ['./jitsi.share.scss']
|
||||
})
|
||||
export class JitsiShareDialog {
|
||||
|
||||
jitsiRoom: any;
|
||||
|
||||
constructor(
|
||||
private i18n: I18nService,
|
||||
private snackBar: MatSnackBar,
|
||||
public dialogRef: MatDialogRef<JitsiShareDialog>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any) {
|
||||
this.jitsiRoom = data;
|
||||
}
|
||||
|
||||
copyToClipboard(jitsiRoom: any) {
|
||||
const selBox = document.createElement('textarea');
|
||||
selBox.value = jitsiRoom.url;
|
||||
document.body.appendChild(selBox);
|
||||
selBox.focus();
|
||||
selBox.select();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(selBox);
|
||||
this.snackBar.open(this.i18n.get("jitsi.share.clipboard.copied", []), this.i18n.get("close", []), {
|
||||
duration: 3000
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user