Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#88 folder browser #131

Merged
merged 4 commits into from
Mar 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.marklogic.hub.model;

public class SearchPathModel {

private String folder;
private String path;

public SearchPathModel() {
}

public SearchPathModel(String path) {
this.path = path;
}

public SearchPathModel(String path, String folder) {
this.path = path;
this.folder = folder;
}

public String getFolder() {
return folder;
}

public void setFolder(String folder) {
this.folder = folder;
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.marklogic.hub.web.controller.api;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.marklogic.hub.config.EnvironmentConfiguration;
import com.marklogic.hub.model.SearchPathModel;
import com.marklogic.hub.util.FileUtil;
import com.marklogic.hub.web.controller.BaseController;

@RestController
@RequestMapping("/api/utils")
public class UtilController extends BaseController {

private static final Logger LOGGER = LoggerFactory.getLogger(UtilController.class);

@Autowired
private EnvironmentConfiguration environmentConfiguration;

@RequestMapping(value = "/searchPath", method = RequestMethod.POST, consumes = {
MediaType.APPLICATION_JSON_UTF8_VALUE }, produces = { MediaType.APPLICATION_JSON_UTF8_VALUE })
public Map searchPath(@RequestBody SearchPathModel searchPathModel) {
return searchPathUnix(searchPathModel.getPath());
}

public Map searchPathUnix(String searchPath) {

LOGGER.debug("Search Path:" + searchPath);
List<SearchPathModel> paths = new ArrayList<SearchPathModel>();
if (StringUtils.isEmpty(searchPath)) {
File[] roots = File.listRoots();
for (int i = 0; i < roots.length; i++) {
LOGGER.debug("Path:" + roots[i].getAbsolutePath());
paths.add(new SearchPathModel(roots[i].getAbsolutePath(), roots[i].getAbsolutePath()));
}
} else {
if (!searchPath.equals("/")) {
searchPath = searchPath + java.io.File.separator;
}

List<String> folders = FileUtil.listDirectFolders(searchPath);
for (String folder : folders) {
String path = searchPath + folder;
LOGGER.debug("Path:" + path);
paths.add(new SearchPathModel(path, folder));
}
}

Map returnValue = new HashMap();

returnValue.put("paths", paths);

return returnValue;
}
}
4 changes: 3 additions & 1 deletion quick-start/src/main/resources/static/app/quickStartApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
'angularBootstrapNavTree',
'ngAnimate',
'ui.bootstrap',
'ngMaterial'
'ngMaterial',
'treeControl'
//'angucomplete-alt'
];
angular.module('quickStartApp', dependencies)
.factory('$exceptionHandler', ExceptionHandler)
Expand Down
155 changes: 83 additions & 72 deletions quick-start/src/main/resources/static/app/services/dataHubService.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function () {
(function() {

'use strict';

Expand Down Expand Up @@ -27,42 +27,43 @@
runInputFlow: runInputFlow,
testFlow: testFlow,
saveFlow: saveFlow,
displayMessage: displayMessage
displayMessage: displayMessage,
searchPath: searchPath
});

function login(loginForm) {
return $http.post('api/data-hub/login', loginForm)
.success(function (data) {
self.status = data;
if(!self.status.installed) {
self.action.type = 'Install';
self.action.message = 'Install is in progress...';
self.action.progressType = 'success';
}
})
.error(function () {
self.status = null;
});
.success(function(data) {
self.status = data;
if (!self.status.installed) {
self.action.type = 'Install';
self.action.message = 'Install is in progress...';
self.action.progressType = 'success';
}
})
.error(function() {
self.status = null;
});
}

function getLoginStatus() {
return $http.get('api/data-hub/login')
.success(function (data) {
self.status = data;
})
.error(function () {
self.status = null;
});
.success(function(data) {
self.status = data;
})
.error(function() {
self.status = null;
});
}

function logout() {
return $http.post('api/data-hub/logout')
.success(function (data) {
self.status = data;
})
.error(function () {
self.status = null;
});
.success(function(data) {
self.status = data;
})
.error(function() {
self.status = null;
});
}

function reloadRoute() {
Expand All @@ -71,17 +72,17 @@

function install() {
return $http.post('api/data-hub/install')
.success(function (status) {
self.status = status;
self.action.type = null;
self.displayMessage('Install is successful.', 'success', 'notification', false);
self.reloadRoute();
})
.error(function () {
self.action.message = 'Install is unsuccessful.';
self.action.progressType = 'danger';
//self.displayMessage('Install is unsuccessful.', 'error', 'notification', false);
});
.success(function(status) {
self.status = status;
self.action.type = null;
self.displayMessage('Install is successful.', 'success', 'notification', false);
self.reloadRoute();
})
.error(function() {
self.action.message = 'Install is unsuccessful.';
self.action.progressType = 'danger';
//self.displayMessage('Install is unsuccessful.', 'error', 'notification', false);
});
}

function preUninstall() {
Expand All @@ -93,37 +94,37 @@

function uninstall() {
return $http.post('api/data-hub/uninstall')
.success(function (status) {
self.status = status;
self.action.type = 'Uninstall';
self.action.message = 'Uninstall is successful.';
//self.displayMessage('Uninstall is successful.', 'success', 'notification', false);
//self.reloadRoute();
})
.error(function () {
self.action.message = 'Uninstall is unsuccessful.';
self.action.progressType = 'danger';
//self.displayMessage('Uninstall is unsuccessful.', 'error', 'notification', false);
});
.success(function(status) {
self.status = status;
self.action.type = 'Uninstall';
self.action.message = 'Uninstall is successful.';
//self.displayMessage('Uninstall is successful.', 'success', 'notification', false);
//self.reloadRoute();
})
.error(function() {
self.action.message = 'Uninstall is unsuccessful.';
self.action.progressType = 'danger';
//self.displayMessage('Uninstall is unsuccessful.', 'error', 'notification', false);
});
}

function installUserModules() {
return $http.post('api/data-hub/install-user-modules')
.success(function (data) {
self.status = data;
self.displayMessage('Deploy to server is successful.', 'success', 'notification', false);
})
.error(function () {
self.displayMessage('Deploy to server is unsuccessful.', 'error', 'notification', false);
});
.success(function(data) {
self.status = data;
self.displayMessage('Deploy to server is successful.', 'success', 'notification', false);
})
.error(function() {
self.displayMessage('Deploy to server is unsuccessful.', 'error', 'notification', false);
});
}

function saveEntity(entityForm) {
return $http.post('api/entities', entityForm)
.success(function (status) {
self.status = status;
self.displayMessage('New entity is created successfully.', 'success', 'notification', false);
});
.success(function(status) {
self.status = status;
self.displayMessage('New entity is created successfully.', 'success', 'notification', false);
});
}

function displayEntity(entityName) {
Expand Down Expand Up @@ -163,33 +164,41 @@

function saveFlow(flowForm) {
return $http.post('api/flows', flowForm)
.success(function (selectedEntity) {
self.status.selectedEntity = selectedEntity;
self.displayMessage('New flow is created successfully.', 'success', 'notification', false);
});
.success(function(selectedEntity) {
self.status.selectedEntity = selectedEntity;
self.displayMessage('New flow is created successfully.', 'success', 'notification', false);
});
}

function displayMessage(message,messageType,elementId,isModal) {
if(typeof elementId === 'undefined') {
function searchPath(pathPrefix) {
var data = {
path: pathPrefix
};

return $http.post('api/utils/searchPath', data);
}

function displayMessage(message, messageType, elementId, isModal) {
if (typeof elementId === 'undefined') {
elementId = 'messageDiv';
}
var messageClass = 'alert';
if(messageType === 'error') {
if (messageType === 'error') {
messageClass += ' alert-error alert-danger';
} else if (messageType === 'success') {
messageClass += ' alert-success';
} else if (messageType === 'warning') {
messageClass += ' alert-warning';
}
$('#'+elementId).html('<div class="'+messageClass+'">'+
'<a href="dismiss" class="close" data-dismiss="alert">&times;</a>'+message+'</div>');
$('#' + elementId).html('<div class="' + messageClass + '">' +
'<a href="dismiss" class="close" data-dismiss="alert">&times;</a>' + message + '</div>');

if(isModal) {
if (isModal) {
$('.modal-body').scrollTop(0);
} else {
$('#'+elementId).scrollTop(0);
$('#' + elementId).scrollTop(0);
}
setTimeout(function () {
setTimeout(function() {
$('.alert').fadeOut();
}, 5000);
}
Expand All @@ -206,7 +215,9 @@
var params = {
'taskId': taskId
};
return $http.get('api/task/wait', {'params': params});
return $http.get('api/task/wait', {
'params': params
});
}

function cancelTask(taskId) {
Expand Down
Loading