RED-3800: RSS typings
This commit is contained in:
parent
6a6fc39e61
commit
9ffe74d6ee
@ -13,8 +13,8 @@
|
||||
<div class="bold">{{ entry.key }}</div>
|
||||
<div>
|
||||
<iqser-editable-input
|
||||
(save)="saveEdit($event, entry)"
|
||||
[buttonsType]="iconButtonTypes.dark"
|
||||
(save)="saveEdit($event, entry.value.originalKey)"
|
||||
[buttonsType]="circleButtonTypes.dark"
|
||||
[cancelTooltip]="'rss-dialog.actions.cancel-edit' | translate"
|
||||
[editTooltip]="'rss-dialog.actions.edit' | translate"
|
||||
[saveTooltip]="'rss-dialog.actions.save' | translate"
|
||||
@ -22,11 +22,11 @@
|
||||
>
|
||||
<ng-container slot="editing">
|
||||
<iqser-circle-button
|
||||
(action)="undo(entry)"
|
||||
(action)="undo(entry.value.originalKey)"
|
||||
*ngIf="entry.value.value"
|
||||
[showDot]="true"
|
||||
[tooltip]="'rss-dialog.actions.undo' | translate: { value: entry.value.originalValue }"
|
||||
[type]="iconButtonTypes.dark"
|
||||
[type]="circleButtonTypes.dark"
|
||||
class="ml-2"
|
||||
icon="red:undo"
|
||||
></iqser-circle-button>
|
||||
@ -34,12 +34,10 @@
|
||||
</iqser-editable-input>
|
||||
</div>
|
||||
<div>{{ entry.value.transformation }}</div>
|
||||
<!-- <div>{{ entry.value.scmAnnotations || '-' }}</div>-->
|
||||
<div>
|
||||
<ul *ngIf="entry.value.scmAnnotations; else noAnnotations" class="pl-0">
|
||||
<li
|
||||
*ngFor="let annotation of entry.value.scmAnnotations"
|
||||
class="mb-8"
|
||||
[innerHTML]="
|
||||
'rss-dialog.annotations'
|
||||
| translate
|
||||
@ -50,6 +48,7 @@
|
||||
type: annotation.type
|
||||
}
|
||||
"
|
||||
class="mb-8"
|
||||
></li>
|
||||
</ul>
|
||||
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { BaseDialogComponent, IconButtonTypes } from '@iqser/common-ui';
|
||||
import { BaseDialogComponent, CircleButtonTypes } from '@iqser/common-ui';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { RssService } from '@services/files/rss.service';
|
||||
import { IFile, IRssEntry } from '@red/domain';
|
||||
import { IFile, RssEntry, RssResult } from '@red/domain';
|
||||
import { BehaviorSubject, firstValueFrom } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { FilesMapService } from '@services/files/files-map.service';
|
||||
import { UserPreferenceService } from '@users/user-preference.service';
|
||||
import { KeyValue } from '@angular/common';
|
||||
@ -18,9 +17,9 @@ interface RssData {
|
||||
styleUrls: ['./rss-dialog.component.scss'],
|
||||
})
|
||||
export class RssDialogComponent extends BaseDialogComponent implements OnInit {
|
||||
readonly iconButtonTypes = IconButtonTypes;
|
||||
readonly circleButtonTypes = CircleButtonTypes;
|
||||
|
||||
rssData$ = new BehaviorSubject<IRssEntry>(null);
|
||||
rssData$ = new BehaviorSubject<RssEntry>(null);
|
||||
|
||||
constructor(
|
||||
protected readonly _dialogRef: MatDialogRef<RssDialogComponent>,
|
||||
@ -36,7 +35,7 @@ export class RssDialogComponent extends BaseDialogComponent implements OnInit {
|
||||
await this.#loadData();
|
||||
}
|
||||
|
||||
originalOrder = (a: KeyValue<string, any>, b: KeyValue<string, any>): number => 0;
|
||||
originalOrder = (a: KeyValue<string, RssResult>, b: KeyValue<string, RssResult>): number => 0;
|
||||
|
||||
exportJSON() {
|
||||
this._rssService.exportJSON(this.data.file.dossierId, this.data.file.fileId, this.data.file.filename).subscribe();
|
||||
@ -58,38 +57,21 @@ export class RssDialogComponent extends BaseDialogComponent implements OnInit {
|
||||
this.exportJSON();
|
||||
}
|
||||
|
||||
async undo(entry: KeyValue<string, any>) {
|
||||
async undo(originalKey: string) {
|
||||
this._loadingService.start();
|
||||
await firstValueFrom(this._rssService.revertOverride(this.data.file.dossierId, this.data.file.fileId, [entry.value.originalKey]));
|
||||
await firstValueFrom(this._rssService.revertOverride(this.data.file.dossierId, this.data.file.fileId, [originalKey]));
|
||||
await this.#loadData();
|
||||
}
|
||||
|
||||
async saveEdit(event: string, entry: KeyValue<string, any>) {
|
||||
async saveEdit(event: string, originalKey: string) {
|
||||
this._loadingService.start();
|
||||
await firstValueFrom(
|
||||
this._rssService.override(this.data.file.dossierId, this.data.file.fileId, { [entry.value.originalKey]: event }),
|
||||
);
|
||||
await firstValueFrom(this._rssService.override(this.data.file.dossierId, this.data.file.fileId, { [originalKey]: event }));
|
||||
await this.#loadData();
|
||||
}
|
||||
|
||||
async #loadData(): Promise<void> {
|
||||
this._loadingService.start();
|
||||
const rssData = await firstValueFrom(
|
||||
this._rssService.getRSSData(this.data.file.dossierId, this.data.file.fileId).pipe(
|
||||
map(entry => {
|
||||
const mapped = {};
|
||||
for (const key of Object.keys(entry.result)) {
|
||||
const newKey = key.replace(new RegExp('_', 'g'), ' ');
|
||||
(<any>entry.result[key]).originalKey = key;
|
||||
mapped[newKey] = entry.result[key];
|
||||
}
|
||||
return {
|
||||
filaName: entry.filaName,
|
||||
result: mapped,
|
||||
};
|
||||
}),
|
||||
),
|
||||
);
|
||||
const rssData = await firstValueFrom(this._rssService.getRSSData(this.data.file.dossierId, this.data.file.fileId));
|
||||
this.rssData$.next(rssData);
|
||||
this._loadingService.stop();
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { GenericService, QueryParam, RequiredParam, Validate } from '@iqser/common-ui';
|
||||
import { IRssData, IRssEntry } from '@red/domain';
|
||||
import { IRssData, IRssEntry, RssEntry } from '@red/domain';
|
||||
import { catchError, map, tap } from 'rxjs/operators';
|
||||
import { of } from 'rxjs';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { HttpHeaders } from '@angular/common/http';
|
||||
import { saveAs } from 'file-saver';
|
||||
|
||||
@ -11,19 +11,55 @@ export class RssService extends GenericService<void> {
|
||||
protected readonly _defaultModelPath = 'import-redactions';
|
||||
|
||||
@Validate()
|
||||
getRSSData(@RequiredParam() dossierId: string, @RequiredParam() fileId: string) {
|
||||
getRSSData(@RequiredParam() dossierId: string, @RequiredParam() fileId: string): Observable<RssEntry> {
|
||||
const queryParams: QueryParam[] = [];
|
||||
queryParams.push({ key: 'fileId', value: fileId });
|
||||
|
||||
const rssData$ = this._getOne<IRssData>([dossierId], 'rss/detailed', queryParams);
|
||||
return rssData$.pipe(
|
||||
return this._getOne<IRssData>([dossierId], 'rss/detailed', queryParams).pipe(
|
||||
map(data => data.files[0]),
|
||||
catchError(() => of({} as IRssEntry)),
|
||||
map(data => new RssEntry(data)),
|
||||
);
|
||||
}
|
||||
|
||||
@Validate()
|
||||
getRSSDataAsXML(@RequiredParam() dossierId: string, @RequiredParam() fileId: string) {
|
||||
override(
|
||||
@RequiredParam() dossierId: string,
|
||||
@RequiredParam() fileId: string,
|
||||
@RequiredParam() componentOverrides: Record<string, string>,
|
||||
): Observable<void> {
|
||||
return this._post({ componentOverrides }, `rss/override/${dossierId}/${fileId}`);
|
||||
}
|
||||
|
||||
@Validate()
|
||||
revertOverride(
|
||||
@RequiredParam() dossierId: string,
|
||||
@RequiredParam() fileId: string,
|
||||
@RequiredParam() components: string[],
|
||||
): Observable<void> {
|
||||
return this._post({ components }, `rss/override/revert/${dossierId}/${fileId}`);
|
||||
}
|
||||
|
||||
exportJSON(dossierId: string, fileId: string, name: string): Observable<RssEntry> {
|
||||
return this.getRSSData(dossierId, fileId).pipe(
|
||||
tap(data => {
|
||||
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
|
||||
saveAs(blob, name + '.rss.json');
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
exportXML(dossierId: string, fileId: string, name: string): Observable<string> {
|
||||
return this._getRSSDataAsXML(dossierId, fileId).pipe(
|
||||
tap(data => {
|
||||
const blob = new Blob([data], { type: 'application/xml' });
|
||||
saveAs(blob, name + '.rss.xml');
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@Validate()
|
||||
private _getRSSDataAsXML(@RequiredParam() dossierId: string, @RequiredParam() fileId: string) {
|
||||
const queryParams: QueryParam[] = [];
|
||||
queryParams.push({ key: 'fileId', value: fileId });
|
||||
|
||||
@ -39,36 +75,4 @@ export class RssService extends GenericService<void> {
|
||||
observe: 'body',
|
||||
});
|
||||
}
|
||||
|
||||
@Validate()
|
||||
override(
|
||||
@RequiredParam() dossierId: string,
|
||||
@RequiredParam() fileId: string,
|
||||
@RequiredParam() componentOverrides: Record<string, string>,
|
||||
) {
|
||||
return this._post({ componentOverrides }, `rss/override/${dossierId}/${fileId}`);
|
||||
}
|
||||
|
||||
@Validate()
|
||||
revertOverride(@RequiredParam() dossierId: string, @RequiredParam() fileId: string, @RequiredParam() components: string[]) {
|
||||
return this._post({ components }, `rss/override/revert/${dossierId}/${fileId}`);
|
||||
}
|
||||
|
||||
exportJSON(dossierId: string, fileId: string, name: string) {
|
||||
return this.getRSSData(dossierId, fileId).pipe(
|
||||
tap(data => {
|
||||
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
|
||||
saveAs(blob, name + '.rss.json');
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
exportXML(dossierId: string, fileId: string, name: string) {
|
||||
return this.getRSSDataAsXML(dossierId, fileId).pipe(
|
||||
tap(data => {
|
||||
const blob = new Blob([data], { type: 'application/xml' });
|
||||
saveAs(blob, name + '.rss.xml');
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
export * from './rss-data';
|
||||
export * from './rss-entry';
|
||||
export * from './rss-result';
|
||||
|
||||
@ -1,4 +1,23 @@
|
||||
import { IRssResult, RssResult } from './rss-result';
|
||||
|
||||
export interface IRssEntry {
|
||||
filaName: string;
|
||||
result: { [key: string]: string };
|
||||
filename: string;
|
||||
result: Record<string, IRssResult>;
|
||||
}
|
||||
|
||||
export class RssEntry implements IRssEntry {
|
||||
readonly filename: string;
|
||||
readonly result: Record<string, RssResult>;
|
||||
|
||||
constructor(entry: IRssEntry) {
|
||||
this.filename = entry.filename;
|
||||
|
||||
const mappedResult: Record<string, RssResult> = {};
|
||||
for (const key of Object.keys(entry.result)) {
|
||||
const newKey = key.replace(new RegExp('_', 'g'), ' ');
|
||||
console.log([key, newKey]);
|
||||
mappedResult[newKey] = new RssResult(entry.result[key], key);
|
||||
}
|
||||
this.result = mappedResult;
|
||||
}
|
||||
}
|
||||
|
||||
27
libs/red-domain/src/lib/rss/rss-result.ts
Normal file
27
libs/red-domain/src/lib/rss/rss-result.ts
Normal file
@ -0,0 +1,27 @@
|
||||
export interface IScmAnnotation {
|
||||
readonly type: string;
|
||||
readonly pages: number[];
|
||||
readonly ruleNumber: number;
|
||||
readonly reason: string;
|
||||
}
|
||||
|
||||
export interface IRssResult {
|
||||
readonly value: string;
|
||||
readonly originalValue: string;
|
||||
readonly scmAnnotations: IScmAnnotation[];
|
||||
readonly transformation: string;
|
||||
}
|
||||
|
||||
export class RssResult implements IRssResult {
|
||||
readonly value: string;
|
||||
readonly originalValue: string;
|
||||
readonly scmAnnotations: IScmAnnotation[];
|
||||
readonly transformation: string;
|
||||
|
||||
constructor(result: IRssResult, readonly originalKey: string) {
|
||||
this.value = result.value;
|
||||
this.originalValue = result.originalValue;
|
||||
this.scmAnnotations = result.scmAnnotations;
|
||||
this.transformation = result.transformation;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user