mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-20 04:26:53 +00:00
It works! Not pretty tho
This commit is contained in:
6 files changed
+229
-2
No files matched your search
+39
@@ -0,0 +1,39 @@
|
||||
<div class="modal-header">
|
||||
<div>
|
||||
<h4 class="modal-title" i18n>What's new in Paperless-ngx</h4>
|
||||
@if (since()) {
|
||||
<p class="text-muted small mb-0" i18n>Updated from {{ since() }} to {{ version }}</p>
|
||||
}
|
||||
</div>
|
||||
<button type="button" class="btn-close" aria-label="Close" i18n-aria-label (click)="close()"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
@if (!updateCheckingEnabled) {
|
||||
<p class="mb-0" i18n>Release notes are fetched from GitHub when update checking is enabled.</p>
|
||||
<a class="small" [href]="releaseUrl" target="_blank" rel="noopener noreferrer">
|
||||
<ng-container i18n>View on GitHub</ng-container>
|
||||
<pngx-bs-icon name="box-arrow-up-right" class="ms-1"></pngx-bs-icon>
|
||||
</a>
|
||||
} @else if (loading()) {
|
||||
<div class="d-flex align-items-center gap-2 text-muted">
|
||||
<div class="spinner-border spinner-border-sm" role="status"></div>
|
||||
<ng-container i18n>Loading release notes...</ng-container>
|
||||
</div>
|
||||
} @else if (!releases()?.length) {
|
||||
<p class="mb-0" i18n>Release notes could not be loaded.</p>
|
||||
} @else {
|
||||
@for (release of releases(); track release.version) {
|
||||
<section class="release-notes" [class.mt-4]="!$first">
|
||||
<h5>{{ release.version }}</h5>
|
||||
<div class="release-notes-body" [innerHTML]="release.body | markdown: false"></div>
|
||||
</section>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<div class="modal-footer justify-content-between">
|
||||
<a class="btn btn-primary d-flex align-items-center" [href]="releaseUrl" target="_blank" rel="noopener noreferrer">
|
||||
<ng-container i18n>View on GitHub</ng-container>
|
||||
<pngx-bs-icon name="box-arrow-up-right" class="ms-2 mt-n1"></pngx-bs-icon>
|
||||
</a>
|
||||
<button type="button" class="btn btn-outline-secondary" (click)="close()" i18n>Close</button>
|
||||
</div>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
:host ::ng-deep .release-notes-body > h2 {
|
||||
display: none !important;
|
||||
}
|
||||
+106
@@ -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<ReleaseNotesDialogComponent>
|
||||
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()
|
||||
})
|
||||
})
|
||||
+65
@@ -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<string | null>(null)
|
||||
readonly releases = signal<AppRelease[] | null>(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()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user