add admin interface, angular migration
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { I18nService } from './../../../services/i18n.service';
|
||||
import { JukeboxManagementService } from '../../../services/admin/jukebox.management.service';
|
||||
import { ConfirmDialog } from './../../../ui/confirm/confirm.component';
|
||||
|
||||
@Component({
|
||||
standalone: false,
|
||||
selector: 'app-admin-jukebox',
|
||||
templateUrl: './jukebox.component.html',
|
||||
styleUrls: ['../admin.scss']
|
||||
})
|
||||
export class AdminJukeboxComponent implements OnInit {
|
||||
|
||||
configForm: FormGroup;
|
||||
config: any = null;
|
||||
status: any = null;
|
||||
loading: boolean = false;
|
||||
|
||||
constructor(
|
||||
private jukeboxManagementService: JukeboxManagementService,
|
||||
private i18n: I18nService,
|
||||
private formBuilder: FormBuilder,
|
||||
public dialog: MatDialog
|
||||
) {
|
||||
this.configForm = this.formBuilder.group({
|
||||
active: [false],
|
||||
autoplay: [false],
|
||||
channel: ['', Validators.required],
|
||||
maxQueueSize: [10, [Validators.required, Validators.min(1)]],
|
||||
maxSearchResults: [10, [Validators.required, Validators.min(1)]]
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadConfig();
|
||||
this.loadStatus();
|
||||
}
|
||||
|
||||
loadConfig(): void {
|
||||
this.loading = true;
|
||||
this.jukeboxManagementService.getConfig().subscribe({
|
||||
next: (data: any) => {
|
||||
this.config = data;
|
||||
this.configForm.patchValue(data);
|
||||
this.loading = false;
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error loading jukebox config:', error);
|
||||
this.loading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
loadStatus(): void {
|
||||
this.jukeboxManagementService.getStatus().subscribe({
|
||||
next: (data: any) => {
|
||||
this.status = data;
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error loading jukebox status:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
saveConfig(): void {
|
||||
if (this.configForm.invalid) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.loading = true;
|
||||
this.jukeboxManagementService.setConfig(this.configForm.value).subscribe({
|
||||
next: (data: any) => {
|
||||
this.config = data;
|
||||
this.loading = false;
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error saving jukebox config:', error);
|
||||
this.loading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleActive(): void {
|
||||
if (this.config?.active) {
|
||||
this.disable();
|
||||
} else {
|
||||
this.activate();
|
||||
}
|
||||
}
|
||||
|
||||
activate(): void {
|
||||
this.jukeboxManagementService.setActive().subscribe({
|
||||
next: () => {
|
||||
this.loadConfig();
|
||||
this.loadStatus();
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error activating jukebox:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
disable(): void {
|
||||
this.jukeboxManagementService.disable().subscribe({
|
||||
next: () => {
|
||||
this.loadConfig();
|
||||
this.loadStatus();
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error disabling jukebox:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user