pragma-schema
Advanced tools
Comparing version 1.0.56 to 1.0.57
{ | ||
"name": "pragma-schema", | ||
"version": "1.0.56", | ||
"version": "1.0.57", | ||
"description": "utility for building pragma schema structures", | ||
"main": "commonjs/src/schema.js", | ||
"scripts": { | ||
"test": "nyc mocha --compilers js:babel-core/register --recursive", | ||
"test-teamcity": "nyc --reporter=teamcity --reporter=lcov --reporter=text-summary --check-coverage --lines 85 mocha --reporter mocha-teamcity-reporter --compilers js:babel-core/register --recursive", | ||
"build": "cross-env BABEL_ENV=development & bucli -c all", | ||
"publish": "bucli -p", | ||
"build-publish": "node ./build/publish.js" | ||
"test-puppeteer-teamcity": "nyc mocha test/puppeteer/puppeteer-bootstrap.js --timeout 60000 test/puppeteer/lib/launch-unit-tests.js", | ||
"publish": "node ./build/publish.js", | ||
"run": "ws --port 1100" | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"es2015" | ||
], | ||
"plugins": [ | ||
"transform-decorators-legacy", | ||
"transform-class-properties" | ||
] | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"require": [ | ||
"babel-register" | ||
], | ||
"check-coverage": false, | ||
"cache": true, | ||
"all": true, | ||
"reporter": [ | ||
"lcov", | ||
"text-summary" | ||
], | ||
"include": [ | ||
"src/*.js" | ||
], | ||
"exclude": [ | ||
"app/**/*.*", | ||
"node_modules/**/*.*", | ||
"jspm_packages/**/*.*" | ||
], | ||
"cache": true, | ||
"all": true | ||
"lcov" | ||
] | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.26.0", | ||
"babel-plugin-transform-class-properties": "^6.24.1", | ||
"babel-plugin-transform-decorators-legacy": "^1.3.4", | ||
"babel-preset-env": "^1.6.0", | ||
"chai": "^3.5.0", | ||
@@ -51,19 +24,11 @@ "chai-as-promised": "^6.0.0", | ||
"istanbul": "^0.4.5", | ||
"jspm": "^0.16.53", | ||
"mocha": "^3.5.3", | ||
"nyc": "^10.3.2", | ||
"sinon": "^2.4.1", | ||
"mocha-teamcity-reporter": "^2.4.0" | ||
"mocha-teamcity-reporter": "^2.4.0", | ||
"puppeteer": "^1.8.0", | ||
"puppeteer-to-istanbul": "^1.2.2", | ||
"lodash": "^4.17.11" | ||
}, | ||
"jspm": { | ||
"registry": "npm", | ||
"main": "schema", | ||
"format": "amd", | ||
"directories": { | ||
"dist": "amd/src/" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": {} | ||
}, | ||
"dependencies": {} | ||
} |
216
schema.js
@@ -189,4 +189,4 @@ class IdObject { | ||
add(id, name) { | ||
const dsId = id == undefined ? this.length + 1 : id; | ||
const dsName = name == undefined ? `dataset ${dsId}` : name; | ||
const dsId = id == null ? this.length + 1 : id; | ||
const dsName = name == null ? `dataset ${dsId}` : name; | ||
const itemToAdd = new Dataset(dsId, dsName); | ||
@@ -214,3 +214,3 @@ this.push(itemToAdd); | ||
add(id) { | ||
const templateId = id == undefined ? this.length : id; | ||
const templateId = id == null ? this.length : id; | ||
const itemToAdd = new Template(templateId); | ||
@@ -307,3 +307,3 @@ this.push(itemToAdd); | ||
} | ||
add(action, parameters) { | ||
@@ -339,8 +339,8 @@ const id = this.length; | ||
} | ||
addParameter(key, value) { | ||
if (this.parameters == null) { | ||
this.parameters = {}; | ||
} | ||
} | ||
this.parameters[key] = value; | ||
@@ -369,3 +369,3 @@ } | ||
} | ||
addInitialDataset() { | ||
@@ -378,13 +378,29 @@ this.datasets.add(0, "model"); | ||
export class SchemaElementFactory { | ||
static group(title) { | ||
return { | ||
"element": "group", | ||
"title": title, | ||
"elements": [] | ||
static addAttributes(obj, attributes) { | ||
if (attributes !== undefined) { | ||
obj.attributes = attributes; | ||
} | ||
else { | ||
obj.attributes = {}; | ||
} | ||
this.removeAttributeWithValue(obj, 'readonly', false); | ||
this.removeAttributeWithValue(obj, 'disabled', false); | ||
} | ||
static removeAttributeWithValue(obj, atrribute, value) { | ||
if (obj.attributes[atrribute] === value) { | ||
delete obj.attributes[atrribute]; | ||
} | ||
} | ||
static addStyles(obj, styles) { | ||
if (styles !== undefined) { | ||
obj.styles = styles; | ||
} | ||
} | ||
static button(title, action, styles) { | ||
const element = { | ||
"element": "button", | ||
"element": "button", | ||
"title": title, | ||
@@ -395,6 +411,13 @@ "action": action | ||
SchemaElementFactory.addStyles(element, styles); | ||
return element; | ||
} | ||
static card() { | ||
return { | ||
"element": "card", | ||
"elements": [] | ||
}; | ||
} | ||
static checkbox(title, field, attributes, styles) { | ||
@@ -413,37 +436,31 @@ const result = { | ||
static input(title, field, attributes, styles) { | ||
const result = { | ||
"element": "input", | ||
"title": title, | ||
"field": field | ||
/** | ||
* Construct dynamic-crud-toolbar element | ||
* @param actions: Array of actions | ||
* @param forVisualisation: id of visualisation toolbar is bound to | ||
* @returns dynamic-crud-toolbar schema object | ||
*/ | ||
static dynamicCrudToolbar(actions, forVisualisation) { | ||
return { | ||
element: "dynamic-crud-toolbar", | ||
attributes: { | ||
actions: actions, | ||
for: forVisualisation | ||
} | ||
}; | ||
SchemaElementFactory.addAttributes(result, attributes); | ||
SchemaElementFactory.addStyles(result, styles); | ||
return result; | ||
} | ||
static readonly(title, field, styles) { | ||
const result = { | ||
"element": "readonly", | ||
"title": title, | ||
"field": field | ||
}; | ||
SchemaElementFactory.addStyles(result, styles); | ||
return result; | ||
static element() { | ||
return { | ||
element: "", | ||
elements: [] | ||
} | ||
} | ||
static select(title, field, dataSourceId, attributes, styles) { | ||
static gridColumn(attributes) { | ||
const result = { | ||
"element": "select", | ||
"title": title, | ||
"field": field, | ||
"datasource": dataSourceId, | ||
"element": "pragma-grid-column" | ||
}; | ||
SchemaElementFactory.addAttributes(result, attributes); | ||
SchemaElementFactory.addStyles(result, styles); | ||
@@ -453,29 +470,21 @@ return result; | ||
static memo(title, field, attributes, styles) { | ||
const result = { | ||
"element": "memo", | ||
"title": title, | ||
"field": field | ||
static gridVisualisation(attributes) { | ||
const element = { | ||
"element": "pragma-grid", | ||
"elements": [] | ||
}; | ||
SchemaElementFactory.addAttributes(result, attributes); | ||
SchemaElementFactory.addStyles(result, styles); | ||
SchemaElementFactory.addAttributes(element, attributes); | ||
return result; | ||
return element; | ||
} | ||
static template(templateId) { | ||
static group(title) { | ||
return { | ||
"element": "template", | ||
"template": templateId | ||
"element": "group", | ||
"title": title, | ||
"elements": [] | ||
} | ||
} | ||
static card() { | ||
return { | ||
"element": "card", | ||
"elements": [] | ||
}; | ||
} | ||
static htmlElement(htmlTag, content) { | ||
@@ -488,8 +497,11 @@ return { | ||
static gridColumn(attributes) { | ||
static input(title, field, attributes, styles) { | ||
const result = { | ||
"element": "pragma-grid-column" | ||
"element": "input", | ||
"title": title, | ||
"field": field | ||
}; | ||
SchemaElementFactory.addAttributes(result, attributes); | ||
SchemaElementFactory.addStyles(result, styles); | ||
@@ -499,12 +511,5 @@ return result; | ||
static element() { | ||
return { | ||
element: "", | ||
elements: [] | ||
} | ||
} | ||
static gridVisualisation(attributes) { | ||
static listVisualisation(attributes) { | ||
const element = { | ||
"element": "pragma-grid", | ||
"element": "pragma-list", | ||
"elements": [] | ||
@@ -518,13 +523,15 @@ }; | ||
static listVisualisation(attributes) { | ||
const element = { | ||
"element": "pragma-list", | ||
"elements": [] | ||
static memo(title, field, attributes, styles) { | ||
const result = { | ||
"element": "memo", | ||
"title": title, | ||
"field": field | ||
}; | ||
SchemaElementFactory.addAttributes(element, attributes); | ||
SchemaElementFactory.addAttributes(result, attributes); | ||
SchemaElementFactory.addStyles(result, styles); | ||
return element; | ||
return result; | ||
} | ||
static panelBar(title, actions, styles) { | ||
@@ -539,13 +546,45 @@ return { | ||
} | ||
static readonly(title, field, styles) { | ||
const result = { | ||
"element": "readonly", | ||
"title": title, | ||
"field": field | ||
}; | ||
SchemaElementFactory.addStyles(result, styles); | ||
return result; | ||
} | ||
static select(title, field, dataSourceId, attributes, styles) { | ||
const result = { | ||
"element": "select", | ||
"title": title, | ||
"field": field, | ||
"datasource": dataSourceId, | ||
}; | ||
SchemaElementFactory.addAttributes(result, attributes); | ||
SchemaElementFactory.addStyles(result, styles); | ||
return result; | ||
} | ||
static splitView(attributes) { | ||
return { | ||
"element": "split-view", | ||
"element": "split-view", | ||
"attributes": attributes || [], | ||
"left": [], | ||
"left": [], | ||
"right": [] | ||
}; | ||
} | ||
static template(templateId) { | ||
return { | ||
"element": "template", | ||
"template": templateId | ||
} | ||
} | ||
static translation(value) { | ||
@@ -561,17 +600,2 @@ if(value !== undefined) { | ||
} | ||
static addAttributes(obj, attributes) { | ||
if (attributes !== undefined) { | ||
obj.attributes = attributes; | ||
} | ||
else { | ||
obj.attributes = []; | ||
} | ||
} | ||
static addStyles(obj, styles) { | ||
if (styles !== undefined) { | ||
obj.styles = styles; | ||
} | ||
} | ||
} |
15707
11
492