mirror of https://github.com/Ombi-app/Ombi
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.8 KiB
49 lines
1.8 KiB
import { Component, OnInit, SecurityContext } from "@angular/core";
|
|
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
|
|
import { DomSanitizer } from "@angular/platform-browser";
|
|
import { AuthService } from "../auth/auth.service";
|
|
import { CustomPageService, NotificationService } from "../services";
|
|
|
|
@Component({
|
|
templateUrl: "./custompage.component.html",
|
|
styleUrls: ["./custompage.component.scss"],
|
|
})
|
|
export class CustomPageComponent implements OnInit {
|
|
|
|
public form: FormGroup;
|
|
public isEditing: boolean;
|
|
public isAdmin: boolean;
|
|
|
|
constructor(private auth: AuthService, private settings: CustomPageService, private fb: FormBuilder,
|
|
private notificationService: NotificationService,
|
|
private sanitizer: DomSanitizer) {
|
|
}
|
|
|
|
public ngOnInit() {
|
|
this.settings.getCustomPage().subscribe(x => {
|
|
x.html = this.sanitizer.sanitize(SecurityContext.HTML, this.sanitizer.bypassSecurityTrustHtml(x.html));
|
|
this.form = this.fb.group({
|
|
enabled: [x.enabled],
|
|
title: [x.title, [Validators.required]],
|
|
html: [x.html, [Validators.required]],
|
|
fontAwesomeIcon: [x.fontAwesomeIcon, [Validators.required]],
|
|
});
|
|
});
|
|
this.isAdmin = this.auth.hasRole("EditCustomPage");
|
|
}
|
|
|
|
public onSubmit() {
|
|
if (this.form.invalid) {
|
|
this.notificationService.error("Please check your entered values");
|
|
return;
|
|
}
|
|
this.settings.saveCustomPage(this.form.value).subscribe(x => {
|
|
if (x) {
|
|
this.notificationService.success("Successfully saved Custom Page settings");
|
|
} else {
|
|
this.notificationService.success("There was an error when saving the Custom Page settings");
|
|
}
|
|
});
|
|
}
|
|
}
|