getDataStoreIndex: getDataStoreIndex,
prepareAllRequestData: prepareAllRequestData,
prepareReceivedData: prepareReceivedData,
+ putIntoObj: putIntoObj,
validateFile: validateFile,
};
return service;
+ /**
+ * Put data to output container if root node is rpc
+ * @param data
+ * @param node
+ * @returns {*}
+ */
function checkRpcReceivedData(data, node){
return node.type === 'rpc' ? cutData(data) : data;
}
}
+ /**
+ * Put source object into destination object by source properties
+ * @param sourceObj
+ * @param destinationObj
+ */
+ function putIntoObj(sourceObj, destinationObj, containter){
+ Object.keys(sourceObj).forEach(function(prop){
+ destinationObj[containter] = destinationObj[containter] ? destinationObj[containter] : {};
+ destinationObj[containter][prop] = sourceObj[prop];
+ });
+ }
+
/**
* Prepare request date before filling into node depends on method and node type
* @param node
*/
function prepareReceivedData(node, method, rData, sData, outputType){
var prepareType = {
- rpc: function(){
+ rpc: function (){
if ( outputType === 'form' ){
var dObj = {};
} else {
return rData;
}
-
- /**
- * Put source object into destination object by source properties
- * @param sourceObj
- * @param destinationObj
- */
- function putIntoObj(sourceObj, destinationObj, containter){
- Object.keys(sourceObj).forEach(function(prop){
- destinationObj[containter] = destinationObj[containter] ? destinationObj[containter] : {};
- destinationObj[containter][prop] = sourceObj[prop];
- });
- }
},
- default: function(){
+ default: function (){
var methodType = {
GET: function () {
- node.clear();
+ if ( node ){
+ node.clear();
+ }
return rData;
},
DELETE: function () {
- node.clear();
+ if ( node ) {
+ node.clear();
+ }
return {};
},
- PUT: function () {
+ DEFAULT: function () {
return rData;
},
- DEFAULT: function () {
- return outputType === 'form' ? sData : rData;
- }
};
return (methodType[method] || methodType.DEFAULT)();
customRestangular: null,
headers: {},
operation: '',
- reqString: selectedSubApi ? selectedSubApi.buildApiRequestString() : '',
+ reqString:
+ selectedSubApi ?
+ RequestsService.applyParamsToStr(params, selectedSubApi.buildApiRequestString()) : '',
reqHeaders: {},
reqData: '',
srcData: '',
else {
allPreparedData.srcData = requestData;
}
- allPreparedData.reqData = RequestsService.applyParams(params, allPreparedData.srcData);
+
+ allPreparedData.reqData = RequestsService.applyParamsToObj(params, allPreparedData.srcData);
+
// prepare req data
if (operation === 'GET' || operation === 'DELETE'){
allPreparedData.srcData = null;
allPreparedData.reqData = null;
}
- else if (operation === 'POST'){
- allPreparedData.reqData = YangUtilsService.postRequestData(
- allPreparedData.reqData,
- allPreparedData.reqString,
- selectedSubApi
- );
+ else if ( operation === 'POST' ){
+
+ if ( selectedSubApi ) {
+ allPreparedData.reqData = YangUtilsService.postRequestData(
+ allPreparedData.reqData,
+ allPreparedData.reqString,
+ selectedSubApi
+ );
+ }
}
// set correct host into restangular based on shown data type and prepare data
if ( dataType === 'req-data' ){
+ requestUrl = RequestsService.applyParamsToStr(params, requestUrl);
var parser = locationHelper(requestUrl, ['pathname', 'origin']),
raParam = '';
function finishExecuting(response){
// finish track time response
time.finished = new Date().getMilliseconds();
+ var spentRequestTime = time.finished - time.started;
return {
status: response.status,
statusText: response.statusText,
- time: (time.finished - time.started),
+ time: spentRequestTime < 0 ? -(spentRequestTime) : spentRequestTime,
requestData: allPreparedData.reqData,
requestSrcData: allPreparedData.srcData,
};