Skip to content

Commit

Permalink
Fixed: #302 - Run On Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
delchev committed Jul 17, 2018
1 parent cfdd741 commit 3ae7731
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 4 deletions.
23 changes: 21 additions & 2 deletions ide/ui/ide-git/src/main/resources/ide-git/git/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,10 @@ angular.module('workspace', ['workspace.config', 'ngAnimate', 'ngSanitize', 'ui.
announceFileSelected: announceFileSelected,
announceFileCreated: announceFileCreated,
announceFileOpen: announceFileOpen,
announcePull: announcePull
announcePull: announcePull,
on: function(evt, cb){
messageHub.subscribe(cb, evt);
}
};
}])
.factory('$treeConfig', [function(){
Expand Down Expand Up @@ -543,7 +546,7 @@ angular.module('workspace', ['workspace.config', 'ngAnimate', 'ngSanitize', 'ui.
.factory('workspaceTreeAdapter', ['$treeConfig', 'workspaceService', 'gitService', '$messageHub', function($treeConfig, WorkspaceService, GitService, $messageHub){
return new WorkspaceTreeAdapter($treeConfig, WorkspaceService, GitService, $messageHub);
}])
.controller('WorkspaceController', ['workspaceService', 'workspaceTreeAdapter', 'gitService', function (workspaceService, workspaceTreeAdapter, gitService) {
.controller('WorkspaceController', ['workspaceService', 'workspaceTreeAdapter', 'gitService', '$messageHub', function (workspaceService, workspaceTreeAdapter, gitService, $messageHub) {

this.wsTree;
this.workspaces;
Expand Down Expand Up @@ -604,4 +607,20 @@ angular.module('workspace', ['workspace.config', 'ngAnimate', 'ngSanitize', 'ui.
this.wsTree.refresh();
};

$messageHub.on('git.repository.run', function(msg){
gitService.cloneProject(this.wsTree, this.selectedWs, msg.data.repository, msg.data.username, msg.data.password);
if (msg.data.uri) {
run();
}

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

async function run() {
await sleep(2000);
window.open(msg.data.uri, '_blank');
}
}.bind(this));

}]);
23 changes: 23 additions & 0 deletions ide/ui/ide-git/src/main/resources/ide-git/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@
}
}
};

var getParameterByName = function (name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
};

var messageHub = new FramesMessageHub();
var send = function(evtName, data, absolute){
messageHub.post({data: data}, (absolute ? '' : 'git.') + evtName);
};
var run = function() {
send("repository.run", metadata, false);
}
var metadata = {};
metadata.repository = getParameterByName("repository");
metadata.username = getParameterByName("username");
metadata.password = getParameterByName("password");
metadata.uri = getParameterByName("uri");
if (metadata.repository) {
window.setTimeout(run, 2000);
}

}]);
</script>
Expand Down
1 change: 1 addition & 0 deletions ide/ui/ide-git/src/main/resources/ide-git/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"guid":"ide-git","repository":{"type":"git","branch":"master","url":"https://github.com/dirigiblelabs/ide-git.git"}}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
import org.eclipse.dirigible.core.git.utils.GitProjectProperties;
import org.eclipse.dirigible.core.publisher.api.PublisherException;
import org.eclipse.dirigible.core.publisher.service.PublisherCoreService;
import org.eclipse.dirigible.core.publisher.synchronizer.PublisherSynchronizer;
import org.eclipse.dirigible.core.workspace.api.IProject;
import org.eclipse.dirigible.core.workspace.api.IWorkspace;
import org.eclipse.dirigible.core.workspace.service.WorkspacesCoreService;
import org.eclipse.dirigible.repository.api.IRepositoryStructure;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.TransportException;
Expand Down Expand Up @@ -271,7 +273,8 @@ protected void publishProjects(IWorkspace workspace, Set<String> clonedProjects)
for (IProject project : projects) {
if (project.getName().equals(projectName)) {
try {
publisherCoreService.createPublishRequest(workspace.getName(), projectName);
publisherCoreService.createPublishRequest(generateWorkspacePath(workspace.getName()), projectName);
PublisherSynchronizer.forceSynchronization();
logger.info(String.format("Project [%s] has been published", project.getName()));
} catch (PublisherException e) {
logger.error(String.format("An error occurred while publishing the cloned project [%s]", project.getName()), e);
Expand All @@ -282,5 +285,20 @@ protected void publishProjects(IWorkspace workspace, Set<String> clonedProjects)
}
}
}

/**
* Generate workspace path.
*
* @param user
* the user
* @param workspace
* the workspace
* @return the string builder
*/
private String generateWorkspacePath(String workspace) {
StringBuilder relativePath = new StringBuilder(IRepositoryStructure.PATH_USERS).append(IRepositoryStructure.SEPARATOR).append(UserFacade.getName())
.append(IRepositoryStructure.SEPARATOR).append(workspace);
return relativePath.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public PublishRequestDefinition createPublishRequest(String workspace, String pa
*/
@Override
public PublishRequestDefinition createPublishRequest(String workspace, String path) throws PublisherException {
return createPublishRequest(workspace, path, IRepositoryStructure.PATH_REGISTRY);
return createPublishRequest(workspace, path, IRepositoryStructure.PATH_REGISTRY_PUBLIC);
}

/*
Expand Down

0 comments on commit 3ae7731

Please sign in to comment.