diff --git a/src-ui/src/app/components/app-frame/app-frame.component.ts b/src-ui/src/app/components/app-frame/app-frame.component.ts index 7c1e7d929e..2ee4464b01 100644 --- a/src-ui/src/app/components/app-frame/app-frame.component.ts +++ b/src-ui/src/app/components/app-frame/app-frame.component.ts @@ -68,6 +68,7 @@ import { SwitchComponent } from '../common/input/switch/switch.component' import { BrandMarkComponent } from '../common/logo/brand-mark/brand-mark.component' import { LogoComponent } from '../common/logo/logo.component' import { ProfileEditDialogComponent } from '../common/profile-edit-dialog/profile-edit-dialog.component' +import { ReleaseNotesDialogComponent } from '../common/release-notes-dialog/release-notes-dialog.component' import { UploadStatusTrayComponent } from '../common/upload-status-tray/upload-status-tray.component' import { DocumentDetailComponent } from '../document-detail/document-detail.component' import { ComponentWithPermissions } from '../with-permissions/with-permissions.component' @@ -552,8 +553,18 @@ export class AppFrameComponent } showReleaseNotes() { - // TODO: open release notes modal - this.settingsService.markReleasesSeen().pipe(first()).subscribe() + const since = this.settingsService.unseenReleasesSince() + const modal = this.modalService.open(ReleaseNotesDialogComponent, { + size: 'lg', + scrollable: true, + }) + modal.componentInstance.load(since) + if (since) { + this.settingsService + .markReleasesSeen() + .pipe(first()) + .subscribe({ error: () => {} }) + } } setUpdateChecking(enable: boolean) { diff --git a/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.html b/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.html new file mode 100644 index 0000000000..f9dee23bce --- /dev/null +++ b/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.html @@ -0,0 +1,39 @@ + + + diff --git a/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.scss b/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.scss new file mode 100644 index 0000000000..134bdf9a92 --- /dev/null +++ b/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.scss @@ -0,0 +1,3 @@ +:host ::ng-deep .release-notes-body > h2 { + display: none !important; +} diff --git a/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.spec.ts b/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.spec.ts new file mode 100644 index 0000000000..82dbab34cc --- /dev/null +++ b/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.spec.ts @@ -0,0 +1,106 @@ +import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http' +import { + HttpTestingController, + provideHttpClientTesting, +} from '@angular/common/http/testing' +import { ComponentFixture, TestBed } from '@angular/core/testing' +import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' +import { SETTINGS_KEYS } from 'src/app/data/ui-settings' +import { SettingsService } from 'src/app/services/settings.service' +import { environment } from 'src/environments/environment' +import { ReleaseNotesDialogComponent } from './release-notes-dialog.component' + +describe('ReleaseNotesDialogComponent', () => { + let component: ReleaseNotesDialogComponent + let fixture: ComponentFixture + let httpTestingController: HttpTestingController + let settingsService: SettingsService + + function create(updateCheckingEnabled: boolean) { + settingsService = TestBed.inject(SettingsService) + settingsService.set(SETTINGS_KEYS.VERSION, '3.5.1') + settingsService.set( + SETTINGS_KEYS.UPDATE_CHECKING_ENABLED, + updateCheckingEnabled + ) + fixture = TestBed.createComponent(ReleaseNotesDialogComponent) + component = fixture.componentInstance + } + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [ReleaseNotesDialogComponent], + providers: [ + NgbActiveModal, + provideHttpClient(withInterceptorsFromDi()), + provideHttpClientTesting(), + ], + }) + httpTestingController = TestBed.inject(HttpTestingController) + }) + + afterEach(() => { + httpTestingController.verify() + }) + + it('should load and render release notes since a version', () => { + create(true) + component.load('3.4.2') + const req = httpTestingController.expectOne( + `${environment.apiBaseUrl}release_notes/?since=3.4.2` + ) + req.flush({ + version: '3.5.1', + releases: [ + { + version: '3.5.1', + name: 'Paperless-ngx v3.5.1', + body: '## paperless-ngx 3.5.1\r\n\r\n### Bug Fixes\r\n\r\n- Fix: a thing ([#1](https://github.com/paperless-ngx/paperless-ngx/pull/1))', + html_url: '', + published_at: '', + }, + ], + }) + fixture.detectChanges() + + const text = fixture.nativeElement.textContent + expect(text).toContain('Updated from 3.4.2 to 3.5.1') + expect(text).toContain('Bug Fixes') + expect(text).not.toContain('paperless-ngx 3.5.1') + expect(text).not.toContain('(github.com)') + }) + + it('should show a message if release notes could not be loaded', () => { + create(true) + component.load(null) + httpTestingController + .expectOne(`${environment.apiBaseUrl}release_notes/`) + .flush('error', { status: 500, statusText: 'error' }) + fixture.detectChanges() + + expect(fixture.nativeElement.textContent).toContain( + 'Release notes could not be loaded' + ) + }) + + it('should not fetch release notes if update checking is disabled', () => { + create(false) + component.load('3.4.2') + fixture.detectChanges() + + httpTestingController.expectNone(`${environment.apiBaseUrl}release_notes/`) + expect(fixture.nativeElement.textContent).toContain( + 'when update checking is enabled' + ) + expect(component.releaseUrl).toEqual( + 'https://github.com/paperless-ngx/paperless-ngx/releases/tag/v3.5.1' + ) + }) + + it('should support close', () => { + create(false) + const closeSpy = jest.spyOn(component.activeModal, 'close') + component.close() + expect(closeSpy).toHaveBeenCalled() + }) +}) diff --git a/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.ts b/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.ts new file mode 100644 index 0000000000..3673bee237 --- /dev/null +++ b/src-ui/src/app/components/common/release-notes-dialog/release-notes-dialog.component.ts @@ -0,0 +1,65 @@ +import { Component, inject, signal } from '@angular/core' +import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' +import { first } from 'rxjs' +import { BootstrapIconComponent } from 'src/app/components/common/bootstrap-icon/bootstrap-icon.component' +import { SETTINGS_KEYS } from 'src/app/data/ui-settings' +import { MarkdownPipe } from 'src/app/pipes/markdown.pipe' +import { + AppRelease, + RemoteVersionService, +} from 'src/app/services/rest/remote-version.service' +import { SettingsService } from 'src/app/services/settings.service' + +const RELEASES_URL = 'https://github.com/paperless-ngx/paperless-ngx/releases' + +@Component({ + selector: 'pngx-release-notes-dialog', + templateUrl: './release-notes-dialog.component.html', + styleUrls: ['./release-notes-dialog.component.scss'], + imports: [BootstrapIconComponent, MarkdownPipe], +}) +export class ReleaseNotesDialogComponent { + readonly activeModal = inject(NgbActiveModal) + private readonly remoteVersionService = inject(RemoteVersionService) + private readonly settingsService = inject(SettingsService) + + readonly since = signal(null) + readonly releases = signal(null) + readonly loading = signal(false) + + readonly version: string = this.settingsService.get(SETTINGS_KEYS.VERSION) + readonly updateCheckingEnabled: boolean = this.settingsService.get( + SETTINGS_KEYS.UPDATE_CHECKING_ENABLED + ) + + get releaseUrl(): string { + return this.version ? `${RELEASES_URL}/tag/v${this.version}` : RELEASES_URL + } + + /** + * Load notes for releases after `since`, or the running version's + * notes if `since` is null. + */ + load(since: string | null): void { + this.since.set(since) + if (!this.updateCheckingEnabled) return + this.loading.set(true) + this.remoteVersionService + .getReleaseNotes(since ?? undefined) + .pipe(first()) + .subscribe({ + next: (notes) => { + this.releases.set(notes.releases) + this.loading.set(false) + }, + error: () => { + this.releases.set([]) + this.loading.set(false) + }, + }) + } + + close(): void { + this.activeModal.close() + } +} diff --git a/src-ui/src/styles.scss b/src-ui/src/styles.scss index bfa1981cf9..100d872f29 100644 --- a/src-ui/src/styles.scss +++ b/src-ui/src/styles.scss @@ -13,6 +13,9 @@ $form-file-button-hover-bg: var(--pngx-bg-alt); @include meta.load-css("print"); // re-created bootstrap styles +.mt-n1 { + margin-top: -0.25rem; +} .mt-n2 { margin-top: -0.5rem; }