Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Effects #80

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/data/EffectRepository.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Effect from '~/domain/Effect.mjs';
import StorageRepository from './StorageRepository.mjs';
import EffectToJsonMapper from '~/mappers/EffectToJsonMapper.mjs';
import pkg from '~/../package.json' with { type: 'json' };
import type { SemVerString } from '~/lib/SemVer.mjs';

export default class EffectRepository extends StorageRepository<Effect> {
constructor(storage: Storage) {
super('effects', storage, new EffectToJsonMapper(pkg.version as SemVerString));
}
}
6 changes: 6 additions & 0 deletions src/domain/Effect.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Requirement from './Requirement.mjs';

/**
* An Effect is an environment property affected by a System.
*/
export default class Effect extends Requirement { }
2 changes: 2 additions & 0 deletions src/domain/Environment.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ export default class Environment extends Entity {
constraintIds: Uuid[];
invariantIds: Uuid[];
assumptionIds: Uuid[];
effectIds: Uuid[];

constructor(options: Properties<Environment>) {
super(options);
this.glossaryIds = options.glossaryIds;
this.constraintIds = options.constraintIds;
this.invariantIds = options.invariantIds;
this.assumptionIds = options.assumptionIds;
this.effectIds = options.effectIds;
}
}
20 changes: 20 additions & 0 deletions src/mappers/EffectToJsonMapper.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import SemVer from '~/lib/SemVer.mjs';
import RequirementToJsonMapper, { type RequirementJson } from './RequirementToJsonMapper.mjs';
import Effect from '~/domain/Effect.mjs';

export interface EffectJson extends RequirementJson { }

export default class EffectToJsonMapper extends RequirementToJsonMapper {
override mapFrom(target: EffectJson): Effect {
const version = new SemVer(target.serializationVersion);

if (version.gte('0.4.0'))
return new Effect(target);

throw new Error(`Unsupported serialization version: ${version}`);
}

override mapTo(source: Effect): EffectJson {
return super.mapTo(source);
}
}
7 changes: 5 additions & 2 deletions src/mappers/EnvironmentToJsonMapper.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface EnvironmentJson extends EntityJson {
constraintIds: Uuid[];
invariantIds: Uuid[];
assumptionIds: Uuid[];
effectIds: Uuid[];
}

export default class EnvironmentToJsonMapper extends EntityToJsonMapper {
Expand All @@ -19,7 +20,8 @@ export default class EnvironmentToJsonMapper extends EntityToJsonMapper {
...target,
constraintIds: target.constraintIds ?? [],
invariantIds: target.invariantIds ?? [],
assumptionIds: target.assumptionIds ?? []
assumptionIds: target.assumptionIds ?? [],
effectIds: target.effectIds ?? []
});

throw new Error(`Unsupported serialization version: ${version}`);
Expand All @@ -31,7 +33,8 @@ export default class EnvironmentToJsonMapper extends EntityToJsonMapper {
glossaryIds: source.glossaryIds,
constraintIds: source.constraintIds,
invariantIds: source.invariantIds,
assumptionIds: source.assumptionIds
assumptionIds: source.assumptionIds,
effectIds: source.effectIds
};
}
}
1 change: 1 addition & 0 deletions src/presentation/Application.mts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default class Application extends Container {
(await import('./pages/solution/environment/ConstraintsPage.mjs')).default,
(await import('./pages/solution/environment/InvariantsPage.mjs')).default,
(await import('./pages/solution/environment/AssumptionsPage.mjs')).default,
(await import('./pages/solution/environment/EffectsPage.mjs')).default,
(await import('./pages/solution/goals/GoalsIndexPage.mjs')).default,
(await import('./pages/solution/goals/RationalePage.mjs')).default,
(await import('./pages/solution/goals/FunctionalityPage.mjs')).default,
Expand Down
3 changes: 2 additions & 1 deletion src/presentation/pages/solution/NewSolutionPage.mts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ export default class NewSolutionPage extends Page {
glossaryIds: [],
constraintIds: [],
invariantIds: [],
assumptionIds: []
assumptionIds: [],
effectIds: []
}),
goals = new Goals({
id: solution.goalsId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { p } = html;
export default class AssumptionPage extends Page {
static override route = '/:solution/environment/assumptions';
static {
customElements.define('x-page-assumtptions', this);
customElements.define('x-page-assumptions', this);
}

#solutionRepository = new SolutionRepository(localStorage);
Expand Down
78 changes: 78 additions & 0 deletions src/presentation/pages/solution/environment/EffectsPage.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import type { Uuid } from '~/types/Uuid.mjs';
import type Environment from '~/domain/Environment.mjs';
import Effect from '~/domain/Effect.mjs';
import SolutionRepository from '~/data/SolutionRepository.mjs';
import EnvironmentRepository from '~/data/EnvironmentRepository.mjs';
import EffectRepository from '~/data/EffectRepository.mjs';
import Page from '~/presentation/pages/Page.mjs';
import { DataTable } from '~/presentation/components/DataTable.mjs';
import html from '~/presentation/lib/html.mjs';

const { p } = html;

export default class EffectsPage extends Page {
static override route = '/:solution/environment/effects';
static {
customElements.define('x-page-effects', this);
}

#solutionRepository = new SolutionRepository(localStorage);
#environmentRepository = new EnvironmentRepository(localStorage);
#effectRepository = new EffectRepository(localStorage);
#environment?: Environment;

constructor() {
super({ title: 'Effects' }, []);

const dataTable = new DataTable<Effect>({
columns: {
id: { headerText: 'ID', readonly: true, formType: 'hidden', unique: true },
statement: { headerText: 'Statement', required: true, formType: 'text', unique: true }
},
select: async () => {
if (!this.#environment)
return [];

return await this.#effectRepository.getAll(t => this.#environment!.effectIds.includes(t.id));
},
onCreate: async item => {
const effect = new Effect({ ...item, id: self.crypto.randomUUID() });
this.#environment!.effectIds.push(effect.id);
await Promise.all([
this.#effectRepository.add(effect),
this.#environmentRepository.update(this.#environment!)
]);
},
onUpdate: async item => {
await this.#effectRepository.update(new Effect({
...item
}));
},
onDelete: async id => {
this.#environment!.effectIds = this.#environment!.effectIds.filter(x => x !== id);
await Promise.all([
this.#effectRepository.delete(id),
this.#environmentRepository.update(this.#environment!)
]);
}
});

this.append(
p(`
An Effect is an environment property affected by a System.
Example: "The running system will cause the temperature of the room to increase."
`),
dataTable
);

this.#environmentRepository.addEventListener('update', () => dataTable.renderData());
this.#effectRepository.addEventListener('update', () => dataTable.renderData());
const solutionId = this.urlParams['solution'] as Uuid;
this.#solutionRepository.getBySlug(solutionId).then(solution => {
this.#environmentRepository.get(solution!.environmentId).then(environment => {
this.#environment = environment;
dataTable.renderData();
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export default class EnvironmentsIndexPage extends Page {
icon: 'sunrise',
href: `${location.pathname}/assumptions`
}),
new MiniCard({
title: 'Effects',
icon: 'cloud-lightning',
href: `${location.pathname}/effects`
})
])
);
}
Expand Down