Skip to content

Commit

Permalink
Metadata forms: add backwards compatibility for Draft7 schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
lwesterhof committed Nov 29, 2023
1 parent f9c25c5 commit e43cb65
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 17 deletions.
6 changes: 3 additions & 3 deletions deposit/metadata-form/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion deposit/metadata-form/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ let schema = {};
let uiSchema = {};
let yodaFormData = {};

let validator;
let formProperties;

let saving = false;
let back = false;

let form = document.getElementById('form');

const validator = customizeValidator({ AjvClass: Ajv2019, ajvOptionsOverrides: {verbose: true, addUsedSchema: false } });
const validatorAjvDraft7 = customizeValidator({ ajvOptionsOverrides: {verbose: true, addUsedSchema: false } });
const validatorAjv2019 = customizeValidator({ AjvClass: Ajv2019, ajvOptionsOverrides: {verbose: true, addUsedSchema: false } });

const enumWidget = (props) => {
let enumArray = props['schema']['enum'];
Expand Down Expand Up @@ -685,6 +687,13 @@ function loadForm() {
}

} else {
// Select validator based on schema.
if (schema.$schema == "http://json-schema.org/draft-07/schema") {
validator = validatorAjvDraft7
} else {
validator = validatorAjv2019
}

// Metadata present or user has write access, load the form.
if (!formProperties.data.can_edit)
uiSchema['ui:readonly'] = true;
Expand Down
2 changes: 1 addition & 1 deletion deposit/static/deposit/js/metadata-form.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions research/metadata-form/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion research/metadata-form/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ let schema = {};
let uiSchema = {};
let yodaFormData = {};

let validator;
let formProperties;

let saving = false;

let form = document.getElementById('form');

const validator = customizeValidator({ AjvClass: Ajv2019, ajvOptionsOverrides: {verbose: true, addUsedSchema: false } });
const validatorAjvDraft7 = customizeValidator({ ajvOptionsOverrides: {verbose: true, addUsedSchema: false } });
const validatorAjv2019 = customizeValidator({ AjvClass: Ajv2019, ajvOptionsOverrides: {verbose: true, addUsedSchema: false } });

const enumWidget = (props) => {
let enumArray = props['schema']['enum'];
Expand Down Expand Up @@ -699,6 +701,13 @@ function loadForm() {
}

} else {
// Select validator based on schema.
if (schema.$schema == "http://json-schema.org/draft-07/schema") {
validator = validatorAjvDraft7
} else {
validator = validatorAjv2019
}

// Metadata present or user has write access, load the form.
if (!formProperties.data.can_edit)
uiSchema['ui:readonly'] = true;
Expand Down
6 changes: 3 additions & 3 deletions research/static/research/js/metadata-form.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions vault/metadata-form/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion vault/metadata-form/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ let uiSchema = {};
let yodaFormData = {};

let actual_edit_mode = false; // if can edit, it is not directly shown.

let validator;
let formProperties;

let saving = false;

let form = document.getElementById('form');

const validator = customizeValidator({ AjvClass: Ajv2019, ajvOptionsOverrides: {verbose: true, addUsedSchema: false } });
const validatorAjvDraft7 = customizeValidator({ ajvOptionsOverrides: {verbose: true, addUsedSchema: false } });
const validatorAjv2019 = customizeValidator({ AjvClass: Ajv2019, ajvOptionsOverrides: {verbose: true, addUsedSchema: false } });

const enumWidget = (props) => {
let enumArray = props['schema']['enum'];
Expand Down Expand Up @@ -643,6 +646,13 @@ function loadForm() {
$('#no-metadata').removeClass('hide');

} else {
// Select validator based on schema.
if (schema.$schema == "http://json-schema.org/draft-07/schema") {
validator = validatorAjvDraft7
} else {
validator = validatorAjv2019
}

// Metadata present or user has write access, load the form and must be in actual_edit_mode as chosen by user
if (formProperties.data.can_edit && actual_edit_mode) {
uiSchema = formProperties.data.uischema; // take over original ui-shema again- not the readonly one
Expand Down
2 changes: 1 addition & 1 deletion vault/static/vault/js/metadata-form.js

Large diffs are not rendered by default.

0 comments on commit e43cb65

Please sign in to comment.