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.
143 lines
5.3 KiB
143 lines
5.3 KiB
import { OverlayContainer } from '@angular/cdk/overlay';
|
|
|
|
import { Component, OnInit, HostBinding } from "@angular/core";
|
|
import { NavigationStart, Router } from "@angular/router";
|
|
import { TranslateService } from "@ngx-translate/core";
|
|
import { AuthService } from "./auth/auth.service";
|
|
import { ILocalUser } from "./auth/IUserLogin";
|
|
import { IdentityService, NotificationService, CustomPageService } from "./services";
|
|
import { JobService, SettingsService } from "./services";
|
|
|
|
import { ICustomizationSettings, ICustomPage } from "./interfaces";
|
|
|
|
@Component({
|
|
selector: "app-ombi",
|
|
templateUrl: "./app.component.html",
|
|
styleUrls: ["./app.component.scss"],
|
|
})
|
|
export class AppComponent implements OnInit {
|
|
|
|
public customizationSettings: ICustomizationSettings;
|
|
public customPageSettings: ICustomPage;
|
|
public issuesEnabled = false;
|
|
public user: ILocalUser;
|
|
public showNav: boolean;
|
|
public updateAvailable: boolean;
|
|
public currentUrl: string;
|
|
public userAccessToken: string;
|
|
public voteEnabled = false;
|
|
public applicationName: string = "Ombi"
|
|
public isAdmin: boolean;
|
|
|
|
private checkedForUpdate: boolean;
|
|
|
|
|
|
@HostBinding('class') public componentCssClass;
|
|
|
|
constructor(public notificationService: NotificationService,
|
|
public authService: AuthService,
|
|
private readonly router: Router,
|
|
private readonly settingsService: SettingsService,
|
|
private readonly jobService: JobService,
|
|
public readonly translate: TranslateService,
|
|
private readonly identityService: IdentityService,
|
|
private readonly customPageService: CustomPageService,
|
|
public overlayContainer: OverlayContainer) {
|
|
|
|
// const base = this.platformLocation.getBaseHrefFromDOM();
|
|
// if (base.length > 1) {
|
|
// __webpack_public_path__ = base + "/dist/";
|
|
// }
|
|
|
|
this.translate.addLangs(["en", "de", "fr", "da", "es", "it", "nl", "sv", "no", "pl", "pt"]);
|
|
// this language will be used as a fallback when a translation isn't found in the current language
|
|
this.translate.setDefaultLang("en");
|
|
|
|
// See if we can match the supported langs with the current browser lang
|
|
const browserLang: string = translate.getBrowserLang();
|
|
this.translate.use(browserLang.match(/en|fr|da|de|es|it|nl|sv|no|pl|pt/) ? browserLang : "en");
|
|
}
|
|
|
|
public ngOnInit() {
|
|
const theme = localStorage.getItem("theme");
|
|
this.onSetTheme(theme);
|
|
this.user = this.authService.claims();
|
|
this.isAdmin = this.authService.hasRole("admin");
|
|
|
|
this.settingsService.getCustomization().subscribe(x => {
|
|
this.customizationSettings = x;
|
|
|
|
if (this.customizationSettings && this.customizationSettings.applicationName) {
|
|
this.applicationName = this.customizationSettings.applicationName;
|
|
}
|
|
|
|
if (this.customizationSettings.useCustomPage) {
|
|
this.customPageService.getCustomPage().subscribe(c => {
|
|
this.customPageSettings = c;
|
|
if (!this.customPageSettings.title) {
|
|
this.customPageSettings.title = "Custom Page";
|
|
this.customPageSettings.fontAwesomeIcon = "fa-check";
|
|
}
|
|
});
|
|
}
|
|
});
|
|
this.settingsService.issueEnabled().subscribe(x => this.issuesEnabled = x);
|
|
this.settingsService.voteEnabled().subscribe(x => this.voteEnabled = x);
|
|
|
|
this.router.events.subscribe((event: NavigationStart) => {
|
|
this.currentUrl = event.url;
|
|
if (event instanceof NavigationStart) {
|
|
this.user = this.authService.claims();
|
|
this.showNav = this.authService.loggedIn();
|
|
|
|
// tslint:disable-next-line:no-string-literal
|
|
if (this.user !== null && this.user.name && !this.checkedForUpdate && this.user.roles["Admin"]) {
|
|
this.checkedForUpdate = true;
|
|
this.jobService.getCachedUpdate().subscribe(x => {
|
|
this.updateAvailable = x;
|
|
},
|
|
err => this.checkedForUpdate = true);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public roleClass() {
|
|
if (this.user.roles.some(r => r === "Admin")) {
|
|
return "adminUser";
|
|
} else if (this.user.roles.some(r => r === "PowerUser")) {
|
|
return "powerUser";
|
|
}
|
|
return "user";
|
|
}
|
|
|
|
public hasRole(role: string): boolean {
|
|
return this.user.roles.some(r => r === role);
|
|
}
|
|
|
|
public openMobileApp(event: any) {
|
|
event.preventDefault();
|
|
if (!this.customizationSettings.applicationUrl) {
|
|
this.notificationService.warning("Mobile", "Please ask your admin to setup the Application URL!");
|
|
return;
|
|
}
|
|
|
|
this.identityService.getAccessToken().subscribe(x => {
|
|
const url = `ombi://${this.customizationSettings.applicationUrl}_${x}`;
|
|
window.location.assign(url);
|
|
});
|
|
}
|
|
|
|
public logOut() {
|
|
this.authService.logout();
|
|
this.router.navigate(["login"]);
|
|
}
|
|
|
|
public onSetTheme(theme: string) {
|
|
if (theme) {
|
|
this.overlayContainer.getContainerElement().classList.add(theme);
|
|
this.componentCssClass = theme;
|
|
}
|
|
}
|
|
}
|