Skip to content

Commit

Permalink
removed unused code and lots of renaming for more clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
hofstef committed Sep 5, 2024
1 parent 5fc4079 commit 10dfde0
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 80 deletions.
20 changes: 4 additions & 16 deletions src/app/tools/icon-set-config/domain/allIcons.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Dictionary } from 'src/app/domain/entities/dictionary';

export let appendedIcons = new Dictionary();
export let customIcons = new Dictionary();

// These SVGs are used to render the actors/work objects on the canvas and in the iconset configuration. For palette and context pad, icons.css is used.
export const allIcons = {
export const builtInIcons = {
Person:
'<svg viewBox="0 0 24 26" xmlns="http://www.w3.org/2000/svg"><path d="M12 5.9c1.16 0 2.1.94 2.1 2.1s-.94 2.1-2.1 2.1S9.9 9.16 9.9 8s.94-2.1 2.1-2.1m0 9c2.97 0 6.1 1.46 6.1 2.1v1.1H5.9V17c0-.64 3.13-2.1 6.1-2.1M12 4C9.79 4 8 5.79 8 8s1.79 4 4 4 4-1.79 4-4-1.79-4-4-4zm0 9c-2.67 0-8 1.34-8 4v3h16v-3c0-2.66-5.33-4-8-4z"/><path d="M0 0h24v24H0z" fill="none"/></svg>',
Group:
Expand Down Expand Up @@ -230,20 +230,8 @@ export const allIcons = {
'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px"><g><rect fill="none" height="24" width="24"/><path d="M19,3H5C3.89,3,3,3.9,3,5v14c0,1.1,0.89,2,2,2h14c1.1,0,2-0.9,2-2V5C21,3.9,20.11,3,19,3z M19,19H5V7h14V19z M17,12H7v-2 h10V12z M13,16H7v-2h6V16z"/></g></svg>',
};

export function getAllStandardIconKeys(): string[] {
const allIconsDict = new Dictionary();

allIconsDict.addEach(allIcons);

return allIconsDict.keysArray();
}

export function overrideAppendedIcons(newIcons: Dictionary): void {
appendedIcons = newIcons;
}

export function updateAppendedIcons(newIcons: Dictionary): void {
export function addCustomIcons(newIcons: Dictionary): void {
for (const key in newIcons.keysArray().entries()) {
appendedIcons.add(newIcons.get(key), key);
customIcons.add(newIcons.get(key), key);
}
}
35 changes: 13 additions & 22 deletions src/app/tools/icon-set-config/domain/iconConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,57 @@
import { Dictionary } from 'src/app/domain/entities/dictionary';
import {
overrideAppendedIcons,
updateAppendedIcons,
} from 'src/app/tools/icon-set-config/domain/allIcons';
import { addCustomIcons } from 'src/app/tools/icon-set-config/domain/allIcons';
import { Configuration } from 'src/app/domain/entities/configuration';
import { INITIAL_ICON_SET_NAME } from '../../../domain/entities/constants';
import { IconSetConfiguration } from '../../../domain/entities/icon-set-configuration';

export class IconConfiguration {
domainName = INITIAL_ICON_SET_NAME;
iconSetName = INITIAL_ICON_SET_NAME;

private allIconDictionary: Dictionary;

constructor(allIconDictionary: Dictionary) {
this.allIconDictionary = allIconDictionary;
}

/**
* Select the Iconset which you want to use
*/
getDefaultConf(): Configuration {
return defaultConf;
}

updateAllIconRegistry(allIconDictionary: Dictionary): void {
this.allIconDictionary = allIconDictionary;
}

appendSRCFile(
addCustomIcons(
actors: string[],
actorsDict: Dictionary,
workObjects: string[],
workObjectsDict: Dictionary,
): void {
const newAppendedIcons: { [key: string]: any } = {};
const newCustomIcons: { [key: string]: any } = {};

actors.forEach((name: string) => {
if (!this.allIconDictionary.has(name)) {
newAppendedIcons[name] = actorsDict.get(name);
newCustomIcons[name] = actorsDict.get(name);
}
});

workObjects.forEach((name: string) => {
if (!this.allIconDictionary.has(name)) {
newAppendedIcons[name] = workObjectsDict.get(name);
newCustomIcons[name] = workObjectsDict.get(name);
}
});
const appen = new Dictionary();
Object.keys(newAppendedIcons).forEach((key) => {
appen.set(key, newAppendedIcons[key]);

const customIcons = new Dictionary();
Object.keys(newCustomIcons).forEach((key) => {
customIcons.set(key, newCustomIcons[key]);
});

updateAppendedIcons(appen);
addCustomIcons(customIcons);
}

createCustomConf(iconSetConfiguration: IconSetConfiguration): Configuration {
this.domainName = iconSetConfiguration.name;
this.iconSetName = iconSetConfiguration.name;

let actors = iconSetConfiguration.actors;
let workObjects = iconSetConfiguration.workObjects;

this.appendSRCFile(
this.addCustomIcons(
actors.keysArray(),
actors,
workObjects.keysArray(),
Expand Down
6 changes: 0 additions & 6 deletions src/app/tools/icon-set-config/domain/iconFilterEnum.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/app/tools/icon-set-config/domain/iconFilterOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum IconFilterOptions {
ONLY_ACTORS = 'ICON_FILTER_ACTOR',
ONLY_WORKOBJECTS = 'ICON_FILTER_WORKOBJECT',
ONLY_UNASSIGNED = 'ICON_FILTER_UNASSIGNED',
NO_FILTER = '',
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<button
mat-button
[class.activeActor]="(filter | async) === 'ICON_FILTER_ACTOR'"
title="Actors"
title="Icons used as actors"
(click)="filterForActors()"
>
<span>Actors</span>
Expand All @@ -24,10 +24,10 @@
[class.activeWorkObject]="
(filter | async) === 'ICON_FILTER_WORKOBJECT'
"
title="Workobjects"
title="Icons used as work objects"
(click)="filterForWorkobjects()"
>
<span>Workobjects</span>
<span>Work Objects</span>
</button>
<input
class="textInput"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { ElementRegistryService } from 'src/app/domain/services/element-registry.service';
import { sanitizeIconName } from 'src/app/utils/sanitizer';
import { ElementTypes } from '../../../../domain/entities/elementTypes';
import { IconFilterEnum } from '../../domain/iconFilterEnum';
import { IconFilterOptions } from '../../domain/iconFilterOptions';
import { IconSetCustomizationService } from '../../services/icon-set-customization.service';
import { CustomIconSetConfiguration } from '../../../../domain/entities/custom-icon-set-configuration';

Expand All @@ -21,7 +21,7 @@ import { CustomIconSetConfiguration } from '../../../../domain/entities/custom-i
export class IconSetConfigurationComponent implements OnInit {
private iconSetConfigurationTypes: CustomIconSetConfiguration;

filter = new BehaviorSubject<IconFilterEnum>(IconFilterEnum.ICON_FILTER_NONE);
filter = new BehaviorSubject<IconFilterOptions>(IconFilterOptions.NO_FILTER);

selectedActors = new BehaviorSubject<string[]>([]);
selectedWorkobjects = new BehaviorSubject<string[]>([]);
Expand Down Expand Up @@ -151,26 +151,26 @@ export class IconSetConfigurationComponent implements OnInit {

/** Filter **/
filterForActors(): void {
if (this.filter.value !== IconFilterEnum.ICON_FILTER_ACTOR) {
this.filter.next(IconFilterEnum.ICON_FILTER_ACTOR);
if (this.filter.value !== IconFilterOptions.ONLY_ACTORS) {
this.filter.next(IconFilterOptions.ONLY_ACTORS);
} else {
this.filter.next(IconFilterEnum.ICON_FILTER_NONE);
this.filter.next(IconFilterOptions.NO_FILTER);
}
}

filterForWorkobjects(): void {
if (this.filter.value !== IconFilterEnum.ICON_FILTER_WORKOBJECT) {
this.filter.next(IconFilterEnum.ICON_FILTER_WORKOBJECT);
if (this.filter.value !== IconFilterOptions.ONLY_WORKOBJECTS) {
this.filter.next(IconFilterOptions.ONLY_WORKOBJECTS);
} else {
this.filter.next(IconFilterEnum.ICON_FILTER_NONE);
this.filter.next(IconFilterOptions.NO_FILTER);
}
}

filterForUnassigned(): void {
if (this.filter.value !== IconFilterEnum.ICON_FILTER_UNASSIGNED) {
this.filter.next(IconFilterEnum.ICON_FILTER_UNASSIGNED);
if (this.filter.value !== IconFilterOptions.ONLY_UNASSIGNED) {
this.filter.next(IconFilterOptions.ONLY_UNASSIGNED);
} else {
this.filter.next(IconFilterEnum.ICON_FILTER_NONE);
this.filter.next(IconFilterOptions.NO_FILTER);
}
}

Expand All @@ -183,23 +183,23 @@ export class IconSetConfigurationComponent implements OnInit {
this.allFilteredIconNames.next(filteredByNameAndType.sort(this.sortByName));
}

private getFilteredNamesForType(type: IconFilterEnum): string[] {
private getFilteredNamesForType(type: IconFilterOptions): string[] {
let allFiltered: string[] = [];
switch (type) {
case IconFilterEnum.ICON_FILTER_NONE:
case IconFilterOptions.NO_FILTER:
allFiltered = this.allIconNames.value;
break;
case IconFilterEnum.ICON_FILTER_ACTOR:
case IconFilterOptions.ONLY_ACTORS:
allFiltered = this.allIconNames.value.filter((name) =>
this.iconSetCustomizationService.isIconActor(name),
);
break;
case IconFilterEnum.ICON_FILTER_WORKOBJECT:
case IconFilterOptions.ONLY_WORKOBJECTS:
allFiltered = this.allIconNames.value.filter((name) =>
this.iconSetCustomizationService.isIconWorkObject(name),
);
break;
case IconFilterEnum.ICON_FILTER_UNASSIGNED:
case IconFilterOptions.ONLY_UNASSIGNED:
allFiltered = this.allIconNames.value.filter(
(name) =>
!this.iconSetCustomizationService.isIconActor(name) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
BusinessObject,
testBusinessObject,
} from '../../../domain/entities/businessObject';
import { allIcons } from '../domain/allIcons';
import { builtInIcons } from '../domain/allIcons';
import { IconSetConfiguration } from '../../../domain/entities/icon-set-configuration';

describe('IconDictionaryService', () => {
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('IconDictionaryService', () => {
service.registerIconForType(
ElementTypes.WORKOBJECT,
'Hotel',
allIcons['Hotel'],
builtInIcons['Hotel'],
);

expect(service.getWorkObjectsDictionary().has('Hotel')).toBeTruthy();
Expand All @@ -139,7 +139,7 @@ describe('IconDictionaryService', () => {
service.registerIconForType(
ElementTypes.ACTOR,
'Hotel',
allIcons['Hotel'],
builtInIcons['Hotel'],
);

expect(service.getActorsDictionary().has('Hotel')).toBeTruthy();
Expand Down
23 changes: 12 additions & 11 deletions src/app/tools/icon-set-config/services/icon-dictionary.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
IconConfiguration,
} from 'src/app/tools/icon-set-config/domain/iconConfiguration';
import {
allIcons,
appendedIcons,
builtInIcons,
customIcons,
} from 'src/app/tools/icon-set-config/domain/allIcons';
import { sanitizeIconName } from '../../../utils/sanitizer';
import getIconId = ElementTypes.getIconId;
Expand All @@ -32,10 +32,11 @@ export class IconDictionaryService {
private readonly iconConfig: IconConfiguration;

constructor() {
this.allIconDictionary.addEach(allIcons);
this.allIconDictionary.addEach(builtInIcons);
this.iconConfig = new IconConfiguration(this.allIconDictionary);
}

// TODO: only used in tests
initTypeDictionaries(actors: string[], workObjects: string[]): void {
if (!actors || actors.length == 0) {
actors = defaultConf.actors;
Expand All @@ -45,7 +46,7 @@ export class IconDictionaryService {
}

const allTypes = new Dictionary();
allTypes.addEach(allIcons);
allTypes.addEach(builtInIcons);
allTypes.appendDict(this.getAppendedIconDictionary());

this.initDictionary(
Expand Down Expand Up @@ -123,8 +124,8 @@ export class IconDictionaryService {
}

const allTypes = new Dictionary();
allTypes.addEach(allIcons);
allTypes.appendDict(appendedIcons);
allTypes.addEach(builtInIcons);
allTypes.appendDict(customIcons);

iconTypes.forEach((name) => {
if (!collection.has(name)) {
Expand Down Expand Up @@ -276,7 +277,7 @@ export class IconDictionaryService {
}

addIMGToIconDictionary(input: string, name: string): void {
appendedIcons.set(name, input);
customIcons.set(name, input);
}

addIconsToCss(customIcons: Dictionary) {
Expand Down Expand Up @@ -314,9 +315,9 @@ export class IconDictionaryService {

getAppendedIconDictionary(): Dictionary {
const appendedDict = new Dictionary();
appendedIcons.keysArray().forEach((key) => {
customIcons.keysArray().forEach((key) => {
if (!this.allIconDictionary.has(key)) {
appendedDict.set(key, appendedIcons.get(key));
appendedDict.set(key, customIcons.get(key));
}
});
return appendedDict;
Expand Down Expand Up @@ -351,8 +352,8 @@ export class IconDictionaryService {
getIconSource(name: string): string | null {
if (this.allIconDictionary.has(name)) {
return this.allIconDictionary.get(name);
} else if (appendedIcons.has(name)) {
return appendedIcons.get(name);
} else if (customIcons.has(name)) {
return customIcons.get(name);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class IconSetConfigurationService {

this.iconDictionaryService
.getIconConfiguration()
.appendSRCFile(actorKeys, actorDict, workObjectKeys, workObjectDict);
.addCustomIcons(actorKeys, actorDict, workObjectKeys, workObjectDict);

this.iconDictionaryService.addIconsFromIconSetConfiguration(
ElementTypes.ACTOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import ContextPadProvider from "bpmn-js/lib/features/context-pad/ContextPadProvi
import { assign, bind } from "min-dash";
import { generateAutomaticNumber } from "../numbering/numbering";
import { ElementTypes } from "src/app/domain/entities/elementTypes";
import { getAllStandardIconKeys } from "src/app/tools/icon-set-config/domain/allIcons";
import {
hexToRGBA,
isHexWithAlpha,
Expand Down Expand Up @@ -68,7 +67,6 @@ export default function DomainStoryContextPadProvider(
}),
);

const allStandardIconKeys = getAllStandardIconKeys();
let actions = cached(element);

startConnect = function (event, element, autoActivate) {
Expand Down

0 comments on commit 10dfde0

Please sign in to comment.