Skip to content

Commit

Permalink
Merge pull request #202 from dainst/outliers-modal-count
Browse files Browse the repository at this point in the history
Display count of affected resources in each modal of the warning system
  • Loading branch information
lsteinmann authored Jul 25, 2024
2 parents 1de3ee9 + 03cce60 commit 1785859
Show file tree
Hide file tree
Showing 22 changed files with 456 additions and 142 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Field, Document } from 'idai-field-core';

export type AffectedDocument = {
document: Document,
fields: Array<Field>
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export class ConvertFieldDataModalComponent {
public inputTypeLabel: string;

public convertAll: boolean;
public countAffected: number;

private affectedDocuments: Array<Document>;


constructor(public activeModal: NgbActiveModal,
Expand All @@ -43,6 +46,18 @@ export class ConvertFieldDataModalComponent {
}


public async initialize() {

const findResult = await this.datastore.find({
categories: [this.category.name],
constraints: { ['invalidFields:contain']: this.fieldName }
}, { includeResourcesWithoutValidParent: true });

this.countAffected = findResult.totalCount;
this.affectedDocuments = findResult.documents.filter(document => this.isConvertible(document));
}


public getFieldLabelHTML(): string {

return this.fieldLabel
Expand Down Expand Up @@ -89,15 +104,9 @@ export class ConvertFieldDataModalComponent {

private async convertMultiple() {

const documents = (await this.datastore.find({
categories: [this.category.name],
constraints: { ['invalidFields:contain']: this.fieldName }
}, { includeResourcesWithoutValidParent: true })).documents
.filter(document => this.isConvertible(document));

documents.forEach(document => this.convert(document));
this.affectedDocuments.forEach(document => this.convert(document));

await this.datastore.bulkUpdate(documents);
await this.datastore.bulkUpdate(this.affectedDocuments);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ <h5 class="modal-title" i18n="@@navbar.taskbar.convertFieldData.header">Felddate
konvertiert werden, so dass sie dem Eingabetyp <b>{{inputTypeLabel}}</b> entsprechen.
</span>

<div id="multiple-switch" class="row">
<div id="multiple-switch"
class="row"
[disableTooltip]="countAffected !== 1"
[class.disabled]="countAffected === 1"
ngbTooltip="Nur diese Ressource ist betroffen."
i18n-ngbTooltip="@@navbar.taskbar.warningsModal.singleResourceAffected"
container="body">
<div class="col-auto mr-auto">
<span i18n="@@navbar.taskbar.convertFieldData.all">In allen Ressourcen dieser Kategorie konvertieren</span>
</div>
<div class="col-auto">
<label class="switch">
<input type="checkbox" [checked]="convertAll" (change)="convertAll = !convertAll">
<label class="switch" [class.disabled]="countAffected === 1">
<input type="checkbox"
[checked]="convertAll"
(change)="convertAll = !convertAll"
[disabled]="countAffected === 1">
<span class="slider round"></span>
</label>
</div>
Expand All @@ -23,7 +32,7 @@ <h5 class="modal-title" i18n="@@navbar.taskbar.convertFieldData.header">Felddate
<div *ngIf="convertAll">
<div class="text-center alert alert-warning"
i18n="@@navbar.taskbar.convertFieldData.all.info">
Bitte beachten Sie: Durch diese Aktion werden in allen Ressourcen der
Bitte beachten Sie: Durch diese Aktion werden in allen <b>{{countAffected}}</b> Ressourcen der
Kategorie <b>{{getCategoryLabel()}}</b> ungültige Daten im
Feld <span [innerHTML]="getFieldLabelHTML()"></span> konvertiert (falls möglich).
</div>
Expand All @@ -35,7 +44,8 @@ <h5 class="modal-title" i18n="@@navbar.taskbar.convertFieldData.header">Felddate
(click)="performConversion()">
<span i18n="@@buttons.ok">OK</span>
</div>
<div class="btn btn-secondary"
<div id="cancel-button"
class="btn btn-secondary"
(click)="cancel()">
<span i18n="@@buttons.cancel">Abbrechen</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export class DeleteFieldDataModalComponent {

public deleteAll: boolean;
public confirmFieldName: string;

public countAffected: number;

private affectedDocuments: Array<Document>;

constructor(public activeModal: NgbActiveModal,
private modalService: NgbModal,
Expand All @@ -43,6 +45,18 @@ export class DeleteFieldDataModalComponent {
}


public async initialize() {

const findResult = await this.datastore.find({
categories: [this.category.name],
constraints: { [this.warningType + ':contain']: this.fieldName }
}, { includeResourcesWithoutValidParent: true });

this.countAffected = findResult.totalCount;
this.affectedDocuments = findResult.documents;
}


public getFieldLabelHTML(): string {

return this.fieldLabel
Expand Down Expand Up @@ -100,15 +114,10 @@ export class DeleteFieldDataModalComponent {

private async deleteMultiple() {

const documents = (await this.datastore.find({
categories: [this.category.name],
constraints: { [this.warningType + ':contain']: this.fieldName }
}, { includeResourcesWithoutValidParent: true })).documents;

documents.forEach(document => {
this.affectedDocuments.forEach(document => {
delete document.resource[this.fieldName];
});

await this.datastore.bulkUpdate(documents);
await this.datastore.bulkUpdate(this.affectedDocuments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ <h5 class="modal-title" i18n="@@navbar.taskbar.deleteFieldData.header">Felddaten
Daten wirklich löschen?
</span>

<div id="multiple-switch" class="row">
<div id="multiple-switch"
class="row"
[disableTooltip]="countAffected !== 1"
[class.disabled]="countAffected === 1"
ngbTooltip="Nur diese Ressource ist betroffen."
i18n-ngbTooltip="@@navbar.taskbar.warningsModal.singleResourceAffected"
container="body">
<div class="col-auto mr-auto">
<span i18n="@@navbar.taskbar.deleteFieldData.all">Bei allen Ressourcen dieser Kategorie löschen</span>
</div>
<div class="col-auto">
<label class="switch">
<input type="checkbox" [checked]="deleteAll" (change)="deleteAll = !deleteAll">
<label class="switch" [class.disabled]="countAffected === 1">
<input type="checkbox"
[checked]="deleteAll"
(change)="deleteAll = !deleteAll"
[disabled]="countAffected === 1">
<span class="slider round"></span>
</label>
</div>
Expand All @@ -23,13 +32,13 @@ <h5 class="modal-title" i18n="@@navbar.taskbar.deleteFieldData.header">Felddaten
<div *ngIf="deleteAll">
<div *ngIf="warningType === 'unconfiguredFields'" class="text-center alert alert-warning"
i18n="@@navbar.taskbar.deleteFieldData.all.info.unconfigured">
Bitte beachten Sie: Durch diese Aktion werden bei allen Ressourcen der
Bitte beachten Sie: Durch diese Aktion werden bei allen <b>{{countAffected}}</b> Ressourcen der
Kategorie <b>{{getCategoryLabel()}}</b> sämtliche eingetragenen Daten im
Feld <span [innerHTML]="getFieldLabelHTML()"></span> gelöscht.
</div>
<div *ngIf="warningType === 'invalidFields'" class="text-center alert alert-warning"
i18n="@@navbar.taskbar.deleteFieldData.all.info.invalid">
Bitte beachten Sie: Durch diese Aktion werden bei allen Ressourcen der
Bitte beachten Sie: Durch diese Aktion werden bei <b>{{countAffected}}</b> allen Ressourcen der
Kategorie <b>{{getCategoryLabel()}}</b> sämtliche ungültigen Daten im
Feld <span [innerHTML]="getFieldLabelHTML()"></span> gelöscht. Gültige Daten bleiben erhalten.
</div>
Expand All @@ -52,7 +61,8 @@ <h5 class="modal-title" i18n="@@navbar.taskbar.deleteFieldData.header">Felddaten
(click)="performDeletion()">
<span i18n="@@buttons.ok">OK</span>
</div>
<div class="btn btn-secondary"
<div id="cancel-button"
class="btn btn-secondary"
(click)="cancel()">
<span i18n="@@buttons.cancel">Abbrechen</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { flatten, isArray, isObject, isString, isEmpty } from 'tsfun';
import { BaseField, CategoryForm, Datastore, Dimension, Document, Field, ProjectConfiguration } from 'idai-field-core';
import { DeletionInProgressModalComponent } from '../../../widgets/deletion-in-progress-modal.component';
import { AngularUtility } from '../../../../angular/angular-utility';
import { AffectedDocument } from '../affected-document';


@Component({
Expand All @@ -21,8 +22,10 @@ export class DeleteOutliersModalComponent {
public field: Field;
public fieldLabel: string|undefined;
public outlierValue: string;

public deleteAll: boolean;
public countAffected: number;

private affectedDocuments: Array<AffectedDocument>;


constructor(public activeModal: NgbActiveModal,
Expand All @@ -33,13 +36,37 @@ export class DeleteOutliersModalComponent {

public cancel = () => this.activeModal.dismiss('cancel');


public async onKeyDown(event: KeyboardEvent) {

if (event.key === 'Escape') this.activeModal.dismiss('cancel');
}


public async initialize() {

this.affectedDocuments = [];

const foundDocuments: Array<Document> = (await this.datastore.find({
constraints: { ['outlierValues:contain']: this.outlierValue }
}, { includeResourcesWithoutValidParent: true })).documents;

for (let document of foundDocuments) {
const category: CategoryForm = this.projectConfiguration.getCategory(document.resource.category);
const affectedDocument: AffectedDocument = { document: document, fields: [] };

for (let fieldName of Object.keys(document.warnings.outliers.fields)) {
const field: Field = CategoryForm.getField(category, fieldName);
if (!this.hasOutlierValue(document, field)) continue;
affectedDocument.fields.push(field);
}

if (affectedDocument.fields.length) this.affectedDocuments.push(affectedDocument);
}

this.countAffected = this.affectedDocuments.length;
}

public getFieldLabelHTML(): string {

return this.fieldLabel
Expand Down Expand Up @@ -88,24 +115,15 @@ export class DeleteOutliersModalComponent {

private async deleteMultiple() {

const documents = (await this.datastore.find({
constraints: { ['outlierValues:contain']: this.outlierValue }
}, { includeResourcesWithoutValidParent: true })).documents;

const changedDocuments: Array<Document> = [];

for (let document of documents) {
const category: CategoryForm = this.projectConfiguration.getCategory(document.resource.category);

for (let fieldName of Object.keys(document.warnings.outliers.fields)) {
const field: Field = CategoryForm.getField(category, fieldName);
if (!this.hasOutlierValue(document, field)) continue;
this.deleteValue(document, document.resource, field);
if (!changedDocuments.includes(document)) changedDocuments.push(document);
for (let affectedDocument of this.affectedDocuments) {
for (let field of affectedDocument.fields) {
this.deleteValue(affectedDocument.document, affectedDocument.document.resource, field);
}
}

await this.datastore.bulkUpdate(changedDocuments);
await this.datastore.bulkUpdate(
this.affectedDocuments.map(affectedDocument => affectedDocument.document)
);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ <h5 class="modal-title" i18n="@@navbar.taskbar.deleteOutliers.header">
Wert <b>{{outlierValue}}</b> wirklich löschen?
</div>

<div id="multiple-switch" class="row">
<div id="multiple-switch"
class="row"
[disableTooltip]="countAffected !== 1"
[class.disabled]="countAffected === 1"
ngbTooltip="Nur diese Ressource ist betroffen."
i18n-ngbTooltip="@@navbar.taskbar.warningsModal.singleResourceAffected"
container="body">
<div class="col-auto mr-auto">
<span i18n="@@navbar.taskbar.deleteOutliers.all">Alle Vorkommnisse dieses Werts löschen</span>
</div>
<div class="col-auto">
<label class="switch">
<input type="checkbox" [checked]="deleteAll" (change)="deleteAll = !deleteAll">
<label class="switch" [class.disabled]="countAffected === 1">
<input type="checkbox"
[checked]="deleteAll"
(change)="deleteAll = !deleteAll"
[disabled]="countAffected === 1">
<span class="slider round"></span>
</label>
</div>
Expand All @@ -26,7 +35,7 @@ <h5 class="modal-title" i18n="@@navbar.taskbar.deleteOutliers.header">
<div class="text-center alert alert-warning"
i18n="@@navbar.taskbar.deleteOutliers.all.info">
Bitte beachten Sie: Durch diese Aktion wird der nicht in der Werteliste enthaltene Wert
<b>{{outlierValue}}</b> in sämtlichen Feldern aller Ressourcen gelöscht.
<b>{{outlierValue}}</b> in sämtlichen Feldern aller <b>{{countAffected}}</b> Ressourcen gelöscht.
</div>
</div>
</div>
Expand All @@ -36,7 +45,8 @@ <h5 class="modal-title" i18n="@@navbar.taskbar.deleteOutliers.header">
(click)="performDeletion()">
<span i18n="@@buttons.ok">OK</span>
</div>
<div class="btn btn-secondary"
<div id="cancel-button"
class="btn btn-secondary"
(click)="cancel()">
<span i18n="@@buttons.cancel">Abbrechen</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export class DeleteResourceModalComponent {

public deleteAll: boolean;
public confirmValue: string;
public countAffected: number;

private affectedDocuments: Array<Document>;


constructor(public activeModal: NgbActiveModal,
Expand All @@ -31,7 +34,6 @@ export class DeleteResourceModalComponent {

public isMultipleSwitchAvailable = () => this.warningType === 'unconfiguredCategory';


public cancel = () => this.activeModal.dismiss('cancel');


Expand All @@ -40,6 +42,21 @@ export class DeleteResourceModalComponent {
if (event.key === 'Escape') this.activeModal.dismiss('cancel');
}


public async initialize() {

const foundDocuments: Array<Document> = (await this.datastore.find(
{ categories: ['UNCONFIGURED'] },
{ includeResourcesWithoutValidParent: true }
)).documents;

this.affectedDocuments = foundDocuments.filter(document => {
return document.resource.category === this.document.resource.category;
});

this.countAffected = this.affectedDocuments.length;
}


public isDeletionAllowed(): boolean {

Expand Down Expand Up @@ -90,13 +107,8 @@ export class DeleteResourceModalComponent {


private async deleteMultiple() {

const documents = (await this.datastore.find(
{ categories: ['UNCONFIGURED'] },
{ includeResourcesWithoutValidParent: true }
)).documents.filter(document => document.resource.category === this.document.resource.category);

for (let document of documents) {
for (let document of this.affectedDocuments) {
await this.relationsManager.remove(document);
}
}
Expand Down
Loading

0 comments on commit 1785859

Please sign in to comment.