diff --git a/src/Ombi.Api.Discord/DiscordApi.cs b/src/Ombi.Api.Discord/DiscordApi.cs index 122c51a87..86ecb00a0 100644 --- a/src/Ombi.Api.Discord/DiscordApi.cs +++ b/src/Ombi.Api.Discord/DiscordApi.cs @@ -14,12 +14,12 @@ namespace Ombi.Api.Discord Api = api; } - private const string BaseUrl = "https://discordapp.com/api/"; + private const string _baseUrl = "https://discordapp.com/api/"; private IApi Api { get; } public async Task SendMessage(DiscordWebhookBody body, string webhookId, string webhookToken) { - var request = new Request($"webhooks/{webhookId}/{webhookToken}", BaseUrl, HttpMethod.Post); + var request = new Request($"webhooks/{webhookId}/{webhookToken}", _baseUrl, HttpMethod.Post); request.AddJsonBody(body); diff --git a/src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs b/src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs index 0de749308..2bda53875 100644 --- a/src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs +++ b/src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs @@ -67,11 +67,9 @@ namespace Ombi.Schedule.Jobs.Sonarr var strat = _ctx.Database.CreateExecutionStrategy(); await strat.ExecuteAsync(async () => { - using (var tran = await _ctx.Database.BeginTransactionAsync()) - { - await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SonarrCache"); - tran.Commit(); - } + using var tran = await _ctx.Database.BeginTransactionAsync(); + await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SonarrCache"); + tran.Commit(); }); var sonarrCacheToSave = new HashSet(); @@ -97,11 +95,9 @@ namespace Ombi.Schedule.Jobs.Sonarr strat = _ctx.Database.CreateExecutionStrategy(); await strat.ExecuteAsync(async () => { - using (var tran = await _ctx.Database.BeginTransactionAsync()) - { - await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SonarrEpisodeCache"); - tran.Commit(); - } + using var tran = await _ctx.Database.BeginTransactionAsync(); + await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SonarrEpisodeCache"); + tran.Commit(); }); foreach (var s in ids) @@ -111,7 +107,7 @@ namespace Ombi.Schedule.Jobs.Sonarr continue; } - _log.LogDebug("Syncing series: {0}", s.Title); + _log.LogDebug($"Syncing series: {s.Title}"); var episodes = await _api.GetEpisodes(s.Id, settings.ApiKey, settings.FullUri); var monitoredEpisodes = episodes.Where(x => x.monitored || x.hasFile); @@ -156,13 +152,11 @@ namespace Ombi.Schedule.Jobs.Sonarr strat = _ctx.Database.CreateExecutionStrategy(); await strat.ExecuteAsync(async () => { - using (var tran = await _ctx.Database.BeginTransactionAsync()) - { - await _ctx.SonarrEpisodeCache.AddRangeAsync(episodesToAdd); - _log.LogDebug("Commiting the transaction"); - await _ctx.SaveChangesAsync(); - tran.Commit(); - } + using var tran = await _ctx.Database.BeginTransactionAsync(); + await _ctx.SonarrEpisodeCache.AddRangeAsync(episodesToAdd); + _log.LogDebug("Commiting the transaction"); + await _ctx.SaveChangesAsync(); + tran.Commit(); }); } diff --git a/src/Ombi/ClientApp/src/app/settings/plex/components/models/PlexSyncType.ts b/src/Ombi/ClientApp/src/app/settings/plex/components/models/PlexSyncType.ts new file mode 100644 index 000000000..2e3005d0d --- /dev/null +++ b/src/Ombi/ClientApp/src/app/settings/plex/components/models/PlexSyncType.ts @@ -0,0 +1,6 @@ +export enum PlexSyncType { + Full = 0, + RecentlyAdded = 1, + ClearAndReSync = 2, + WatchlistImport = 3, +} \ No newline at end of file diff --git a/src/Ombi/ClientApp/src/app/settings/plex/components/models/index.ts b/src/Ombi/ClientApp/src/app/settings/plex/components/models/index.ts new file mode 100644 index 000000000..0b787b38d --- /dev/null +++ b/src/Ombi/ClientApp/src/app/settings/plex/components/models/index.ts @@ -0,0 +1 @@ +export * from './PlexSyncType'; \ No newline at end of file diff --git a/src/Ombi/ClientApp/src/app/settings/plex/components/plex-form/plex-form.component.scss b/src/Ombi/ClientApp/src/app/settings/plex/components/plex-form/plex-form.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/Ombi/ClientApp/src/app/settings/plex/components/plex-form/plex-form.component.stories.ts b/src/Ombi/ClientApp/src/app/settings/plex/components/plex-form/plex-form.component.stories.ts new file mode 100644 index 000000000..e7e3af237 --- /dev/null +++ b/src/Ombi/ClientApp/src/app/settings/plex/components/plex-form/plex-form.component.stories.ts @@ -0,0 +1,37 @@ +// also exported from '@storybook/angular' if you can deal with breaking changes in 6.1 +import { APP_BASE_HREF, CommonModule } from '@angular/common'; +import { Story, Meta, moduleMetadata } from '@storybook/angular'; +import { SharedModule } from '../../../../shared/shared.module'; +import { PlexFormComponent } from './plex-form.component'; + + + +// More on default export: https://storybook.js.org/docs/angular/writing-stories/introduction#default-export +export default { + title: 'Plex Form Component', + component: PlexFormComponent, + decorators: [ + moduleMetadata({ + providers: [ + { + provide: APP_BASE_HREF, + useValue: "" + }, + ], + imports: [ + CommonModule, + SharedModule + ] + }) + ] +} as Meta; + +// More on component templates: https://storybook.js.org/docs/angular/writing-stories/introduction#using-args +const Template: Story = (args: PlexFormComponent) => ({ + props: args, +}); + +export const Default = Template.bind({}); +Default.args = { +}; + diff --git a/src/Ombi/ClientApp/src/app/settings/plex/components/plex-form/plex-form.component.ts b/src/Ombi/ClientApp/src/app/settings/plex/components/plex-form/plex-form.component.ts new file mode 100644 index 000000000..b9e8c7edc --- /dev/null +++ b/src/Ombi/ClientApp/src/app/settings/plex/components/plex-form/plex-form.component.ts @@ -0,0 +1,25 @@ +import { Component, EventEmitter, Input, Output } from "@angular/core"; +import { IPlexServer, IPlexServerResponse, IPlexServerViewModel } from "app/interfaces"; +import { PlexSyncType } from "../models"; + +@Component({ + templateUrl: "./plex-form.component.html", + styleUrls: ["./plex-form.component.scss"], + selector: "settings-plex-form" +}) +export class PlexFormComponent { + + @Input() public server: IPlexServer; + @Input() public advancedEnabled: boolean = false; + @Input() public loadedServers: IPlexServerViewModel; + + @Output() public loadLibraries = new EventEmitter(); + @Output() public loadServers = new EventEmitter(); + @Output() public selectServer = new EventEmitter(); + @Output() public test = new EventEmitter(); + @Output() public runSync = new EventEmitter(); + + public username: string; + public password: string; + public PlexSyncType = PlexSyncType; +} diff --git a/src/Ombi/ClientApp/src/app/settings/plex/plex.component.html b/src/Ombi/ClientApp/src/app/settings/plex/plex.component.html index 63a6140a9..0c50d6ea5 100644 --- a/src/Ombi/ClientApp/src/app/settings/plex/plex.component.html +++ b/src/Ombi/ClientApp/src/app/settings/plex/plex.component.html @@ -26,182 +26,31 @@ + +
+
+


