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

View File

@ -87,7 +87,7 @@ export class AchievementComponent extends ComponentWithTable implements OnInit,
private route: ActivatedRoute) {
super("achievement", ["id", "name", "description", "attribute", "operator", "value"],
(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
) {
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) {
super("ScheduledEvent", ["id", "interval", "name", "description", "channel_id", "start_time", "end_time", "type", "location"],
(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 { UserDTO } from "../../../../../../models/auth/auth-user.dto";
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 { LazyLoadEvent, MenuItem } from "primeng/api";
import { Table } from "primeng/table";
@ -74,7 +79,7 @@ export class ShortRoleNamesComponent extends ComponentWithTable implements OnIni
private route: ActivatedRoute
) {
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;
});
}

View File

@ -52,7 +52,7 @@
</div>
</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-text">{{'common.member' | translate}}</div>
<p-sortIcon field="attribute" class="table-header-icon"></p-sortIcon>
@ -98,7 +98,7 @@
placeholder="{{'common.description' | translate}}">
</form>
</th>
<th hideable-th="user" [parent]="this">
<th hideable-th="member" [parent]="this">
<form [formGroup]="filterForm">
<input type="text" pInputText formControlName="user"
placeholder="{{'common.member' | translate}}">
@ -144,8 +144,8 @@
</p-cellEditor>
</td>
<td hideable-td="user" [parent]="this">
<span class="p-column-title">{{'common.user' | translate}}:</span>
<td hideable-td="member" [parent]="this">
<span class="p-column-title">{{'common.member' | translate}}:</span>
<p-cellEditor>
<ng-template pTemplate="input">
<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 sidebar: SidebarService,
private route: ActivatedRoute) {
super("UserWarning", ["id", "name"],
super("UserWarning", ["id", "description", "member", "author"],
(oldElement: UserWarning, newElement: UserWarning) => {
return oldElement.id === newElement.id;
});