diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs index 14d781064..d73e8550d 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs @@ -51,15 +51,13 @@ namespace Ombi.Schedule.Jobs.Plex public class PlexContentSync : IPlexContentSync { public PlexContentSync(ISettingsService plex, IPlexApi plexApi, ILogger logger, IPlexContentRepository repo, - IPlexEpisodeSync epsiodeSync, IRefreshMetadata metadataRefresh, IPlexAvailabilityChecker checker, IHubContext hub) + IPlexEpisodeSync epsiodeSync, IHubContext hub) { Plex = plex; PlexApi = plexApi; Logger = logger; Repo = repo; EpisodeSync = epsiodeSync; - Metadata = metadataRefresh; - Checker = checker; Notification = hub; Plex.ClearCache(); } @@ -69,8 +67,6 @@ namespace Ombi.Schedule.Jobs.Plex private ILogger Logger { get; } private IPlexContentRepository Repo { get; } private IPlexEpisodeSync EpisodeSync { get; } - private IRefreshMetadata Metadata { get; } - private IPlexAvailabilityChecker Checker { get; } private IHubContext Notification { get; set; } public async Task Execute(IJobExecutionContext context) diff --git a/src/Ombi/ClientApp/src/app/interfaces/IHub.ts b/src/Ombi/ClientApp/src/app/interfaces/IHub.ts new file mode 100644 index 000000000..d0673ed0d --- /dev/null +++ b/src/Ombi/ClientApp/src/app/interfaces/IHub.ts @@ -0,0 +1,7 @@ +import { UserType } from "./IUser"; + +export interface IConnectedUser { + userId: string; + displayName: string; + userType: UserType +} \ No newline at end of file diff --git a/src/Ombi/ClientApp/src/app/interfaces/index.ts b/src/Ombi/ClientApp/src/app/interfaces/index.ts index e1cf823e8..25e73355d 100644 --- a/src/Ombi/ClientApp/src/app/interfaces/index.ts +++ b/src/Ombi/ClientApp/src/app/interfaces/index.ts @@ -18,3 +18,4 @@ export * from "./ILidarr"; export * from "./ISearchMusicResult"; export * from "./IVote"; export * from "./IFailedRequests"; +export * from "./IHub"; diff --git a/src/Ombi/ClientApp/src/app/services/hub.service.ts b/src/Ombi/ClientApp/src/app/services/hub.service.ts new file mode 100644 index 000000000..6df2cc271 --- /dev/null +++ b/src/Ombi/ClientApp/src/app/services/hub.service.ts @@ -0,0 +1,19 @@ +import { APP_BASE_HREF } from "@angular/common"; +import { Injectable, Inject } from "@angular/core"; +import { Observable } from "rxjs"; + +import { HttpClient } from "@angular/common/http"; + +import { IConnectedUser } from "../interfaces"; +import { ServiceHelpers } from "./service.helpers"; + +@Injectable() +export class HubService extends ServiceHelpers { + constructor(public http: HttpClient, @Inject(APP_BASE_HREF) href:string) { + super(http, "/api/v2/hub/", href); + } + + public getConnectedUsers(): Promise { + return this.http.get(`${this.url}users`, {headers: this.headers}).toPromise(); + } +} diff --git a/src/Ombi/ClientApp/src/app/services/index.ts b/src/Ombi/ClientApp/src/app/services/index.ts index 911f41910..7cc93827a 100644 --- a/src/Ombi/ClientApp/src/app/services/index.ts +++ b/src/Ombi/ClientApp/src/app/services/index.ts @@ -19,3 +19,4 @@ export * from "./requestretry.service"; export * from "./searchV2.service"; export * from "./custompage.service"; export * from "./message.service"; +export * from "./hub.service"; diff --git a/src/Ombi/ClientApp/src/app/settings/about/about.component.html b/src/Ombi/ClientApp/src/app/settings/about/about.component.html index 195e59bcc..ca57adf14 100644 --- a/src/Ombi/ClientApp/src/app/settings/about/about.component.html +++ b/src/Ombi/ClientApp/src/app/settings/about/about.component.html @@ -1,106 +1,71 @@ - - +
-
- About -
-
- - - - - - - - - - - - - - - - - - - - + About - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Version - - {{about.version}} (New Update Available) -
- Branch - - {{about.branch}} -
- Github - - https://github.com/tidusjar/Ombi -
- Discord - - https://discord.gg/Sa7wNWb -
- Reddit - - https://www.reddit.com/r/Ombi/ -
- Issues - - https://github.com/tidusjar/Ombi/issues -
- Wiki - - https://github.com/tidusjar/Ombi/wiki -
- OS Architecture - - {{about.osArchitecture}} -
- OS Description - - {{about.osDescription}} -
- Process Architecture - - {{about.processArchitecture}} -
- Application Base Path - - {{about.applicationBasePath}} -
-
-
-
+
+
+
Users Online
+
{{connectedUsers.length}}
+
+
+
Version
+
{{about.version}} (New Update Available)
+
+ +
+
Branch
+
{{about.branch}}
+
+ + + + + + + + + + + +
+
OS Architecture
+
{{about.osArchitecture}}
+
+ +
+
OS Description
+
{{about.osDescription}}
+
+ +
+
Process Architecture
+
{{about.processArchitecture}}
+
+ +
+
Application Base Path
+
{{about.applicationBasePath}}
+
+ +
diff --git a/src/Ombi/ClientApp/src/app/settings/about/about.component.scss b/src/Ombi/ClientApp/src/app/settings/about/about.component.scss new file mode 100644 index 000000000..c99e10bc3 --- /dev/null +++ b/src/Ombi/ClientApp/src/app/settings/about/about.component.scss @@ -0,0 +1,20 @@ +.mat-table { + display: block; + } + + .mat-row, + .mat-header-row { + display: flex; + border-bottom-width: 1px; + border-bottom-style: solid; + align-items: center; + min-height: 48px; + padding: 0 24px; + } + + .mat-cell, + .mat-header-cell { + flex: 1; + overflow: hidden; + word-wrap: break-word; + } \ No newline at end of file diff --git a/src/Ombi/ClientApp/src/app/settings/about/about.component.ts b/src/Ombi/ClientApp/src/app/settings/about/about.component.ts index af75a8bf1..a9a761c84 100644 --- a/src/Ombi/ClientApp/src/app/settings/about/about.component.ts +++ b/src/Ombi/ClientApp/src/app/settings/about/about.component.ts @@ -1,19 +1,23 @@ import { Component, OnInit } from "@angular/core"; import { IAbout } from "../../interfaces/ISettings"; -import { JobService, SettingsService } from "../../services"; +import { JobService, SettingsService, HubService } from "../../services"; +import { IConnectedUser } from "../../interfaces"; @Component({ templateUrl: "./about.component.html", + styleUrls: ["./about.component.scss"] }) export class AboutComponent implements OnInit { public about: IAbout; public newUpdate: boolean; + public connectedUsers: IConnectedUser[]; constructor(private readonly settingsService: SettingsService, - private readonly jobService: JobService) { } + private readonly jobService: JobService, + private readonly hubService: HubService) { } - public ngOnInit() { + public async ngOnInit() { this.settingsService.about().subscribe(x => this.about = x); this.jobService.getCachedUpdate().subscribe(x => { if (x === true) { @@ -21,5 +25,6 @@ export class AboutComponent implements OnInit { } }); + this.connectedUsers = await this.hubService.getConnectedUsers(); } } diff --git a/src/Ombi/ClientApp/src/app/settings/settings.module.ts b/src/Ombi/ClientApp/src/app/settings/settings.module.ts index 514bfd91b..0c8b7cd45 100644 --- a/src/Ombi/ClientApp/src/app/settings/settings.module.ts +++ b/src/Ombi/ClientApp/src/app/settings/settings.module.ts @@ -51,6 +51,7 @@ import { SettingsMenuComponent } from "./settingsmenu.component"; import { AutoCompleteModule, CalendarModule, DialogModule, InputSwitchModule, InputTextModule, MenuModule, RadioButtonModule, TooltipModule } from "primeng/primeng"; import { MatMenuModule} from "@angular/material"; import { SharedModule } from "../shared/shared.module"; +import { HubService } from "../services/hub.service"; const routes: Routes = [ { path: "Ombi", component: OmbiComponent, canActivate: [AuthGuard] }, @@ -160,6 +161,7 @@ const routes: Routes = [ NotificationMessageService, LidarrService, RequestRetryService, + HubService, ], }) diff --git a/src/Ombi/Controllers/V2/HubController.cs b/src/Ombi/Controllers/V2/HubController.cs index 8fb5f864b..9b6c5fc34 100644 --- a/src/Ombi/Controllers/V2/HubController.cs +++ b/src/Ombi/Controllers/V2/HubController.cs @@ -1,53 +1,56 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; +using System; +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; -using Ombi.Api.TheMovieDb.Models; -using Ombi.Core.Engine.V2; using System.Collections.Generic; -using System.Linq; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.SignalR; -using Ombi.Core; -using Ombi.Core.Engine.Interfaces; -using Ombi.Core.Models.Search; -using Ombi.Core.Models.Search.V2; -using Ombi.Helpers; +using Microsoft.EntityFrameworkCore; +using Ombi.Attributes; +using Ombi.Core.Authentication; using Ombi.Hubs; using Ombi.Models; namespace Ombi.Controllers.V2 { [ApiV2] - [Authorize] + [Admin] [ApiController] public class HubController : ControllerBase { - public HubController(IHubContext hub) + public HubController(OmbiUserManager um) { - _hub = hub; + _um = um; } - private readonly IHubContext _hub; + private readonly OmbiUserManager _um; /// - /// Returns search results for both TV and Movies + /// Returns the currently connected users in Ombi /// /// - [HttpGet("{searchTerm}")] - public async Task MultiSearch(string searchTerm) + [HttpGet("Users")] + public async Task> GetConnectedUsers() { - await _hub.Clients.All.SendAsync("Notification", searchTerm); - } + var users = NotificationHub.UsersOnline.Values; + var allUsers = _um.Users; + var model = new List(); + foreach (var user in users) + { + var ombiUser = await allUsers.FirstOrDefaultAsync(x => x.Id.Equals(user.UserId, StringComparison.InvariantCultureIgnoreCase)); - /// - /// Returns search results for both TV and Movies - /// - /// - [HttpGet("admin/{searchTerm}")] - public async Task Admin(string searchTerm) - { - var admins = NotificationHub.UsersOnline.Where(x => x.Value.Roles.Contains(OmbiRoles.Admin)).Select(x => x.Key).ToList(); - await _hub.Clients.Clients(admins).SendAsync("Notification", searchTerm); + if (ombiUser == null) + { + continue; + } + + model.Add(new ConnectedUsersViewModel + { + UserId = ombiUser.Id, + DisplayName = ombiUser.UserAlias, + UserType = ombiUser.UserType + }); + } + + return model; } } } \ No newline at end of file diff --git a/src/Ombi/Models/ConnectedUsersViewModel.cs b/src/Ombi/Models/ConnectedUsersViewModel.cs new file mode 100644 index 000000000..68f855379 --- /dev/null +++ b/src/Ombi/Models/ConnectedUsersViewModel.cs @@ -0,0 +1,12 @@ + +using Ombi.Store.Entities; + +namespace Ombi.Models +{ + public class ConnectedUsersViewModel + { + public string UserId { get; set; } + public string DisplayName { get; set; } + public UserType UserType { get; set; } + } +} \ No newline at end of file