-
- - -
- - Server Name - - -
-
- - Hostname or IP - - + + - - Port - - - - - SSL - -
-
- - Plex Authorization Token - - - - - Machine Identifier - - -
-
- - Externally Facing Hostname - - - - Current URL: "{{server.serverHostname}}/web/app#!/server/{{server.machineIdentifier}}/details?key=%2flibrary%2Fmetadata%2F53334" - Current URL: "https://app.plex.tv/web/app#!/server/{{server.machineIdentifier}}/details?key=%2flibrary%2Fmetadata%2F53334" - -
-
-
- - Episode Batch Size - - -
-
-
- -
-
-
- - Server - - - {{s.name}} - - -
-
-
- -
- Note: if nothing is selected, we will monitor all libraries -
-
- -
-
-
-
-
-
-
- {{lib.title}} -
-
-
-
-
-
-
- -
- - Username - - -
-
- - Password - - -
-
-
-
- -
-
-
- -
-
- -
-
-
-
-
- -
-
- -
-
- -
-
-
diff --git a/src/Ombi/ClientApp/src/app/settings/plex/plex.component.ts b/src/Ombi/ClientApp/src/app/settings/plex/plex.component.ts index 086bc3d15..f466f4a6e 100644 --- a/src/Ombi/ClientApp/src/app/settings/plex/plex.component.ts +++ b/src/Ombi/ClientApp/src/app/settings/plex/plex.component.ts @@ -8,6 +8,7 @@ import { MatTabChangeEvent, MatTabGroup } from "@angular/material/tabs"; import {UntypedFormControl} from '@angular/forms'; import { MatDialog } from "@angular/material/dialog"; import { PlexWatchlistComponent } from "./components/watchlist/plex-watchlist.component"; +import { PlexSyncType } from "./components/models"; @Component({ templateUrl: "./plex.component.html", @@ -40,7 +41,7 @@ export class PlexComponent implements OnInit, OnDestroy { }); } - public requestServers(server: IPlexServer) { + public requestServers() { this.plexService.getServers(this.username, this.password).pipe( takeUntil(this.subscriptions), ).subscribe(x => { @@ -151,7 +152,24 @@ export class PlexComponent implements OnInit, OnDestroy { }); } - public runCacher(): void { + public runSync(type: PlexSyncType) { + switch (type) { + case PlexSyncType.Full: + this.runCacher(); + return; + case PlexSyncType.RecentlyAdded: + this.runRecentlyAddedCacher(); + return; + case PlexSyncType.ClearAndReSync: + this.clearDataAndResync(); + return; + case PlexSyncType.WatchlistImport: + this.runWatchlistImport(); + return; + } + } + + private runCacher(): void { this.jobService.runPlexCacher().subscribe(x => { if (x) { this.notificationService.success("Triggered the Plex Full Sync"); @@ -159,7 +177,7 @@ export class PlexComponent implements OnInit, OnDestroy { }); } - public runRecentlyAddedCacher(): void { + private runRecentlyAddedCacher(): void { this.jobService.runPlexRecentlyAddedCacher().subscribe(x => { if (x) { this.notificationService.success("Triggered the Plex Recently Added Sync"); @@ -167,7 +185,7 @@ export class PlexComponent implements OnInit, OnDestroy { }); } - public clearDataAndResync(): void { + private clearDataAndResync(): void { this.jobService.clearMediaserverData().subscribe(x => { if (x) { this.notificationService.success("Triggered the Clear MediaServer Resync"); @@ -175,7 +193,7 @@ export class PlexComponent implements OnInit, OnDestroy { }); } - public runWatchlistImport(): void { + private runWatchlistImport(): void { this.jobService.runPlexWatchlistImport().subscribe(x => { if (x) { this.notificationService.success("Triggered the Watchlist Import"); diff --git a/src/Ombi/ClientApp/src/app/settings/settings.module.ts b/src/Ombi/ClientApp/src/app/settings/settings.module.ts index f153be982..b872b53ee 100644 --- a/src/Ombi/ClientApp/src/app/settings/settings.module.ts +++ b/src/Ombi/ClientApp/src/app/settings/settings.module.ts @@ -84,6 +84,7 @@ import { WebhookComponent } from "./notifications/webhook.component"; import { WhatsAppComponent } from "./notifications/twilio/whatsapp.component"; import { WikiComponent } from "./wiki.component"; import { PlexWatchlistComponent } from "./plex/components/watchlist/plex-watchlist.component"; +import { PlexFormComponent } from "./plex/components/plex-form/plex-form.component"; const routes: Routes = [ { path: "Ombi", component: OmbiComponent, canActivate: [AuthGuard] }, @@ -191,6 +192,7 @@ const routes: Routes = [ CloudMobileComponent, UpdateDialogComponent, PlexWatchlistComponent, + PlexFormComponent, ], exports: [ RouterModule,