update partey timeslots + minetest

This commit is contained in:
_Bastler
2021-07-29 17:41:25 +02:00
parent 72178dd7c4
commit a11c74b91b
13 changed files with 723 additions and 3 deletions
@@ -0,0 +1,263 @@
import {Component, OnInit, ViewChild, Inject} from '@angular/core';
import {Sort} from '@angular/material/sort';
import {MatSnackBar} from '@angular/material/snack-bar';
import {FormBuilder, FormGroup, Validators, NgForm} from '@angular/forms';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
import {DatePipe} from '@angular/common';
import {FormControl} from '@angular/forms';
import {debounceTime} from 'rxjs/operators';
import {PageEvent} from '@angular/material/paginator';
import {ParteyTimeslotsService} from '../../../services/partey.timeslots.service';
import {ConfirmDialog} from '../../../ui/confirm/confirm.component';
import {I18nService} from './../../../services/i18n.service';
@Component({
selector: 'app-partey-timeslots',
templateUrl: './timeslots.component.html',
styleUrls: ['./timeslots.component.scss']
})
export class ParteyTimeslotsComponent implements OnInit {
form: FormGroup;
@ViewChild('formDirective') private formDirective: NgForm;
timeslotsQuota: number = 0;
timeslots: any;
timeslot: any = {};
success: boolean;
working: boolean;
datetimeformat: string;
page: any = {page: 0, size: 10, sort: "id", desc: false};
filter: any = {};
pageSizeOptions: number[] = [5, 10, 25, 50];
visibilities = ["PRIVATE", "PROTECTED", "PUBLIC"];
types = ["VIDEO", "AUDIO"];
timeslotsColumns = ["type", "starts", "ends", "title", "description", "stream", "edit", "delete"];
searchFormControl = new FormControl();
ownerFormControl = new FormControl();
afterFormControl = new FormControl();
typeFormControl = new FormControl();
constructor(
private formBuilder: FormBuilder,
private parteyTimeslotsService: ParteyTimeslotsService,
private i18n: I18nService,
private datePipe: DatePipe,
private snackBar: MatSnackBar,
public dialog: MatDialog) {}
ngOnInit(): void {
this.datetimeformat = this.i18n.get('format.datetime', []);
this.form = this.formBuilder.group({
room: ['', Validators.required],
starts: ['', Validators.nullValidator],
moderationStarts: ['', Validators.nullValidator],
expires: ['', Validators.nullValidator],
});
this.filter.owner = "";
this.ownerFormControl.setValue("");
this.filter.type = "";
this.typeFormControl.setValue("");
this.filter.after = new Date().toUTCString();
this.afterFormControl.setValue(new Date());
this.searchFormControl.valueChanges.pipe(debounceTime(500)).subscribe(value => {
this.filter.search = value;
this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe((data: any) => {
this.timeslots = data;
}, (error) => {})
})
this.ownerFormControl.valueChanges.subscribe(value => {
this.filter.owner = value;
this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe((data: any) => {
this.timeslots = data;
}, (error) => {})
})
this.typeFormControl.valueChanges.subscribe(value => {
this.filter.type = value;
this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe((data: any) => {
this.timeslots = data;
}, (error) => {})
})
this.afterFormControl.valueChanges.subscribe((value: Date) => {
this.filter.after = value && value.toUTCString() || undefined;
this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe((data: any) => {
this.timeslots = data;
}, (error) => {})
})
this.refresh();
}
refresh() {
this.timeslotsQuota = 0;
this.parteyTimeslotsService.quota().subscribe((data: number) => {
this.timeslotsQuota = data;
})
this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe((data: any) => {
this.timeslots = data;
})
}
updatePages(event: PageEvent) {
this.page.page = event.pageIndex;
this.page.size = event.pageSize;
this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe((data: any) => {
this.timeslots = data;
}, (error) => {})
}
updateSort(sort: Sort) {
if(sort.direction == "") {
this.page.sort = "id";
this.page.desc = false;
} else {
this.page.sort = sort.active;
this.page.desc = sort.direction == "desc";
}
this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe((data: any) => {
this.timeslots = data;
}, (error) => {})
}
confirmDelete(timeslot) {
const dialogRef = this.dialog.open(ConfirmDialog, {
data: {
'label': 'partey.timeslots.confirmDelete',
'args': [timeslot.title, this.datePipe.transform(new Date(timeslot.starts), this.datetimeformat)]
}
})
dialogRef.afterClosed().subscribe(result => {
if(result) {
this.parteyTimeslotsService.delete(timeslot.id).subscribe((result: any) => {
this.refresh();
})
}
});
}
openCreate(type) {
const dialogRef = this.dialog.open(ParteyTimeslotDialog, {
data: {"type": type ? type : "VIDEO", "visibility": "PROTECTED"},
minWidth: '400px'
});
dialogRef.afterClosed().subscribe(result => {
if(result) {
this.refresh();
}
});
}
openEdit(timeslot) {
const timeslotClone = JSON.parse(JSON.stringify(timeslot));
const dialogRef = this.dialog.open(ParteyTimeslotDialog, {
data: timeslotClone,
minWidth: '400px'
});
dialogRef.afterClosed().subscribe(result => {
if(result) {
this.refresh();
}
});
}
copySecretToClipboard(secret) {
const selBox = document.createElement('textarea');
selBox.value = secret;
document.body.appendChild(selBox);
selBox.focus();
selBox.select();
document.execCommand('copy');
document.body.removeChild(selBox);
this.snackBar.open(this.i18n.get("partey.timeslots.secret.copied", []), this.i18n.get("close", []), {
duration: 3000
});
}
}
@Component({
selector: 'app-timeslot-dialog',
templateUrl: 'timeslot.dialog.html',
styleUrls: ['./timeslot.dialog.scss']
})
export class ParteyTimeslotDialog {
form: FormGroup;
timeslot;
visibilities = ["PRIVATE", "PROTECTED", "PUBLIC"];
types = ["VIDEO", "AUDIO"];
constructor(
private parteyTimeslotsService: ParteyTimeslotsService,
private formBuilder: FormBuilder,
private dialog: MatDialog,
public dialogRef: MatDialogRef<ParteyTimeslotDialog>,
@Inject(MAT_DIALOG_DATA) public data: any) {
this.timeslot = data;
}
ngOnInit() {
this.form = this.formBuilder.group({
starts: ['', Validators.required],
ends: ['', Validators.required],
title: ['', Validators.nullValidator],
description: ['', Validators.nullValidator],
stream: ['', this.timeslot.type == 'VIDEO' ? Validators.required : Validators.nullValidator],
});
}
create(timeslot) {
this.parteyTimeslotsService.create(timeslot).subscribe((result: any) => {
this.dialogRef.close(timeslot);
}, (error) => {
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]);
}
}
});
}
save(timeslot) {
this.parteyTimeslotsService.update(timeslot).subscribe((result: any) => {
this.dialogRef.close(timeslot);
}, (error) => {
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]);
}
}
});
}
}