basic editor interface
This commit is contained in:
parent
57dc0e929b
commit
ed3f0abf23
3 changed files with 123 additions and 1 deletions
53
sites/shared/components/workbench/gist-validator.js
Normal file
53
sites/shared/components/workbench/gist-validator.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
import defaultSettings from './default-settings'
|
||||
|
||||
class GistValidator {
|
||||
givenGist
|
||||
design
|
||||
errors
|
||||
valid = true
|
||||
|
||||
constructor(givenGist, design) {
|
||||
this.givenGist = givenGist
|
||||
this.design = design
|
||||
this.errors = {}
|
||||
}
|
||||
|
||||
validateSettings() {
|
||||
for (var key in defaultSettings) {
|
||||
if (typeof this.givenGist[key] !== typeof defaultSettings[key]) {
|
||||
this.errors[key] = 'TypeError'
|
||||
this.valid = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
validateMeasurements() {
|
||||
this.errors.measurements = {}
|
||||
for (const m of this.design.patternConfig.measurements || []) {
|
||||
if (this.givenGist.measurements[m] === undefined) {
|
||||
this.errors.measurements[m] = 'MissingMeasurement'
|
||||
this.valid = false
|
||||
} else if (isNaN(this.givenGist.measurements[m])) {
|
||||
this.errors.measurements[m] = 'TypeError'
|
||||
this.valid = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
validateOptions() {
|
||||
console.log(this.design.patternConfig)
|
||||
}
|
||||
|
||||
validate() {
|
||||
this.validateSettings()
|
||||
this.validateMeasurements()
|
||||
this.validateOptions()
|
||||
|
||||
return { valid: this.valid, errors: this.errors }
|
||||
}
|
||||
}
|
||||
|
||||
export default function validateGist(givenGist, design) {
|
||||
const validator = new GistValidator(givenGist, design)
|
||||
return validator.validate()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue