Improved data import

This commit is contained in:
Sven Heidemann 2024-01-26 11:06:01 +01:00
parent 3683f5f3d1
commit 4d386759c0
7 changed files with 26 additions and 23 deletions

View File

@ -1,7 +1,6 @@
import { Component, EventEmitter, Input, Output, ViewChild } from "@angular/core"; import { Component, EventEmitter, Input, Output, ViewChild } from "@angular/core";
import { ToastService } from "../../../../services/toast/toast.service"; import { ToastService } from "../../../../services/toast/toast.service";
import { TranslateService } from "@ngx-translate/core"; import { TranslateService } from "@ngx-translate/core";
import { elementAt } from "rxjs";
interface UploadEvent { interface UploadEvent {
originalEvent: Event; originalEvent: Event;
@ -60,22 +59,21 @@ export class DataImportAndExportComponent {
const fileReader = new FileReader(); const fileReader = new FileReader();
fileReader.onload = () => { fileReader.onload = () => {
if (!fileReader.result) return; if (!fileReader.result) return;
const newData: any[] = JSON.parse(fileReader.result.toString()); let incomingData: any[] = JSON.parse(fileReader.result.toString());
this.upload.clear(); this.upload.clear();
newData.forEach(element => {
element.id = 0; let newData: any[];
}); newData = [];
this.data.forEach(element => {
const existingElement = newData.find(x => this.validator(x, element)); incomingData.forEach(element => {
const existingElement = this.data.find(x => this.validator(x, element));
if (existingElement) { if (existingElement) {
const index = this.data.indexOf(element); this.data[this.data.indexOf(existingElement)] = element;
const oldId = element.id; } else {
element = existingElement; newData.push(element);
element.id = oldId;
this.data[index] = element;
newData.splice(newData.indexOf(existingElement), 1);
} }
}); });
this.callback(this.data, false); this.callback(this.data, false);
this.callback(newData, true); this.callback(newData, true);
this.data.push(...newData); this.data.push(...newData);

View File

@ -87,7 +87,7 @@ export class AchievementComponent extends ComponentWithTable implements OnInit,
private route: ActivatedRoute) { private route: ActivatedRoute) {
super("achievement", ["id", "name", "description", "attribute", "operator", "value"], super("achievement", ["id", "name", "description", "attribute", "operator", "value"],
(oldElement: Achievement, newElement: Achievement) => { (oldElement: Achievement, newElement: Achievement) => {
return oldElement.name === newElement.name; return oldElement.id === newElement.id;
}); });
} }

View File

@ -73,7 +73,7 @@ export class LevelsComponent extends ComponentWithTable implements OnInit, OnDes
private route: ActivatedRoute private route: ActivatedRoute
) { ) {
super("level", ["id", "icon", "name", "color", "min_xp", "permissions"], (oldElement: Level, newElement: Level) => { super("level", ["id", "icon", "name", "color", "min_xp", "permissions"], (oldElement: Level, newElement: Level) => {
return oldElement.name === newElement.name; return oldElement.id === newElement.id;
}); });
} }

View File

@ -87,7 +87,7 @@ export class ScheduledEventsComponent extends ComponentWithTable implements OnIn
private route: ActivatedRoute) { private route: ActivatedRoute) {
super("ScheduledEvent", ["id", "interval", "name", "description", "channel_id", "start_time", "end_time", "type", "location"], super("ScheduledEvent", ["id", "interval", "name", "description", "channel_id", "start_time", "end_time", "type", "location"],
(oldElement: ScheduledEvent, newElement: ScheduledEvent) => { (oldElement: ScheduledEvent, newElement: ScheduledEvent) => {
return oldElement.name === newElement.name; return oldElement.id === newElement.id;
}); });
} }

View File

