From 4155af45f50c92b96595a1ea6a11cd97f9217f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Thu, 14 Mar 2024 14:44:06 +0100 Subject: [PATCH] Frontend to update ntfy data --- frontend/src/api/.openapi-generator/FILES | 2 + frontend/src/api/api.module.ts | 1 + frontend/src/api/api/api.ts | 4 +- frontend/src/api/api/ntfy.service.ts | 210 ++++++++++++++++++ frontend/src/api/model/models.ts | 1 + frontend/src/api/model/ntfyInformation.ts | 32 +++ frontend/src/app/app.module.ts | 4 + .../connection-settings.component.css | 0 .../connection-settings.component.html | 1 + .../connection-settings.component.spec.ts | 21 ++ .../connection-settings.component.ts | 10 + .../ntfy-settings/ntfy-settings.component.css | 0 .../ntfy-settings.component.html | 24 ++ .../ntfy-settings.component.spec.ts | 21 ++ .../ntfy-settings/ntfy-settings.component.ts | 49 ++++ .../user-settings.component.html | 6 + openapi.yaml | 71 +++++- 17 files changed, 454 insertions(+), 3 deletions(-) create mode 100644 frontend/src/api/api/ntfy.service.ts create mode 100644 frontend/src/api/model/ntfyInformation.ts create mode 100644 frontend/src/app/user-settings/connection-settings/connection-settings.component.css create mode 100644 frontend/src/app/user-settings/connection-settings/connection-settings.component.html create mode 100644 frontend/src/app/user-settings/connection-settings/connection-settings.component.spec.ts create mode 100644 frontend/src/app/user-settings/connection-settings/connection-settings.component.ts create mode 100644 frontend/src/app/user-settings/connection-settings/ntfy-settings/ntfy-settings.component.css create mode 100644 frontend/src/app/user-settings/connection-settings/ntfy-settings/ntfy-settings.component.html create mode 100644 frontend/src/app/user-settings/connection-settings/ntfy-settings/ntfy-settings.component.spec.ts create mode 100644 frontend/src/app/user-settings/connection-settings/ntfy-settings/ntfy-settings.component.ts diff --git a/frontend/src/api/.openapi-generator/FILES b/frontend/src/api/.openapi-generator/FILES index fa0da49..3595c4b 100644 --- a/frontend/src/api/.openapi-generator/FILES +++ b/frontend/src/api/.openapi-generator/FILES @@ -5,6 +5,7 @@ api/account.service.ts api/api.ts api/history.service.ts api/login.service.ts +api/ntfy.service.ts api/properties.service.ts api/schedule.service.ts api/task.service.ts @@ -32,6 +33,7 @@ model/loginRequest.ts model/loginResponse.ts model/manualScheduleStopInfo.ts model/models.ts +model/ntfyInformation.ts model/passwordChangeRequest.ts model/propertiesInfo.ts model/propertyInfo.ts diff --git a/frontend/src/api/api.module.ts b/frontend/src/api/api.module.ts index 1a6b886..63562e7 100644 --- a/frontend/src/api/api.module.ts +++ b/frontend/src/api/api.module.ts @@ -5,6 +5,7 @@ import { HttpClient } from '@angular/common/http'; import { AccountService } from './api/account.service'; import { HistoryService } from './api/history.service'; import { LoginService } from './api/login.service'; +import { NtfyService } from './api/ntfy.service'; import { PropertiesService } from './api/properties.service'; import { ScheduleService } from './api/schedule.service'; import { TaskService } from './api/task.service'; diff --git a/frontend/src/api/api/api.ts b/frontend/src/api/api/api.ts index d483dcf..75dbaae 100644 --- a/frontend/src/api/api/api.ts +++ b/frontend/src/api/api/api.ts @@ -4,6 +4,8 @@ export * from './history.service'; import { HistoryService } from './history.service'; export * from './login.service'; import { LoginService } from './login.service'; +export * from './ntfy.service'; +import { NtfyService } from './ntfy.service'; export * from './properties.service'; import { PropertiesService } from './properties.service'; export * from './schedule.service'; @@ -14,4 +16,4 @@ export * from './taskgroup.service'; import { TaskgroupService } from './taskgroup.service'; export * from './users.service'; import { UsersService } from './users.service'; -export const APIS = [AccountService, HistoryService, LoginService, PropertiesService, ScheduleService, TaskService, TaskgroupService, UsersService]; +export const APIS = [AccountService, HistoryService, LoginService, NtfyService, PropertiesService, ScheduleService, TaskService, TaskgroupService, UsersService]; diff --git a/frontend/src/api/api/ntfy.service.ts b/frontend/src/api/api/ntfy.service.ts new file mode 100644 index 0000000..facc48a --- /dev/null +++ b/frontend/src/api/api/ntfy.service.ts @@ -0,0 +1,210 @@ +/** + * API Title + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +/* tslint:disable:no-unused-variable member-ordering */ + +import { Inject, Injectable, Optional } from '@angular/core'; +import { HttpClient, HttpHeaders, HttpParams, + HttpResponse, HttpEvent, HttpParameterCodec, HttpContext + } from '@angular/common/http'; +import { CustomHttpParameterCodec } from '../encoder'; +import { Observable } from 'rxjs'; + +import { NtfyInformation } from '../model/models'; +import { SimpleStatusResponse } from '../model/models'; + +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; + + + +@Injectable({ + providedIn: 'root' +}) +export class NtfyService { + + protected basePath = 'http://127.0.0.1:8080/api'; + public defaultHeaders = new HttpHeaders(); + public configuration = new Configuration(); + public encoder: HttpParameterCodec; + + constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + if (configuration) { + this.configuration = configuration; + } + if (typeof this.configuration.basePath !== 'string') { + if (typeof basePath !== 'string') { + basePath = this.basePath; + } + this.configuration.basePath = basePath; + } + this.encoder = this.configuration.encoder || new CustomHttpParameterCodec(); + } + + + private addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + if (typeof value === "object" && value instanceof Date === false) { + httpParams = this.addToHttpParamsRecursive(httpParams, value); + } else { + httpParams = this.addToHttpParamsRecursive(httpParams, value, key); + } + return httpParams; + } + + private addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + if (value == null) { + return httpParams; + } + + if (typeof value === "object") { + if (Array.isArray(value)) { + (value as any[]).forEach( elem => httpParams = this.addToHttpParamsRecursive(httpParams, elem, key)); + } else if (value instanceof Date) { + if (key != null) { + httpParams = httpParams.append(key, + (value as Date).toISOString().substr(0, 10)); + } else { + throw Error("key may not be null if value is Date"); + } + } else { + Object.keys(value).forEach( k => httpParams = this.addToHttpParamsRecursive( + httpParams, value[k], key != null ? `${key}.${k}` : k)); + } + } else if (key != null) { + httpParams = httpParams.append(key, value); + } else { + throw Error("key may not be null if value is not object or array"); + } + return httpParams; + } + + /** + * Get ntfy information + * Get ntfy information + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public ntfyGet(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable; + public ntfyGet(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>; + public ntfyGet(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>; + public ntfyGet(observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable { + + let localVarHeaders = this.defaultHeaders; + + let localVarCredential: string | undefined; + // authentication (API_TOKEN) required + localVarCredential = this.configuration.lookupCredential('API_TOKEN'); + if (localVarCredential) { + localVarHeaders = localVarHeaders.set('Authorization', 'Bearer ' + localVarCredential); + } + + let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept; + if (localVarHttpHeaderAcceptSelected === undefined) { + // to determine the Accept header + const httpHeaderAccepts: string[] = [ + 'application/json' + ]; + localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts); + } + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); + } + + let localVarHttpContext: HttpContext | undefined = options && options.context; + if (localVarHttpContext === undefined) { + localVarHttpContext = new HttpContext(); + } + + + let responseType_: 'text' | 'json' = 'json'; + if(localVarHttpHeaderAcceptSelected && localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } + + return this.httpClient.get(`${this.configuration.basePath}/ntfy`, + { + context: localVarHttpContext, + responseType: responseType_, + withCredentials: this.configuration.withCredentials, + headers: localVarHeaders, + observe: observe, + reportProgress: reportProgress + } + ); + } + + /** + * Edit ntfy information + * Edit ntfy information + * @param ntfyInformation + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public ntfyPost(ntfyInformation?: NtfyInformation, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable; + public ntfyPost(ntfyInformation?: NtfyInformation, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>; + public ntfyPost(ntfyInformation?: NtfyInformation, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>; + public ntfyPost(ntfyInformation?: NtfyInformation, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable { + + let localVarHeaders = this.defaultHeaders; + + let localVarCredential: string | undefined; + // authentication (API_TOKEN) required + localVarCredential = this.configuration.lookupCredential('API_TOKEN'); + if (localVarCredential) { + localVarHeaders = localVarHeaders.set('Authorization', 'Bearer ' + localVarCredential); + } + + let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept; + if (localVarHttpHeaderAcceptSelected === undefined) { + // to determine the Accept header + const httpHeaderAccepts: string[] = [ + 'application/json' + ]; + localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts); + } + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); + } + + let localVarHttpContext: HttpContext | undefined = options && options.context; + if (localVarHttpContext === undefined) { + localVarHttpContext = new HttpContext(); + } + + + // to determine the Content-Type header + const consumes: string[] = [ + 'application/json' + ]; + const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes); + if (httpContentTypeSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Content-Type', httpContentTypeSelected); + } + + let responseType_: 'text' | 'json' = 'json'; + if(localVarHttpHeaderAcceptSelected && localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } + + return this.httpClient.post(`${this.configuration.basePath}/ntfy`, + ntfyInformation, + { + context: localVarHttpContext, + responseType: responseType_, + withCredentials: this.configuration.withCredentials, + headers: localVarHeaders, + observe: observe, + reportProgress: reportProgress + } + ); + } + +} diff --git a/frontend/src/api/model/models.ts b/frontend/src/api/model/models.ts index 466da64..028c0ee 100644 --- a/frontend/src/api/model/models.ts +++ b/frontend/src/api/model/models.ts @@ -15,6 +15,7 @@ export * from './inlineResponse409'; export * from './loginRequest'; export * from './loginResponse'; export * from './manualScheduleStopInfo'; +export * from './ntfyInformation'; export * from './passwordChangeRequest'; export * from './propertiesInfo'; export * from './propertyInfo'; diff --git a/frontend/src/api/model/ntfyInformation.ts b/frontend/src/api/model/ntfyInformation.ts new file mode 100644 index 0000000..5919525 --- /dev/null +++ b/frontend/src/api/model/ntfyInformation.ts @@ -0,0 +1,32 @@ +/** + * API Title + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export interface NtfyInformation { + /** + * host of ntfy service + */ + ntfy_host: string; + /** + * topic of ntfy service + */ + ntfy_topic: string; + /** + * username of ntfy account for publishing news + */ + ntfy_user: string; + /** + * token to ntfy useraccount + */ + ntfy_token?: string; +} + diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 99fa84e..61f2d42 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -89,6 +89,8 @@ import { ScheduleHistoryComponent } from './statistics/schedule-history/schedule import {MatButtonToggleModule} from "@angular/material/button-toggle"; import {MatGridListModule} from "@angular/material/grid-list"; import { StopScheduleManuallyComponent } from './dashboard/active-schedule/stop-schedule-manually/stop-schedule-manually.component'; +import { ConnectionSettingsComponent } from './user-settings/connection-settings/connection-settings.component'; +import { NtfySettingsComponent } from './user-settings/connection-settings/ntfy-settings/ntfy-settings.component'; @NgModule({ declarations: [ AppComponent, @@ -134,6 +136,8 @@ import { StopScheduleManuallyComponent } from './dashboard/active-schedule/stop- HeatmapActivityComponent, ScheduleHistoryComponent, StopScheduleManuallyComponent, + ConnectionSettingsComponent, + NtfySettingsComponent, ], imports: [ BrowserModule, diff --git a/frontend/src/app/user-settings/connection-settings/connection-settings.component.css b/frontend/src/app/user-settings/connection-settings/connection-settings.component.css new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/user-settings/connection-settings/connection-settings.component.html b/frontend/src/app/user-settings/connection-settings/connection-settings.component.html new file mode 100644 index 0000000..376ad7e --- /dev/null +++ b/frontend/src/app/user-settings/connection-settings/connection-settings.component.html @@ -0,0 +1 @@ + diff --git a/frontend/src/app/user-settings/connection-settings/connection-settings.component.spec.ts b/frontend/src/app/user-settings/connection-settings/connection-settings.component.spec.ts new file mode 100644 index 0000000..28ff0a8 --- /dev/null +++ b/frontend/src/app/user-settings/connection-settings/connection-settings.component.spec.ts @@ -0,0 +1,21 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ConnectionSettingsComponent } from './connection-settings.component'; + +describe('ConnectionSettingsComponent', () => { + let component: ConnectionSettingsComponent; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ConnectionSettingsComponent] + }); + fixture = TestBed.createComponent(ConnectionSettingsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/user-settings/connection-settings/connection-settings.component.ts b/frontend/src/app/user-settings/connection-settings/connection-settings.component.ts new file mode 100644 index 0000000..aa9b358 --- /dev/null +++ b/frontend/src/app/user-settings/connection-settings/connection-settings.component.ts @@ -0,0 +1,10 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-connection-settings', + templateUrl: './connection-settings.component.html', + styleUrls: ['./connection-settings.component.css'] +}) +export class ConnectionSettingsComponent { + +} diff --git a/frontend/src/app/user-settings/connection-settings/ntfy-settings/ntfy-settings.component.css b/frontend/src/app/user-settings/connection-settings/ntfy-settings/ntfy-settings.component.css new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/user-settings/connection-settings/ntfy-settings/ntfy-settings.component.html b/frontend/src/app/user-settings/connection-settings/ntfy-settings/ntfy-settings.component.html new file mode 100644 index 0000000..560cfc7 --- /dev/null +++ b/frontend/src/app/user-settings/connection-settings/ntfy-settings/ntfy-settings.component.html @@ -0,0 +1,24 @@ + + Hostname + + + + + Topic + + + + + Username + + + + + Token + + + +
+ +
+ diff --git a/frontend/src/app/user-settings/connection-settings/ntfy-settings/ntfy-settings.component.spec.ts b/frontend/src/app/user-settings/connection-settings/ntfy-settings/ntfy-settings.component.spec.ts new file mode 100644 index 0000000..1620a14 --- /dev/null +++ b/frontend/src/app/user-settings/connection-settings/ntfy-settings/ntfy-settings.component.spec.ts @@ -0,0 +1,21 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { NtfySettingsComponent } from './ntfy-settings.component'; + +describe('NtfySettingsComponent', () => { + let component: NtfySettingsComponent; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [NtfySettingsComponent] + }); + fixture = TestBed.createComponent(NtfySettingsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/user-settings/connection-settings/ntfy-settings/ntfy-settings.component.ts b/frontend/src/app/user-settings/connection-settings/ntfy-settings/ntfy-settings.component.ts new file mode 100644 index 0000000..3b9e8ee --- /dev/null +++ b/frontend/src/app/user-settings/connection-settings/ntfy-settings/ntfy-settings.component.ts @@ -0,0 +1,49 @@ +import { Component } from '@angular/core'; +import {NtfyService} from "../../../../api"; +import {Form, FormBuilder, FormControl, FormGroup, Validators} from "@angular/forms"; +import {MatSnackBar} from "@angular/material/snack-bar"; + +@Component({ + selector: 'app-ntfy-settings', + templateUrl: './ntfy-settings.component.html', + styleUrls: ['./ntfy-settings.component.css'] +}) +export class NtfySettingsComponent { + + host_formCtrl = new FormControl('', [Validators.required]) + topic_formCtrl = new FormControl('', [Validators.required]) + user_formCtrl = new FormControl('', [Validators.required]) + token_formCtrl = new FormControl('', [Validators.required]) + + constructor(private ntfyService: NtfyService, + private snackbar: MatSnackBar) { + } + + ngOnInit() { + this.ntfyService.ntfyGet().subscribe({ + next: resp => { + this.host_formCtrl.setValue(resp.ntfy_host); + this.topic_formCtrl.setValue(resp.ntfy_topic); + this.user_formCtrl.setValue(resp.ntfy_user); + this.token_formCtrl.setValue(resp.ntfy_token!); + } + }) + } + + save() { + const token = this.token_formCtrl.value === "****" ? "" : this.token_formCtrl.value! + const user = this.user_formCtrl.value === "****" ? "" : this.user_formCtrl.value! + this.ntfyService.ntfyPost({ + ntfy_host: this.host_formCtrl.value!, + ntfy_topic: this.topic_formCtrl.value!, + ntfy_token: token, + ntfy_user: user + }).subscribe({ + next: resp => { + this.snackbar.open("Ntfy-Configuration updated", "", {duration: 2000}) + this.user_formCtrl.setValue("****"); + this.token_formCtrl.setValue("****"); + } + }) + } +} diff --git a/frontend/src/app/user-settings/user-settings.component.html b/frontend/src/app/user-settings/user-settings.component.html index f11bfb6..044e1b5 100644 --- a/frontend/src/app/user-settings/user-settings.component.html +++ b/frontend/src/app/user-settings/user-settings.component.html @@ -4,4 +4,10 @@ + + +
+ +
+
diff --git a/openapi.yaml b/openapi.yaml index 997da1b..2001027 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -2027,7 +2027,53 @@ paths: type: array items: $ref: '#/components/schemas/ScheduleInfo' - + /ntfy: + get: + security: + - API_TOKEN: [] + tags: + - ntfy + description: Get ntfy information + summary: Get ntfy information + responses: + 200: + description: Operation successfull + content: + application/json: + schema: + $ref: '#/components/schemas/NtfyInformation' + 404: + description: Not found + content: + application/json: + schema: + $ref: '#/components/schemas/SimpleStatusResponse' + post: + security: + - API_TOKEN: [] + tags: + - ntfy + description: Edit ntfy information + summary: Edit ntfy information + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/NtfyInformation' + responses: + 200: + description: Operation successfull + content: + application/json: + schema: + $ref: '#/components/schemas/SimpleStatusResponse' + 404: + description: Operation successfull + content: + application/json: + schema: + $ref: '#/components/schemas/SimpleStatusResponse' + components: securitySchemes: @@ -2712,4 +2758,25 @@ components: duration: type: number description: duration in minutes - example: 10 \ No newline at end of file + example: 10 + NtfyInformation: + required: + - ntfy_host + - ntfy_topic + additionalProperties: false + properties: + ntfy_host: + type: string + description: host of ntfy service + example: https://ntfy.fawkes100.de + ntfy_topic: + type: string + description: topic of ntfy service + example: Topicname + ntfy_user: + type: string + description: username of ntfy account for publishing news + example: password + ntfy_token: + type: string + description: token to ntfy useraccount \ No newline at end of file