WIP: add asn prefix

This commit is contained in:
Jakob Englisch
2025-01-05 18:58:29 +01:00
parent aef68f0b41
commit d974bc542e
16 changed files with 179 additions and 12 deletions

View File

@@ -12,6 +12,14 @@
</div>
<div class="position-relative" [class.col-md-9]="horizontal">
<div class="input-group" [class.is-invalid]="error">
@if (prefix) {
<ng-select class="form-control"
[items]="prefix"
bindLabel="name"
bindValue="id"
[(ngModel)]="prefixSelect"
></ng-select>
}
<input #inputField type="number" class="form-control" [step]="step" [id]="inputId" [(ngModel)]="value" (change)="onChange(value)" [class.is-invalid]="error" [disabled]="disabled">
@if (showAdd) {
<button class="btn btn-outline-secondary" type="button" id="button-addon1" (click)="nextAsn()" [disabled]="disabled">+1</button>

View File

@@ -2,11 +2,13 @@ import { Component, forwardRef, Input } from '@angular/core'
import {
FormsModule,
NG_VALUE_ACCESSOR,
ReactiveFormsModule,
ReactiveFormsModule
} from '@angular/forms'
import { NgxBootstrapIconsModule } from 'ngx-bootstrap-icons'
import { DocumentService } from 'src/app/services/rest/document.service'
import { AbstractInputComponent } from '../abstract-input'
import { NgSelectModule } from '@ng-select/ng-select'
import { AsnPrefix } from "../../../../data/asn-prefix";
@Component({
providers: [
@@ -19,12 +21,18 @@ import { AbstractInputComponent } from '../abstract-input'
selector: 'pngx-input-number',
templateUrl: './number.component.html',
styleUrls: ['./number.component.scss'],
imports: [FormsModule, ReactiveFormsModule, NgxBootstrapIconsModule],
imports: [FormsModule, ReactiveFormsModule, NgxBootstrapIconsModule, NgSelectModule],
})
export class NumberComponent extends AbstractInputComponent<number> {
@Input()
showAdd: boolean = true
@Input()
prefix: AsnPrefix[]
@Input()
prefixSelect: number
@Input()
step: number = 1

View File

@@ -106,7 +106,7 @@
<ng-template ngbNavContent>
<div>
<pngx-input-text #inputTitle i18n-title title="Title" formControlName="title" [horizontal]="true" (keyup)="titleKeyUp($event)" [error]="error?.title"></pngx-input-text>
<pngx-input-number i18n-title title="Archive serial number" [error]="error?.archive_serial_number" [horizontal]="true" formControlName='archive_serial_number'></pngx-input-number>
<pngx-input-number [prefix]="asnPrefix" [prefixSelect]="archive_serial_number_prefix" i18n-title title="Archive serial number" [error]="error?.archive_serial_number" [horizontal]="true" formControlName='archive_serial_number'></pngx-input-number>
<pngx-input-date i18n-title title="Date created" formControlName="created_date" [suggestions]="suggestions?.dates" [showFilter]="true" [horizontal]="true" (filterDocuments)="filterDocuments($event)"
[error]="error?.created_date"></pngx-input-date>
<pngx-input-select [items]="correspondents" i18n-title title="Correspondent" formControlName="correspondent" [allowNull]="true" [showFilter]="true" [horizontal]="true" (filterDocuments)="filterDocuments($event, DataType.Correspondent)"

View File

@@ -67,6 +67,7 @@ import {
PermissionsService,
PermissionType,
} from 'src/app/services/permissions.service'
import { AsnPrefixService } from 'src/app/services/rest/asn-prefix.service'
import { CorrespondentService } from 'src/app/services/rest/correspondent.service'
import { CustomFieldsService } from 'src/app/services/rest/custom-fields.service'
import { DocumentTypeService } from 'src/app/services/rest/document-type.service'
@@ -102,6 +103,7 @@ import { DocumentHistoryComponent } from '../document-history/document-history.c
import { DocumentNotesComponent } from '../document-notes/document-notes.component'
import { ComponentWithPermissions } from '../with-permissions/with-permissions.component'
import { MetadataCollapseComponent } from './metadata-collapse/metadata-collapse.component'
import { AsnPrefix } from "../../data/asn-prefix";
enum DocumentDetailNavIDs {
Details = 1,
@@ -171,8 +173,7 @@ enum ZoomSetting {
})
export class DocumentDetailComponent
extends ComponentWithPermissions
implements OnInit, OnDestroy, DirtyComponent
{
implements OnInit, OnDestroy, DirtyComponent {
@ViewChild('inputTitle')
titleInput: TextComponent
@@ -200,6 +201,7 @@ export class DocumentDetailComponent
tiffURL: string
tiffError: string
asnPrefix: AsnPrefix[]
correspondents: Correspondent[]
documentTypes: DocumentType[]
storagePaths: StoragePath[]
@@ -211,6 +213,7 @@ export class DocumentDetailComponent
correspondent: new FormControl(),
document_type: new FormControl(),
storage_path: new FormControl(),
archive_serial_number_prefix: new FormControl(),
archive_serial_number: new FormControl(),
tags: new FormControl([]),
permissions_form: new FormControl(null),
@@ -258,6 +261,7 @@ export class DocumentDetailComponent
constructor(
private documentsService: DocumentService,
private route: ActivatedRoute,
private asnPrefixService: AsnPrefixService,
private correspondentService: CorrespondentService,
private documentTypeService: DocumentTypeService,
private router: Router,
@@ -347,6 +351,17 @@ export class DocumentDetailComponent
.pipe(first(), takeUntil(this.unsubscribeNotifier))
.subscribe((result) => (this.correspondents = result.results))
}
if (
this.permissionsService.currentUserCan(
PermissionAction.View,
PermissionType.AsnPrefix
)
) {
this.asnPrefixService
.listAll()
.pipe(first(), takeUntil(this.unsubscribeNotifier))
.subscribe((result) => (this.asnPrefix = result.results))
}
if (
this.permissionsService.currentUserCan(
PermissionAction.View,
@@ -403,9 +418,8 @@ export class DocumentDetailComponent
this.previewText = res.toString()
},
error: (err) => {
this.previewText = $localize`An error occurred loading content: ${
err.message ?? err.toString()
}`
this.previewText = $localize`An error occurred loading content: ${err.message ?? err.toString()
}`
},
})
this.thumbUrl = this.documentsService.getThumbUrl(documentId)
@@ -449,7 +463,7 @@ export class DocumentDetailComponent
this.documentForm.get('permissions_form').value['owner']
openDocument['permissions'] =
this.documentForm.get('permissions_form').value[
'set_permissions'
'set_permissions'
]
delete openDocument['permissions_form']
}
@@ -494,6 +508,7 @@ export class DocumentDetailComponent
correspondent: doc.correspondent,
document_type: doc.document_type,
storage_path: doc.storage_path,
archive_serial_number_prefix: doc.archive_serial_number_prefix,
archive_serial_number: doc.archive_serial_number,
tags: [...doc.tags],
permissions_form: {
@@ -793,7 +808,7 @@ export class DocumentDetailComponent
save(close: boolean = false) {
this.networkActive = true
;(document.activeElement as HTMLElement)?.dispatchEvent(new Event('change'))
; (document.activeElement as HTMLElement)?.dispatchEvent(new Event('change'))
this.documentsService
.update(this.document)
.pipe(first())
@@ -1046,7 +1061,7 @@ export class DocumentDetailComponent
this.previewZoomScale = ZoomSetting.PageWidth
this.previewZoomSetting =
Object.values(ZoomSetting)[
Math.min(Object.values(ZoomSetting).length - 1, currentIndex + 1)
Math.min(Object.values(ZoomSetting).length - 1, currentIndex + 1)
]
}

View File

@@ -0,0 +1,9 @@
import {ObjectWithId} from "./object-with-id";
export interface AsnPrefix extends ObjectWithId {
name?: string
slug?: string
document_count?: number
}

View File

@@ -1,4 +1,5 @@
import { Observable } from 'rxjs'
import { AsnPrefix } from './asn-prefix'
import { Correspondent } from './correspondent'
import { CustomFieldInstance } from './custom-field-instance'
import { DocumentNote } from './document-note'
@@ -118,6 +119,10 @@ export interface SearchHit {
}
export interface Document extends ObjectWithPermissions {
archive_serial_number_prefix$?: Observable<AsnPrefix>
archive_serial_number_prefix?: number
correspondent$?: Observable<Correspondent>
correspondent?: number

View File

@@ -12,6 +12,7 @@ export enum PermissionAction {
export enum PermissionType {
Document = '%s_document',
Tag = '%s_tag',
AsnPrefix = '%s_asnprefix',
Correspondent = '%s_correspondent',
DocumentType = '%s_documenttype',
StoragePath = '%s_storagepath',

View File

@@ -0,0 +1,13 @@
import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { AsnPrefix } from 'src/app/data/asn-prefix'
import { AbstractNameFilterService } from './abstract-name-filter-service'
@Injectable({
providedIn: 'root',
})
export class AsnPrefixService extends AbstractNameFilterService<AsnPrefix> {
constructor(http: HttpClient) {
super(http, 'asn_prefix')
}
}