-
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
9 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
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 Assumption from '~/domain/Assumption.mjs'; | ||
import StorageRepository from './StorageRepository.mjs'; | ||
import pkg from '~/../package.json' with { type: 'json' }; | ||
import type { SemVerString } from '~/lib/SemVer.mjs'; | ||
import AssumptionToJsonMapper from '~/mappers/AssumptionToJsonMapper.mjs'; | ||
|
||
export default class AssumptionRepository extends StorageRepository<Assumption> { | ||
constructor(storage: Storage) { | ||
super('assumption', storage, new AssumptionToJsonMapper(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,8 @@ | ||
import Requirement from './Requirement.mjs'; | ||
|
||
/** | ||
* An assumption is a property of the environment that is assumed to be true. | ||
* Assumptions are used to simplify the problem and to make it more tractable. | ||
* An example of an assumption would be: "Screen resolutions will not change during the execution of the program." | ||
*/ | ||
export default class Assumption extends Requirement { } |
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,20 @@ | ||
import RequirementToJsonMapper, { type RequirementJson } from './RequirementToJsonMapper.mjs'; | ||
import SemVer from '~/lib/SemVer.mjs'; | ||
import Assumption from '~/domain/Assumption.mjs'; | ||
|
||
export interface AssumptionJson extends RequirementJson { } | ||
|
||
export default class AssumptionToJsonMapper extends RequirementToJsonMapper { | ||
override mapFrom(target: AssumptionJson): Assumption { | ||
const version = new SemVer(target.serializationVersion); | ||
|
||
if (version.gte('0.4.0')) | ||
return new Assumption(target); | ||
|
||
throw new Error(`Unsupported serialization version: ${version}`); | ||
} | ||
|
||
override mapTo(source: Assumption): AssumptionJson { | ||
return super.mapTo(source); | ||
} | ||
} |
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
79 changes: 79 additions & 0 deletions
79
src/presentation/pages/solution/environment/AssumptionsPage.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,79 @@ | ||
import type { Uuid } from '~/types/Uuid.mjs'; | ||
import type Environment from '~/domain/Environment.mjs'; | ||
import Assumption from '~/domain/Assumption.mjs'; | ||
import SolutionRepository from '~/data/SolutionRepository.mjs'; | ||
import EnvironmentRepository from '~/data/EnvironmentRepository.mjs'; | ||
import AssumptionRepository from '~/data/AssumptionRepository.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 AssumptionPage extends Page { | ||
static override route = '/:solution/environment/assumptions'; | ||
static { | ||
customElements.define('x-page-assumtptions', this); | ||
} | ||
|
||
#solutionRepository = new SolutionRepository(localStorage); | ||
#environmentRepository = new EnvironmentRepository(localStorage); | ||
#assumptionRepository = new AssumptionRepository(localStorage); | ||
#environment?: Environment; | ||
|
||
constructor() { | ||
super({ title: 'Assumptions' }, []); | ||
|
||
const dataTable = new DataTable<Assumption>({ | ||
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.#assumptionRepository.getAll(t => this.#environment!.assumptionIds.includes(t.id)); | ||
}, | ||
onCreate: async item => { | ||
const assumption = new Assumption({ ...item, id: self.crypto.randomUUID() }); | ||
this.#environment!.assumptionIds.push(assumption.id); | ||
await Promise.all([ | ||
this.#assumptionRepository.add(assumption), | ||
this.#environmentRepository.update(this.#environment!) | ||
]); | ||
}, | ||
onUpdate: async item => { | ||
await this.#assumptionRepository.update(new Assumption({ | ||
...item | ||
})); | ||
}, | ||
onDelete: async id => { | ||
this.#environment!.assumptionIds = this.#environment!.assumptionIds.filter(x => x !== id); | ||
await Promise.all([ | ||
this.#assumptionRepository.delete(id), | ||
this.#environmentRepository.update(this.#environment!) | ||
]); | ||
} | ||
}); | ||
|
||
this.append( | ||
p(` | ||
An assumption is a property of the environment that is assumed to be true. | ||
Assumptions are used to simplify the problem and to make it more tractable. | ||
An example of an assumption would be: "Screen resolution will not change during the execution of the program". | ||
`), | ||
dataTable | ||
); | ||
|
||
this.#environmentRepository.addEventListener('update', () => dataTable.renderData()); | ||
this.#assumptionRepository.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