Skip to content

Commit

Permalink
simplification because iconset name is no longer displayed in title
Browse files Browse the repository at this point in the history
  • Loading branch information
hofstef committed Dec 3, 2024
1 parent 498118f commit 40dbb97
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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 {}
Expand Down Expand Up @@ -68,6 +68,6 @@ export class IconSetDetailsComponent implements OnInit {
}

exportIconSet(): void {
this.customizationService.exportIconSet();
this.configurationService.exportConfiguration();
}
}
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -25,17 +25,20 @@ export interface FileConfiguration {
providedIn: 'root',
})
export class IconSetConfigurationService {
private iconSetNameSubject = new BehaviorSubject<string>(
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 {
Expand All @@ -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(
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -194,7 +197,7 @@ export class IconSetConfigurationService {
});

return {
name: this.titleService.getIconSetName(),
name: this.iconSetNameSubject.value,
actors: newActors,
workObjects: newWorkobjects,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -26,7 +25,6 @@ describe(IconSetCustomizationService.name, () => {

let matSnackbarSpy: jasmine.SpyObj<MatSnackBar>;
let iconDictionarySpy: jasmine.SpyObj<IconDictionaryService>;
let configurationServiceSpy: jasmine.SpyObj<IconSetConfigurationService>;

beforeEach(() => {
const matSnackbarMock = jasmine.createSpyObj(MatSnackBar.name, ['open']);
Expand All @@ -43,15 +41,6 @@ describe(IconSetCustomizationService.name, () => {
'unregisterIconForType',
],
);
const configurationServiceMock = jasmine.createSpyObj(
IconSetConfigurationService.name,
[
'createMinimalConfigurationWithDefaultIcons',
'getCurrentConfigurationNamesWithoutPrefix',
'setStoredIconSetConfiguration',
'getStoredIconSetConfiguration',
],
);

const elementRegistryServiceMock = jasmine.createSpyObj(
ElementRegistryService.name,
Expand Down Expand Up @@ -94,10 +83,7 @@ describe(IconSetCustomizationService.name, () => {
provide: IconDictionaryService,
useValue: iconDictionaryMock,
},
{
provide: IconSetConfigurationService,
useValue: configurationServiceMock,
},

{
provide: ElementRegistryService,
useValue: elementRegistryServiceMock,
Expand All @@ -108,9 +94,6 @@ describe(IconSetCustomizationService.name, () => {
iconDictionarySpy = TestBed.inject(
IconDictionaryService,
) as jasmine.SpyObj<IconDictionaryService>;
configurationServiceSpy = TestBed.inject(
IconSetConfigurationService,
) as jasmine.SpyObj<IconSetConfigurationService>;

iconDictionarySpy.getAllIconDictionary.and.returnValue(new Dictionary());
iconDictionarySpy.getFullDictionary.and.returnValue(new Dictionary());
Expand All @@ -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);
});
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -47,7 +45,6 @@ export class IconSetCustomizationService {
private iconSetConfigurationService: IconSetConfigurationService,
private iconDictionaryService: IconDictionaryService,
iconSetChangedService: IconSetChangedService,
private titleService: TitleService,
private elementRegistryService: ElementRegistryService,
private snackbar: MatSnackBar,
) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -378,10 +375,6 @@ export class IconSetCustomizationService {
}
}

exportIconSet(): void {
this.iconSetConfigurationService.exportConfiguration();
}

getAndClearSavedConfiguration(): IconSet | undefined {
const temp = this.changedIconSetConfiguration;
this.changedIconSetConfiguration = undefined;
Expand Down
13 changes: 0 additions & 13 deletions src/app/tools/title/services/title.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -17,15 +16,11 @@ import { TitleDialogComponent } from '../presentation/title-dialog/title-dialog.
export class TitleService {
private titleSubject = new BehaviorSubject<string>(INITIAL_TITLE);
private descriptionSubject = new BehaviorSubject<string>(INITIAL_DESCRIPTION);
private iconSetNameSubject = new BehaviorSubject<string>(
INITIAL_ICON_SET_NAME,
);
private showDescriptionSubject = new BehaviorSubject<boolean>(true);

title$ = this.titleSubject.asObservable();
description$ = this.descriptionSubject.asObservable();
showDescription$ = this.showDescriptionSubject.asObservable();
iconSetName$ = this.iconSetNameSubject.asObservable();

constructor(
private commandStackService: CommandStackService,
Expand Down Expand Up @@ -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;
}
Expand All @@ -86,10 +77,6 @@ export class TitleService {
return this.descriptionSubject.value;
}

getIconSetName(): string {
return this.iconSetNameSubject.value;
}

getVersion(): string {
return environment.version;
}
Expand Down

0 comments on commit 40dbb97

Please sign in to comment.