-
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.
Implemented initial constraints page (#76)
- Loading branch information
Showing
11 changed files
with
154 additions
and
6 deletions.
There are no files selected for viewing
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 Constraint from '~/domain/Constraint.mjs'; | ||
import StorageRepository from './StorageRepository.mjs'; | ||
import ConstraintToJsonMapper from '~/mappers/ConstraintToJsonMapper.mjs'; | ||
import pkg from '~/../package.json' with { type: 'json' }; | ||
import type { SemVerString } from '~/lib/SemVer.mjs'; | ||
|
||
export default class ConstraintRepository extends StorageRepository<Constraint> { | ||
constructor(storage: Storage) { | ||
super('constraints', storage, new ConstraintToJsonMapper(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,18 @@ | ||
import type { Properties } from '~/types/Properties.mjs'; | ||
import Requirement from './Requirement.mjs'; | ||
|
||
export enum ConstraintCategory { | ||
BusinessRule = 'Business Rule', | ||
PhysicalLaw = 'Physical Law', | ||
EngineeringDecision = 'Engineering Decision' | ||
} | ||
|
||
export default class Constraint extends Requirement { | ||
constructor(options: Properties<Constraint>) { | ||
super(options); | ||
|
||
this.category = options.category; | ||
} | ||
|
||
category: ConstraintCategory; | ||
} |
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,25 @@ | ||
import Constraint, { ConstraintCategory } from '~/domain/Constraint.mjs'; | ||
import RequirementToJsonMapper, { type RequirementJson } from './RequirementToJsonMapper.mjs'; | ||
import SemVer from '~/lib/SemVer.mjs'; | ||
|
||
export interface ConstraintJson extends RequirementJson { | ||
category: ConstraintCategory; | ||
} | ||
|
||
export default class ConstraintToJsonMapper extends RequirementToJsonMapper { | ||
override mapFrom(target: ConstraintJson): Constraint { | ||
const version = new SemVer(target.serializationVersion); | ||
|
||
if (version.gte('0.4.0')) | ||
return new Constraint(target); | ||
|
||
throw new Error(`Unsupported serialization version: ${version}`); | ||
} | ||
|
||
override mapTo(source: Constraint): ConstraintJson { | ||
return { | ||
...super.mapTo(source), | ||
category: source.category | ||
}; | ||
} | ||
} |
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
82 changes: 82 additions & 0 deletions
82
src/presentation/pages/solution/environment/ConstraintsPage.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,82 @@ | ||
import type { Uuid } from '~/types/Uuid.mjs'; | ||
import type Environment from '~/domain/Environment.mjs'; | ||
import Constraint, { ConstraintCategory } from '~/domain/Constraint.mjs'; | ||
import SolutionRepository from '~/data/SolutionRepository.mjs'; | ||
import EnvironmentRepository from '~/data/EnvironmentRepository.mjs'; | ||
import ConstraintRepository from '~/data/ConstraintRepository.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 ConstraintsPage extends Page { | ||
static override route = '/:solution/environment/constraints'; | ||
static { | ||
customElements.define('x-page-constraints', this); | ||
} | ||
|
||
#solutionRepository = new SolutionRepository(localStorage); | ||
#environmentRepository = new EnvironmentRepository(localStorage); | ||
#constraintRepository = new ConstraintRepository(localStorage); | ||
#environment?: Environment; | ||
|
||
constructor() { | ||
super({ title: 'Constraints' }, []); | ||
|
||
const dataTable = new DataTable<Constraint>({ | ||
columns: { | ||
id: { headerText: 'ID', readonly: true, formType: 'hidden', unique: true }, | ||
statement: { headerText: 'Statement', required: true, formType: 'text', unique: true }, | ||
category: { | ||
headerText: 'Category', formType: 'select', | ||
options: Object.values(ConstraintCategory).map(x => ({ value: x, text: x })) | ||
} | ||
}, | ||
select: async () => { | ||
if (!this.#environment) | ||
return []; | ||
|
||
return await this.#constraintRepository.getAll(t => this.#environment!.constraintIds.includes(t.id)); | ||
}, | ||
onCreate: async item => { | ||
const constraint = new Constraint({ ...item, id: self.crypto.randomUUID() }); | ||
this.#environment!.constraintIds.push(constraint.id); | ||
await Promise.all([ | ||
this.#constraintRepository.add(constraint), | ||
this.#environmentRepository.update(this.#environment!) | ||
]); | ||
}, | ||
onUpdate: async item => { | ||
await this.#constraintRepository.update(new Constraint({ | ||
...item | ||
})); | ||
}, | ||
onDelete: async id => { | ||
this.#environment!.constraintIds = this.#environment!.constraintIds.filter(x => x !== id); | ||
await Promise.all([ | ||
this.#constraintRepository.delete(id), | ||
this.#environmentRepository.update(this.#environment!) | ||
]); | ||
} | ||
}); | ||
|
||
this.append( | ||
p(` | ||
Environmental constraints are the limitations and obligations that | ||
the environment imposes on the project and system. | ||
`), | ||
dataTable | ||
); | ||
|
||
this.#environmentRepository.addEventListener('update', () => dataTable.renderData()); | ||
this.#constraintRepository.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