Skip to content

Commit

Permalink
Account import improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
luisa-beerboom committed Oct 19, 2023
1 parent aa45061 commit 17d6cab
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 11 deletions.
4 changes: 3 additions & 1 deletion client/src/app/domain/models/organizations/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class OrganizationSetting {
public saml_metadata_idp!: string;
public saml_metadata_sp!: string;
public saml_private_key!: string;
public genders!: string[];
}

export class Organization extends BaseModel<Organization> {
Expand Down Expand Up @@ -87,7 +88,8 @@ export class Organization extends BaseModel<Organization> {
`users_email_replyto`,
`users_email_subject`,
`users_email_body`,
`url`
`url`,
`genders`
];
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/app/domain/models/users/user.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const userHeadersAndVerboseNames: { [key in keyof User]?: any } = {
last_name: _(`Surname`),
email: _(`Email`),
pronoun: _(`Pronoun`),
gender: _(`Gender`),
gender: _(`Gender, possible options: %gender%`),
username: _(`Username`),
default_password: _(`Initial password`),
is_active: _(`Active`),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export class OrganizationRepositoryService extends BaseRepository<ViewOrganizati
`default_language`,
`saml_metadata_idp`,
`saml_metadata_sp`,
`saml_private_key`
`saml_private_key`,
`genders`
);
return {
...super.getFieldsets(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { BaseViaBackendImportListComponent } from 'src/app/site/base/base-via-backend-import-list.component';
import { OrganizationSettingsService } from 'src/app/site/pages/organization/services/organization-settings.service';
import { ComponentServiceCollectorService } from 'src/app/site/services/component-service-collector.service';
import { ImportListHeaderDefinition } from 'src/app/ui/modules/import-list';

Expand All @@ -17,14 +18,18 @@ export class AccountImportListComponent extends BaseViaBackendImportListComponen

public columns: ImportListHeaderDefinition[] = Object.keys(accountHeadersAndVerboseNames).map(header => ({
property: header,
label: (<any>accountHeadersAndVerboseNames)[header],
label: ((<any>accountHeadersAndVerboseNames)[header] as string).replace(
`%gender%`,
this.orgaSettings.instant(`genders`).join(`, `)
),
isTableColumn: true
}));

public constructor(
componentServiceCollector: ComponentServiceCollectorService,
protected override translate: TranslateService,
public override importer: AccountImportService
public override importer: AccountImportService,
public orgaSettings: OrganizationSettingsService
) {
super(componentServiceCollector, translate, importer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class AccountImportService extends BaseBackendImportService {
created: _(`Accounts created`),
updated: _(`Accounts updated`),
error: _(`Accounts with errors`),
warning: _(`Accounts with warnings (will be skipped)`)
warning: _(`Accounts with warnings (columns will be skipped)`)
};

public constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ <h2>{{ finishedWithWarning ? ('Rows with warnings' | translate) : ('Preview' | t

<ng-template #nonObjectEntryTemplate let-entry="entry" let-type="type">
<ng-container *ngIf="type === 'string'">{{ entry | translate }}</ng-container>
<ng-container *ngIf="type === 'number' || type === 'integer'">{{ entry }}</ng-container>
<ng-container *ngIf="type === 'number' || type === 'integer' || type === 'decimal'">{{ entry }}</ng-container>
<ng-container *ngIf="type === 'date'">{{ entry }}</ng-container>
<mat-checkbox *ngIf="type === 'boolean'" [checked]="entry" disabled></mat-checkbox>
&nbsp;
Expand All @@ -216,16 +216,34 @@ <h2>{{ finishedWithWarning ? ('Rows with warnings' | translate) : ('Preview' | t
rowClass="import-list-preview-row"
>
<div
*osScrollingTableCell="'status'; row as row; config: { width: 25, position: START_POSITION }"
*osScrollingTableCell="'errors'; row as row; config: { width: 25, position: START_POSITION }"
class="flex-vertical-center"
>
<mat-icon
[ngClass]="{ 'red-warning-text': row.state === 'error', warn: row.state === 'warning' }"
*ngIf="row.state === 'error'"
class="red-warning-text"
matTooltip="{{ getRowTooltip(row) }}"
matTooltipPosition="right"
>
{{ getActionIcon(row) }}
</mat-icon>
<mat-icon
*ngIf="row.state !== 'error' && row.messages.length"
class="warn"
matTooltip="{{ getWarningRowTooltip(row) }}"
matTooltipPosition="right"
>
warning
</mat-icon>
</div>

<div
*osScrollingTableCell="'status'; row as row; config: { width: 25, position: START_POSITION }"
class="flex-vertical-center"
>
<mat-icon *ngIf="row.state !== 'error'" matTooltip="{{ getRowTooltip(row) }}" matTooltipPosition="right">
{{ getActionIcon(row) }}
</mat-icon>
</div>
<div *osScrollingTableCell="'id'; value as value; config: { width: 25, position: START_POSITION }">
<div *osScrollingTableCellLabel>#</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export class BackendImportListComponent implements OnInit, OnDestroy {
_(`There is an unspecified error in this line, which prevents the import.`)
);
case BackendImportState.Warning:
return this.getErrorDescription(row) ?? _(`This row will not be imported, due to an unknown reason.`);
return this.getErrorDescription(row) ?? _(`The affected columns will not be imported.`);
case BackendImportState.New:
return this.translate.instant(this.modelName) + ` ` + this.translate.instant(`will be imported`);
case BackendImportState.Done: // item will be updated / has been imported
Expand All @@ -397,6 +397,18 @@ export class BackendImportListComponent implements OnInit, OnDestroy {
}
}

public getWarningRowTooltip(row: BackendImportIdentifiedRow): string {
switch (row.state) {
case BackendImportState.Error: // no import possible
return (
this.getErrorDescription(row) ??
_(`There is an unspecified error in this line, which prevents the import.`)
);
default:
return this.getErrorDescription(row) ?? _(`The affected columns will not be imported.`);
}
}

/**
* A function to trigger the csv example download.
*/
Expand Down Expand Up @@ -466,7 +478,7 @@ export class BackendImportListComponent implements OnInit, OnDestroy {
}

private getErrorDescription(entry: BackendImportIdentifiedRow): string {
return entry.messages?.map(error => this.translate.instant(this._importer.verbose(error))).join(`,\n `);
return entry.messages?.map(error => this.translate.instant(this._importer.verbose(error))).join(`\n `);
}

private fillPreviewData(previews: BackendImportPreview[]) {
Expand Down

0 comments on commit 17d6cab

Please sign in to comment.