Skip to content

Commit

Permalink
Merge f9a9728 into 0a84802
Browse files Browse the repository at this point in the history
  • Loading branch information
itayw committed Oct 2, 2013
2 parents 0a84802 + f9a9728 commit f3177c5
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 306 deletions.
22 changes: 12 additions & 10 deletions joola.io.sdk.js
Expand Up @@ -27,16 +27,18 @@ var joola = {};
global.joola = joola;
joola.config = nconf;
if (!global.test)
joola.logger = logger;
joola.logger = logger;
else
joola.logger = logger.falseLogger;
//Configuration
var loadConfig = function (callback) {
joola.config.argv()
.env();
nconf.use('http', { url: 'http://localhost:40001/conf/joola.io.sdk',
callback: function () {
joola.config.file({ file: joola.config.get('conf') || './config/joola.io.sdk.json' });
callback: function (err) {
if (err) {
joola.config.file({ file: joola.config.get('conf') || './config/joola.io.sdk.json' });
}
//Configuration loaded

//Validate config
Expand All @@ -50,20 +52,20 @@ var loadConfig = function (callback) {
};

var setupApplication = function (callback) {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.compress());
app.use(express.bodyParser());
app.use(express.methodOverride());

var winstonStream = {
write: function (message, encoding) {
logger.info(message);
joola.logger.info(message);
}
};
app.use(express.logger((global.test ? function (req, res) {
} : {stream: winstonStream})));

app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.compress());
app.use(express.bodyParser());
app.use(express.methodOverride());

callback();
};

Expand Down
6 changes: 3 additions & 3 deletions lib/joolaio.dataaccess.js
Expand Up @@ -110,7 +110,7 @@ joolaio.dataaccess.fetch = function (sender, endPoint, queryOptions, callback, t
else if (result.resultcode == 500)
throw { message: result.resulttext};
else if (typeof(callback) === "function")
callback(sender, result, this /*error*/);
callback(sender, result.data, this /*error*/);
else {
oResult = result;
}
Expand Down Expand Up @@ -158,9 +158,9 @@ joolaio.dataaccess.prepareAjax = function (sender, endPoint, queryOptions, callb
dataType: 'json',
url: endPoint,
contentType: 'application/json;',
/*xhrFields: {
/* xhrFields: {
withCredentials: true
},*/
}, */
data: queryOptions,
beforeSend: function (xhr, settings) {
xhr.setRequestHeader('joola-token', joolaio.TOKEN);
Expand Down
36 changes: 4 additions & 32 deletions lib/joolaio.objects.Auth.js
Expand Up @@ -31,58 +31,30 @@ joolaio.objects.Auth.prototype.checkToken = function (sender, options, callback)
var result;

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/auth.checkToken', options, function (sender, data, error) {
joolaio.dataaccess.fetch(this, '/auth/checkToken', options, function (sender, data, error) {

result = data.authenticated;
callback(sender, result);
});
else {

result = joolaio.dataaccess.fetch(this, '/auth.checkToken', options, null);
result = joolaio.dataaccess.fetch(this, '/auth/checkToken', options, null);
result = result.authenticated;
}

return result;
};

joolaio.objects.Auth.prototype.CheckSession = function (sender, options, callback) {
var result;

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/engine/Auth.svc/CheckSession', null, function (sender, data, error) {
result = $.parseJSON(data.data);
callback(sender, result);
});
else
result = joolaio.dataaccess.fetch(this, '/engine/Auth.svc/CheckSession', null, null);

return result;
};

joolaio.objects.Auth.prototype.GetToken = function (sender, options, callback) {
var result;

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/engine/Auth.svc/GetToken', null, function (sender, data, error) {
result = $.parseJSON(data.data);
callback(sender, result);
});
else
result = joolaio.dataaccess.fetch(this, '/engine/Auth.svc/GetToken', null, null);

return result;
};

joolaio.objects.Auth.prototype.GetUser = function (sender, options, callback) {
var result;

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/auth.getUser', null, function (sender, data, error) {
joolaio.dataaccess.fetch(this, '/auth/getUser', null, function (sender, data, error) {
result = data.user;
callback(sender, result);
});
else {
result = joolaio.dataaccess.fetch(this, '/auth.getUser', null, null);
result = joolaio.dataaccess.fetch(this, '/auth/getUser', null, null);
result = result.user;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/joolaio.objects.Dashboards.js
Expand Up @@ -38,7 +38,7 @@ joolaio.objects.Dashboards.List = function (sender, options, callback) {
return joolaio.objects.Dashboards;

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/dashboards.list', null, function (sender, data, error) {
joolaio.dataaccess.fetch(this, '/dashboards/list', null, function (sender, data, error) {
result = data.dashboards;
joolaio.objects.Dashboards.splice(0, joolaio.objects.Dashboards.length);
$(result).each(function (index, item) {
Expand All @@ -47,7 +47,7 @@ joolaio.objects.Dashboards.List = function (sender, options, callback) {
callback(sender, result);
});
else {
result = joolaio.dataaccess.fetch(this, '/dashboards.list', null, null);
result = joolaio.dataaccess.fetch(this, '/dashboards/list', null, null);
var data = result.dashboards;
joolaio.objects.Dashboards.splice(0, joolaio.objects.Dashboards.length);
$(data).each(function (index, item) {
Expand All @@ -67,12 +67,12 @@ joolaio.objects.Dashboards.Get = function (sender, options, callback, force) {
});

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/dashboards.get', {id: options.id}, function (sender, data, error) {
joolaio.dataaccess.fetch(this, '/dashboards/get', {id: options.id}, function (sender, data, error) {
result = data.dashboard;
callback(sender, result);
});
else {
result = joolaio.dataaccess.fetch(this, 'dashboards.get', {id: options.id}, null);
result = joolaio.dataaccess.fetch(this, 'dashboards/get', {id: options.id}, null);
result = result.dashboard;
}

Expand Down
23 changes: 4 additions & 19 deletions lib/joolaio.objects.Dimensions.js
Expand Up @@ -35,7 +35,7 @@ joolaio.objects.Dimensions.List = function (sender, options, callback) {
return joolaio.objects.Dimensions;

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/dimensions.list', {}, function (sender, data, error) {
joolaio.dataaccess.fetch(this, '/dimensions/list', {}, function (sender, data, error) {
result = data.dimensions;
joolaio.objects.Dimensions.splice(0, joolaio.objects.Dimensions.length);
$(result).each(function (index, item) {
Expand All @@ -46,7 +46,7 @@ joolaio.objects.Dimensions.List = function (sender, options, callback) {
callback(sender, result);
});
else {
result = joolaio.dataaccess.fetch(this, '/dimensions.list', null, null);
result = joolaio.dataaccess.fetch(this, '/dimensions/list', null, null);
var data = result.dimensions;
joolaio.objects.Dimensions.splice(0, joolaio.objects.Dimensions.length);
$(data).each(function (index, item) {
Expand All @@ -70,12 +70,12 @@ joolaio.objects.Dimensions.Get = function (sender, options, callback, force) {
}

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/dimensions.get', {id: options.id}, function (sender, data, error) {
joolaio.dataaccess.fetch(this, '/dimensions/get', {id: options.id}, function (sender, data, error) {
result = data.dimension;
callback(sender, result);
});
else {
result = joolaio.dataaccess.fetch(this, '/dimensions.get', {id: options.id}, null);
result = joolaio.dataaccess.fetch(this, '/dimensions/get', {id: options.id}, null);
result = result.dimension;
}

Expand All @@ -90,20 +90,5 @@ joolaio.objects.Dimensions.Set = function (sender, options, callback) {
callback(result);
};

joolaio.objects.Dimensions.Categories_List = function (sender, options, callback) {
var result;

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/engine/Dimensions.svc/Categories_List', {}, function (sender, data, error) {
result = $.parseJSON(data.data);
callback(sender, result);
});
else
result = joolaio.dataaccess.fetch(this, '/engine/Dimensions.svc/Categories_List', null, null);

return result;
};


joolaio.loaded.push('joolaio.objects.Dimensions');
joolaio.debug.log('INFO', 'joolaio.objects.Dimensions', 6, 'JS source loaded');
93 changes: 4 additions & 89 deletions lib/joolaio.objects.Metrics.js
Expand Up @@ -36,7 +36,7 @@ joolaio.objects.Metrics.List = function (sender, options, callback) {
return joolaio.objects.Metrics;

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/metrics.list', {}, function (sender, data, error) {
joolaio.dataaccess.fetch(this, '/metrics/list', {}, function (sender, data, error) {
result = data.metrics;
joolaio.objects.Metrics.splice(0, joolaio.objects.Metrics.length);
$(result).each(function (index, m) {
Expand Down Expand Up @@ -67,7 +67,7 @@ joolaio.objects.Metrics.List = function (sender, options, callback) {
callback(sender, result);
});
else {
result = joolaio.dataaccess.fetch(this, '/metrics.list', null, null);
result = joolaio.dataaccess.fetch(this, '/metrics/list', null, null);
var data = result.metrics;
joolaio.objects.Metrics.splice(0, joolaio.objects.Metrics.length);
$(data).each(function (index, m) {
Expand Down Expand Up @@ -112,12 +112,12 @@ joolaio.objects.Metrics.Get = function (sender, options, callback, force) {
}

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/metrics.get', {id: options.id}, function (sender, data, error) {
joolaio.dataaccess.fetch(this, '/metrics/get', {id: options.id}, function (sender, data, error) {
result = data.metric;
callback(sender, result);
});
else {
result = joolaio.dataaccess.fetch(this, '/metrics.get', {id: options.id}, null);
result = joolaio.dataaccess.fetch(this, '/metrics/get', {id: options.id}, null);
result = result.metric;
}

Expand All @@ -132,90 +132,5 @@ joolaio.objects.Metrics.Set = function (sender, options, callback) {
callback(result);
};

joolaio.objects.Metrics.AddGroup = function (sender, options, callback) {
var result;

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/engine/Metrics.svc/AddGroup', {TabID: options.tabID, name: options.name}, function (sender, data, error) {
result = $.parseJSON(data.data);
callback(sender, result);
});
else
result = joolaio.dataaccess.fetch(this, '/engine/Metrics.svc/AddGroup', {TabID: options.tabID, name: options.name}, null);

return result;
};

joolaio.objects.Metrics.DeleteGroup = function (sender, options, callback) {
var result;

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/engine/Metrics.svc/DeleteGroup', {id: options.id}, function (sender, data, error) {
result = $.parseJSON(data.data);
callback(sender, result);
});
else
result = joolaio.dataaccess.fetch(this, '/engine/Metrics.svc/DeleteGroup', {id: options.id}, null);

return result;
};

joolaio.objects.Metrics.UpdateGroup = function (sender, id, prop, val, callback) {
var result;

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/engine/Metrics.svc/UpdateGroup', {id: id, property: prop, value: val}, function (sender, data, error) {
result = $.parseJSON(data.data);
callback(sender, result);
});
else
result = joolaio.dataaccess.fetch(this, '/engine/Metrics.svc/UpdateGroup', {id: id, property: prop, value: val}, null);

return result;
};

joolaio.objects.Metrics.UpdateGroupMetric = function (sender, id, ms_id, ordinal, callback) {
var result;

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/engine/Metrics.svc/UpdateGroupMetric', {id: id, metricID: ms_id, ordinal: ordinal}, function (sender, data, error) {
result = $.parseJSON(data.data);
callback(sender, result);
});
else
result = joolaio.dataaccess.fetch(this, '/engine/Metrics.svc/UpdateGroupMetric', {id: id, metricID: ms_id, ordinal: ordinal}, null);

return result;
};

joolaio.objects.Metrics.DeleteGroupMetric = function (sender, id, ms_id, ordinal, callback) {
var result;

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/engine/Metrics.svc/DeleteGroupMetric', {id: id, metricID: ms_id}, function (sender, data, error) {
result = $.parseJSON(data.data);
callback(sender, result);
});
else
result = joolaio.dataaccess.fetch(this, '/engine/Metrics.svc/DeleteGroupMetric', {id: id, metricID: ms_id}, null);

return result;
};

joolaio.objects.Metrics.Categories_List = function (sender, options, callback) {
var result;

if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/engine/Metrics.svc/Categories_List', {}, function (sender, data, error) {
result = $.parseJSON(data.data);
callback(sender, result);
});
else
result = joolaio.dataaccess.fetch(this, '/engine/Metrics.svc/Categories_List', null, null);

return result;
};


joolaio.loaded.push('joolaio.objects.Metrics');
joolaio.debug.log('INFO', 'joolaio.objects.Metrics', 6, 'JS source loaded');
8 changes: 4 additions & 4 deletions lib/joolaio.objects.Query.js
Expand Up @@ -33,7 +33,7 @@ joolaio.objects.Query.prototype.SystemStartDate = function (sender, options, cal

joolaio.inSaveState = true;
if (typeof callback == 'function')
joolaio.dataaccess.fetch(this, '/status.systemStartDate', null, function (sender, data, error) {
joolaio.dataaccess.fetch(this, '/status/systemStartDate', null, function (sender, data, error) {
result = data.startDate;
if (result == null) {
result = new Date();
Expand All @@ -47,7 +47,7 @@ joolaio.objects.Query.prototype.SystemStartDate = function (sender, options, cal
callback(sender, result);
});
else {
result = joolaio.dataaccess.fetch(this, '/status.systemStartDate', null, null);
result = joolaio.dataaccess.fetch(this, '/status/systemStartDate', null, null);
result = result.startDate;
if (result == null) {
result = new Date();
Expand All @@ -70,7 +70,7 @@ joolaio.objects.Query.prototype.SystemEndDate = function (sender, options, callb

joolaio.inSaveState = true;
if (typeof callback == 'function') {
joolaio.dataaccess.fetch(this, '/status.systemEndDate', null, function (sender, data, error) {
joolaio.dataaccess.fetch(this, '/status/systemEndDate', null, function (sender, data, error) {
result = data.endDate;
if (result == null) {
result = new Date();
Expand All @@ -84,7 +84,7 @@ joolaio.objects.Query.prototype.SystemEndDate = function (sender, options, callb
});
}
else {
result = joolaio.dataaccess.fetch(this, '/status.systemEndDate', null, null);
result = joolaio.dataaccess.fetch(this, '/status/systemEndDate', null, null);
result = result.endDate;
if (result == null) {
result = new Date();
Expand Down

0 comments on commit f3177c5

Please sign in to comment.