Skip to content

Commit

Permalink
Fixing ArrayEditor change event and correcting UI schema import
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeppe Zapp committed Aug 28, 2019
1 parent 5da6b7f commit 194ea57
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hashbrown-cms",
"repository": "https://github.com/HashBrownCMS/hashbrown-cms.git",
"version": "1.2.0",
"version": "1.2.1",
"description": "A free and open-source headless CMS",
"main": "hashbrown.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/Client/Routes/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Crisp.Router.route('/schemas/', function() {
_.p('Click on a Schema to edit it.'),
_.button({class: 'widget widget--button'}, 'Import schemas')
.click(() => {
let url = 'https://uischema.org/all.json';
let url = 'https://uischema.org/schemas.json';

let modal = UI.messageModal(
'Import schemas',
Expand All @@ -23,7 +23,7 @@ Crisp.Router.route('/schemas/', function() {
type: 'text',
value: url,
isRequired: true,
placeholder: 'E.g. https://uischema.org/all.json',
placeholder: 'E.g. https://uischema.org/schemas.json',
onChange: (newValue) => {
url = newValue;
}
Expand Down
8 changes: 8 additions & 0 deletions src/Client/Views/Editors/FieldEditors/ArrayEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,18 @@ class ArrayEditor extends HashBrown.Views.Editors.FieldEditors.FieldEditor {
// Hook up the change event
editorInstance.on('change', (newValue) => {
$label.html(editorInstance.getFieldLabel());

item.value = newValue;

this.trigger('change', this.value);
});

editorInstance.on('silentchange', (newValue) => {
$label.html(editorInstance.getFieldLabel());

item.value = newValue;

this.trigger('silentchange', this.value);
});

$placeholder.replaceWith($field);
Expand Down
8 changes: 8 additions & 0 deletions src/Server/Controllers/SchemaController.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class SchemaController extends HashBrown.Controllers.ResourceController {
let response = await HashBrown.Helpers.RequestHelper.request('get', url);

if(Array.isArray(response)) {
// Sort schemas without parents first, to avoid dependency exceptions
response.sort((a, b) => {
if(!a['@parent']) { return -1; }
if(!b['@parent']) { return 1; }

return 0;
});

for(let json of response) {
await HashBrown.Helpers.SchemaHelper.importSchema(req.project, req.environment, json);
}
Expand Down
13 changes: 13 additions & 0 deletions src/Server/Helpers/SchemaHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ class SchemaHelper extends SchemaHelperCommon {
let info = i18n[key] || {};
let type = json[key];

if(type && type['@type']) {
type = type['@type'];
}

if(!type) { throw new Error('Type for key "' + key + '" was null'); }

let def = {
Expand Down Expand Up @@ -296,6 +300,15 @@ class SchemaHelper extends SchemaHelperCommon {
} else if(type === 'bool') {
def.schemaId = 'boolean';

} else if(type === 'text') {
def.schemaId = 'string';
def.config = {
isMultiLine: true
};

} else if(type === 'html') {
def.schemaId = 'richText';

} else {
def.schemaId = getId(type);

Expand Down

0 comments on commit 194ea57

Please sign in to comment.