From 40dbb971e62b3b19d15a8bca076cf35f72deb165 Mon Sep 17 00:00:00 2001 From: hofstef Date: Tue, 3 Dec 2024 19:17:41 +0100 Subject: [PATCH] simplification because iconset name is no longer displayed in title --- .../icon-set-details.component.ts | 8 ++-- .../icon-set-configuration.service.ts | 21 +++++----- .../icon-set-customization.service.spec.ts | 39 +------------------ .../icon-set-customization.service.ts | 9 +---- src/app/tools/title/services/title.service.ts | 13 ------- 5 files changed, 18 insertions(+), 72 deletions(-) diff --git a/src/app/tools/icon-set-config/presentation/icon-set-details/icon-set-details.component.ts b/src/app/tools/icon-set-config/presentation/icon-set-details/icon-set-details.component.ts index 611e6a49..b07609ee 100644 --- a/src/app/tools/icon-set-config/presentation/icon-set-details/icon-set-details.component.ts +++ b/src/app/tools/icon-set-config/presentation/icon-set-details/icon-set-details.component.ts @@ -1,8 +1,8 @@ import { Component, OnInit } from '@angular/core'; import { Observable } from 'rxjs'; import { IconSetCustomizationService } from 'src/app/tools/icon-set-config/services/icon-set-customization.service'; +import { IconSetConfigurationService } from 'src/app/tools/icon-set-config/services/icon-set-configuration.service'; import { IconListItem } from 'src/app/tools/icon-set-config/domain/iconListItem'; -import { TitleService } from 'src/app/tools/title/services/title.service'; @Component({ selector: 'app-icon-set-details', @@ -20,9 +20,9 @@ export class IconSetDetailsComponent implements OnInit { constructor( private customizationService: IconSetCustomizationService, - titleService: TitleService, + private configurationService: IconSetConfigurationService, ) { - this.iconSetName = titleService.iconSetName$; + this.iconSetName = configurationService.iconSetName$; } ngOnInit(): void {} @@ -68,6 +68,6 @@ export class IconSetDetailsComponent implements OnInit { } exportIconSet(): void { - this.customizationService.exportIconSet(); + this.configurationService.exportConfiguration(); } } diff --git a/src/app/tools/icon-set-config/services/icon-set-configuration.service.ts b/src/app/tools/icon-set-config/services/icon-set-configuration.service.ts index fed9d953..015685e1 100644 --- a/src/app/tools/icon-set-config/services/icon-set-configuration.service.ts +++ b/src/app/tools/icon-set-config/services/icon-set-configuration.service.ts @@ -1,10 +1,10 @@ import { Injectable } from '@angular/core'; +import { BehaviorSubject } from 'rxjs'; import { ElementRegistryService } from 'src/app/domain/services/element-registry.service'; import { IconDictionaryService } from 'src/app/tools/icon-set-config/services/icon-dictionary.service'; import { Dictionary } from 'src/app/domain/entities/dictionary'; import { ElementTypes } from 'src/app/domain/entities/elementTypes'; import { defaultIconSet } from '../domain/iconConfiguration'; -import { TitleService } from '../../title/services/title.service'; import { ICON_SET_CONFIGURATION_KEY, INITIAL_ICON_SET_NAME, @@ -25,17 +25,20 @@ export interface FileConfiguration { providedIn: 'root', }) export class IconSetConfigurationService { + private iconSetNameSubject = new BehaviorSubject( + INITIAL_ICON_SET_NAME, + ); + + iconSetName$ = this.iconSetNameSubject.asObservable(); + constructor( private iconDictionaryService: IconDictionaryService, private elementRegistryService: ElementRegistryService, - private titleService: TitleService, private storageService: StorageService, ) {} - setIconSetName(iconSetName: string): void { - this.titleService.setIconSetName( - iconSetName ? iconSetName : INITIAL_ICON_SET_NAME, - ); + setIconSetName(name: string): void { + this.iconSetNameSubject.next(name); // ? name : INITIAL_ICON_SET_NAME); } exportConfiguration(): void { @@ -45,7 +48,7 @@ export class IconSetConfigurationService { } const configJSONString = JSON.stringify(iconSetConfiguration, null, 2); - const filename = this.titleService.getIconSetName(); + const filename = this.iconSetNameSubject.value; const element = document.createElement('a'); element.setAttribute( @@ -139,7 +142,7 @@ export class IconSetConfigurationService { getCurrentConfigurationNamesWithoutPrefix(): CustomIconSetConfiguration { return { - name: this.titleService.getIconSetName() || INITIAL_ICON_SET_NAME, + name: this.iconSetNameSubject.value || INITIAL_ICON_SET_NAME, actors: this.iconDictionaryService .getActorsDictionary() .keysArray() @@ -194,7 +197,7 @@ export class IconSetConfigurationService { }); return { - name: this.titleService.getIconSetName(), + name: this.iconSetNameSubject.value, actors: newActors, workObjects: newWorkobjects, }; diff --git a/src/app/tools/icon-set-config/services/icon-set-customization.service.spec.ts b/src/app/tools/icon-set-config/services/icon-set-customization.service.spec.ts index 39db0da4..3576f73a 100644 --- a/src/app/tools/icon-set-config/services/icon-set-customization.service.spec.ts +++ b/src/app/tools/icon-set-config/services/icon-set-customization.service.spec.ts @@ -7,7 +7,6 @@ import { import { IconDictionaryService } from './icon-dictionary.service'; import { MockProvider, MockProviders } from 'ng-mocks'; import { TitleService } from '../../title/services/title.service'; -import { IconSetConfigurationService } from './icon-set-configuration.service'; import { ImportDomainStoryService } from '../../import/services/import-domain-story.service'; import { Dictionary } from '../../../domain/entities/dictionary'; import { Observable, of } from 'rxjs'; @@ -26,7 +25,6 @@ describe(IconSetCustomizationService.name, () => { let matSnackbarSpy: jasmine.SpyObj; let iconDictionarySpy: jasmine.SpyObj; - let configurationServiceSpy: jasmine.SpyObj; beforeEach(() => { const matSnackbarMock = jasmine.createSpyObj(MatSnackBar.name, ['open']); @@ -43,15 +41,6 @@ describe(IconSetCustomizationService.name, () => { 'unregisterIconForType', ], ); - const configurationServiceMock = jasmine.createSpyObj( - IconSetConfigurationService.name, - [ - 'createMinimalConfigurationWithDefaultIcons', - 'getCurrentConfigurationNamesWithoutPrefix', - 'setStoredIconSetConfiguration', - 'getStoredIconSetConfiguration', - ], - ); const elementRegistryServiceMock = jasmine.createSpyObj( ElementRegistryService.name, @@ -94,10 +83,7 @@ describe(IconSetCustomizationService.name, () => { provide: IconDictionaryService, useValue: iconDictionaryMock, }, - { - provide: IconSetConfigurationService, - useValue: configurationServiceMock, - }, + { provide: ElementRegistryService, useValue: elementRegistryServiceMock, @@ -108,9 +94,6 @@ describe(IconSetCustomizationService.name, () => { iconDictionarySpy = TestBed.inject( IconDictionaryService, ) as jasmine.SpyObj; - configurationServiceSpy = TestBed.inject( - IconSetConfigurationService, - ) as jasmine.SpyObj; iconDictionarySpy.getAllIconDictionary.and.returnValue(new Dictionary()); iconDictionarySpy.getFullDictionary.and.returnValue(new Dictionary()); @@ -122,12 +105,6 @@ describe(IconSetCustomizationService.name, () => { actors: [], workobjects: [], }); - configurationServiceSpy.getCurrentConfigurationNamesWithoutPrefix.and.returnValue( - structuredClone(testCustomIconSetConfiguration), - ); - configurationServiceSpy.createMinimalConfigurationWithDefaultIcons.and.returnValue( - INITIAL_ICON_SET_CONFIGURATION, - ); service = TestBed.inject(IconSetCustomizationService); }); @@ -166,10 +143,6 @@ describe(IconSetCustomizationService.name, () => { expect(selectedWorkObjects).toContain('Document'); expect(selectedWorkObjects).toContain('TestWorkObject'); - expect( - configurationServiceSpy.setStoredIconSetConfiguration, - ).toHaveBeenCalled(); - expect(iconDictionarySpy.getIconSource).toHaveBeenCalledWith('Person'); expect(iconDictionarySpy.getIconSource).toHaveBeenCalledWith('TestActor'); expect(iconDictionarySpy.getIconSource).toHaveBeenCalledWith('Document'); @@ -210,16 +183,6 @@ describe(IconSetCustomizationService.name, () => { }); }); - describe('reset Domain', () => { - it('should call correct function', () => { - service.resetIconSet(); - - expect( - configurationServiceSpy.createMinimalConfigurationWithDefaultIcons, - ).toHaveBeenCalled(); - }); - }); - describe('addNewIcon', () => { it('should add Icon', () => { service.addNewIcon('test'); diff --git a/src/app/tools/icon-set-config/services/icon-set-customization.service.ts b/src/app/tools/icon-set-config/services/icon-set-customization.service.ts index 642b2b88..6a3f5eca 100644 --- a/src/app/tools/icon-set-config/services/icon-set-customization.service.ts +++ b/src/app/tools/icon-set-config/services/icon-set-customization.service.ts @@ -13,10 +13,8 @@ import { import { Dictionary } from '../../../domain/entities/dictionary'; import { ElementTypes } from '../../../domain/entities/elementTypes'; import { IconListItem } from '../domain/iconListItem'; -import { TitleService } from '../../title/services/title.service'; import { IconSetConfigurationService } from './icon-set-configuration.service'; import { IconDictionaryService } from './icon-dictionary.service'; -import getIconId = ElementTypes.getIconId; import { IconSet } from '../../../domain/entities/iconSet'; import { CustomIconSetConfiguration } from '../../../domain/entities/custom-icon-set-configuration'; @@ -47,7 +45,6 @@ export class IconSetCustomizationService { private iconSetConfigurationService: IconSetConfigurationService, private iconDictionaryService: IconDictionaryService, iconSetChangedService: IconSetChangedService, - private titleService: TitleService, private elementRegistryService: ElementRegistryService, private snackbar: MatSnackBar, ) { @@ -149,7 +146,7 @@ export class IconSetCustomizationService { } changeName(iconSetName: string): void { - this.titleService.setIconSetName(iconSetName); + this.iconSetConfigurationService.setIconSetName(iconSetName); const changedIconSet = this.iconSetConfigurationTypes.value; changedIconSet.name = iconSetName; this.iconSetConfigurationTypes.next(changedIconSet); @@ -378,10 +375,6 @@ export class IconSetCustomizationService { } } - exportIconSet(): void { - this.iconSetConfigurationService.exportConfiguration(); - } - getAndClearSavedConfiguration(): IconSet | undefined { const temp = this.changedIconSetConfiguration; this.changedIconSetConfiguration = undefined; diff --git a/src/app/tools/title/services/title.service.ts b/src/app/tools/title/services/title.service.ts index c11b45f3..2f3391a3 100644 --- a/src/app/tools/title/services/title.service.ts +++ b/src/app/tools/title/services/title.service.ts @@ -3,7 +3,6 @@ import { BehaviorSubject } from 'rxjs'; import { environment } from '../../../../environments/environment'; import { INITIAL_DESCRIPTION, - INITIAL_ICON_SET_NAME, INITIAL_TITLE, } from '../../../domain/entities/constants'; import { CommandStackService } from '../../../domain/services/command-stack.service'; @@ -17,15 +16,11 @@ import { TitleDialogComponent } from '../presentation/title-dialog/title-dialog. export class TitleService { private titleSubject = new BehaviorSubject(INITIAL_TITLE); private descriptionSubject = new BehaviorSubject(INITIAL_DESCRIPTION); - private iconSetNameSubject = new BehaviorSubject( - INITIAL_ICON_SET_NAME, - ); private showDescriptionSubject = new BehaviorSubject(true); title$ = this.titleSubject.asObservable(); description$ = this.descriptionSubject.asObservable(); showDescription$ = this.showDescriptionSubject.asObservable(); - iconSetName$ = this.iconSetNameSubject.asObservable(); constructor( private commandStackService: CommandStackService, @@ -74,10 +69,6 @@ export class TitleService { this.showDescriptionSubject.next(show); } - setIconSetName(name: string): void { - this.iconSetNameSubject.next(name); - } - getTitle(): string { return this.titleSubject.value; } @@ -86,10 +77,6 @@ export class TitleService { return this.descriptionSubject.value; } - getIconSetName(): string { - return this.iconSetNameSubject.value; - } - getVersion(): string { return environment.version; }