Email Version availability (#2345)

This commit is contained in:
Joe Milazzo 2023-10-22 13:19:50 -05:00 committed by GitHub
parent d1157e90c4
commit bcb75ed241
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 137 additions and 39 deletions

View file

@ -5,6 +5,7 @@ import {ServerInfoSlim} from '../admin/_models/server-info';
import { UpdateVersionEvent } from '../_models/events/update-version-event';
import { Job } from '../_models/job/job';
import { KavitaMediaError } from '../admin/_models/media-error';
import {TextResonse} from "../_types/text-response";
@Injectable({
providedIn: 'root'
@ -67,4 +68,8 @@ export class ServerService {
clearMediaAlerts() {
return this.httpClient.post(this.baseUrl + 'server/clear-media-alerts', {});
}
getEmailVersion() {
return this.httpClient.get<string>(this.baseUrl + 'server/email-version', TextResonse);
}
}

View file

@ -1,13 +1,14 @@
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, inject, OnInit} from '@angular/core';
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
import {ToastrService} from 'ngx-toastr';
import {take} from 'rxjs';
import {forkJoin, take} from 'rxjs';
import {EmailTestResult, SettingsService} from '../settings.service';
import {ServerSettings} from '../_models/server-settings';
import {NgbTooltip} from '@ng-bootstrap/ng-bootstrap';
import {NgIf, NgTemplateOutlet} from '@angular/common';
import {TranslocoModule, TranslocoService} from "@ngneat/transloco";
import {translate, TranslocoModule, TranslocoService} from "@ngneat/transloco";
import {SafeHtmlPipe} from "../../pipe/safe-html.pipe";
import {ServerService} from "../../_services/server.service";
@Component({
selector: 'app-manage-email-settings',
@ -22,9 +23,13 @@ export class ManageEmailSettingsComponent implements OnInit {
serverSettings!: ServerSettings;
settingsForm: FormGroup = new FormGroup({});
link = '<a href="https://github.com/Kareadita/KavitaEmail" target="_blank" rel="noopener noreferrer">Kavita Email</a>';
emailVersion: string | null = null;
private readonly cdRef = inject(ChangeDetectorRef);
private readonly serverService = inject(ServerService);
private readonly settingsService = inject(SettingsService);
private readonly toastr = inject(ToastrService);
constructor(private settingsService: SettingsService, private toastr: ToastrService, private translocoService: TranslocoService) { }
constructor() { }
ngOnInit(): void {
this.settingsService.getServerSettings().pipe(take(1)).subscribe((settings: ServerSettings) => {
@ -33,6 +38,11 @@ export class ManageEmailSettingsComponent implements OnInit {
this.settingsForm.addControl('hostName', new FormControl(this.serverSettings.hostName, []));
this.cdRef.markForCheck();
});
this.serverService.getEmailVersion().subscribe(version => {
this.emailVersion = version;
this.cdRef.markForCheck();
});
}
resetForm() {
@ -51,7 +61,7 @@ export class ManageEmailSettingsComponent implements OnInit {
this.settingsService.updateServerSettings(modelSettings).pipe(take(1)).subscribe((settings: ServerSettings) => {
this.serverSettings = settings;
this.resetForm();
this.toastr.success(this.translocoService.translate('toasts.server-settings-updated'));
this.toastr.success(translate('toasts.server-settings-updated'));
}, (err: any) => {
console.error('error: ', err);
});
@ -61,7 +71,7 @@ export class ManageEmailSettingsComponent implements OnInit {
this.settingsService.resetServerSettings().pipe(take(1)).subscribe((settings: ServerSettings) => {
this.serverSettings = settings;
this.resetForm();
this.toastr.success(this.translocoService.translate('toasts.server-settings-updated'));
this.toastr.success(translate('toasts.server-settings-updated'));
}, (err: any) => {
console.error('error: ', err);
});
@ -71,7 +81,7 @@ export class ManageEmailSettingsComponent implements OnInit {
this.settingsService.resetEmailServerSettings().pipe(take(1)).subscribe((settings: ServerSettings) => {
this.serverSettings.emailServiceUrl = settings.emailServiceUrl;
this.resetForm();
this.toastr.success(this.translocoService.translate('toasts.email-service-reset'));
this.toastr.success(translate('toasts.email-service-reset'));
}, (err: any) => {
console.error('error: ', err);
});
@ -79,11 +89,14 @@ export class ManageEmailSettingsComponent implements OnInit {
testEmailServiceUrl() {
if (this.settingsForm.get('emailServiceUrl')?.value === '') return;
this.settingsService.testEmailServerSettings(this.settingsForm.get('emailServiceUrl')?.value).pipe(take(1)).subscribe(async (result: EmailTestResult) => {
forkJoin([this.settingsService.testEmailServerSettings(this.settingsForm.get('emailServiceUrl')?.value), this.serverService.getEmailVersion()])
.pipe(take(1)).subscribe(async (results) => {
const result = results[0] as EmailTestResult;
if (result.successful) {
this.toastr.success(this.translocoService.translate('toasts.email-service-reachable'));
const version = ('. Kavita Email: ' + results[1] ? 'v' + results[1] : '');
this.toastr.success(translate('toasts.email-service-reachable') + version);
} else {
this.toastr.error(this.translocoService.translate('toasts.email-service-unresponsive') + result.errorMessage);
this.toastr.error(translate('toasts.email-service-unresponsive') + result.errorMessage.split('(')[0]);
}
}, (err: any) => {

View file

@ -1907,7 +1907,7 @@
"reading-list-imported": "Reading List imported",
"incognito-off": "Incognito mode is off. Progress will now start being tracked.",
"email-service-reset": "Email Service Reset",
"email-service-reachable": "Email Service was reachable",
"email-service-reachable": "Kavita Email Connection Successful",
"email-service-unresponsive": "Email Service Url did not respond.",
"refresh-covers-queued": "Refresh covers queued for {{name}}",
"library-file-analysis-queued": "Library file analysis queued for {{name}}",