diff --git a/src/Ombi.Api.CloudService/Class1.cs b/src/Ombi.Api.CloudService/CloudMobileNotification.cs similarity index 81% rename from src/Ombi.Api.CloudService/Class1.cs rename to src/Ombi.Api.CloudService/CloudMobileNotification.cs index 704883f07..aba2d90d3 100644 --- a/src/Ombi.Api.CloudService/Class1.cs +++ b/src/Ombi.Api.CloudService/CloudMobileNotification.cs @@ -1,4 +1,6 @@ using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Ombi.Helpers; using System; using System.Collections.Generic; using System.Net.Http; @@ -14,17 +16,18 @@ namespace Ombi.Api.CloudService { private readonly IApi _api; private readonly ILogger _logger; - private const string BaseUrl = "https://ombinotifications.azurewebsites.net/api/"; + private readonly string _baseUrl; - public CloudMobileNotification(IApi api, ILogger logger) + public CloudMobileNotification(IApi api, ILogger logger, IOptions settings) { _api = api; + _baseUrl = settings.Value.NotificationService; _logger = logger; } public async Task SendMessage(MobileNotificationRequest notification) { - var request = new Request("MobileNotification", BaseUrl, HttpMethod.Post); + var request = new Request("MobileNotification", _baseUrl, HttpMethod.Post); request.AddJsonBody(notification); var response = await _api.Request(request); diff --git a/src/Ombi.Helpers/ApplicationSettings.cs b/src/Ombi.Helpers/ApplicationSettings.cs index 12be2087c..753b5a4d4 100644 --- a/src/Ombi.Helpers/ApplicationSettings.cs +++ b/src/Ombi.Helpers/ApplicationSettings.cs @@ -3,5 +3,6 @@ public class ApplicationSettings { public string OmbiService { get; set; } + public string NotificationService { get; set; } } } \ No newline at end of file diff --git a/src/Ombi/ClientApp/src/app/interfaces/IUser.ts b/src/Ombi/ClientApp/src/app/interfaces/IUser.ts index 9b0500891..d3b6c783a 100644 --- a/src/Ombi/ClientApp/src/app/interfaces/IUser.ts +++ b/src/Ombi/ClientApp/src/app/interfaces/IUser.ts @@ -71,6 +71,18 @@ export interface IMobileUsersViewModel { devices: number; } +export interface ICloudMobileModel { + userId: string; + username: string; + devices: ICloudMobileDevices[]; +} +export interface ICloudMobileDevices { + token: string; + userId: string; + addedAt: Date; + user: IUser; +} + export interface IMassEmailUserModel { user: IUser; selected: boolean; diff --git a/src/Ombi/ClientApp/src/app/services/cloudmobile.service.ts b/src/Ombi/ClientApp/src/app/services/cloudmobile.service.ts new file mode 100644 index 000000000..d1675ae75 --- /dev/null +++ b/src/Ombi/ClientApp/src/app/services/cloudmobile.service.ts @@ -0,0 +1,22 @@ +import { APP_BASE_HREF } from "@angular/common"; +import { Injectable, Inject } from "@angular/core"; + +import { HttpClient } from "@angular/common/http"; +import { Observable } from "rxjs"; + +import { ICloudMobileDevices, ICloudMobileModel } from "../interfaces"; +import { ServiceHelpers } from "./service.helpers"; + +@Injectable() +export class CloudMobileService extends ServiceHelpers { + constructor(http: HttpClient, @Inject(APP_BASE_HREF) href:string) { + super(http, "/api/v2/mobile/", href); + } + public getDevices(): Observable { + return this.http.get(`${this.url}users/`, {headers: this.headers}); + } + + public send(userId: string, message: string): Promise { + return this.http.post(`${this.url}send/`, { userId, message }, {headers: this.headers}).toPromise(); + } +} diff --git a/src/Ombi/ClientApp/src/app/settings/notifications/cloudmobile.component.html b/src/Ombi/ClientApp/src/app/settings/notifications/cloudmobile.component.html new file mode 100644 index 000000000..c34f61687 --- /dev/null +++ b/src/Ombi/ClientApp/src/app/settings/notifications/cloudmobile.component.html @@ -0,0 +1,55 @@ + + +
+
+ Mobile Notifications + +
+
+
+ + + + + + + + + + + + + + +
+ + + + + Username {{element.username}}
+ + +
+ + Message + + +
+
+ +
+
+
+ +
+ +
+ +
+
+ +
+
+
+
+
\ No newline at end of file diff --git a/src/Ombi/ClientApp/src/app/settings/notifications/cloudmobile.coponent.ts b/src/Ombi/ClientApp/src/app/settings/notifications/cloudmobile.coponent.ts new file mode 100644 index 000000000..c10ab97b6 --- /dev/null +++ b/src/Ombi/ClientApp/src/app/settings/notifications/cloudmobile.coponent.ts @@ -0,0 +1,82 @@ +import { Component, OnInit } from "@angular/core"; +import { FormBuilder, FormGroup } from "@angular/forms"; + +import { IMobileNotifcationSettings, IMobileUsersViewModel, INotificationTemplates, NotificationType, ICloudMobileDevices, ICloudMobileModel } from "../../interfaces"; +import { TesterService } from "../../services"; +import { NotificationService } from "../../services"; +import { MobileService, SettingsService } from "../../services"; +import { CloudMobileService } from "../../services/cloudmobile.service"; +import { SelectionModel } from "@angular/cdk/collections"; +import { MatTableDataSource } from "@angular/material"; + +@Component({ + templateUrl: "./cloudmobile.component.html", +}) +export class CloudMobileComponent implements OnInit { + + public NotificationType = NotificationType; + public templates: INotificationTemplates[]; + public form: FormGroup; + public devices: MatTableDataSource; + public selection = new SelectionModel(true, []); + displayedColumns: string[] = ['select', 'username']; + public message: string; + + constructor(private settingsService: SettingsService, + private notificationService: NotificationService, + private fb: FormBuilder, + private mobileService: CloudMobileService) { } + + public async ngOnInit() { + this.settingsService.getMobileNotificationSettings().subscribe(x => { + this.templates = x.notificationTemplates; + + this.form = this.fb.group({ + }); + }); + + var result = await this.mobileService.getDevices().toPromise(); + if (result.length > 0) { + this.devices = new MatTableDataSource(result); + } + } + + public onSubmit(form: FormGroup) { + if (form.invalid) { + this.notificationService.error("Please check your entered values"); + return; + } + + const settings = form.value; + settings.notificationTemplates = this.templates; + + this.settingsService.saveMobileNotificationSettings(settings).subscribe(x => { + if (x) { + this.notificationService.success("Successfully saved the Mobile settings"); + } else { + this.notificationService.success("There was an error when saving the Mobile settings"); + } + }); + + } + + public async sendMessage(form: FormGroup) { + if (form.invalid) { + this.notificationService.error("Please check your entered values"); + return; + } + if (this.selection.selected.length <= 0) { + this.notificationService.warning("Warning", "Please select a user to send the test notification"); + return; + } + + await this.selection.selected.forEach(async (u) => { + await this.mobileService.send(u.userId, this.message); + + this.notificationService.success( + "Successfully sent a Mobile message"); + + + }); + } +} diff --git a/src/Ombi/ClientApp/src/app/settings/notifications/mobile.component.html b/src/Ombi/ClientApp/src/app/settings/notifications/mobile.component.html index 2b7ea9b2c..829133665 100644 --- a/src/Ombi/ClientApp/src/app/settings/notifications/mobile.component.html +++ b/src/Ombi/ClientApp/src/app/settings/notifications/mobile.component.html @@ -2,7 +2,7 @@
- Mobile Notifications + Legacy Mobile Notifications
@@ -35,7 +35,7 @@
- +