From 4d386759c051efdfa2a2445509574d86a0100ab2 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 26 Jan 2024 11:06:01 +0100 Subject: [PATCH] Improved data import --- .../data-import-and-export.component.ts | 24 +++++++++---------- .../achievement/achievement.component.ts | 2 +- .../components/levels/levels.component.ts | 2 +- .../scheduled-events.component.ts | 2 +- .../short-role-names.component.ts | 9 +++++-- .../user-warning/user-warning.component.html | 8 +++---- .../user-warning/user-warning.component.ts | 2 +- 7 files changed, 26 insertions(+), 23 deletions(-) diff --git a/web/src/app/modules/shared/components/data-import-and-export/data-import-and-export.component.ts b/web/src/app/modules/shared/components/data-import-and-export/data-import-and-export.component.ts index 8bab8927..2d49e508 100644 --- a/web/src/app/modules/shared/components/data-import-and-export/data-import-and-export.component.ts +++ b/web/src/app/modules/shared/components/data-import-and-export/data-import-and-export.component.ts @@ -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); diff --git a/web/src/app/modules/view/server/achievements/components/achievement/achievement.component.ts b/web/src/app/modules/view/server/achievements/components/achievement/achievement.component.ts index e2b6e508..547e42f7 100644 --- a/web/src/app/modules/view/server/achievements/components/achievement/achievement.component.ts +++ b/web/src/app/modules/view/server/achievements/components/achievement/achievement.component.ts @@ -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; }); } diff --git a/web/src/app/modules/view/server/levels/components/levels/levels.component.ts b/web/src/app/modules/view/server/levels/components/levels/levels.component.ts index 19cb3469..32e713cd 100644 --- a/web/src/app/modules/view/server/levels/components/levels/levels.component.ts +++ b/web/src/app/modules/view/server/levels/components/levels/levels.component.ts @@ -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; }); } diff --git a/web/src/app/modules/view/server/scheduled-events/components/scheduled-events/scheduled-events.component.ts b/web/src/app/modules/view/server/scheduled-events/components/scheduled-events/scheduled-events.component.ts index a41c585c..ff31e343 100644 --- a/web/src/app/modules/view/server/scheduled-events/components/scheduled-events/scheduled-events.component.ts +++ b/web/src/app/modules/view/server/scheduled-events/components/scheduled-events/scheduled-events.component.ts @@ -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; }); } diff --git a/web/src/app/modules/view/server/short-role-name/components/short-role-names/short-role-names.component.ts b/web/src/app/modules/view/server/short-role-name/components/short-role-names/short-role-names.component.ts index f20fe69e..f74130e4 100644 --- a/web/src/app/modules/view/server/short-role-name/components/short-role-names/short-role-names.component.ts +++ b/web/src/app/modules/view/server/short-role-name/components/short-role-names/short-role-names.component.ts @@ -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; }); } diff --git a/web/src/app/modules/view/server/user-warning/components/user-warning/user-warning.component.html b/web/src/app/modules/view/server/user-warning/components/user-warning/user-warning.component.html index 2cdc08c9..22393b64 100644 --- a/web/src/app/modules/view/server/user-warning/components/user-warning/user-warning.component.html +++ b/web/src/app/modules/view/server/user-warning/components/user-warning/user-warning.component.html @@ -52,7 +52,7 @@ - +
{{'common.member' | translate}}
@@ -98,7 +98,7 @@ placeholder="{{'common.description' | translate}}"> - +
@@ -144,8 +144,8 @@ - - {{'common.user' | translate}}: + + {{'common.member' | translate}}: { return oldElement.id === newElement.id; });