From e8124a2800358a0334e0c4fc4c365d3cc3cc22ba Mon Sep 17 00:00:00 2001 From: "Daniel Kuzma -X (dakuzma - PANTHEON TECHNOLOGIES at Cisco)" Date: Fri, 24 Jun 2016 10:46:07 +0200 Subject: [PATCH] Yangman + Yangtutils - request header + rpc element bug fixing - preprocessing of received data for filling - rpc element - fill method changed - searchnodebypath was extended for searching witchout identifiers - header - fix fill header path between form and json - fix rpc output data in codemirror - fix history saving request - bad url - fix showing delete request in json view Change-Id: Ic348a87e2cd16a6dca8afa3600fcddaea7ad30a2 Signed-off-by: Daniel Kuzma -X (dakuzma - PANTHEON TECHNOLOGIES at Cisco) --- .../services/node-wrapper.services.js | 17 +++-- .../yangutils/services/path-utils.services.js | 13 ++-- .../controllers/module-detail.controller.js | 2 +- .../controllers/request-header.controller.js | 44 ++++++++---- .../yangman/controllers/yangman.controller.js | 4 +- .../yangman/services/yangman.services.js | 68 +++++++++++++++++++ 6 files changed, 119 insertions(+), 29 deletions(-) diff --git a/modules/common-yangutils-resources/src/main/resources/yangutils/services/node-wrapper.services.js b/modules/common-yangutils-resources/src/main/resources/yangutils/services/node-wrapper.services.js index 33e959c7..dc9d7609 100644 --- a/modules/common-yangutils-resources/src/main/resources/yangutils/services/node-wrapper.services.js +++ b/modules/common-yangutils-resources/src/main/resources/yangutils/services/node-wrapper.services.js @@ -663,17 +663,20 @@ define([], function () { }; node.fill = function (name, data) { - var filled = false, + var match = comparePropToElemByName(name, node.label), nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY); - nodesToFill.forEach(function (child) { - var childFilled = child.fill(name, data); - filled = filled || childFilled; - }); + if (match && nodesToFill.length) { + nodesToFill.forEach(function (child) { + for (var prop in data) { + child.fill(prop, data[prop]); + } + }); + } - node.expanded = filled; + node.expanded = match; - return filled; + return match; }; node.clear = function () { diff --git a/modules/common-yangutils-resources/src/main/resources/yangutils/services/path-utils.services.js b/modules/common-yangutils-resources/src/main/resources/yangutils/services/path-utils.services.js index 1789a9ad..44068ffd 100644 --- a/modules/common-yangutils-resources/src/main/resources/yangutils/services/path-utils.services.js +++ b/modules/common-yangutils-resources/src/main/resources/yangutils/services/path-utils.services.js @@ -53,7 +53,7 @@ define([], function () { } // TODO: add service's description - function translate(path, prefixConverter, importNodes, getDefaultModuleCallback) { + function translate(path, prefixConverter, importNodes, getDefaultModuleCallback, notIdentifiers) { var pathStrElements = path.split('/').filter(function (e) { return e !== ''; }), @@ -72,9 +72,10 @@ define([], function () { for (index = 0; index < maxIndex; index += 1) { var actElem = pathStrElements[index], - lastElem = getLastElement(pathArrayElements); + lastElem = getLastElement(pathArrayElements), + checkIdentifier = notIdentifiers ? false : isIdentifier(actElem); - if (isIdentifier(actElem) && lastElem) { + if (checkIdentifier && lastElem) { lastElem.addIdentifier(actElem.slice(1, -1)); } else { @@ -132,7 +133,7 @@ define([], function () { if ( pathItem.hasIdentifier() ){ pathItem.identifiers.forEach(function (identifier){ pathPosition++; - identifier.value = pathArray[pathPosition]; + identifier.value = isIdentifier(pathArray[pathPosition]) ? '' : pathArray[pathPosition]; }); } pathPosition++; @@ -148,8 +149,8 @@ define([], function () { } // TODO: add service's description - function searchNodeByPath(pathString, treeApis, treeData, disabledExpand) { - var pathArray = translate(trimPath(pathString)), + function searchNodeByPath(pathString, treeApis, treeData, disabledExpand, notIdentifiers) { + var pathArray = translate(trimPath(pathString), null, null, null, notIdentifiers), module = pathArray.length > 1 ? pathArray[1].module : null, selectedTreeApi = module ? treeApis.filter(function (treeApi) { return treeApi.module === module; diff --git a/modules/yangman-resources/src/main/resources/yangman/controllers/module-detail.controller.js b/modules/yangman-resources/src/main/resources/yangman/controllers/module-detail.controller.js index 18a15d95..0ac81771 100644 --- a/modules/yangman-resources/src/main/resources/yangman/controllers/module-detail.controller.js +++ b/modules/yangman-resources/src/main/resources/yangman/controllers/module-detail.controller.js @@ -43,7 +43,7 @@ define([ if (apiIndex !== undefined && subApiIndex !== undefined ) { - $scope.setApi($scope.apis[apiIndex], $scope.apis[apiIndex].subApis[subApiIndex]); + $scope.setApi($scope.apis[apiIndex], $scope.apis[apiIndex].subApis[subApiIndex], true); $scope.setNode($scope.selectedSubApi.node); } else { diff --git a/modules/yangman-resources/src/main/resources/yangman/controllers/request-header.controller.js b/modules/yangman-resources/src/main/resources/yangman/controllers/request-header.controller.js index 1bd31d1b..7c24413d 100644 --- a/modules/yangman-resources/src/main/resources/yangman/controllers/request-header.controller.js +++ b/modules/yangman-resources/src/main/resources/yangman/controllers/request-header.controller.js @@ -39,9 +39,12 @@ define([ /** * Set selected operations based on data store */ - $scope.$on('SET_SEL_OPERATIONS', function (event, operations) { + $scope.$on('SET_SEL_OPERATIONS', function (event, operations, setUrl) { setAllowedMethods(operations); - setRequestUrl(); + + if ( setUrl ) { + setRequestUrl(); + } }); /** @@ -51,6 +54,7 @@ define([ init(); setRequestUrl(args.params.path); setRequestMethod(args.params.method); + setJsonView(); (args.cbk || angular.noop)(); }); @@ -194,7 +198,7 @@ define([ $scope.rootBroadcast('YANGMAN_GET_API_TREE_DATA', null, function (treeApis) { var apisIndexes = - PathUtilsService.searchNodeByPath(requestUrl, treeApis, null, true); + PathUtilsService.searchNodeByPath(requestUrl, treeApis, null, true, true); if ( apisIndexes ){ // set apis @@ -218,6 +222,9 @@ define([ // set node $scope.setNode($scope.selectedSubApi.node); + // fill subapi path + PathUtilsService.fillPath($scope.selectedSubApi.pathArray, requestUrl); + setRequestUrl(); } }); } @@ -254,6 +261,7 @@ define([ * Execute request operation */ function executeOperation(requestData, executeCbk){ + setRequestUrl(requestHeader.selectedShownDataType === 'req-data' ? requestHeader.requestUrl : null); var historyReq = RequestService.createHistoryRequest(null, null, requestHeader.requestUrl, requestHeader.selectedOperation, '', '', ''); @@ -272,37 +280,45 @@ define([ ); /** - * + * Success callback after executin operation * @param reqInfo * @param response */ function executeReqSuccCbk(reqInfo, response) { + var preparedReceivedData = YangmanService.prepareReceivedData( + $scope.node, + requestHeader.selectedOperation, + response.data ? response.data.plain() : {}, + reqInfo.requestSrcData, + requestHeader.selectedShownDataType + ); + requestHeader.statusObj = reqInfo; // create and set history request historyReq.setExecutionData( reqInfo.requestSrcData, - response.data ? response.data.plain() : {}, + preparedReceivedData, reqInfo.status ); - setNodeDataFromRequestData(requestHeader.requestUrl); - if (requestHeader.selectedShownDataType === 'req-data'){ - sendRequestData(response.data ? response.data.plain() : '{}', 'RECEIVED'); + setNodeDataFromRequestData(requestHeader.requestUrl); + sendRequestData(preparedReceivedData, 'RECEIVED'); sendRequestData(reqInfo.requestSrcData || {}, 'SENT'); } else { if ($scope.node){ - $scope.node.clear(); + YangmanService.fillNodeFromResponse( $scope.node, - requestHeader.selectedOperation === 'GET' || requestHeader.selectedOperation === 'DELETE' ? - response.data : - reqInfo.requestSrcData + preparedReceivedData ); + $scope.node.expanded = true; + $scope.rootBroadcast('YANGMAN_DISABLE_ADDING_LIST_ELEMENT'); + sendRequestData(YangmanService.checkRpcReceivedData(preparedReceivedData, $scope.node), 'RECEIVED'); } } @@ -312,7 +328,7 @@ define([ } /** - * + * Error callback after executin operation * @param reqInfo * @param response */ @@ -323,6 +339,8 @@ define([ historyReq.setExecutionData(reqInfo.requestSrcData, null, reqInfo.status); $scope.rootBroadcast('YANGMAN_SAVE_EXECUTED_REQUEST', historyReq); + setNodeDataFromRequestData(requestHeader.requestUrl); + if (response.data) { if ( requestHeader.selectedShownDataType === 'req-data' ) { // try to fill code mirror editor diff --git a/modules/yangman-resources/src/main/resources/yangman/controllers/yangman.controller.js b/modules/yangman-resources/src/main/resources/yangman/controllers/yangman.controller.js index fb917d30..2c96fa21 100644 --- a/modules/yangman-resources/src/main/resources/yangman/controllers/yangman.controller.js +++ b/modules/yangman-resources/src/main/resources/yangman/controllers/yangman.controller.js @@ -268,11 +268,11 @@ define([ * @param api * @param subApi */ - function setApi(api, subApi){ + function setApi(api, subApi, setUrl){ $scope.selectedApi = api; $scope.selectedSubApi = subApi; - $scope.$broadcast('SET_SEL_OPERATIONS', subApi ? $scope.selectedSubApi.operations : []); + $scope.$broadcast('SET_SEL_OPERATIONS', subApi ? $scope.selectedSubApi.operations : [], setUrl); } /** diff --git a/modules/yangman-resources/src/main/resources/yangman/services/yangman.services.js b/modules/yangman-resources/src/main/resources/yangman/services/yangman.services.js index 265a90d1..4e81ca78 100644 --- a/modules/yangman-resources/src/main/resources/yangman/services/yangman.services.js +++ b/modules/yangman-resources/src/main/resources/yangman/services/yangman.services.js @@ -22,15 +22,83 @@ define([], function () { RequestsService ){ var service = { + checkRpcReceivedData: checkRpcReceivedData, executeRequestOperation: executeRequestOperation, fillNodeFromResponse: fillNodeFromResponse, getDataStoreIndex: getDataStoreIndex, prepareAllRequestData: prepareAllRequestData, + prepareReceivedData: prepareReceivedData, validateFile: validateFile, }; return service; + function checkRpcReceivedData(data, node){ + return node.type === 'rpc' ? cutData(data) : data; + + function cutData(data){ + return { + output: data[node.label].output, + }; + } + } + + /** + * Prepare request date before filling into node depends on method and node type + * @param node + * @param method + * @param rData + * @param sData + * @param outputType + * @returns {*} + */ + function prepareReceivedData(node, method, rData, sData, outputType){ + var prepareType = { + rpc: function(){ + + if ( outputType === 'form' ){ + var dObj = {}; + putIntoObj(rData, dObj, node.label); + putIntoObj(sData[node.label] ? sData[node.label] : sData, dObj, node.label); + return 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(){ + var methodType = { + GET: function () { + return rData; + }, + DELETE: function () { + node.clear(); + + return {}; + }, + DEFAULT: function () { + return outputType === 'form' ? sData : rData; + } + }; + + return (methodType[method] || methodType.DEFAULT)(); + } + }; + + return (prepareType[node ? node.type : 'default'] || prepareType.default)(); + } + /** * Validating collection import file * @param data -- 2.36.6