define([
'app/yangman/controllers/params-admin.controller',
+ 'app/yangman/services/time-tracking.services',
], function (ParamsAdminCtrl) {
'use strict';
RequestHeaderCtrl.$inject = [
'$mdDialog', '$mdToast', '$scope', '$rootScope', 'ENV', 'YangmanService', 'ParametersService',
- 'PathUtilsService', 'RequestsService', '$filter', 'DataBackupService', 'constants'
+ 'PathUtilsService', 'RequestsService', '$filter', 'DataBackupService', 'constants', 'TimeTrackingService'
];
function RequestHeaderCtrl($mdDialog, $mdToast, $scope, $rootScope, ENV, YangmanService, ParametersService,
- PathUtilsService, RequestService, $filter, DataBackupService, constants) {
+ PathUtilsService, RequestService, $filter, DataBackupService, constants,
+ TimeTrackingService) {
var requestHeader = this;
requestHeader.allOperations = [constants.OPERATION_GET, constants.OPERATION_POST, constants.OPERATION_PUT, constants.OPERATION_DELETE];
/**
* Set selected operations based on data store
*/
- $scope.$on('SET_SEL_OPERATIONS', function (event, operations, setUrl) {
+ $scope.$on(constants.SET_SEL_OPERATIONS, function (event, operations, setUrl) {
setAllowedMethods(operations);
if ( setUrl ) {
/**
* Watching for changes in shown detail data type (radio button)
*/
- $scope.$on('YANGMAN_HEADER_INIT', function (event, args) {
+ $scope.$on(constants.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) {
+ $scope.$on(constants.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', function (event, args) {
+ $scope.$on(constants.YANGMAN_EXECUTE_WITH_DATA, function (event, args) {
executeOperation(args.params.data ? angular.fromJson(args.params.data) : {}, args.cbk);
});
locals: {
parametersList: $scope.parametersList,
},
- }).then(function (){
- $scope.parametersList.loadListFromStorage();
-
- });
+ }).then(
+ function (){
+ $scope.parametersList.loadListFromStorage();
+ },
+ function (){
+ $scope.parametersList.loadListFromStorage();
+ }
+ );
}
/**
} else {
$scope.setJsonView(true, false);
}
-
- // sendRequestData({}, 'RECEIVED');
}
/**
var sentData = { reqData: null },
allData = { sent: null, received: null };
- $scope.rootBroadcast('YANGMAN_GET_CODEMIRROR_DATA_RECEIVED', params);
- $scope.rootBroadcast('YANGMAN_GET_CODEMIRROR_DATA_SENT', sentData);
+ $scope.rootBroadcast(constants.YANGMAN_GET_CODEMIRROR_DATA_RECEIVED, params);
+ $scope.rootBroadcast(constants.YANGMAN_GET_CODEMIRROR_DATA_SENT, sentData);
allData.sent = sentData.reqData ? angular.fromJson(sentData.reqData) : {};
allData.received = params.reqData ? angular.fromJson(params.reqData) : {};
dataType = requestHeader.selectedOperation === constants.OPERATION_GET ? constants.REQUEST_DATA_TYPE_RECEIVED : 'SENT';
}
- $scope.rootBroadcast('YANGMAN_GET_CODEMIRROR_DATA_' + dataType, params);
+ $scope.rootBroadcast(constants.YANGMAN_GET_CODEMIRROR_DATA + dataType, params);
return params.reqData ? angular.fromJson(params.reqData) : {};
},
};
*/
function sendRequestData(data, type){
$scope.rootBroadcast(
- 'YANGMAN_SET_CODEMIRROR_DATA_' + type,
+ constants.YANGMAN_SET_CODEMIRROR_DATA + type,
{ data: data instanceof Object ? JSON.stringify(data, null, 4) : data }
);
}
function sendErrorData(response) {
- $scope.rootBroadcast('YANGMAN_SET_ERROR_DATA', response);
+ $scope.rootBroadcast(constants.YANGMAN_SET_ERROR_DATA, response);
}
/**
});
}
+ /**
+ * Try to set current (depending on url) selectedApi and selectedSubApi to $scope if it exists in api tree data
+ * @param url
+ * @param cbk
+ * @param fill
+ */
function setApiByUrl(url, cbk, fill){
- $scope.rootBroadcast('YANGMAN_GET_API_TREE_DATA', null, function (treeApis) {
+ $scope.rootBroadcast(constants.YANGMAN_GET_API_TREE_DATA, null, function (treeApis) {
var apisIndexes =
PathUtilsService.searchNodeByPath(url, treeApis, null, true, true);
null, null, requestHeader.requestUrl, requestHeader.selectedOperation, '', '', ''
);
- $scope.rootBroadcast('YANGMAN_GET_CODEMIRROR_DATA_SENT', sentData);
- $scope.rootBroadcast('YANGMAN_GET_CODEMIRROR_DATA_RECEIVED', receivedData);
+ $scope.rootBroadcast(constants.YANGMAN_GET_CODEMIRROR_DATA_SENT, sentData);
+ $scope.rootBroadcast(constants.YANGMAN_GET_CODEMIRROR_DATA_RECEIVED, receivedData);
RequestService.fillRequestByMethod(
historyReq, sentData, receivedData, requestHeader.selectedOperation, $scope.node,
requestHeader.selectedShownDataType
);
- $scope.rootBroadcast('YANGMAN_SAVE_REQUEST_TO_COLLECTION', { event: event, reqObj: historyReq });
+ $scope.rootBroadcast(constants.YANGMAN_SAVE_REQUEST_TO_COLLECTION, { event: event, reqObj: historyReq });
}
function showRequestProgress(){
- $scope.rootBroadcast('YANGMAN_EXECUTING_REQUEST_PROGRESS_START');
+ $scope.rootBroadcast(constants.YANGMAN_EXECUTING_REQUEST_PROGRESS_START);
}
- function finishRequestProgress (message){
- $scope.rootBroadcast('YANGMAN_EXECUTING_REQUEST_PROGRESS_STOP');
- // $mdToast.show(
- // $mdToast.simple()
- // .textContent(message)
- // .position('bottom right')
- // .parent(angular.element('.yangmanModule__right-panel__header'))
- // .hideDelay(1500)
- // );
+ function finishRequestProgress(message){
+ $scope.rootBroadcast(constants.YANGMAN_EXECUTING_REQUEST_PROGRESS_STOP);
}
-
/**
* Execute request operation
*/
function executeOperation(requestData, executeCbk){
+ TimeTrackingService.startTimer();
var allowExecuteOperation =
requestHeader.selectedShownDataType === constants.DISPLAY_TYPE_FORM && $scope.selectedSubApi ?
!PathUtilsService.checkEmptyIdentifiers($scope.selectedSubApi.pathArray) : true;
+
if ( allowExecuteOperation ) {
showRequestProgress();
- setRequestUrl(requestHeader.selectedShownDataType === constants.DISPLAY_TYPE_REQ_DATA ? requestHeader.requestUrl : null);
- $scope.rootBroadcast('YANGMAN_SET_ERROR_MESSAGE', '');
+ $scope.rootBroadcast(constants.YANGMAN_SET_ERROR_MESSAGE, '');
- if ( requestHeader.selectedShownDataType !== constants.DISPLAY_TYPE_FORM ){
+ setRequestUrl(
+ requestHeader.selectedShownDataType === constants.DISPLAY_TYPE_REQ_DATA ?
+ requestHeader.requestUrl :
+ null
+ );
+ if ( requestHeader.selectedShownDataType === constants.DISPLAY_TYPE_REQ_DATA ){
setApiByUrl(requestHeader.requestUrl, null, true);
}
- var historyReq = RequestService.createHistoryRequest(null, null, requestHeader.requestUrl,
- requestHeader.selectedOperation, '', '', '');
+ var historyReq = RequestService.createHistoryRequest(
+ null,
+ null,
+ requestHeader.requestUrl,
+ requestHeader.selectedOperation,
+ '', '', ''
+ );
YangmanService.executeRequestOperation(
$scope.selectedApi,
requestHeader.executedOperation = requestHeader.selectedOperation;
} else {
$scope.rootBroadcast(
- 'YANGMAN_SET_ERROR_MESSAGE',
- $filter('translate')('YANGMAN_ERROR_EMPTY_IDENTIFIERS')
+ constants.YANGMAN_SET_ERROR_MESSAGE,
+ $filter('translate')(constants.YANGMAN_ERROR_EMPTY_IDENTIFIERS)
);
}
* @param response
*/
function executeReqSuccCbk(reqInfo, response) {
+
var preparedReceivedData = YangmanService.prepareReceivedData(
$scope.node,
requestHeader.selectedOperation,
sendRequestData(reqInfo.requestSrcData || {}, 'SENT');
} else {
- if ($scope.node){
+ if ($scope.node && requestHeader.selectedOperation !== constants.OPERATION_DELETE){
YangmanService.fillNodeFromResponse($scope.node, preparedReceivedData);
YangmanService.handleNodeIdentifier(
);
$scope.node.expanded = true;
- $scope.rootBroadcast('YANGMAN_DISABLE_ADDING_LIST_ELEMENT');
+ $scope.rootBroadcast(constants.YANGMAN_DISABLE_ADDING_LIST_ELEMENT);
preparedReceivedData = YangmanService.checkRpcReceivedData(preparedReceivedData, $scope.node);
sendRequestData(preparedReceivedData, constants.REQUEST_DATA_TYPE_RECEIVED);
}
}
// create and set history request
+ requestHeader.statusObj.time = TimeTrackingService.returnTime();
+
historyReq.setExecutionData(
reqInfo.requestSrcData,
preparedReceivedData,
reqInfo.status,
reqInfo.status,
reqInfo.statusText,
- reqInfo.time
+ requestHeader.statusObj.time
);
- $scope.rootBroadcast('YANGMAN_SAVE_EXECUTED_REQUEST', historyReq, function (){
- $scope.rootBroadcast('YANGMAN_SELECT_THE_NEWEST_REQUEST');
+ $scope.rootBroadcast(constants.YANGMAN_SAVE_EXECUTED_REQUEST, historyReq, function (){
+ $scope.rootBroadcast(constants.YANGMAN_SELECT_THE_NEWEST_REQUEST);
});
(executeCbk || angular.noop)(historyReq);
-
}
/**
finishRequestProgress();
+ requestHeader.statusObj.time = TimeTrackingService.returnTime();
+
historyReq.setExecutionData(
reqInfo.requestSrcData,
response.data,
reqInfo.status,
reqInfo.status,
reqInfo.statusText,
- reqInfo.time
+ requestHeader.statusObj.time
);
- $scope.rootBroadcast('YANGMAN_SAVE_EXECUTED_REQUEST', historyReq, function (){
- $scope.rootBroadcast('YANGMAN_SELECT_THE_NEWEST_REQUEST');
+ $scope.rootBroadcast(constants.YANGMAN_SAVE_EXECUTED_REQUEST, historyReq, function (){
+ $scope.rootBroadcast(constants.YANGMAN_SELECT_THE_NEWEST_REQUEST);
});
- //setNodeDataFromRequestData(requestHeader.requestUrl);
-
if (response.data) {
// try to fill code mirror editor
sendRequestData(response.data, constants.REQUEST_DATA_TYPE_RECEIVED);
* Check data before executin operations
*/
function prepareDataAndExecute(cbk){
+ if (requestHeader.statusObj) {
+ requestHeader.statusObj.statusText = null;
+ requestHeader.statusObj.time = null;
+ }
+
if ( requestHeader.requestUrl.length ) {
if ( requestHeader.selectedShownDataType === constants.DISPLAY_TYPE_REQ_DATA ) {
// get json data
var params = { reqData: null };
- $scope.rootBroadcast('YANGMAN_GET_CODEMIRROR_DATA_SENT', params);
+ $scope.rootBroadcast(constants.YANGMAN_GET_CODEMIRROR_DATA_SENT, params);
executeOperation(params.reqData ? angular.fromJson(params.reqData) : {}, cbk);
} else {
executeOperation({}, cbk);
'MAIN_SCOPE'
);
- $scope.rootBroadcast('YANGMAN_GET_API_TREE_DATA', null, function (treeApis) {
+ $scope.rootBroadcast(constants.YANGMAN_GET_API_TREE_DATA, null, function (treeApis) {
DataBackupService.storeFromScope(
['treeApis'],
{ treeApis: treeApis },
$scope.setGlobalParams(mountPointApis, augmentations);
$scope.setDataStore(null);
requestHeader.statusObj = reqObj;
- $scope.rootBroadcast('YANGMAN_SET_API_TREE_DATA', mountPointTreeApis);
+ $scope.rootBroadcast(constants.YANGMAN_SET_API_TREE_DATA, mountPointTreeApis);
}
/**