Skip to content

Commit

Permalink
fix: theme import
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryT-CG committed Mar 25, 2024
1 parent 5ec9487 commit 85dfd84
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/app/theme/theme-import/theme-import.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
type="text"
id="theme_import_themeName"
class="w-full pt-3 pb-2"
[(ngModel)]="themeSnapshot.themes"
[(ngModel)]="themeName"
(ngModelChange)="checkThemeExistence()"
(keyup)="checkThemeExistence()"
[pTooltip]="'THEME.THEME_NAME' | translate"
tooltipPosition="top"
tooltipEvent="focus"
Expand Down
28 changes: 16 additions & 12 deletions src/app/theme/theme-import/theme-import.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class ThemeImportComponent implements OnInit {
ngOnInit(): void {
this.httpHeaders = new HttpHeaders()
this.httpHeaders = this.httpHeaders.set('Content-Type', 'application/json')
this.getThemes(false)
this.getThemes()
}

public async onImportThemeSelect(event: { files: FileList }): Promise<void> {
Expand All @@ -47,8 +47,10 @@ export class ThemeImportComponent implements OnInit {
if (this.isThemeImportRequestDTO(themeSnapshot)) {
this.themeSnapshot = themeSnapshot
this.themeImportError = false
if (themeSnapshot.themes !== undefined) {
this.properties = themeSnapshot.themes[Object.keys(themeSnapshot.themes)[0]].properties
if (themeSnapshot.themes) {
let key: string[] = Object.keys(themeSnapshot.themes)
this.themeName = key[0]
this.properties = themeSnapshot.themes[key[0]].properties
}
this.checkThemeExistence()
} else {
Expand All @@ -62,12 +64,7 @@ export class ThemeImportComponent implements OnInit {
}

public checkThemeExistence() {
this.themeNameExists = false
if (this.themeSnapshot?.themes) {
if (this.themes.find((theme) => Object.keys(this.themeSnapshot!.themes!).indexOf(theme.name!) > -1)) {
this.themeNameExists = true
}
}
this.themeNameExists = this.themes.filter((theme) => theme.name === this.themeName).length > 0
}

public onImportThemeHide(): void {
Expand All @@ -78,6 +75,14 @@ export class ThemeImportComponent implements OnInit {
this.themeImportError = false
}
public onThemeUpload(): void {
if (!this.themeSnapshot || !this.themeSnapshot.themes) return
let key: string[] = Object.keys(this.themeSnapshot?.themes)
if (key[0] !== this.themeName) {
// save the theme properties to be reassigned on new key
let themeProps = Object.getOwnPropertyDescriptor(this.themeSnapshot.themes, key[0])
Object.defineProperty(this.themeSnapshot.themes, this.themeName, themeProps ?? {})
delete this.themeSnapshot.themes[key[0]]
}
this.themeApi
.importThemes({
themeSnapshot: this.themeSnapshot as ThemeSnapshot
Expand All @@ -88,7 +93,7 @@ export class ThemeImportComponent implements OnInit {
this.onImportThemeClear()
this.displayThemeImport = false
this.uploadEmitter.emit()
this.router.navigate([`./${data.id}`], { relativeTo: this.route })
this.router.navigate([`./${this.themeName}`], { relativeTo: this.route })
},
error: () => {
this.msgService.error({ summaryKey: 'THEME.IMPORT.IMPORT_THEME_FAIL' })
Expand All @@ -101,12 +106,11 @@ export class ThemeImportComponent implements OnInit {
return !!(typeof dto === 'object' && dto?.themes)
}

private getThemes(emit: boolean): void {
private getThemes(): void {
this.themeApi.getThemes({}).subscribe((themes) => {
if (themes.stream) {
this.themes = themes.stream
}
// if (emit) this.uploadEmitter.emit()
})
}
}
2 changes: 1 addition & 1 deletion src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"DELETE": {
"LABEL": "Löschen",
"TOOLTIP": "Theme löschen",
"THEME_MESSAGE": "Möchten Sie {{ITEM}} löschen?",
"THEME_MESSAGE": "Möchten Sie \"{{ITEM}}\" löschen?",
"MESSAGE_INFO": "Diese Aktion kann nicht rückgängig gemacht werden!",
"THEME_NOK": "Theme konnte nicht gelöscht werden",
"THEME_OK": "Theme erfolgreich gelöscht"
Expand Down
2 changes: 1 addition & 1 deletion src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"DELETE": {
"LABEL": "Delete",
"TOOLTIP": "Delete theme",
"THEME_MESSAGE": "Do you want to delete {{ITEM}}?",
"THEME_MESSAGE": "Do you want to delete \"{{ITEM}}\"?",
"MESSAGE_INFO": "This action cannot be undone!",
"THEME_NOK": "Theme could not be deleted",
"THEME_OK": "Theme deleted successfully"
Expand Down

0 comments on commit 85dfd84

Please sign in to comment.