Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ed6b938
HUB-2766 model code can now pass bid adjustment in tree fields, still…
Dec 6, 2019
cc3a6cd
HUB-2766- added field bid adjustments to formbuilder
Dec 11, 2019
31be649
HUB-2766
Dec 13, 2019
6a2771f
HUB-2766 typo fix
Dec 13, 2019
67ee0bc
HUB-2766 minor typo
Dec 13, 2019
2126763
HUB-2766 index search
Dec 13, 2019
97fc806
HUB-2766 added modified javascript version
Dec 13, 2019
591f78a
HUB-2766
Dec 13, 2019
814d605
bump version to 2.3.0
balihoo-cnorwood Dec 17, 2019
1aa2024
HUB-2766 updated coffee script file with latest from formRender.jsx
Dec 18, 2019
b06fcf3
HUB-2766 bid adjustment flag in tree
Dec 18, 2019
1a36b54
HUB-2766 compiled local output and tested coffee script locally: lint…
Dec 19, 2019
75a7d81
HUB-2766 removed console.log
balihoo-wwilkins Jan 6, 2020
f4af1a1
HUB-2766 updated code to check optionObject.path if array and pop arr…
Jan 9, 2020
f74bfe8
HUB-2766 removed modelField.js,do gulp compile and go to lib folder t…
Jan 9, 2020
24279cc
changing to version 2.2.10 - save 2.3.0 when ready to merge and publish
balihoo-cnorwood Jan 9, 2020
21c0ca9
tweak version, update docs
balihoo-cnorwood Jan 9, 2020
3dbc6a1
versionhistory fix
balihoo-cnorwood Jan 9, 2020
aba8dd4
remove package-lock.json - should not store this in repo - https://gi…
balihoo-cnorwood Jan 9, 2020
6caa42a
fix build
balihoo-cnorwood Jan 10, 2020
26f7f98
Temporarily adding lib/*.js to see if we can test without npm publish
balihoo-cnorwood Jan 10, 2020
1639ef3
Downgraded coffee script version due to conflict in form-builder
balihoo-mpatel Sep 10, 2021
997e44f
added libs temporary
balihoo-mpatel Sep 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
.vscode/
node_modules/
*.tgz
lib
6 changes: 3 additions & 3 deletions doc/Development.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

## Requirements

* npm - I use v1.4.3. Different versions can store packages in very different ways, so be aware of that if you use something different.
* node - 0.10.26. Note that the package in the apt repos is much older, and there are much newer ones available. Newer 10.x versions are probably ok.
* npm - tested with npm v6.4.1 - Different versions can store packages in very different ways, so be aware of that if you use something different.
* node - 0.10.26, tested up to v10.14.1 - Note that the package in the apt repos is much older, and there are much newer ones available. Newer 10.x versions are probably ok.
* gulp - Part of the required packages, but is useful to have a global version too. `npm install -g gulp`

## Git and npm

Use the standard git-branch-merge workflow to update master, then `npm publish`

This package is published to the public npm repositories, then referenced from other places by version there. So follow (semver)[http://semver.org/] policies with the package name, then npm publish when you have something working.
This package is published to the public npm repositories, then referenced from other places by version there. So follow [semver](http://semver.org/) policies with the package name, then npm publish when you have something working.

Depending on the features added, you may need to then update the reference in these places:

Expand Down
3 changes: 3 additions & 0 deletions doc/VersionHistory.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Version History

# 2.2.x
- Testing support for bid adjustments

# 2.2.1
- Fix a bug where applying a value to a multiselect field where some of those values aren't options would sometimes not add all new values as options.

Expand Down
224 changes: 224 additions & 0 deletions lib/building.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
var CoffeeScript, ModelGroup, Mustache, _, globals, jiff, throttledAlert, vm;

CoffeeScript = require('coffee-script');

Mustache = require('mustache');

_ = require('underscore');

vm = require('vm');

jiff = require('jiff');

globals = require('./globals');

ModelGroup = require('./modelGroup');

globals = require('./globals');

if (typeof alert !== "undefined" && alert !== null) {
throttledAlert = _.throttle(alert, 500);
}


/*
An array of functions that can test a built model.
Model code may add tests to this array during build. The tests themselves will not be run at the time, but are
made avaiable via this export so processes can run the tests when appropriate.
Tests may modify the model state, so the model should be rebuilt prior to running each test.
*/

exports.modelTests = [];

exports.fromCode = function(code, data, element, imports, isImport) {
var assert, emit, newRoot, test;
data = (function() {
switch (typeof data) {
case 'object':
return jiff.clone(data);
case 'string':
return JSON.parse(data);
default:
return {};
}
})();
globals.runtime = false;
exports.modelTests = [];
test = function(func) {
return exports.modelTests.push(func);
};
assert = function(bool, message) {
if (message == null) {
message = "A model test has failed";
}
if (!bool) {
return globals.handleError(message);
}
};
emit = function(name, context) {
if (element && $) {
return element.trigger($.Event(name, context));
}
};
newRoot = new ModelGroup();
newRoot.recalculating = false;
newRoot.recalculateCycle = function() {};
(function(root) {
var field, group, sandbox, validate;
field = newRoot.field.bind(newRoot);
group = newRoot.group.bind(newRoot);
root = newRoot.root;
validate = newRoot.validate;
if (typeof window === "undefined" || window === null) {
sandbox = {
field: field,
group: group,
root: root,
validate: validate,
data: data,
imports: imports,
test: test,
assert: assert,
Mustache: Mustache,
emit: emit,
_: _,
console: {
log: function() {},
error: function() {}
},
print: function() {}
};
return vm.runInNewContext('"use strict";' + code, sandbox);
} else {
return eval('"use strict";' + code);
}
})(null);
newRoot.postBuild();
globals.runtime = true;
newRoot.applyData(data);
newRoot.getChanges = exports.getChanges.bind(null, newRoot);
newRoot.setDirty(newRoot.id, 'multiple');
newRoot.recalculateCycle = function() {
var results;
results = [];
while (!this.recalculating && this.dirty) {
this.recalculating = true;
this.recalculateRelativeProperties();
results.push(this.recalculating = false);
}
return results;
};
newRoot.recalculateCycle();
newRoot.on('change:isValid', function() {
if (!isImport) {
return emit('validate', {
isValid: newRoot.isValid
});
}
});
newRoot.on('recalculate', function() {
if (!isImport) {
return emit('change');
}
});
newRoot.trigger('change:isValid');
newRoot.trigger('recalculate');
newRoot.styles = false;
return newRoot;
};

exports.fromCoffee = function(code, data, element, imports, isImport) {
return exports.fromCode(CoffeeScript.compile(code), data, element, imports, isImport);
};

exports.fromPackage = function(pkg, data, element) {
var buildModelWithRecursiveImports;
buildModelWithRecursiveImports = function(p, el, isImport) {
var buildImport, builtImports, f, form;
form = ((function() {
var i, len, ref, results;
ref = p.forms;
results = [];
for (i = 0, len = ref.length; i < len; i++) {
f = ref[i];
if (f.formid === p.formid) {
results.push(f);
}
}
return results;
})())[0];
if (form == null) {
return;
}
builtImports = {};
buildImport = function(impObj) {
return builtImports[impObj.namespace] = buildModelWithRecursiveImports({
formid: impObj.importformid,
data: data,
forms: p.forms
}, element, true);
};
if (form.imports) {
form.imports.forEach(buildImport);
}
return exports.fromCoffee(form.model, data, el, builtImports, isImport);
};
if (typeof pkg.formid === 'string') {
pkg.formid = parseInt(pkg.formid);
}
data = _.extend(pkg.data || {}, data || {});
return buildModelWithRecursiveImports(pkg, element, false);
};

exports.getChanges = function(modelAfter, beforeData) {
var after, before, changedPath, changedPaths, changedPathsUniqObject, changedPathsUnique, changes, i, internalPatch, j, key, len, len1, modelBefore, outputPatch, p, path, val;
modelBefore = modelAfter.cloneModel();
modelBefore.applyData(beforeData, true);
internalPatch = jiff.diff(modelBefore.buildOutputData(void 0, true), modelAfter.buildOutputData(void 0, true), {
invertible: false
});
outputPatch = jiff.diff(modelBefore.buildOutputData(), modelAfter.buildOutputData(), {
invertible: false
});
changedPaths = (function() {
var i, len, results;
results = [];
for (i = 0, len = internalPatch.length; i < len; i++) {
p = internalPatch[i];
results.push(p.path.replace(/\/[0-9]+$/, ''));
}
return results;
})();
changedPathsUniqObject = {};
for (i = 0, len = changedPaths.length; i < len; i++) {
val = changedPaths[i];
changedPathsUniqObject[val] = val;
}
changedPathsUnique = (function() {
var results;
results = [];
for (key in changedPathsUniqObject) {
results.push(key);
}
return results;
})();
changes = [];
for (j = 0, len1 = changedPathsUnique.length; j < len1; j++) {
changedPath = changedPathsUnique[j];
path = changedPath.slice(1);
before = modelBefore.child(path);
after = modelAfter.child(path);
if (!_.isEqual(before != null ? before.value : void 0, after != null ? after.value : void 0)) {
changes.push({
name: changedPath,
title: after.title,
before: before.buildOutputData(void 0, true),
after: after.buildOutputData(void 0, true)
});
}
}
return {
changes: changes,
patch: outputPatch
};
};
47 changes: 47 additions & 0 deletions lib/formbuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var Backbone, ModelBase, building, globals;

if (typeof window !== "undefined" && window !== null) {
window.formbuilder = exports;
}

Backbone = require('backbone');

ModelBase = require('./modelBase');

building = require('./building');

globals = require('./globals');

exports.fromCode = building.fromCode;

exports.fromCoffee = building.fromCoffee;

exports.fromPackage = building.fromPackage;

exports.getChanges = building.getChanges;

exports.mergeData = globals.mergeData;

exports.applyData = function(modelObject, inData, clear, purgeDefaults) {
return modelObject.applyData(inData, clear, purgeDefaults);
};

exports.buildOutputData = function(model) {
return model.buildOutputData();
};

Object.defineProperty(exports, 'modelTests', {
get: function() {
return building.modelTests;
}
});

Object.defineProperty(exports, 'handleError', {
get: function() {
return globals.handleError;
},
set: function(f) {
return globals.handleError = f;
},
enumerable: true
});
35 changes: 35 additions & 0 deletions lib/globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module.exports = {
runtime: false,
handleError: function(err) {
if (!(err instanceof Error)) {
err = new Error(err);
}
throw err;
},
makeErrorMessage: function(model, propName, err) {
var nameStack, node, stack;
stack = [];
node = model;
while (node.name != null) {
stack.push(node.name);
node = node.parent;
}
stack.reverse();
nameStack = stack.join('.');
return "The '" + propName + "' function belonging to the field named '" + nameStack + "' threw an error with the message '" + err.message + "'";
},
mergeData: function(a, b) {
var key, value;
if ((b != null ? b.constructor : void 0) === Object) {
for (key in b) {
value = b[key];
if ((a[key] != null) && a[key].constructor === Object && (value != null ? value.constructor : void 0) === Object) {
module.exports.mergeData(a[key], value);
} else {
a[key] = value;
}
}
}
return a;
}
};
Loading