"YANGMAN_OK": "OK",
"YANGMAN_REQ_DELETE": "Delete request",
"YANGMAN_REQ_DUPLICATE": "Duplicate request",
- "YANGMAN_REQ_FILL_FORM": "Fill form",
+ "YANGMAN_REQ_SHOW_FORM": "Show form",
"YANGMAN_REQ_RUN": "Run request",
- "YANGMAN_REQ_SHOW_RCVD_DATA": "Show received data",
- "YANGMAN_REQ_SHOW_SENT_DATA": "Show sent data",
+ "YANGMAN_REQ_SHOW_JSON_DATA": "Show json data",
"YANGMAN_REQ_URL": "Request URL",
"YANGMAN_REQS_DELETE": "Delete selected",
"YANGMAN_REQS_DUPLICATE": "Duplicating request",
"YANGMAN_PARAMS_VALUE": "value",
"YANGMAN_PARAM_KEY_REQUIRED": "Required value",
"YANGMAN_PARAM_EXISTING_KEY": "Duplicate value",
- "YANGMAN_SORTING": "Sorting"
+ "YANGMAN_SORTING": "Sorting",
+ "YANGMAN_CLEAR_HISTORY": "Clear history"
+
}
--- /dev/null
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+(function(mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("codemirror"));
+ else if (typeof define == "function" && define.amd) // AMD
+ define(["codemirror"], mod);
+ else // Plain browser env
+ mod(CodeMirror);
+})(function(CodeMirror) {
+ "use strict";
+
+ var WORD = /[<<\w$]+/, RANGE = 500;
+ CodeMirror.registerHelper("hint", "anyword", function(editor, options) {
+ var acList = [],
+ word = options && options.word || WORD,
+ cur = editor.getCursor(),
+ curLine = editor.getLine(cur.line),
+ end = cur.ch,
+ start = end,
+ paramList = editor.data.parameterListObj.list;
+
+ function forEachParam(arr, f, fParam) {
+ for (var i = 0, e = arr.length; i < e; ++i){
+ f(arr[i].key, fParam);
+ }
+ }
+
+
+ function maybeAdd(possibleWord, word) {
+ var pw = '<<' + possibleWord + '>>';
+ if (pw.lastIndexOf(word, 0) == 0 && !arrayContains(acList, pw))
+ acList.push(pw);
+ }
+
+ function arrayContains(arr, item) {
+ if (!Array.prototype.indexOf) {
+ var i = arr.length;
+ while (i--) {
+ if (arr[i] === item) {
+ return true;
+ }
+ }
+ return false;
+ }
+ return arr.indexOf(item) != -1;
+ }
+
+
+ options.completeSingle = false;
+
+ while (start && word.test(curLine.charAt(start - 1)))
+ --start;
+
+ var curWord = curLine.slice(start, end);
+
+ if(curWord.length > 1){
+ forEachParam(paramList, maybeAdd, curWord);
+ }
+
+
+
+ return {list: acList, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
+ });
+});
-define([
-], function () {
+define([], function () {
'use strict';
angular.module('app.yangman').controller('EditCollectionDialogCtrl', EditCollectionDialogCtrl);
*/
function setDataStore(dataStore, module){
$scope.setModule(module);
- $scope.setDataStore(dataStore, true);
+ $scope.setDataStore(dataStore, true, 1);
}
/**
}
/**
- * Sort parameters, so that empty params will be always the last
+ * Sort parameters with empty params at the end of list
* @param item
* @returns {*}
*/
angular.module('app.yangman').controller('RequestDataCtrl', RequestDataCtrl);
- RequestDataCtrl.$inject = ['$scope'];
+ RequestDataCtrl.$inject = ['$scope', 'RequestsService'];
- function RequestDataCtrl($scope) {
+ function RequestDataCtrl($scope, RequestsService) {
var requestData = this;
+ requestData.paramsArray = [];
+
requestData.dataEditorOptions = {
mode: 'javascript',
lineNumbers: true,
theme: 'eclipse',
- readOnly: false,
+ readOnly: requestData.type === 'RECEIVED',
lineWrapping: true,
matchBrackets: true,
extraKeys: { 'Ctrl-Space': 'autocomplete' },
requestData.type = null;
// methods
- requestData.getDataEditorOptions = getDataEditorOptions;
requestData.init = init;
+
+ function initCMOpts() {
+ requestData.dataEditorOptions.readOnly = requestData.type === 'RECEIVED';
+ requestData.dataEditorOptions.theme = requestData.type === 'RECEIVED' ? 'eclipse-disabled' : 'eclipse';
+
+ if (requestData.type === 'SENT') {
+ requestData.dataEditorOptions.onLoad = function (cmInstance){
+ cmInstance.data = { parameterListObj: $scope.parametersList || { list: [] } };
+
+ cmInstance.on('changes', function (){
+ if (angular.isFunction(cmInstance.showHint)){
+ cmInstance.showHint();
+ }
+ });
+
+ cmInstance.on('cursorActivity', function (){
+ var lineString = cmInstance.getLine(cmInstance.getCursor().line);
+ requestData.paramsArray = RequestsService.scanDataParams($scope.parametersList, lineString);
+
+ if (!$scope.$$phase) {
+ $scope.$apply();
+ }
+ });
+
+ cmInstance.refresh();
+ };
+ }
+ }
+
/**
* Initialization
* @param type
*/
function init(type){
requestData.type = type;
+ initCMOpts();
+
// watchers
$scope.$on('YANGMAN_REFRESH_CM_DATA_' + type, refreshData);
$scope.$on('YANGMAN_GET_CODEMIRROR_DATA_' + type, function (event, args){
args.params.reqData = requestData.data;
});
+
}
/**
$scope.requestToShow.setDataForView(true, $scope.requestToShow[$scope.requestDataToShow]);
}
- /**
- *
- * @param read
- * @param theme
- * @returns {
- * {mode: string,
- * lineNumbers: boolean,
- * theme: string,
- * readOnly: boolean,
- * lineWrapping: boolean,
- * matchBrackets: boolean,
- * extraKeys: {Ctrl-Space: string},
- * onLoad: Function}|*
- * }
- */
- function getDataEditorOptions(read, theme){
- requestData.dataEditorOptions.readOnly = read;
- requestData.dataEditorOptions.theme = theme;
-
- return requestData.dataEditorOptions;
- }
-
}
});
-define([], function () {
+define([
+ 'app/yangman/controllers/params-admin.controller',
+], function (ParamsAdminCtrl) {
'use strict';
angular.module('app.yangman').controller('RequestHeaderCtrl', RequestHeaderCtrl);
- RequestHeaderCtrl.$inject = ['$scope', '$rootScope', 'ENV', 'YangmanService', 'PathUtilsService', '$filter'];
+ RequestHeaderCtrl.$inject = [
+ '$mdDialog', '$scope', '$rootScope', 'ENV', 'YangmanService', 'ParametersService', 'PathUtilsService',
+ 'RequestsService', '$filter',
+ ];
- function RequestHeaderCtrl($scope, $rootScope, ENV, YangmanService, PathUtilsService, $filter) {
+ function RequestHeaderCtrl($mdDialog, $scope, $rootScope, ENV, YangmanService, ParametersService, PathUtilsService,
+ RequestService, $filter) {
var requestHeader = this;
requestHeader.allOperations = ['GET', 'POST', 'PUT', 'DELETE'];
requestHeader.executeOperation = executeOperation;
requestHeader.fillNodeData = fillNodeData;
requestHeader.changeDataType = changeDataType;
- requestHeader.checkExecutedData = checkExecutedData;
+ requestHeader.prepareDataAndExecute = prepareDataAndExecute;
requestHeader.setJsonView = setJsonView;
requestHeader.setRequestUrl = setRequestUrl;
+ requestHeader.showParamsAdmin = showParamsAdmin;
+ requestHeader.saveRequestToCollection = saveRequestToCollection;
+
// watchers
/**
$scope.$on('YANGMAN_HEADER_INIT', function (event, args) {
init();
setRequestUrl(args.params.path);
+ setRequestMethod(args.params.method);
+ (args.cbk || angular.noop)();
+ });
+
+ $scope.$on('YANGMAN_FILL_NODE_FROM_REQ', function (event, args) {
+ setNodeDataFromRequestData(args.params.requestUrl, args.params.leftpanel);
+ (args.cbk || angular.noop)();
});
+ $scope.$on('YANGMAN_EXECUTE_WITH_DATA', executeWithData);
+
init();
+
+ function executeWithData(event, args) {
+ executeOperation(args.params.data ? angular.fromJson(args.params.data) : {}, args.cbk);
+ }
+
+ function setRequestMethod(method){
+ requestHeader.selectedOperation = method;
+ }
+
+ /**
+ * Show popup for parameters administration
+ * @param event
+ */
+ function showParamsAdmin(event) {
+ $mdDialog.show({
+ controller: ParamsAdminCtrl,
+ controllerAs: 'paramsAdmin',
+ templateUrl: $scope.globalViewPath + 'popup/parameters-admin.tpl.html',
+ parent: angular.element('#yangmanModule'),
+ targetEvent: event,
+ clickOutsideToClose: true,
+ locals: {
+ parametersList: $scope.parametersList,
+ },
+ });
+ }
+
/**
* Method for selecting correct json view by selected operation
*/
$scope.setJsonView(true, false);
}
- sendRequestData({}, 'RECEIVED');
+ // sendRequestData({}, 'RECEIVED');
}
/**
- * Method for executing after data type was change (radio button)
+ * Change displayed data type to json or form, after switching set current data to be displayed
*/
function changeDataType(){
$scope.switchSection('rightPanelSection', requestHeader.selectedShownDataType);
requestHeader.setRequestUrl();
+ // if changing to json, fill codemirror data
if ( requestHeader.selectedShownDataType === 'req-data' && $scope.node ){
setJsonView();
sendRequestData($scope.buildRootRequest(), 'SENT');
}
+
+ // if changing to form, try to fill node data
+ if (requestHeader.selectedShownDataType === 'form') {
+ var params = {
+ reqData: null,
+ },
+ reqData = {},
+ dataType = requestHeader.selectedOperation === 'GET' ? 'RECEIVED' : 'SENT';
+
+
+ $scope.rootBroadcast('YANGMAN_GET_CODEMIRROR_DATA_' + dataType, params);
+ reqData = params.reqData ? angular.fromJson(params.reqData) : {};
+ setNodeDataFromRequestData(requestHeader.requestUrl);
+
+ if ( $scope.node ) {
+ YangmanService.fillNodeFromResponse($scope.node, reqData);
+ $scope.node.expanded = true;
+ }
+ }
}
/**
- * Method for sending data to code mirror
+ * Send data to codemirror
* @param data
*/
function sendRequestData(data, type){
$scope.rootBroadcast('YANGMAN_SET_CODEMIRROR_DATA_' + type, { data: JSON.stringify(data, null, 4) });
}
+ /**
+ * Create empty parameters list, load from local storage and set to $scope
+ */
+ function initParams(){
+ var paramsList = ParametersService.createEmptyParametersList('yangman_parameters');
+ paramsList.loadListFromStorage();
+ $scope.setParametersList(paramsList);
+ }
+
/**
* Initialization
*/
function init(){
setAllowedMethods(requestHeader.allOperations);
+ initParams();
requestHeader.selectedShownDataType = $scope.rightPanelSection;
}
*/
function setAllowedMethods(operations){
requestHeader.selectedOperationsList = operations.length ? operations : requestHeader.allOperations;
- requestHeader.selectedOperation = requestHeader.selectedOperationsList[0];
+ if (operations.indexOf(requestHeader.selectedOperation) === -1){
+ requestHeader.selectedOperation = requestHeader.selectedOperationsList[0];
+ }
}
/**
ENV.getBaseURL('MD_SAL') + '/restconf/' + $scope.selectedSubApi.buildApiRequestString() : '');
}
+
+ /**
+ * Try to set api, module, dataStore and node, if api indexes for request url available
+ * and set (or unset) module detail panel to be displayed
+ * @param requestUrl url to try to find
+ * @param leftpanel index of main left tabs to be displayed (we dont want to display module detail in all cases)
+ */
+ function setNodeDataFromRequestData(requestUrl, leftpanel){
+
+ $scope.rootBroadcast('YANGMAN_GET_API_TREE_DATA', null, function (treeApis) {
+ var apisIndexes =
+ PathUtilsService.searchNodeByPath(requestUrl, treeApis, null, true);
+
+ if ( apisIndexes ){
+ // set apis
+ $scope.setApi(
+ $scope.apis[apisIndexes.indexApi],
+ $scope.apis[apisIndexes.indexApi].subApis[apisIndexes.indexSubApi]
+ );
+
+ // set module
+ $scope.setModule($filter('filter')(treeApis, { label: $scope.selectedApi.module })[0]);
+
+ // set datastore
+ $scope.setDataStore(
+ $filter('filter')(
+ $scope.selectedModule.children,
+ { label: $scope.selectedSubApi.storage })[0],
+ true,
+ leftpanel
+ );
+
+ // set node
+ $scope.setNode($scope.selectedSubApi.node);
+
+ }
+ });
+ }
+
+ function saveRequestToCollection(event) {
+ var historyReq = RequestService.createHistoryRequest(null, null, requestHeader.requestUrl,
+ requestHeader.selectedOperation, '', '', ''),
+ reqData = {};
+
+ if ( requestHeader.selectedShownDataType === 'req-data' ) {
+ var params = { reqData: null };
+ $scope.rootBroadcast('YANGMAN_GET_CODEMIRROR_DATA_SENT', params);
+ reqData = params.reqData ? angular.fromJson(params.reqData) : {};
+ }
+
+ var historyReqData = YangmanService.prepareAllRequestData(
+ $scope.selectedApi,
+ $scope.selectedSubApi,
+ requestHeader.selectedOperation,
+ $scope.node,
+ requestHeader.selectedShownDataType,
+ requestHeader.requestUrl,
+ reqData,
+ $scope.parametersList
+ );
+
+ historyReq.setExecutionData(historyReqData.reqData, {}, '');
+
+ $scope.rootBroadcast('YANGMAN_SAVE_REQUEST_TO_COLLECTION', { event: event, reqObj: historyReq });
+ }
+
+
/**
* Execute request operation
*/
- function executeOperation(requestData){
+ function executeOperation(requestData, executeCbk){
+
+ var historyReq = RequestService.createHistoryRequest(null, null, requestHeader.requestUrl,
+ requestHeader.selectedOperation, '', '', '');
YangmanService.executeRequestOperation(
$scope.selectedApi,
requestHeader.selectedShownDataType,
requestHeader.requestUrl,
requestData,
- function (reqInfo, response) {
- requestHeader.statusObj = reqInfo;
-
- console.log('response.data', response.data);
-
- if (response.data) {
-
- if ( requestHeader.selectedShownDataType === 'req-data' ) {
-
- // try to fill code mirror editor
- sendRequestData(response.data.plain(), 'RECEIVED');
-
- // try to find api, subapi and node
- $scope.rootBroadcast('YANGMAN_GET_API_TREE_DATA', null, function (treeApis) {
- var apisIndexes =
- PathUtilsService.searchNodeByPath(requestHeader.requestUrl, treeApis, null, true);
-
- if ( apisIndexes ){
- // set apis
- $scope.setApi(
- $scope.apis[apisIndexes.indexApi],
- $scope.apis[apisIndexes.indexApi].subApis[apisIndexes.indexSubApi]
- );
-
- // set module
- $scope.setModule($filter('filter')(treeApis, { label: $scope.selectedApi.module })[0]);
-
- // set datastore
- $scope.setDataStore(
- $filter('filter')(
- $scope.selectedModule.children,
- { label: $scope.selectedSubApi.storage })[0],
- true,
- 1
- );
-
- // set node
- $scope.setNode($scope.selectedSubApi.node);
-
- if ( $scope.node ) {
- // try to fill node
- YangmanService.fillNodeFromResponse($scope.node, response.data);
- $scope.node.expanded = true;
- }
- }
- });
- } else {
-
- if ( $scope.node ) {
- // try to fill node
- YangmanService.fillNodeFromResponse($scope.node, response.data);
- $scope.node.expanded = true;
- }
- }
-
-
- } else {
- sendRequestData({}, 'RECEIVED');
+ $scope.parametersList,
+ executeReqSuccCbk,
+ executeReqErrCbk
+ );
+
+ /**
+ *
+ * @param reqInfo
+ * @param response
+ */
+ function executeReqSuccCbk(reqInfo, response) {
+ requestHeader.statusObj = reqInfo;
+
+ // create and set history request
+ historyReq.setExecutionData(
+ reqInfo.requestData,
+ response.data ? response.data.plain() : {},
+ reqInfo.status
+ );
+
+ if (response.data) {
+
+ // if executing from json form, try to find api, subapi and node
+ if ( requestHeader.selectedShownDataType === 'req-data' ) {
+ setNodeDataFromRequestData(requestHeader.requestUrl);
}
- }, function (reqInfo, response) {
- requestHeader.statusObj = reqInfo;
-
- if (response.data) {
- if ( requestHeader.selectedShownDataType === 'req-data' ) {
- // try to fill code mirror editor
- sendRequestData(response.data, 'RECEIVED');
- }
+
+ // try to fill code mirror editor
+ sendRequestData(response.data.plain(), 'RECEIVED');
+
+ // try to fill node, if some was found or filled in form
+ if ( $scope.node ) {
+ YangmanService.fillNodeFromResponse($scope.node, response.data);
+ $scope.node.expanded = true;
+ }
+
+ } else {
+ sendRequestData({}, 'RECEIVED');
+ }
+
+ $scope.rootBroadcast('YANGMAN_SAVE_EXECUTED_REQUEST', historyReq);
+ (executeCbk || angular.noop)(historyReq);
+
+ }
+
+ /**
+ *
+ * @param reqInfo
+ * @param response
+ */
+ function executeReqErrCbk(reqInfo, response) {
+
+ requestHeader.statusObj = reqInfo;
+
+ historyReq.setExecutionData(reqInfo.requestData, null, reqInfo.status);
+ $scope.rootBroadcast('YANGMAN_SAVE_EXECUTED_REQUEST', historyReq);
+
+ if (response.data) {
+ if ( requestHeader.selectedShownDataType === 'req-data' ) {
+ // try to fill code mirror editor
+ sendRequestData(response.data, 'RECEIVED');
}
- });
+ }
+ (executeCbk || angular.noop)(historyReq);
+ }
+
}
- // TODO :: description
+ /**
+ * TODO :: description
+ * @param pathElem
+ * @param identifier
+ */
function fillNodeData(pathElem, identifier) {
if ($scope.selectedSubApi && $scope.selectedSubApi.storage === 'config' &&
$scope.selectedSubApi.pathArray.indexOf(pathElem) === ($scope.selectedSubApi.pathArray.length - 1)) {
/**
* Check data before executin operations
*/
- function checkExecutedData(){
+ function prepareDataAndExecute(){
if ( requestHeader.requestUrl.length ) {
- var params = {
- reqData: null,
- };
if ( requestHeader.selectedShownDataType === 'req-data' ) {
// get json data
+ var params = { reqData: null };
$scope.rootBroadcast('YANGMAN_GET_CODEMIRROR_DATA_SENT', params);
- executeOperation(angular.fromJson(params.reqData));
+ executeOperation(params.reqData ? angular.fromJson(params.reqData) : {});
} else {
executeOperation({});
}
angular.module('app.yangman').controller('RequestsListCtrl', RequestsListCtrl);
RequestsListCtrl.$inject = [
- '$filter', '$mdDialog', '$scope', 'HandleFileService', 'PathUtilsService', 'RequestsService',
+ '$filter', '$mdDialog', '$scope', 'HandleFileService', 'PathUtilsService', 'RequestsService', 'YangmanService',
];
- function RequestsListCtrl($filter, $mdDialog, $scope, HandleFileService, PathUtilsService, RequestsService) {
+ function RequestsListCtrl($filter, $mdDialog, $scope, HandleFileService, PathUtilsService, RequestsService,
+ YangmanService) {
var vm = this;
- vm.collectionList = RequestsService.createEmptyCollectionList('yangman_collectionsList', vm.getApiCallback);
+ vm.collectionList = RequestsService.createEmptyCollectionList('yangman_collectionsList');
+ vm.collectionsSortAsc = true;
vm.mainList = null;
- vm.requestList = RequestsService.createEmptyHistoryList('yangman_requestsList', vm.getApiCallback);
+ vm.requestList = RequestsService.createEmptyHistoryList('yangman_requestsList');
vm.search = '';
- vm.collectionsSortAsc = true;
vm.clearFilter = clearFilter;
- vm.filterReq = filterReq;
- vm.filterCol = filterCol;
- vm.filterColName = filterColName;
+ vm.clearHistoryList = clearHistoryList;
vm.colMatchingReqsCount = colMatchingReqsCount;
vm.downloadCollection = downloadCollection;
+ vm.executeRequest = executeRequest;
vm.fakeFilter = fakeFilter;
- vm.getApiCallback = getApiCallback;
+ vm.filterCol = filterCol;
+ vm.filterColName = filterColName;
+ vm.filterReq = filterReq;
+ vm.init = init;
vm.loadRequests = loadRequests;
- vm.toggleCollectionsSort = toggleCollectionsSort;
+ vm.readCollectionFromFile = readCollectionFromFile;
vm.selectRequest = selectRequest;
-
+ vm.showData = showData;
vm.showDgDeleteCollection = showDgDeleteCollection;
vm.showDgDeleteRequests = showDgDeleteRequests;
vm.showDgEditCollection = showDgEditCollection;
- vm.readCollectionFromFile = readCollectionFromFile;
vm.showDgSaveReq = showDgSaveReq;
+ vm.toggleCollectionsSort = toggleCollectionsSort;
+ vm.showForm = showForm;
- vm.showData = showData;
- vm.useAsMainList = useAsMainList;
-
- $scope.$on('YANGMAN_REFRESH_HISTORY', loadHistoryRequests);
$scope.$on('YANGMAN_REFRESH_COLLECTIONS', loadCollectionRequest);
+ $scope.$on('YANGMAN_REFRESH_HISTORY', loadHistoryRequests);
loadRequests();
+ /**
+ * Save request obje to collection from other controller
+ * @param reqObj
+ */
+ function saveRequestFromExt(event, args) {
+ vm.showDgSaveReq(args.params.event, args.params.reqObj, false);
+ }
+
+
+ /**
+ * Clear history requests list and save to storage
+ */
+ function clearHistoryList() {
+ vm.requestList.clear();
+ vm.requestList.saveToStorage();
+ }
+
+ /**
+ * Create history request from other ctrl
+ * @param broadcastEvent
+ * @param params
+ */
+ function saveBcstedHistoryRequest(broadcastEvent, params) {
+ vm.requestList.addRequestToList(params.params);
+ vm.requestList.groupListByDate();
+ vm.requestList.saveToStorage();
+ loadHistoryRequests();
+ }
+
/**
* Clear value of input file used to import collection
*/
*/
function readCollectionFromFile($fileContent) {
var data = $fileContent,
- checkArray = ['sentData',
+ checkArray = [
+ 'sentData',
'receivedData',
'path',
'collection',
);
}
+ /**
+ * Fill request form in right panel with request data
+ * @param reqObj
+ */
+ function showForm(reqObj) {
+ var data = reqObj.method === 'GET' ? reqObj.receivedData : reqObj.sentData;
+
+ $scope.rootBroadcast('YANGMAN_FILL_NODE_FROM_REQ', { requestUrl: reqObj.path, requestData: data },
+ function (){
+ $scope.setRightPanelSection('form');
+ $scope.rootBroadcast('YANGMAN_HEADER_INIT', { path: reqObj.path, method: reqObj.method });
+
+ if ( $scope.node ) {
+ // try to fill node
+ YangmanService.fillNodeFromResponse($scope.node, data);
+ $scope.node.expanded = true;
+ }
+
+ }
+ );
+
+ }
+
+ /**
+ * Force request header to execute request with data from reqObj
+ * @param reqObj
+ */
+ function executeRequest(reqObj) {
+ $scope.rootBroadcast(
+ 'YANGMAN_HEADER_INIT',
+ { path: reqObj.path, method: reqObj.method },
+ function (){
+ $scope.rootBroadcast(
+ 'YANGMAN_EXECUTE_WITH_DATA',
+ { data: reqObj.sentData },
+ function (historyReq){
+ showData(historyReq);
+ }
+ );
+ }
+ );
+
+ }
+
/**
- * Show current reqObj sent data in right panel section
+ * Show current reqObj json data in right panel section
* @param reqObj
* @param dataType
*/
- function showData(reqObj, dataType) {
- $scope.setRequestToShow(reqObj, dataType);
+ function showData(reqObj) {
+
$scope.setRightPanelSection('req-data');
- $scope.broadcastFromRoot('YANGMAN_REFRESH_CM_DATA');
- $scope.rootBroadcast('YANGMAN_HEADER_INIT', { path: $scope.requestToShow.path });
+ $scope.setJsonView(true, reqObj.method !== 'GET');
+
+ $scope.rootBroadcast('YANGMAN_HEADER_INIT', { path: reqObj.path, method: reqObj.method });
+
+ $scope.rootBroadcast(
+ 'YANGMAN_SET_CODEMIRROR_DATA_SENT',
+ { data: reqObj.setDataForView(reqObj.sentData) }
+ );
+ $scope.rootBroadcast(
+ 'YANGMAN_SET_CODEMIRROR_DATA_RECEIVED',
+ { data: reqObj.setDataForView(reqObj.receivedData) }
+ );
+
+ var data = reqObj.method === 'GET' ? reqObj.receivedData : reqObj.sentData;
+
+ $scope.rootBroadcast('YANGMAN_FILL_NODE_FROM_REQ', { requestUrl: reqObj.path, leftpanel: 0},
+ function (){
+ if ( $scope.node ) {
+ // try to fill node
+ YangmanService.fillNodeFromResponse($scope.node, data);
+ $scope.node.expanded = true;
+ }
+
+ }
+ );
}
/**
});
}
vm.mainList.saveToStorage();
- loadRequests();
+ $scope.rootBroadcast('YANGMAN_REFRESH_HISTORY');
});
}
*
* @param list collectionList or requestList object
*/
- function useAsMainList(list){
+ function init(list){
vm.mainList = list;
+
+ if (list === vm.requestList){
+ // saving from request header after execution
+ $scope.$on('YANGMAN_SAVE_EXECUTED_REQUEST', saveBcstedHistoryRequest);
+ // saving from request header
+ $scope.$on('YANGMAN_SAVE_REQUEST_TO_COLLECTION', saveRequestFromExt);
+ }
+
}
/**
$scope.setHistoryReqsSelected(vm.requestList.selectedRequests.length > 0);
}
- /**
- *
- * @param pathString
- * @returns {*}
- */
- function getApiCallback(pathString) {
- var snp = PathUtilsService.getStorageAndNormalizedPath(pathString),
- // if the path is for mountpoint then get the path to treedata structure
- mpSearchPath = MountPointsConnectorService.alterMpPath(pathString),
- apiIndexes = PathUtilsService.searchNodeByPath(mpSearchPath, $scope.treeApis, $scope.treeRows),
- selApi = apiIndexes ? $scope.apis[apiIndexes.indexApi] : null,
- selSubApi = selApi ? selApi.subApis[apiIndexes.indexSubApi] : null,
- copiedApi = selSubApi ?
- selSubApi.clone({ storage: snp.storage, withoutNode: true, clonePathArray: true }) :
- null;
-
- if (copiedApi) {
- copiedApi.pathArray.forEach(function (p) {
- p.hover = false;
- });
-
- PathUtilsService.fillPath(copiedApi.pathArray, snp.normalizedPath);
- }
-
- var searchedModule = PathUtilsService.getModuleNameFromPath(pathString);
-
- if (mpSearchPath.indexOf(mountPrefix) !== -1 && copiedApi){
- copiedApi = $scope.selSubApi &&
- searchedModule === $scope.selSubApi.pathArray[1].module ?
- copiedApi :
- null;
- }
-
- return copiedApi;
- }
}
});
define([
- 'app/yangman/controllers/params-admin.controller',
'app/yangman/yangman.filters',
'app/yangman/controllers/modules-list.controller',
'app/yangman/controllers/module-detail.controller',
'app/yangman/services/requests.services',
'app/yangman/services/parameters.services',
'app/yangman/directives/ui-codemirror.directive',
-], function (ParamsAdminCtrl) {
+], function () {
'use strict';
angular.module('app.yangman').controller('YangmanCtrl', YangmanCtrl);
YangmanCtrl.$inject = [
- '$mdDialog', '$scope', '$rootScope', 'YangmanDesignService', 'ParametersService', 'RequestBuilderService',
+ '$mdDialog', '$scope', '$rootScope', 'YangmanDesignService', 'RequestBuilderService',
'EventDispatcherService', 'constants', 'PathUtilsService',
];
function YangmanCtrl(
- $mdDialog, $scope, $rootScope, YangmanDesignService, ParametersService, RequestBuilderService,
+ $mdDialog, $scope, $rootScope, YangmanDesignService, RequestBuilderService,
EventDispatcherService, constants, PathUtilsService
) {
var main = this;
$scope.setRequestToShow = setRequestToShow;
$scope.setRightPanelSection = setRightPanelSection;
$scope.switchSection = switchSection;
- $scope.showParamsAdmin = showParamsAdmin;
+ $scope.setParametersList = setParametersList;
init();
-
-
/**
- * Show popup for parameters administration
- * @param event
+ * Set parametersList
+ * @param parametersList
*/
- function showParamsAdmin(event) {
- $mdDialog.show({
- controller: ParamsAdminCtrl,
- controllerAs: 'paramsAdmin',
- templateUrl: $scope.globalViewPath + 'popup/parameters-admin.tpl.html',
- parent: angular.element('#yangmanModule'),
- targetEvent: event,
- clickOutsideToClose: true,
- locals: {
- parametersList: $scope.parametersList,
- },
- });
+ function setParametersList(parametersList) {
+ $scope.parametersList = parametersList;
}
/**
*/
function init(){
YangmanDesignService.hideMainMenu();
- $scope.parametersList = ParametersService.createEmptyParametersList('yangman_parameters');
- $scope.parametersList.loadListFromStorage();
EventDispatcherService.registerHandler(constants.EV_FILL_PATH, fillPathIdentifiersByKey);
EventDispatcherService.registerHandler(constants.EV_LIST_CHANGED, fillPathIdentifiersByListData);
/**
* Switcher between modules list and module detail
*/
- function toggleLeftPanel(value){
- main.leftPanelTab = value || (main.leftPanelTab + 1) % 2;
+ function toggleLeftPanel(){
+ main.leftPanelTab = (main.leftPanelTab + 1) % 2;
+ }
+
+ function setLeftPanel(value) {
+ if ( !angular.isUndefined(value) ) {
+ main.leftPanelTab = value;
+ }
}
// TODO :: description
if ( expand ) {
$scope.node = null;
- toggleLeftPanel(leftPanel);
+ // toggleLeftPanel(leftPanel);
+ setLeftPanel(leftPanel);
$scope.$broadcast('YANGMAN_MODULE_D_INIT');
} else {
$scope.rightPanelSection = section;
}
+ /**
+ * Which codemirror instances will be displayed
+ * @param received
+ * @param sent
+ */
function setJsonView(received, sent){
main.jsonView.received = received;
main.jsonView.sent = sent;
require.config({
-
+ paths: {
+ 'codeMirror-yangmanJsonHint': 'app/yangman/assets/js/codemirror/addon/hint/yangman-json-hint',
+ },
});
define(['app/yangman/yangman.module']);
var self = this;
self.collections = [];
- self.getApiFunction = null;
self.selectedRequests = [];
self.addRequestToList = addRequestToList;
self.getCollection = getCollection;
self.getCollectionNames = getCollectionNames;
self.loadListFromFile = loadListFromFile;
- self.refresh = refresh;
self.renameCollection = renameCollection;
self.toggleReqSelection = toggleReqSelection;
self.toJSON = toJSON;
self.getCollectionInJSON = getCollectionInJSON;
- self.setGetApiFunction = setGetApiFunction;
/**
- * Setter for getApiFunction
- * @param getApiFunction
+ *
+ * @param collectionName
*/
- function setGetApiFunction(getApiFunction){
- self.getApiFunction = getApiFunction;
- }
-
function getCollectionInJSON(collectionName){
return JSON.stringify(self.toJSON(collectionName));
}
req.selected = reqObj === req;
});
});
-
}
/**
* @returns {HistoryRequest|*}
*/
function createEntry(elem) {
- return RequestsService.createHistoryRequestFromElement(elem, self.getApiFunction);
+ return RequestsService.createHistoryRequestFromElement(elem);
}
/**
}
}
- /**
- * Refresh each requst in collections using his getApiFunction
- */
- function refresh() {
- self.collections.forEach(function (collection) {
- collection.data.forEach(function (elem) {
- elem.refresh(self.getApiFunction);
- });
- });
- }
/**
*
if (data){
ParsingJsonService.parseJson(data).map(function (elem) {
return RequestsService.createHistoryRequest(elem.sentData, elem.receivedData, elem.path,
- elem.parametrizedPath, elem.method, elem.status, elem.name, elem.collection,
- self.getApiFunction);
+ elem.parametrizedPath, elem.method, elem.status, elem.name, elem.collection);
}).forEach(function (elem) {
self.addRequestToList(elem);
});
var self = this;
// properties
+ self.collection = '';
+ self.method = '';
self.name = '';
- self.sentData = null;
self.path = '';
- self.parametrizedPath = null;
- self.method = '';
- self.status = '';
self.receivedData = null;
- self.api = null;
- self.availability = false;
- self.collection = '';
- self.timestamp = '';
self.selected = false;
+ self.sentData = null;
+ self.status = '';
+ self.timestamp = '';
// functions
- self.getIdentifiers = getIdentifiers;
- self.refresh = refresh;
self.clone = clone;
self.toJSON = toJSON;
- self.clonePathArray = clonePathArray;
- self.setParametrizedPath = setParametrizedPath;
self.getLastPathDataElemName = getLastPathDataElemName;
self.setDataForView = setDataForView;
- self.clearParametrizedData = clearParametrizedData;
- self.copyWithParametrizationAsNatural = copyWithParametrizationAsNatural;
self.setData = setData;
+ self.setExecutionData = setExecutionData;
/**
* Grouped setter
* @param receivedData
* @param status
* @param path
- * @param parametrizedPath
* @param operation
- * @param api
* @param name
* @param collection
* @param timestamp
*/
- function setData(sentData, receivedData, status, path, parametrizedPath, operation, api, name, collection,
- timestamp) {
+ function setData(sentData, receivedData, status, path, operation, name, collection, timestamp) {
self.sentData = sentData === null || sentData === undefined || $.isEmptyObject(sentData) ? null : sentData;
self.name = name;
self.path = path;
- self.parametrizedPath = parametrizedPath;
self.method = operation;
self.status = status;
self.receivedData = receivedData === null || receivedData === undefined || $.isEmptyObject(receivedData) ?
- null :
- receivedData;
- self.api = api;
- self.availability = (api !== null);
+ null : receivedData;
self.collection = collection;
self.timestamp = timestamp;
}
/**
- *
- * @returns {Array}
+ * Set data which might be available after executing request
+ * @param sentData
+ * @param receivedData
+ * @param status - http status from response header
*/
- function getIdentifiers() {
- var identifiers = [];
-
- self.api.pathArray.forEach(function (elem) {
- elem.identifiers.forEach(function (i) {
- identifiers.push(i);
- });
- });
-
- return identifiers;
+ function setExecutionData(sentData, receivedData, status) {
+ self.sentData = sentData;
+ self.receivedData = receivedData;
+ self.status = status ? (status > 199 && status < 205 ? 'success' : 'erorr') : '';
}
- /**
- * Refresh each element using getApiFunction
- * @param getApiFunction
- */
- function refresh(getApiFunction) {
- var refreshedApi = getApiFunction(self.path);
-
- self.api = refreshedApi;
- self.availability = (refreshedApi !== null);
- }
/**
*
- * @returns {{
- * sentData: *,
- * receivedData: *,
- * path: *,
- * collection: *,
- * parametrizedPath: *,
- * method: *,
- * status: *,
- * name: *,
- * timestamp: *
- * }}
+ * @returns {{sentData: (null|*), receivedData: (null|*), path: (string|*), collection: (string|*),
+ * method: (string|*), status: (string|*), name: (string|*), timestamp: (string|*)}}
*/
function toJSON() {
var obj = {
receivedData: self.receivedData,
path: self.path,
collection: self.collection,
- parametrizedPath: self.parametrizedPath,
method: self.method,
status: self.status,
name: self.name,
return obj;
}
- /**
- *
- */
- function clonePathArray() {
- if ( self.api && self.api.pathArray ) {
- self.api.clonedPathArray = self.api.pathArray.map(function (pe) {
- return pe.clone();
- });
- } else {
- self.api.clonedPathArray = [];
- }
- }
- function setParametrizedPath(){
- self.clonePathArray();
- PathUtilsService.fillPath(self.api.clonedPathArray, self.parametrizedPath);
- }
/**
*
* @param data
* @returns {string}
*/
- function setDataForView(sent, data){
+ function setDataForView(data){
var newData = {},
parsedData = '';
parsedData = JSON.stringify(
YangUtilsService.stripAngularGarbage(newData, self.getLastPathDataElemName()), null, 4);
- if ( sent && self.api ) {
- if ( self.parametrizedPath ) {
- self.setParametrizedPath();
- } else {
- self.clonePathArray();
- }
- }
-
return parsedData;
}
- function clearParametrizedData() {
- self.parametrizedPath = null;
- self.clonePathArray();
- }
/**
*
*/
function clone() {
var result = new HistoryRequestModel(PathUtilsService, YangUtilsService, ParsingJsonService);
- result.setData(self.sentData, self.receivedData, self.status, self.path,
- self.parametrizedPath, self.method, self.api, self.name, self.collection, self.timestamp);
- return result;
- }
-
- /**
- *
- * @param parametrizedPath
- * @param getApiFunction
- * @param dataForView
- * @param JSONparsingErrorClbk
- * @returns {*}
- */
- function copyWithParametrizationAsNatural(parametrizedPath, getApiFunction, dataForView,
- JSONparsingErrorClbk){
-
- var parsedJsonObj = null,
- result = null;
-
- parsedJsonObj = ParsingJsonService.parseJson(dataForView, JSONparsingErrorClbk);
-
- if (parsedJsonObj){
- result = new HistoryRequestModel(PathUtilsService, YangUtilsService, ParsingJsonService);
- result.setData(parsedJsonObj, self.receivedData, self.status, parametrizedPath, '', self.method,
- (getApiFunction || angular.noop)(result.path), self.name, self.collection, self.timestamp);
- }
-
+ result.setData(self.sentData, self.receivedData, self.status, self.path, self.method, self.name,
+ self.collection, self.timestamp);
return result;
}
/* jshint validthis: true */
var self = this;
self.list = [];
- self.listGroupedByDate = {};
+ self.dateGroups = [];
self.selectedRequests = [];
self.addRequestToList = addRequestToList;
self.clear = clear;
self.createEntry = createEntry;
self.deleteRequestItem = deleteRequestItem;
- self.getApiFunction = null;
self.groupListByDate = groupListByDate;
- self.refresh = refresh;
self.toggleReqSelection = toggleReqSelection;
- self.setGetApiFunction = setGetApiFunction;
-
- /**
- * Setter for getApiFunction
- * @param getApiFunction
- */
- function setGetApiFunction(getApiFunction){
- self.getApiFunction = getApiFunction;
- }
-
/**
* Mark reqObj as selected
}
+ /**
+ * Round timestamp to day
+ * @param timeStamp
+ * @returns {number|*}
+ */
+ function roundTimestampToDate(timeStamp){
+ timeStamp -= timeStamp % (24 * 60 * 60 * 1000);//subtract amount of time since midnight
+ timeStamp += new Date().getTimezoneOffset() * 60 * 1000;//add on the timezone offset
+ return timeStamp;
+ }
+
/**
* Grouping by date to show date groups in yangman
*/
self.list.forEach(addToListDateGroup);
function addToListDateGroup(elem){
- var groupName = new Date(elem.timestamp).toDateString();
- if (!self.listGroupedByDate.hasOwnProperty(groupName)){
- self.listGroupedByDate[groupName] = [];
+ var groupName = roundTimestampToDate(elem.timestamp),
+ dateGroupArr = self.dateGroups.filter(function(group){
+ return group.name === groupName;
+ }),
+ dateGroup = null;
+
+ if (dateGroupArr.length){
+ dateGroup = dateGroupArr[0];
+ }
+ else {
+ dateGroup = {
+ name: groupName,
+ longName: new Date(groupName).toDateString(),
+ requests: [],
+ };
+ self.dateGroups.push(dateGroup);
}
- self.listGroupedByDate[groupName].push(elem);
+ dateGroup.requests.push(elem);
}
}
* @returns {HistoryRequest|*}
*/
function createEntry(elem) {
- return RequestsService.createHistoryRequestFromElement(elem, self.getApiFunction);
+ return RequestsService.createHistoryRequestFromElement(elem);
}
/**
self.list.push(reqObj);
}
- /**
- * Refresh each element using self.detApiFunction
- */
- function refresh() {
- self.list.forEach(function (elem) {
- elem.refresh(self.getApiFunction);
- });
- }
-
/**
*
* @param elem
function clear() {
self.list = [];
- self.listGroupedByDate = {};
+ self.dateGroups = [];
self.selectedRequests = [];
}
angular.module('app.yangman').service('RequestsService', RequestsService);
- RequestsService.$inject = ['PathUtilsService', 'ParsingJsonService', 'YangUtilsService'];
+ RequestsService.$inject = ['PathUtilsService', 'ParametersService', 'ParsingJsonService', 'YangUtilsService'];
- function RequestsService(PathUtilsService, ParsingJsonService, YangUtilsService){
+ function RequestsService(PathUtilsService, ParametersService, ParsingJsonService, YangUtilsService){
var service = {};
+ service.applyParams = applyParams;
service.createEmptyCollectionList = createEmptyCollectionList;
service.createEmptyHistoryList = createEmptyHistoryList;
service.createHistoryRequestFromElement = createHistoryRequestFromElement;
service.createHistoryRequest = createHistoryRequest;
+ service.scanDataParams = scanDataParams;
service.validateFile = validateFile;
+ service.replaceStringInText = replaceStringInText;
+
+ /**
+ * Scan used parameters in current line of codemirror
+ * @param {ParametersListModel} paramsObj - list of parameters to be searched for
+ * @param {string} lineString - line from current codemirror to be inspected
+ * @returns array of {ParameterModel}
+ */
+ function scanDataParams(paramsObj, lineString) {
+
+ var usedParamLabelArray = [];
+
+ var params = lineString ? lineString.match(/<<(?!<<)[a-zA-Z0-9]+>>/g) : null;
+
+ if ( params ) {
+ params
+ .filter(onlyUnique)
+ .forEach(function (param) {
+ usedParamLabelArray.push(removeUnwantedChars(param));
+ });
+ }
+
+ var returnedParamsList = paramsObj.list.filter( function (param){
+ var paramIndex = usedParamLabelArray.indexOf(param.key);
+ if ( paramIndex !== -1 ) {
+ return usedParamLabelArray.splice(paramIndex, 1);
+ }
+ else {
+ return false;
+ }
+ });
+
+ usedParamLabelArray.forEach(function (param){
+ returnedParamsList.push(ParametersService.createParameter(param));
+ });
+
+ return returnedParamsList;
+
+ /**
+ * remove chars greater then and less then from parameter definition
+ * @param val
+ * @returns {string}
+ */
+ function removeUnwantedChars(val){
+ var string = val.substring(2);
+ return string.substring(0, string.indexOf('>>'));
+ }
+
+ /**
+ * Filter function
+ * @param value
+ * @param index
+ * @param self
+ * @returns {boolean}
+ */
+ function onlyUnique(value, index, self) {
+ return self.indexOf(value) === index;
+ }
+ }
+
+ /**
+ * Replace all parameters with its values
+ * @param paramsObj
+ * @param requestData
+ * @returns {*}
+ */
+ function applyParams(paramsObj, data) {
+ var dataStr = JSON.stringify(data);
+
+ paramsObj.list.forEach(function (param){
+ dataStr = service.replaceStringInText(dataStr, '<<' + param.key + '>>', param.value);
+ });
+
+ return ParsingJsonService.parseJson(dataStr);
+ }
+
+ /**
+ * Service for replacing string in text
+ * @param text
+ * @param strToReplace
+ * @param newStr
+ * @returns {*}
+ */
+ function replaceStringInText(text, strToReplace, newStr) {
+ var replacedText = text;
+ if (text.indexOf(strToReplace) > -1) {
+ replacedText = text.split(strToReplace).join(newStr);
+ }
+ return replacedText;
+ }
+
/**
* Validating collection import file
* @param sentData
* @param receivedData
* @param path
- * @param parametrizedPath
* @param operation
* @param status
* @param name
* @param collection
- * @param getApiFunction
- * @returns {HistoryRequest}
+ * @returns {*}
+ * @param timestamp
*/
- function createHistoryRequest(sentData, receivedData, path, parametrizedPath, operation, status, name,
- collection, timestamp, getApiFunction){
+ function createHistoryRequest(sentData, receivedData, path, operation, status, name, collection) {
- var api = (getApiFunction || angular.noop)(path),
- receivedDataProcessed = status === 'success' ? receivedData : null,
+ var receivedDataProcessed = status === 'success' ? receivedData : null,
result = new HistoryRequestModel(PathUtilsService, YangUtilsService, ParsingJsonService);
- result.setData(sentData, receivedDataProcessed, status, path, parametrizedPath, operation, api, name,
- collection, timestamp);
+ result.setData(sentData, receivedDataProcessed, status, path, operation, name, collection, Date.now());
return result;
}
/**
* Creating {HistoryRequest} from elem containing all necessary data
* @param {Object} elem
- * @param {function} getApiFunction
- * @returns {HistoryRequest}
+ * @returns {*}
*/
- function createHistoryRequestFromElement(elem, getApiFunction) {
- return service.createHistoryRequest(elem.sentData, elem.receivedData,
- elem.path, elem.parametrizedPath,
- elem.method, elem.status, elem.name,
- elem.collection, elem.timestamp, getApiFunction);
+ function createHistoryRequestFromElement(elem) {
+ return service.createHistoryRequest(elem.sentData, elem.receivedData, elem.path, elem.method,
+ elem.status, elem.name, elem.collection, Date.now());
}
/**
* @param getApiFunction
* @returns {CollectionList}
*/
- function createEmptyCollectionList(name, getApiFunction){
+ function createEmptyCollectionList(name){
var result = new CollectionListModel(ParsingJsonService, service);
result.setName(name);
- result.setGetApiFunction(getApiFunction);
return result;
}
/**
* Service for creating empty history list
* @param name
- * @param getApiFunction
- * @returns {HistoryList}
+ * @returns {*}
*/
- function createEmptyHistoryList(name, getApiFunction){
+ function createEmptyHistoryList(name){
var result = new HistoryListModel(ParsingJsonService, service);
result.setName(name);
- result.setGetApiFunction(getApiFunction);
return result;
}
'YangUtilsService',
'YangUtilsRestangularService',
'ENV',
+ 'RequestsService',
];
function YangmanService(
RequestBuilderService,
YangUtilsService,
YangUtilsRestangularService,
- ENV
+ ENV,
+ RequestsService
){
var service = {
executeRequestOperation: executeRequestOperation,
fillNodeFromResponse: fillNodeFromResponse,
getDataStoreIndex: getDataStoreIndex,
+ prepareAllRequestData: prepareAllRequestData,
};
return service;
return result ? rIndex : null;
}
- function executeRequestOperation(
- selectedApi,
- selectedSubApi,
- operation,
- node,
- dataType,
- requestUrl,
- requestData,
- successCbk,
- errorCbk
- ){
- var reqString = selectedSubApi ? selectedSubApi.buildApiRequestString() : '',
- preparedRequestData = {},
- headers,
- time = {
- started: 0,
- finished: 0,
- },
- customRestangular = null;
-
- // set full response detail
- YangUtilsRestangularService.setFullResponse(true);
+ /**
+ * Prepare all necessary data for executing or saving request
+ * @param selectedApi
+ * @param selectedSubApi
+ * @param operation
+ * @param node
+ * @param dataType
+ * @param requestUrl
+ * @param requestData
+ * @param params
+ * @returns {{customRestangular: null, headers: {}, operation: string, reqString: string, reqHeaders: {},
+ * reqData: {}}}
+ */
+ function prepareAllRequestData(selectedApi, selectedSubApi, operation, node, dataType, requestUrl, requestData,
+ params) {
+ var allPreparedData = {
+ customRestangular: null,
+ headers: {},
+ operation: '',
+ reqString: selectedSubApi ? selectedSubApi.buildApiRequestString() : '',
+ reqHeaders: {},
+ reqData: {},
+ };
// set correct host into restangular based on shown data type
if ( dataType === 'req-data' ){
raParam = '';
YangUtilsRestangularService.setBaseUrl(parser.origin);
- reqString = parser.pathname.slice(1).split('/');
- raParam = reqString.shift();
- reqString = reqString.join('/');
+ allPreparedData.reqString = parser.pathname.slice(1).split('/');
+ raParam = allPreparedData.reqString.shift();
+ allPreparedData.reqString = allPreparedData.reqString.join('/');
- customRestangular = YangUtilsRestangularService.one(raParam);
- preparedRequestData = requestData;
+ allPreparedData.customRestangular = YangUtilsRestangularService.one(raParam);
+ allPreparedData.reqData = RequestsService.applyParams(params, requestData);
} else {
YangUtilsRestangularService.setBaseUrl(ENV.getBaseURL('MD_SAL'));
- customRestangular = YangUtilsRestangularService.one('restconf');
+ allPreparedData.customRestangular = YangUtilsRestangularService.one('restconf');
- // if node build sent request
if ( node ) {
node.buildRequest(RequestBuilderService, requestData, node.module);
- angular.copy(requestData, preparedRequestData);
+ angular.copy(requestData, allPreparedData.reqData);
+ allPreparedData.reqData = RequestsService.applyParams(params, allPreparedData.reqData);
- preparedRequestData = YangUtilsService.prepareRequestData(
- preparedRequestData,
+ allPreparedData.reqData = YangUtilsService.prepareRequestData(
+ allPreparedData.reqData,
operation,
- reqString,
+ allPreparedData.reqString,
selectedSubApi
);
- headers = YangUtilsService.prepareHeaders(preparedRequestData);
+ allPreparedData.headers = YangUtilsService.prepareHeaders(allPreparedData.reqData);
}
}
- //reqString = reqPath ? reqPath.slice(selectedApi.basePath.length, reqPath.length) : reqString;
- //var requestPath = selectedApi.basePath + reqString;
+ allPreparedData.operation = YangUtilsService.prepareOperation(operation);
+ return allPreparedData;
+ }
+ /**
+ * Execute request built from this data
+ * @param selectedApi
+ * @param selectedSubApi
+ * @param operation
+ * @param node
+ * @param dataType
+ * @param requestUrl
+ * @param requestData
+ * @param successCbk
+ * @param errorCbk
+ * @param params
+ */
+ function executeRequestOperation(selectedApi, selectedSubApi, operation, node, dataType, requestUrl,
+ requestData, params, successCbk, errorCbk) {
+ var time = {
+ started: 0,
+ finished: 0,
+ };
+ YangUtilsRestangularService.setFullResponse(true);
- operation = YangUtilsService.prepareOperation(operation);
+ // prepare all necessary data
+ var allPreparedData = prepareAllRequestData(selectedApi, selectedSubApi, operation, node, dataType,
+ requestUrl, requestData, params);
// start track time response
time.started = new Date().getMilliseconds();
// executing operation
- customRestangular
- .customOperation(operation.toLowerCase(), reqString, null, headers, preparedRequestData)
- .then(function (response) {
- // finish track time response
- time.finished = new Date().getMilliseconds();
-
- var reqObj = {
- status: response.status,
- statusText: response.statusText,
- time: (time.finished - time.started),
- };
-
- (successCbk || angular.noop)(reqObj, response);
-
- }, function (response) {
- // finish track time response
- time.finished = new Date().getMilliseconds();
-
- var reqObj = {
- status: response.status,
- statusText: response.statusText,
- time: (time.finished - time.started),
- };
-
- (errorCbk || angular.noop)(reqObj, response);
-
- /*var errorMsg = '';
-
- if (resp.data && resp.data.errors && resp.data.errors.error && resp.data.errors.error.length) {
- errorMsg = ': ' + resp.data.errors.error.map(function (e) {
- return e['error-message'];
- }).join(', ');
- }
-
- /!**
- * TODO after first GET we have set $scope.node with data
- * so build from the top of this function return requestData
- *!/
- if (operation === 'GET'){
- requestData = {};
- }
-
- console.info(
- 'error sending request to', selectedSubApi ? selectedSubApi.buildApiRequestString() : '',
- 'reqString', reqString,
- 'got', resp.status,
- 'data', resp.data
- );*/
+ allPreparedData.customRestangular.customOperation(
+ allPreparedData.operation.toLowerCase(),
+ allPreparedData.reqString,
+ null,
+ allPreparedData.headers,
+ allPreparedData.reqData
+ )
+ .then(
+ function (response) {
+ (successCbk || angular.noop)(finishExecuting(response), response);
+ },
+ function (response) {
+ (errorCbk || angular.noop)(finishExecuting(response), response);
}
);
+
+ function finishExecuting(response){
+ // finish track time response
+ time.finished = new Date().getMilliseconds();
+
+ return {
+ status: response.status,
+ statusText: response.statusText,
+ time: (time.finished - time.started),
+ requestData: allPreparedData.reqData,
+ };
+ }
}
/**
* @param data
*/
function fillNodeFromResponse(node, data){
- var props = Object.getOwnPropertyNames(data);
+ var props = data ? Object.getOwnPropertyNames(data) : [];
// fill each property - needed for root mountpoint node,
// in other cases there should be only one property anyway
class="arrow-switcher"
ng-click="main.toggleLeftPanel()"
ng-class="{'arrow-switcher__left' : main.leftPanelTab === 0}"
- ng-show="!main.selectedMainTab && selectedDatastore"> play_arrow </md-icon>
+ ng-show="selectedDatastore"> play_arrow </md-icon>
+ <!--ng-show="!main.selectedMainTab && selectedDatastore"> play_arrow </md-icon>-->
<!-- content -->
<md-tabs md-border-bottom md-selected="main.leftPanelTab" class="yangmanModule__left-panel__detail-list-tabs-container">
<md-tab label="models tree">
<md-list class="yangmanModule__requests-list__collections-list"
ng-cloak
- ng-init="reqList.useAsMainList(reqList.collectionList)"
+ ng-init="reqList.init(reqList.collectionList)"
ng-controller="RequestsListCtrl as reqList">
<md-content class="searchBox" layout="row">
<md-list class="yangmanModule__requests-list h100"
ng-cloak
- ng-init="reqList.useAsMainList(reqList.requestList)"
+ ng-init="reqList.init(reqList.requestList)"
ng-controller="RequestsListCtrl as reqList">
+ <!-- search box -->
<md-content class="searchBox" layout="row">
<md-icon class="material-icons">search</md-icon>
<input class="ng-pristine ng-valid ng-touched"
</md-content>
<md-divider></md-divider>
+ <!-- /search box-->
+ <!-- buttons for saving, deleting, clearing -->
<md-button ng-show="reqList.mainList.selectedRequests.length"
ng-click="reqList.showDgSaveReq($event, main.currentPath)">
{{'YANGMAN_REQS_SAVE_TO_COL'| translate}}
ng-click="reqList.showDgDeleteRequests($event)">
{{'YANGMAN_REQS_DELETE'| translate}}
</md-button>
-
+ <md-button ng-hide="reqList.mainList.selectedRequests.length || !reqList.mainList.list.length"
+ ng-click="reqList.clearHistoryList()">
+ {{'YANGMAN_CLEAR_HISTORY' | translate}}
+ </md-button>
<md-divider ng-show="reqList.mainList.selectedRequests.length"></md-divider>
+ <!-- /buttons for saving, deleting, clearing -->
+ <!-- list of items grouped by date -->
<md-content class="scrollableY">
- <md-list-item ng-repeat="(groupName, requests) in reqList.mainList.listGroupedByDate"
+ <md-list-item ng-repeat="group in reqList.mainList.dateGroups | orderBy: 'name': true"
class="yangmanModule__requests-list__group"
- ng-if="(requests|filter:reqList.filterReq).length">
+ ng-if="(group.requests | filter:reqList.filterReq).length">
<div layout="column" flex>
+ <!-- date group header -->
<md-subheader class="md-no-sticky">
- {{groupName | date : 'short'}}
+ {{group.longName}}
</md-subheader>
+ <!-- /date group header -->
+ <!-- list of requests in current group -->
<md-list>
- <div ng-repeat="request in requests | filter: reqList.filterReq"
+ <div ng-repeat="request in group.requests | filter: reqList.filterReq track by $index | orderBy: 'timestamp'"
layout="row"
ng-include src="globalViewPath + 'leftpanel/request-item.tpl.html'">
</div>
</md-list>
+ <!-- /list of requests in current group -->
</div>
</md-list-item>
</md-content>
+ <!-- /list of items grouped by date -->
+
</md-list>
ng-class="{selected: request.selected}"
layout="row"
flex="100"
- ng-click="reqList.selectRequest($event, request)">
+ ng-click="reqList.selectRequest($event, request); reqList.showData(request);">
<div flex="15" class="yangmanModule__requests-list__group__item__method" layout-align="center center">
- <p class="{{request.method}}"> {{request.method}} </p>
- <md-tooltip md-direction="right">{{request}}</md-tooltip>
+ <p class="{{request.status === 'success' || !request.status ? request.method : 'error'}}"> {{request.method === 'DELETE' ? 'DEL' : request.method }} </p>
+ <md-tooltip md-direction="bottom" ng-show="request.status">{{request.status | uppercase }}</md-tooltip>
</div>
<div flex class="yangmanModule__requests-list__group__item__path" layout="column">
</md-button>
<md-menu-content class="reqMenu">
<md-menu-item>
- <md-button aria-label="{{'YANGMAN_REQ_RUN'| translate}}" class=" " ng-click="" ng-disabled="true">
+ <md-button aria-label="{{'YANGMAN_REQ_RUN'| translate}}" class="" ng-click="reqList.executeRequest(request)">
<i class="material-icons">play_arrow</i>
{{'YANGMAN_REQ_RUN'| translate}}
</md-button>
</md-menu-item>
<md-menu-item>
- <md-button aria-label="{{'YANGMAN_REQ_FILL_FORM'| translate}}" ng-disabled="true">
+ <md-button aria-label="{{'YANGMAN_REQ_SHOW_FORM'| translate}}" ng-click="reqList.showForm(request)">
<i class="material-icons">exit_to_app</i>
- {{'YANGMAN_REQ_FILL_FORM'| translate}}
+ {{'YANGMAN_REQ_SHOW_FORM'| translate}}
</md-button>
</md-menu-item>
<md-menu-item>
<md-button aria-label="{{'YANGMAN_REQ_SHOW_SENT_DATA'| translate}}"
- ng-click="reqList.showData(request, 'sentData')"
- ng-disabled="request.sentData===null">
+ ng-click="reqList.showData(request)">
<i class="material-icons">call_made</i>
- {{'YANGMAN_REQ_SHOW_SENT_DATA'| translate}}
- </md-button>
- </md-menu-item>
- <md-menu-item>
- <md-button aria-label="{{'YANGMAN_REQ_SHOW_RCVD_DATA'| translate}}"
- ng-click="reqList.showData(request, 'receivedData')"
- ng-disabled="request.receivedData===null">
- <i class="material-icons">call_received</i>
- {{'YANGMAN_REQ_SHOW_RCVD_DATA'| translate}}
+ {{'YANGMAN_REQ_SHOW_JSON_DATA'| translate}}
</md-button>
</md-menu-item>
<md-menu-item ng-if="request.collection.length">
<!-- Sent data -->
<div ng-controller="RequestDataCtrl as requestData"
- ng-if="main.jsonView.sent"
+ ng-show="main.jsonView.sent"
ng-init="requestData.init('SENT')"
ng-class="{'half-size': main.jsonView.received && main.jsonView.sent}">
<!-- Received data -->
<div ng-controller="RequestDataCtrl as requestData"
- ng-if="main.jsonView.received"
+ ng-show="main.jsonView.received"
ng-init="requestData.init('RECEIVED')"
ng-class="{'half-size': main.jsonView.received && main.jsonView.sent}">
-<div ng-model="requestData.data"
- ui-codemirror
- ui-codemirror-opts="requestData.getDataEditorOptions(false, 'eclipse')"
- class="codemirror-container">
+<textarea ng-model="requestData.data"
+ ui-codemirror
+ ui-codemirror-opts="requestData.dataEditorOptions"
+ class="codemirror-container">
+</textarea>
+
+<div class="paramsBox" ng-show="requestData.paramsArray.length">
+ <div ng-repeat="param in requestData.paramsArray" class="line">
+ <strong><<{{param.key}}>></strong> : <span>{{param.value !== undefined ? param.value : 'YANGUI_PARAM_DONT_REPLACE' | translate}}</span>
+ </div>
</div>
<!-- Action buttons -->
<md-input-container flex="nogrow" layout="row" layout-align="start start" class="action-buttons">
- <md-button class="md-raised md-primary" ng-click="requestHeader.checkExecutedData()">{{'YANGMAN_SEND' | translate}}</md-button>
- <md-button class="md-raised md-warn">{{'YANGMAN_SAVE' | translate}}</md-button>
+ <md-button class="md-raised md-primary" ng-click="requestHeader.prepareDataAndExecute()">{{'YANGMAN_SEND' | translate}}</md-button>
+ <md-button class="md-raised md-warn" ng-click="requestHeader.saveRequestToCollection($event)">{{'YANGMAN_SAVE' | translate}}</md-button>
+ <md-button class="md-raised" ng-click="requestHeader.showParamsAdmin($event)">{{'YANGMAN_PARAMETERS' | translate}}</md-button>
</md-input-container>
</section>
</span>
</md-content>
</section>
-</md-content>
\ No newline at end of file
+</md-content>
@reqMethodGet: #63d33b;
@reqMethodPut: #6fbad3;
@reqMethodPost: #ea9c30;
-@reqMethodDelete: #ea3b27;
+@reqMethodDelete: #eabb2f;
+@reqError: #ff0000;
// helpers
.pointer{
height: 100%;
padding-right: 2px;
padding-bottom: 10px;
+ position: relative;
+
> div {
height: calc(~'100% - 25px');
}
}
+ .paramsBox{
+ position: absolute;
+ top: 30px;
+ right: 26px;
+ background-color: rgba(235, 235, 228, 0.62);
+ padding: 15px;
+ }
+
.CodeMirror { height: 100%; }
}
.DELETE{
color: @reqMethodDelete;
}
+ .error{
+ color: @reqError;
+ }
}
}
}
md-dialog{
+
+ .md-toolbar-tools{
+ button{
+ min-width: auto;
+ }
+ }
+
md-dialog-content, md-dialog-actions{
h2, span{
color: @fontColor;
'ngMessages',
'common/yangutils/yangutils.module',
'codemirror',
- 'codeMirror-showHint',
+ 'codeMirror-yangmanJsonHint',
'codeMirror-javascriptMode',
'codeMirror-matchBrackets',
], function () {