[transform,refactor][s]: rename costco.js to data.transform.js and rename module to recline.Data.Transform.

This commit is contained in:
Rufus Pollock
2012-07-15 00:38:16 +01:00
parent 178a8c1e42
commit 7546889cf3
3 changed files with 64 additions and 65 deletions

View File

@@ -168,7 +168,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
}; };
this.transform = function(editFunc) { this.transform = function(editFunc) {
var toUpdate = costco.mapDocs(this.data, editFunc); var toUpdate = recline.Data.Transform.mapDocs(this.data, editFunc);
// TODO: very inefficient -- could probably just walk the documents and updates in tandem and update // TODO: very inefficient -- could probably just walk the documents and updates in tandem and update
_.each(toUpdate.updates, function(record, idx) { _.each(toUpdate.updates, function(record, idx) {
self.data[idx] = record; self.data[idx] = record;

View File

@@ -1,19 +1,23 @@
this.recline = this.recline || {};
this.recline.Data = this.recline.Data || {};
(function(my) {
// adapted from https://github.com/harthur/costco. heather rules // adapted from https://github.com/harthur/costco. heather rules
var costco = function() { my.Transform = {};
function evalFunction(funcString) { my.Transform.evalFunction = function(funcString) {
try { try {
eval("var editFunc = " + funcString); eval("var editFunc = " + funcString);
} catch(e) { } catch(e) {
return {errorMessage: e+""}; return {errorMessage: e+""};
} }
return editFunc; return editFunc;
} };
function previewTransform(docs, editFunc, currentColumn) { my.Transform.previewTransform = function(docs, editFunc, currentColumn) {
var preview = []; var preview = [];
var updated = mapDocs($.extend(true, {}, docs), editFunc); var updated = my.Transform.mapDocs($.extend(true, {}, docs), editFunc);
for (var i = 0; i < updated.docs.length; i++) { for (var i = 0; i < updated.docs.length; i++) {
var before = docs[i] var before = docs[i]
, after = updated.docs[i] , after = updated.docs[i]
@@ -26,9 +30,9 @@ var costco = function() {
} }
} }
return preview; return preview;
} };
function mapDocs(docs, editFunc) { my.Transform.mapDocs = function(docs, editFunc) {
var edited = [] var edited = []
, deleted = [] , deleted = []
, failed = [] , failed = []
@@ -58,11 +62,6 @@ var costco = function() {
deletes: deleted, deletes: deleted,
failed: failed failed: failed
}; };
}
return {
evalFunction: evalFunction,
previewTransform: previewTransform,
mapDocs: mapDocs
}; };
}();
}(this.recline.Data))

View File

@@ -57,7 +57,7 @@ my.Transform = Backbone.View.extend({
onSubmit: function(e) { onSubmit: function(e) {
var self = this; var self = this;
var funcText = this.el.find('.expression-preview-code').val(); var funcText = this.el.find('.expression-preview-code').val();
var editFunc = costco.evalFunction(funcText); var editFunc = recline.Data.Transform.evalFunction(funcText);
if (editFunc.errorMessage) { if (editFunc.errorMessage) {
this.trigger('recline:flash', {message: "Error with function! " + editFunc.errorMessage}); this.trigger('recline:flash', {message: "Error with function! " + editFunc.errorMessage});
return; return;
@@ -97,13 +97,13 @@ my.Transform = Backbone.View.extend({
// if you don't setTimeout it won't grab the latest character if you call e.target.value // if you don't setTimeout it won't grab the latest character if you call e.target.value
window.setTimeout( function() { window.setTimeout( function() {
var errors = self.el.find('.expression-preview-parsing-status'); var errors = self.el.find('.expression-preview-parsing-status');
var editFunc = costco.evalFunction(e.target.value); var editFunc = recline.Data.Transform.evalFunction(e.target.value);
if (!editFunc.errorMessage) { if (!editFunc.errorMessage) {
errors.text('No syntax error.'); errors.text('No syntax error.');
var docs = self.model.records.map(function(doc) { var docs = self.model.records.map(function(doc) {
return doc.toJSON(); return doc.toJSON();
}); });
var previewData = costco.previewTransform(docs, editFunc); var previewData = recline.Data.Transform.previewTransform(docs, editFunc);
var $el = self.el.find('.expression-preview-container'); var $el = self.el.find('.expression-preview-container');
var fields = self.model.fields.toJSON(); var fields = self.model.fields.toJSON();
var rows = _.map(previewData.slice(0,4), function(row) { var rows = _.map(previewData.slice(0,4), function(row) {