mirror of https://github.com/rancher/api-ui.git
Add basic support for embedded types
For example, given:
```javascript
{
{
id: 'container',
type: 'schema',
resourceFields: {
restart: {
type: 'restartPolicy'
}
}
},
{
id: 'restartPolicy',
type: 'schema',
resourceFields: {
name: {
type: 'string'
},
maximumRetryCount: {
type: 'int',
}
}
}
}
```
the `restart` field will now show up as a textarea that you can put JSON in.
It would be nicer if it looked up the properties of a restartPolicy and allowed
you to enter them directly, but nesting complex types is not a terribly simple
change so this will provide a way to set embedded types in the meantime.
This commit is contained in:
parent
613e2d8f2a
commit
bb2a818a8f
|
|
@ -1,5 +1,6 @@
|
||||||
.DS_Store
|
.DS_Store
|
||||||
node_modules
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
bower_components
|
bower_components
|
||||||
dist
|
dist
|
||||||
tmp
|
tmp
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "api-ui",
|
"name": "api-ui",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"description": "Embedded UI for any service that implements the Rancher API spec",
|
"description": "Embedded UI for any service that implements the Rancher API spec",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Go Daddy Operating Company, LLC. (http://godaddy.com)",
|
"Go Daddy Operating Company, LLC. (http://godaddy.com)",
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
"url": "https://github.com/rancherio/api-ui.git"
|
"url": "https://github.com/rancherio/api-ui.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "./scripts/server",
|
"start": "./scripts/serve",
|
||||||
"build": "./scripts/build"
|
"build": "./scripts/build"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
||||||
|
|
@ -472,7 +472,6 @@ HTMLApi.prototype.actionLoad = function(name, obj, body)
|
||||||
// The description of the input and output for this action
|
// The description of the input and output for this action
|
||||||
var actionSchema = (isCollection ? objSchema.collectionActions[name] : objSchema.resourceActions[name]);
|
var actionSchema = (isCollection ? objSchema.collectionActions[name] : objSchema.resourceActions[name]);
|
||||||
|
|
||||||
|
|
||||||
// The schema for the input
|
// The schema for the input
|
||||||
var actionInput = {};
|
var actionInput = {};
|
||||||
if ( actionSchema.input )
|
if ( actionSchema.input )
|
||||||
|
|
@ -1349,12 +1348,25 @@ HTMLApi.prototype._flattenFields = function(mode,schema,data)
|
||||||
|
|
||||||
HTMLApi.prototype._flattenField = function(mode, name, field, data, depth)
|
HTMLApi.prototype._flattenField = function(mode, name, field, data, depth)
|
||||||
{
|
{
|
||||||
|
if ( (mode != 'update') && (mode != 'action') && !(mode == 'create' && field.create) )
|
||||||
|
{
|
||||||
|
// This field is not set/changeable
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
depth = depth || 0;
|
depth = depth || 0;
|
||||||
|
|
||||||
var type = field._typeList[depth];
|
var type = field._typeList[depth];
|
||||||
|
|
||||||
if ( mode == 'update' || (mode == 'create' && field.create) || (mode == 'action') )
|
var isEmbedded = false;
|
||||||
|
if ( ['string','password','float','int','date','blob','boolean','enum','reference','array','map'].indexOf(type) === -1 && this.getSchema(type) )
|
||||||
{
|
{
|
||||||
|
// Show embedded types as JSON, until proper support for embedded types is added.
|
||||||
|
type = 'json';
|
||||||
|
isEmbedded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// The value input's name
|
// The value input's name
|
||||||
var formFieldName = name;
|
var formFieldName = name;
|
||||||
|
|
||||||
|
|
@ -1374,7 +1386,7 @@ HTMLApi.prototype._flattenField = function(mode, name, field, data, depth)
|
||||||
formFieldName += '.value{}';
|
formFieldName += '.value{}';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( subType == 'json' )
|
if ( subType == 'json' || (isEmbedded && i === depth) )
|
||||||
{
|
{
|
||||||
formFieldName += '.json{}';
|
formFieldName += '.json{}';
|
||||||
}
|
}
|
||||||
|
|
@ -1399,7 +1411,7 @@ HTMLApi.prototype._flattenField = function(mode, name, field, data, depth)
|
||||||
|
|
||||||
var displayType = field._typeList[ field._typeList.length - 1];
|
var displayType = field._typeList[ field._typeList.length - 1];
|
||||||
var parentType = field._typeList[ field._typeList.length - 2];
|
var parentType = field._typeList[ field._typeList.length - 2];
|
||||||
if ( parentType && parentType == 'reference' )
|
if ( isEmbedded || (parentType && parentType == 'reference') )
|
||||||
{
|
{
|
||||||
var link = null;
|
var link = null;
|
||||||
if ( field.referenceCollection )
|
if ( field.referenceCollection )
|
||||||
|
|
@ -1416,8 +1428,10 @@ HTMLApi.prototype._flattenField = function(mode, name, field, data, depth)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( link )
|
if ( link )
|
||||||
|
{
|
||||||
displayType = '<a tabindex="-1" href="' + link + '" target="_blank">' + displayType + '</a>';
|
displayType = '<a tabindex="-1" href="' + link + '" target="_blank">' + displayType + '</a>';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for ( var i = field._typeList.length - 2 ; i >= depth ; i-- )
|
for ( var i = field._typeList.length - 2 ; i >= depth ; i-- )
|
||||||
{
|
{
|
||||||
|
|
@ -1457,9 +1471,6 @@ HTMLApi.prototype._flattenField = function(mode, name, field, data, depth)
|
||||||
}
|
}
|
||||||
|
|
||||||
return row;
|
return row;
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1751,7 +1762,7 @@ HTMLApi.prototype.subAdd = function(button, name)
|
||||||
children: [field]
|
children: [field]
|
||||||
}
|
}
|
||||||
|
|
||||||
var html = Handlebars.templates['field.hbs'](par);
|
var html = Handlebars.partials['field.hbs'](par);
|
||||||
|
|
||||||
// html = '<div><input type="button" onclick="htmlapi.subRemove(this);" value="-">' + html + '</div>';
|
// html = '<div><input type="button" onclick="htmlapi.subRemove(this);" value="-">' + html + '</div>';
|
||||||
$(button).before(html);
|
$(button).before(html);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue