-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
181 additions
and
62 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import StorageRepository from './StorageRepository.mjs'; | ||
import pkg from '~/../package.json' with { type: 'json' }; | ||
import type { SemVerString } from '~/lib/SemVer.mjs'; | ||
import { ComponentToJsonMapper } from '~/mappers/ComponentToJsonMapper.mjs'; | ||
import type Component from '~/domain/Component.mjs'; | ||
|
||
export default class BehaviorRepository extends StorageRepository<Component> { | ||
constructor(storage: Storage) { | ||
super('components', storage, new ComponentToJsonMapper(pkg.version as SemVerString)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { Properties } from '~/types/Properties.mjs'; | ||
import Requirement from './Requirement.mjs'; | ||
|
||
/** | ||
* A Component is a self-contained element in the Environment that provides an interface | ||
* which can be used by a System to interact with. | ||
*/ | ||
export default class Component extends Requirement { | ||
name: string; | ||
description: string; | ||
|
||
constructor(properties: Omit<Properties<Component>, 'interfaceDefinition'>) { | ||
super(properties); | ||
|
||
this.name = properties.name; | ||
this.description = properties.description; | ||
} | ||
|
||
get interfaceDefinition(): string { | ||
return this.statement; | ||
} | ||
|
||
set interfaceDefinition(value: string) { | ||
this.statement = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import SemVer from '~/lib/SemVer.mjs'; | ||
import type { RequirementJson } from './RequirementToJsonMapper.mjs'; | ||
import RequirementToJsonMapper from './RequirementToJsonMapper.mjs'; | ||
import Component from '~/domain/Component.mjs'; | ||
|
||
export interface ComponentJson extends RequirementJson { | ||
name: string; | ||
description: string; | ||
} | ||
|
||
export class ComponentToJsonMapper extends RequirementToJsonMapper { | ||
override mapFrom(target: ComponentJson): Component { | ||
const version = new SemVer(target.serializationVersion); | ||
|
||
if (version.gte('0.4.0')) | ||
return new Component(target); | ||
|
||
throw new Error(`Unsupported serialization version: ${version}`); | ||
} | ||
|
||
override mapTo(source: Component): ComponentJson { | ||
return { | ||
...super.mapTo(source), | ||
name: source.name, | ||
description: source.description, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/presentation/pages/solution/environment/ComponentsPage.mts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import type { Uuid } from '~/types/Uuid.mjs'; | ||
import type Environment from '~/domain/Environment.mjs'; | ||
import Component from '~/domain/Component.mjs'; | ||
import SolutionRepository from '~/data/SolutionRepository.mjs'; | ||
import EnvironmentRepository from '~/data/EnvironmentRepository.mjs'; | ||
import ComponentRepository from '~/data/ComponentRepository.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 ComponentsPage extends Page { | ||
static override route = '/:solution/environment/components'; | ||
static { | ||
customElements.define('x-page-components', this); | ||
} | ||
|
||
#solutionRepository = new SolutionRepository(localStorage); | ||
#environmentRepository = new EnvironmentRepository(localStorage); | ||
#componentRepository = new ComponentRepository(localStorage); | ||
#environment?: Environment; | ||
|
||
constructor() { | ||
super({ title: 'Components' }, []); | ||
|
||
const dataTable = new DataTable<Component>({ | ||
columns: { | ||
id: { headerText: 'ID', readonly: true, formType: 'hidden', unique: true }, | ||
name: { headerText: 'Name', required: true, formType: 'text', unique: true }, | ||
description: { headerText: 'Description', formType: 'text' }, | ||
interfaceDefinition: { headerText: 'Interface Definition', formType: 'textarea' } | ||
}, | ||
select: async () => { | ||
if (!this.#environment) | ||
return []; | ||
|
||
return await this.#componentRepository.getAll(t => this.#environment!.componentIds.includes(t.id)); | ||
}, | ||
onCreate: async item => { | ||
const component = new Component({ | ||
id: self.crypto.randomUUID(), | ||
name: item.name, | ||
description: item.description, | ||
statement: item.interfaceDefinition | ||
}); | ||
this.#environment!.componentIds.push(component.id); | ||
await Promise.all([ | ||
this.#componentRepository.add(component), | ||
this.#environmentRepository.update(this.#environment!) | ||
]); | ||
}, | ||
onUpdate: async item => { | ||
await this.#componentRepository.update(new Component({ | ||
...item | ||
})); | ||
}, | ||
onDelete: async id => { | ||
this.#environment!.componentIds = this.#environment!.componentIds.filter(x => x !== id); | ||
await Promise.all([ | ||
this.#componentRepository.delete(id), | ||
this.#environmentRepository.update(this.#environment!) | ||
]); | ||
} | ||
}); | ||
|
||
this.append( | ||
p(` | ||
Components are self-contained elements in the Environment that provide | ||
an interface which can be used by a System to interact with. | ||
`), | ||
dataTable | ||
); | ||
|
||
this.#environmentRepository.addEventListener('update', () => dataTable.renderData()); | ||
this.#componentRepository.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(); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters