addition of javascript files for view dashboard

This commit is contained in:
Dante
2015-04-17 15:17:24 -04:00
parent 8927c51cf9
commit 127d1981c8
4 changed files with 1532 additions and 0 deletions

View File

@@ -0,0 +1,180 @@
var ViewDashboardHelper = function () {
};
ViewDashboardHelper.prototype.userDashboards = function(userId, callBack) {
};
ViewDashboardHelper.prototype.stringIfNull = function (val){
if(val === null || val == undefined || val == "?"){
val = "?";
} else {
val = (parseFloat(val)).toFixed(2);
}
return val;
};
ViewDashboardHelper.prototype.assert = function (condition, message) {
if (!condition) {
message = message || "Assertion failed";
if (typeof Error !== "undefined") {
throw new Error(message);
}
throw message; // Fallback
}
}
ViewDashboardHelper.prototype.truncateString = function (string, len) {
this.assert(len != null && len > 0, "Var len not valid. String must by truncated to a positive non zero length.");
this.assert(string != null, "var string can't be null.");
var retval = "";
if(string.length > len){
retval = string.substring(0, len ) + "...";
}
else{
retval = string;
}
return retval;
}
ViewDashboardHelper.prototype.getKeyValue = function (obj, key, undefined) {
var reg = /\./gi
, subKey
, keys
, context
, x
;
if (reg.test(key)) {
keys = key.split(reg);
context = obj;
for (x = 0; x < keys.length; x++) {
subKey = keys[x];
//the values of all keys except for
//the last one should be objects
if (x < keys.length -1) {
if (!context.hasOwnProperty(subKey)) {
return undefined;
}
context = context[subKey];
}
else {
return context[subKey];
}
}
}
else {
return obj[key];
}
};
ViewDashboardHelper.prototype.setKeyValue = function (obj, key, value) {
var reg = /\./gi
, subKey
, keys
, context
, x
;
//check to see if we need to process
//multiple levels of objects
if (reg.test(key)) {
keys = key.split(reg);
context = obj;
for (x = 0; x < keys.length; x++) {
subKey = keys[x];
//the values of all keys except for
//the last one should be objects
if (x < keys.length -1) {
if (!context[subKey]) {
context[subKey] = {};
}
context = context[subKey];
}
else {
context[subKey] = value;
}
}
}
else {
obj[key] = value;
}
};
ViewDashboardHelper.prototype.merge = function (objFrom, objTo, propMap) {
var toKey
, fromKey
, x
, value
, def
, transform
, key
, keyIsArray
;
if (!objTo) {
objTo = {};
}
for(fromKey in propMap) {
if (propMap.hasOwnProperty(fromKey)) {
toKey = propMap[fromKey];
//force toKey to an array of toKeys
if (!Array.isArray(toKey)) {
toKey = [toKey];
}
for(x = 0; x < toKey.length; x++) {
def = null;
transform = null;
key = toKey[x];
keyIsArray = Array.isArray(key);
if (typeof(key) === "object" && !keyIsArray) {
def = key.default || null;
transform = key.transform || null;
key = key.key;
//evaluate if the new key is an array
keyIsArray = Array.isArray(key);
}
if (keyIsArray) {
//key[toKeyName,transform,default]
def = key[2] || null;
transform = key[1] || null;
key = key[0];
}
if (def && typeof(def) === "function" ) {
def = def(objFrom, objTo);
}
value = this.getKeyValue(objFrom, fromKey);
if (transform) {
value = transform(value, objFrom, objTo);
}
if (typeof value !== 'undefined') {
this.setKeyValue(objTo, key, value);
}
else if (typeof def !== 'undefined') {
this.setKeyValue(objTo, key, def);
}
}
}
}
return objTo;
};

View File

@@ -0,0 +1,157 @@
var ViewDashboardModel = function (oauthToken, server, workspace) {
this.server = server;
this.workspace = workspace;
this.baseUrl = "/api/1.0/" + workspace + "/";
this.oauthToken = oauthToken;
this.helper = new ViewDashboardHelper();
};
ViewDashboardModel.prototype.userDashboards = function(userId) {
return this.getJson('dashboard/ownerData/' + userId);
};
ViewDashboardModel.prototype.dashboardIndicators = function(dashboardId, initDate, endDate) {
return this.getJson('dashboard/' + dashboardId + '/indicator?dateIni=' + initDate + '&dateFin=' + endDate);
};
ViewDashboardModel.prototype.peiData = function(indicatorId, measureDate, compareDate) {
var endPoint = "ReportingIndicators/process-efficiency-data?" +
"indicator_uid=" + indicatorId +
"&measure_date=" + measureDate +
"&compare_date=" + compareDate +
"&language=en";
return this.getJson(endPoint);
}
ViewDashboardModel.prototype.statusData = function(indicatorId, measureDate, compareDate) {
var endPoint = "ReportingIndicators/status-indicator";
return this.getJson(endPoint);
}
ViewDashboardModel.prototype.peiDetailData = function(process, initDate, endDate) {
var endPoint = "ReportingIndicators/process-tasks?" +
"process_list=" + process +
"&init_date=" + initDate +
"&end_date=" + endDate +
"&language=en";
return this.getJson(endPoint);
}
ViewDashboardModel.prototype.ueiData = function(indicatorId, measureDate, compareDate) {
var endPoint = "ReportingIndicators/employee-efficiency-data?" +
"indicator_uid=" + indicatorId +
"&measure_date=" + measureDate +
"&compare_date=" + compareDate +
"&language=en";
return this.getJson(endPoint);
}
ViewDashboardModel.prototype.ueiDetailData = function(groupId, initDate, endDate) {
var endPoint = "ReportingIndicators/group-employee-data?" +
"group_uid=" + groupId +
"&init_date=" + initDate +
"&end_date=" + endDate +
"&language=en";
return this.getJson(endPoint);
}
ViewDashboardModel.prototype.generalIndicatorData = function(indicatorId, initDate, endDate) {
var method = "";
var endPoint = "ReportingIndicators/general-indicator-data?" +
"indicator_uid=" + indicatorId +
"&init_date=" + initDate +
"&end_date=" + endDate +
"&language=en";
return this.getJson(endPoint);
}
ViewDashboardModel.prototype.getPositionIndicator = function(callBack) {
this.getJson('dashboard/config').done(function (r) {
var graphData = [];
$.each(r, function(index, originalObject) {
var map = {
"widgetId" : originalObject.widgetId,
"x" : originalObject.x,
"y" : originalObject.y,
"width" : originalObject.width,
"height" : originalObject.height
};
graphData.push(map);
});
callBack(graphData);
});
};
ViewDashboardModel.prototype.setPositionIndicator = function(data) {
var that = this;
this.getPositionIndicator(
function(response){
if (response.length != 0) {
that.putJson('dashboard/config', data);
} else {
that.postJson('dashboard/config', data);
}
}
);
};
ViewDashboardModel.prototype.getJson = function (endPoint) {
var that = this;
var callUrl = this.baseUrl + endPoint
return $.ajax({
url: callUrl,
type: 'GET',
datatype: 'json',
error: function(jqXHR, textStatus, errorThrown) {
throw new Error(callUrl + ' -- ' + errorThrown);
},
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + that.oauthToken);
//xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
}
});
}
ViewDashboardModel.prototype.postJson = function (endPoint, data) {
var that = this;
return $.ajax({
url : this.baseUrl + endPoint,
type : 'POST',
datatype : 'json',
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data),
error: function(jqXHR, textStatus, errorThrown) {
throw new Error(errorThrown);
},
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + that.oauthToken);
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
}
}).fail(function () {
throw new Error('Fail server');
});
};
ViewDashboardModel.prototype.putJson = function (endPoint, data) {
var that = this;
return $.ajax({
url : this.baseUrl + endPoint,
type : 'PUT',
datatype : 'json',
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data),
error: function(jqXHR, textStatus, errorThrown) {
throw new Error(errorThrown);
},
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + that.oauthToken);
//xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
}
}).fail(function () {
throw new Error('Fail server');
});
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff