angular.module('app.yangman').controller('RequestsListCtrl', RequestsListCtrl);
RequestsListCtrl.$inject = [
- '$filter', '$mdDialog', '$scope', 'HandleFileService', 'PathUtilsService', 'RequestsService', 'YangmanService',
- 'YangmanDesignService',
+ '$filter', '$mdDialog', '$scope', 'YMHandleFileService', 'PathUtilsService', 'RequestsService', 'YangmanService',
+ 'YangmanDesignService', 'constants',
];
/**
* @param $filter
* @param $mdDialog
* @param $scope
- * @param HandleFileService
+ * @param YMHandleFileService
* @param PathUtilsService
* @param RequestsService
* @param YangmanService
* @param YangmanDesignService
* @constructor
*/
- function RequestsListCtrl($filter, $mdDialog, $scope, HandleFileService, PathUtilsService, RequestsService,
- YangmanService, YangmanDesignService) {
+ function RequestsListCtrl($filter, $mdDialog, $scope, YMHandleFileService, PathUtilsService, RequestsService,
+ YangmanService, YangmanDesignService, constants) {
var vm = this;
/**
* @type {*|CollectionList}
*/
vm.collectionList = null;
+ vm.constants = constants;
/**
*
vm.clearFilter = clearFilter;
vm.clearHistoryList = clearHistoryList;
vm.colMatchingReqsCount = colMatchingReqsCount;
- vm.deselectAllRequests = deselectAllRequests;
+ vm.deselectAllFilteredRequests = deselectAllFilteredReqs;
vm.downloadCollection = downloadCollection;
vm.executeRequest = executeRequest;
vm.fakeFilter = fakeFilter;
vm.filterReq = filterReq;
vm.init = init;
vm.readCollectionFromFile = readCollectionFromFile;
- vm.selectAllRequests = selectAllRequests;
+ vm.selectAllFilteredRequests = selectAllFilteredReqs;
vm.selectRequest = selectRequest;
vm.showData = showData;
vm.showDgDeleteCollection = showDgDeleteCollection;
vm.showDgSaveReq = showDgSaveReq;
vm.showForm = showForm;
vm.toggleCollectionsSort = toggleCollectionsSort;
-
-
-
+ vm.selectOnlyThisRequest = selectOnlyThisRequest;
+ vm.deselectAllRequests = deselectAllRequests;
+ vm.filterCollReq = filterCollReq;
/**
* Save request obje to collection from other controller
$mdDialog.show(confirm).then(function (){
vm.collectionList.clear();
vm.collectionList.saveToStorage();
- $scope.rootBroadcast('YANGMAN_REFRESH_COLLECTIONS');
+ $scope.rootBroadcast(constants.YANGMAN_REFRESH_COLLECTIONS);
YangmanDesignService.enableMdMenuItem(event);
}, function () {
YangmanDesignService.enableMdMenuItem(event);
* @param params
*/
function saveBcstedHistoryRequest(broadcastEvent, params) {
- vm.requestList.addRequestToList(params.params);
+ vm.requestList.addItemToList(params.params);
vm.requestList.saveToStorage();
loadHistoryList();
(params.cbk || angular.noop)();
* @param $fileContent
*/
function readCollectionFromFile($fileContent) {
- var data = $fileContent,
- checkArray = ['sentData', 'receivedData', 'path', 'collection', 'method', 'status', 'name'];
+ var data = $fileContent;
- if (data && YangmanService.validateFile(data, checkArray)){
+ if (data && YangmanService.validateFile(data, constants.COLLECTION_CHECK_ARRAY)){
try {
vm.collectionList.loadListFromFile(data);
vm.collectionList.saveToStorage();
- $scope.rootBroadcast('YANGMAN_REFRESH_COLLECTIONS');
+ $scope.rootBroadcast(constants.YANGMAN_REFRESH_COLLECTIONS);
clearFileInputValue();
}
catch (e) {
else {
clearFileInputValue();
}
+ removeButtonBackground();
+
+ function removeButtonBackground() {
+ $('#importCollection').next().css({ 'background': 'transparent' });
+ }
}
function toggleCollectionsSort() {
*/
function downloadCollection(collection) {
- var cListJSON = vm.collectionList.getCollectionInJSON(collection.name);
+ var cListJSON = vm.collectionList.getCollectionInRawJSON(collection.name);
- HandleFileService.downloadFile(collection.name + '.json', cListJSON, 'json', 'charset=utf-8',
+ YMHandleFileService.downloadFile(collection.name + '.json', cListJSON, 'json', 'charset=utf-8',
function (){},
function (e){
console.error('ExportCollection error:', e);
* @param reqObj
*/
function showForm(reqObj) {
- var data = reqObj.method === 'GET' ? reqObj.receivedData : reqObj.sentData;
+ var data = reqObj.sentData;
+
+ // exception for get meth
+ if ( reqObj.method === constants.OPERATION_GET ) {
+ data = reqObj.receivedData;
+ }
- $scope.rootBroadcast('YANGMAN_SET_ERROR_DATA',
+ $scope.rootBroadcast(
+ constants.YANGMAN_SET_CODEMIRROR_DATA_RECEIVED, { data: reqObj.setDataForView(reqObj.receivedData) }
+ );
+ $scope.rootBroadcast(
+ constants.YANGMAN_SET_CODEMIRROR_DATA_SENT, { data: reqObj.setDataForView(reqObj.sentData) }
+ );
+
+ $scope.rootBroadcast(constants.YANGMAN_SET_ERROR_DATA,
reqObj.receivedData && reqObj.receivedData.hasOwnProperty('errors') ? reqObj.receivedData : {});
- $scope.rootBroadcast('YANGMAN_FILL_NODE_FROM_REQ', { requestUrl: reqObj.path, requestData: data },
+ $scope.rootBroadcast(constants.YANGMAN_FILL_NODE_FROM_REQ, { requestUrl: reqObj.path, requestData: data },
function (){
- $scope.setRightPanelSection('form');
- $scope.rootBroadcast('YANGMAN_HEADER_INIT', {
+ $scope.setRightPanelSection(constants.DISPLAY_TYPE_FORM);
+ $scope.rootBroadcast(constants.YANGMAN_HEADER_INIT, {
path: reqObj.path,
method: reqObj.method,
statusObj: {
});
if ( $scope.node ) {
+ // prepare data for filling form
+ data = $scope.node.type === constants.NODE_RPC ?
+ YangmanService.prepareReceivedData(
+ $scope.node,
+ reqObj.method,
+ reqObj.receivedData,
+ reqObj.sentData,
+ constants.DISPLAY_TYPE_FORM
+ ) : data;
+
// try to fill node
YangmanService.fillNodeFromResponse($scope.node, data);
$scope.node.expanded = true;
*/
function executeRequest(reqObj) {
showData(reqObj);
- $scope.rootBroadcast('YANGMAN_EXECUTE_WITH_DATA',{ data: reqObj.sentData });
+ $scope.rootBroadcast(constants.YANGMAN_EXECUTE_WITH_DATA,{ data: reqObj.sentData });
}
/**
*/
function showData(reqObj, select){
var headerObj = {
- path: reqObj.path,
- method: reqObj.method
- },
- receivedData = {};
+ path: reqObj.path,
+ method: reqObj.method,
+ };
// action select request
if ( select ) {
time: reqObj.responseTime,
};
- receivedData = reqObj.receivedData;
-
$scope.rootBroadcast(
- 'YANGMAN_SET_ERROR_DATA',
+ constants.YANGMAN_SET_ERROR_DATA,
reqObj.receivedData && reqObj.receivedData.hasOwnProperty('errors') ? reqObj.receivedData : {}
);
}
- $scope.setRightPanelSection('req-data');
- $scope.setJsonView(true, reqObj.method !== 'GET');
+ $scope.setRightPanelSection(constants.DISPLAY_TYPE_REQ_DATA);
+ $scope.setJsonView(true, reqObj.method !== constants.OPERATION_GET);
- $scope.rootBroadcast('YANGMAN_HEADER_INIT', headerObj);
- $scope.rootBroadcast('YANGMAN_FILL_NODE_FROM_REQ', { requestUrl: reqObj.path });
+ $scope.rootBroadcast(constants.YANGMAN_HEADER_INIT, headerObj);
+ $scope.rootBroadcast(constants.YANGMAN_FILL_NODE_FROM_REQ, { requestUrl: reqObj.path });
$scope.rootBroadcast(
- 'YANGMAN_SET_CODEMIRROR_DATA_RECEIVED',
- { data: reqObj.setDataForView(receivedData) }
+ constants.YANGMAN_SET_CODEMIRROR_DATA_RECEIVED,
+ { data: reqObj.setDataForView(reqObj.receivedData) }
);
$scope.rootBroadcast(
- 'YANGMAN_SET_CODEMIRROR_DATA_SENT',
+ constants.YANGMAN_SET_CODEMIRROR_DATA_SENT,
{ data: reqObj.setDataForView(reqObj.sentData) }
);
}
vm.mainList.deleteRequestItem(reqObj);
}
else {
- vm.mainList.selectedRequests.forEach(function (elem){
+ vm.mainList.getSelectedItems(
+ vm.mainList === vm.collectionList ? filterCollReq : filterReq
+ ).forEach(function (elem){
vm.mainList.deleteRequestItem(elem);
});
}
* @returns {boolean}
*/
function filterReq(reqObj){
- return reqObj.path.toLowerCase().indexOf(vm.search.toLowerCase()) > -1;
+ var searchPhrase = vm.search.toLocaleLowerCase();
+ return reqObj.path.toLowerCase().indexOf(searchPhrase) > -1 ||
+ reqObj.collection.toLowerCase().indexOf(searchPhrase) > -1 ||
+ reqObj.method.toLowerCase() === searchPhrase;
}
/**
return true;
}
+
/**
* Show dialog for saving reqObj to collection (used for duplicate req too)
* @param ev
targetEvent: ev,
clickOutsideToClose: true,
locals: {
- requests: reqObj ? [reqObj] : vm.requestList.selectedRequests,
+ requests: reqObj ? [reqObj] : vm.mainList.getSelectedItems(
+ vm.mainList === vm.collectionList ? filterCollReq : filterReq
+ ),
collectionNames: vm.collectionList.getCollectionNames(),
duplicate: duplicate || false,
},
*/
function saveRequests(requests){
requests.forEach(function (reqObj){
- vm.collectionList.addRequestToList(reqObj);
+ vm.collectionList.addItemToList(RequestsService.clearUnnecessaryProperties(reqObj.clone()));
vm.collectionList.saveToStorage();
refreshCollectionsWithExpansion();
});
vm.requestList = RequestsService.createEmptyHistoryList('yangman_requestsList');
- $scope.$on('YANGMAN_REFRESH_COLLECTIONS', loadCollectionsList);
+
+ // if request was selected, deselect requests in all other instances of RequestsListCtrl
+ $scope.$on(constants.YANGMAN_DESELECT_REQUESTS, function (event, params) {
+ if (params.params.broadcastingCtrl !== vm) {
+ deselectAllRequests();
+ }
+ });
+
+ $scope.$on(constants.YANGMAN_REFRESH_COLLECTIONS, function (event, params){
+ loadCollectionsList();
+ (params.cbk || angular.noop)();
+ });
// list type dependend operations
if (mainList === 'history') {
vm.mainList = vm.requestList;
loadHistoryList();
- $scope.$on('YANGMAN_REFRESH_HISTORY', loadHistoryList);
+ $scope.$on(constants.YANGMAN_REFRESH_HISTORY, loadHistoryList);
// 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.$on(constants.YANGMAN_SAVE_EXECUTED_REQUEST, saveBcstedHistoryRequest);
// select newest request
- $scope.$on('YANGMAN_SELECT_THE_NEWEST_REQUEST', selectNewestRequest);
+ $scope.$on(constants.YANGMAN_SELECT_THE_NEWEST_REQUEST, selectNewestRequest);
}
else {
vm.mainList = vm.collectionList;
-
+ // saving from request header
+ $scope.$on(constants.YANGMAN_SAVE_REQUEST_TO_COLLECTION, saveRequestFromExt);
// saving collections expanded status on refresh
- $scope.$on('YANGMAN_REFRESH_AND_EXPAND_COLLECTIONS', function(event, params){
- $scope.rootBroadcast('YANGMAN_REFRESH_COLLECTIONS');
- (params.cbk || angular.noop)();
+ $scope.$on(constants.YANGMAN_REFRESH_AND_EXPAND_COLLECTIONS, function(){
+ var expandedColNames = vm.collectionList.getExpandedCollectionNames();
+ $scope.rootBroadcast(constants.YANGMAN_REFRESH_COLLECTIONS, {}, function (){
+ vm.collectionList.expandCollectionByNames(expandedColNames);
+ });
});
}
-
-
}
* @param requestObj
*/
function selectRequest(event, requestObj){
+ $scope.rootBroadcast(constants.YANGMAN_DESELECT_REQUESTS, { broadcastingCtrl: vm });
vm.mainList.toggleReqSelection(!event.ctrlKey, requestObj);
- $scope.setHistoryReqsSelected(vm.requestList.selectedRequests.length > 0);
if (!event.ctrlKey){
- vm.showData(requestObj, true);
+ if ($scope.rightPanelSection === constants.DISPLAY_TYPE_FORM) {
+ vm.showForm(requestObj, true);
+ }
+ else {
+ vm.showData(requestObj, true);
+ }
}
}
+ /**
+ * Mark only requestObj in current list as selected
+ * Used for example when user clicks on request submenu
+ * @param requestObj
+ */
+ function selectOnlyThisRequest(requestObj){
+ vm.mainList.toggleReqSelection(true, requestObj);
+ }
+
/**
* Deselect history requests
*/
- function deselectAllRequests(){
- vm.mainList.deselectReqs();
+ function deselectAllFilteredReqs(){
+ vm.mainList.deselectAllFilteredItems(vm.mainList === vm.collectionList ? filterCollReq : vm.filterReq);
+ }
+
+ function deselectAllRequests() {
+ vm.mainList.deselectAllItems();
}
/**
* Select history requests
*/
- function selectAllRequests(){
- deselectAllRequests();
- vm.mainList.dateGroups.forEach(function (group){
- vm.mainList.selectReqs(group.requests);
- });
+ function selectAllFilteredReqs(){
+ vm.mainList.selectAllFilteredItems(vm.mainList === vm.collectionList ? filterCollReq : vm.filterReq);
+ }
+
+ /**
+ * Use when selecting filtered requests if they are saved to some collection
+ * Additional filter is if the collection of the request is expanded
+ * @param request
+ * @returns {*|boolean}
+ */
+ function filterCollReq(request) {
+ return vm.collectionList.getCollection(request.collection).expanded && vm.filterReq(request);
}
/**
* Refresh and expand collections
*/
function refreshCollectionsWithExpansion(){
- var expandedCollNames = vm.collectionList.getExpandedCollectionNames();
- $scope.rootBroadcast('YANGMAN_REFRESH_AND_EXPAND_COLLECTIONS', null, function (){
- vm.collectionList.expandCollectionByNames(expandedCollNames);
- });
+ $scope.rootBroadcast(constants.YANGMAN_REFRESH_AND_EXPAND_COLLECTIONS);
}
}