@ -16,7 +16,12 @@ import { Sort, SortDirection } from "../../../../../../models/graphql/filter/sor
import { Subject, throwError } from "rxjs"; import { Subject, throwError } from "rxjs";
import { UserDTO } from "../../../../../../models/auth/auth-user.dto"; import { UserDTO } from "../../../../../../models/auth/auth-user.dto";
import { Queries } from "../../../../../../models/graphql/queries.model"; import { Queries } from "../../../../../../models/graphql/queries.model";
import { ShortRoleNameListQuery, Query, SingleDiscordQuery, ShortRoleNamePositionsQuery } from "../../../../../../models/graphql/query.model"; import {
Query,
ShortRoleNameListQuery,
ShortRoleNamePositionsQuery,
SingleDiscordQuery
} from "../../../../../../models/graphql/query.model";
import { catchError, debounceTime, takeUntil } from "rxjs/operators"; import { catchError, debounceTime, takeUntil } from "rxjs/operators";
import { LazyLoadEvent, MenuItem } from "primeng/api"; import { LazyLoadEvent, MenuItem } from "primeng/api";
import { Table } from "primeng/table"; import { Table } from "primeng/table";
@ -74,7 +79,7 @@ export class ShortRoleNamesComponent extends ComponentWithTable implements OnIni
private route: ActivatedRoute private route: ActivatedRoute
) { ) {
super("short-role-names", ["id", "name", "role", "position"], (oldElement: ShortRoleName, newElement: ShortRoleName) => { super("short-role-names", ["id", "name", "role", "position"], (oldElement: ShortRoleName, newElement: ShortRoleName) => {
return oldElement.shortName === newElement.shortName && return oldElement.id === newElement.id &&
oldElement.roleId === newElement.roleId; oldElement.roleId === newElement.roleId;
}); });
} }

View File

@ -52,7 +52,7 @@
</div> </div>
</th> </th>
<th hideable-th="user" [parent]="this" [sortable]="true"> <th hideable-th="member" [parent]="this" [sortable]="true">
<div class="table-header-label"> <div class="table-header-label">
<div class="table-header-text">{{'common.member' | translate}}</div> <div class="table-header-text">{{'common.member' | translate}}</div>
<p-sortIcon field="attribute" class="table-header-icon"></p-sortIcon> <p-sortIcon field="attribute" class="table-header-icon"></p-sortIcon>
@ -98,7 +98,7 @@
placeholder="{{'common.description' | translate}}"> placeholder="{{'common.description' | translate}}">
</form> </form>
</th> </th>
<th hideable-th="user" [parent]="this"> <th hideable-th="member" [parent]="this">
<form [formGroup]="filterForm"> <form [formGroup]="filterForm">
<input type="text" pInputText formControlName="user" <input type="text" pInputText formControlName="user"
placeholder="{{'common.member' | translate}}"> placeholder="{{'common.member' | translate}}">
@ -144,8 +144,8 @@
</p-cellEditor> </p-cellEditor>
</td> </td>
<td hideable-td="user" [parent]="this"> <td hideable-td="member" [parent]="this">
<span class="p-column-title">{{'common.user' | translate}}:</span> <span class="p-column-title">{{'common.member' | translate}}:</span>
<p-cellEditor> <p-cellEditor>
<ng-template pTemplate="input"> <ng-template pTemplate="input">
<p-dropdown *ngIf="isEditingNew; else userName" optionLabel="name" [options]="users" <p-dropdown *ngIf="isEditingNew; else userName" optionLabel="name" [options]="users"

View File

@ -71,7 +71,7 @@ export class UserWarningComponent extends ComponentWithTable implements OnInit,
private data: DataService, private data: DataService,
private sidebar: SidebarService, private sidebar: SidebarService,
private route: ActivatedRoute) { private route: ActivatedRoute) {
super("UserWarning", ["id", "name"], super("UserWarning", ["id", "description", "member", "author"],
(oldElement: UserWarning, newElement: UserWarning) => { (oldElement: UserWarning, newElement: UserWarning) => {
return oldElement.id === newElement.id; return oldElement.id === newElement.id;
}); });