Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 515770 - Multiple workspace support
  • Loading branch information
squarti committed Apr 27, 2017
1 parent 793b91a commit 4e97242
Show file tree
Hide file tree
Showing 65 changed files with 1,982 additions and 1,445 deletions.
28 changes: 22 additions & 6 deletions bundles/org.eclipse.orion.client.core/web/orion/fileClient.js
Expand Up @@ -142,6 +142,13 @@ define([
}, 100);
return d;
},
/* @callback */
read: function(loc) {
if (loc === "/") {
return this.loadWorkspace(loc);
}
return _noMatch(loc);
},
/**
* @description Computes the project context from the given location
* @param {String} context The resource context to find the project for
Expand All @@ -155,7 +162,6 @@ define([
deleteFile: _noMatch,
moveFile: _noMatch,
copyFile: _noMatch,
read: _noMatch,
write: _noMatch
};

Expand Down Expand Up @@ -340,13 +346,13 @@ define([
},

/**
* Loads all the user's workspaces. Returns a deferred that will provide the loaded
* workspaces when ready.
* Loads all the user's workspaces for the specified file system. Returns a deferred
* that will provide the loaded workspaces when ready.
* @public
* @return {Deferred} A deferred that will load all workspaces
*/
loadWorkspaces: function() {
return _doServiceCall(this._getService(), "loadWorkspaces", arguments); //$NON-NLS-1$
loadWorkspaces: function(systemLocation) {
return _doServiceCall(this._getService(systemLocation), "loadWorkspaces", arguments); //$NON-NLS-1$
},

/**
Expand All @@ -360,6 +366,16 @@ define([
loadWorkspace: function(workspaceLocation) {
return _doServiceCall(this._getService(workspaceLocation), "loadWorkspace", arguments); //$NON-NLS-1$
},

/**
* Gets the workspace of the specified resource location.
*
* @param resourceLocation the resource to lookup the workspace
* @return {Deferred} A deferred that will load the specified workspace
*/
getWorkspace: function(resourceLocation) {
return _doServiceCall(this._getService(resourceLocation), "getWorkspace", arguments); //$NON-NLS-1$
},

/**
* @callback
Expand Down Expand Up @@ -429,7 +445,7 @@ define([
return this._createArtifact(parentLocation, "createFile", eventData, arguments);
},
/**
* Deletes a file, directory, or project.
* Deletes a file, directory, project or workspace.
* @param {String} deleteLocation The location of the file or directory to delete.
* @param {Object} eventData The event data that will be sent back.
* @public
Expand Down
Expand Up @@ -183,7 +183,7 @@ define([
if(workspaceMetadata){
readProjectFromWorkspace.call(that, fileMetadata, workspaceMetadata, deferred);
} else {
this.fileClient.loadWorkspace().then(function(workspace){
this.fileClient.getWorkspace(fileMetadata.Location).then(function(workspace){
readProjectFromWorkspace.call(that, fileMetadata, workspace, deferred);
});
}
Expand Down
12 changes: 6 additions & 6 deletions bundles/org.eclipse.orion.client.git/web/git/git-repository.js
Expand Up @@ -95,12 +95,12 @@ mBootstrap.startup().then(function(core) {
commandRegistry.processURL(window.location.href);
}

function loadWorspace() {
return progress.progress(fileClient.loadWorkspace(), messages["Loading default workspace"]); //$NON-NLS-0$
function loadWorkspace(resource) {
return progress.progress(fileClient.getWorkspace(resource), messages["Loading default workspace"]); //$NON-NLS-0$
}

loadWorspace().then(function(workspace){
explorer.setDefaultPath(workspace.Location);
loadWorkspace(params.resource || params.workspace).then(function(workspace){
explorer.setWorkspace(workspace);

var projectDescription = {};
for(var k in params){
Expand Down Expand Up @@ -134,8 +134,8 @@ mBootstrap.startup().then(function(core) {
if(previousResourceValue !== resource){
previousResourceValue = resource;

loadWorspace().then(function(workspace){
explorer.setDefaultPath(workspace.Location);
loadWorkspace(resource || params.workspace).then(function(workspace){
explorer.setWorkspace(workspace);
explorer.redisplay();
});
}
Expand Down
Expand Up @@ -126,6 +126,18 @@ define([
order: 1000, // low priority
uriTemplate: "{+OrionHome}/git/git-repository.html#"
});

provider.registerService("orion.page.link.related", {}, {
name: gitmessages["Repositories"],
id: "orion.git.repositories2",
nls: "git/nls/gitmessages",
category: "git",
order: 800, // low priority
validationProperties: [
{source: "WorkspaceLocation|Location", variableName: "GitWorkspaceLocation"}
],
uriTemplate: "{+OrionHome}/git/git-repository.html#,workspace={,GitWorkspaceLocation}"
});

provider.registerService("orion.navigate.command", {}, {
name: gitmessages["Git Log"],
Expand Down Expand Up @@ -324,7 +336,7 @@ define([
}
var queries = new URL(window.location.href).query;
var gitFSPattern = queries.get("gitFSPattern");
var gitBase = gitFSPattern ? gitFSPattern : makeParentRelative(new URL("../../gitapi/", window.location.href).href);
var gitBase = gitFSPattern ? gitFSPattern : makeParentRelative(new URL("../../gitapi", window.location.href).href);
var service = new GitFileImpl(gitBase);

provider.registerService("orion.core.file", service, {
Expand Down
95 changes: 82 additions & 13 deletions bundles/org.eclipse.orion.client.git/web/orion/git/GitFileImpl.js
Expand Up @@ -18,12 +18,34 @@ define(["orion/xhr", "orion/Deferred", "orion/encoding-shim", "orion/URL-shim"],
}

var GIT_TIMEOUT = 60000;

function makeAbsolute(loc) {
return new URL(loc, self.location.href).href;
}

function _normalizeLocations(data) {
if (data && typeof data === "object") {
Object.keys(data).forEach(function(key) {
var value = data[key];
if (key.indexOf("Location") !== -1) {
data[key] = makeAbsolute(value);
} else {
_normalizeLocations(value);
}
});
}
return data;
}

GitFileImpl.prototype = {
fetchChildren: function(location) {
var fetchLocation = location;
if (fetchLocation===this.fileBase) {
return new Deferred().resolve([]);
return this.loadWorkspaces().then(function(workspaces) {
return Deferred.all(workspaces.map(function(workspace) {
return this.read(workspace.Location, true);
}.bind(this)));
}.bind(this));
}
//If fetch location does not have ?depth=, then we need to add the depth parameter. Otherwise server will not return any children
if (fetchLocation.indexOf("?depth=") === -1) { //$NON-NLS-0$
Expand All @@ -41,24 +63,71 @@ define(["orion/xhr", "orion/Deferred", "orion/encoding-shim", "orion/URL-shim"],
});
},
loadWorkspaces: function() {
return this.loadWorkspace(this._repoURL);
},
loadWorkspace: function(location) {
var suffix = "/gitapi/";
if (location && location.indexOf(suffix, location.length - suffix.length) !== -1) {
location += "tree/";
var loc = this.fileBase;
var suffix = "/gitapi";
if (loc && loc.indexOf(suffix, loc.length - suffix.length) !== -1) {
loc += "/tree";
}

return xhr("GET", location,{ //$NON-NLS-0$
return xhr("GET", loc, {
headers: {
"Orion-Version": "1", //$NON-NLS-0$ //$NON-NLS-1$
"Content-Type": "charset=UTF-8" //$NON-NLS-0$ //$NON-NLS-1$
"Orion-Version": "1"
},
timeout: GIT_TIMEOUT
}).then(function(result) {
var jsonData = result.response ? JSON.parse(result.response) : {};
return jsonData || {};
});
return jsonData.Workspaces;
}).then(function(result) {
if (this.makeAbsolute) {
_normalizeLocations(result);
}
return result;
}.bind(this));
},
loadWorkspace: function(loc) {
var suffix = "/gitapi";
if (loc && loc.indexOf(suffix, loc.length - suffix.length) !== -1) {
loc += "/tree";
}
return xhr("GET", loc, {
headers: {
"Orion-Version": "1"
},
timeout: GIT_TIMEOUT,
log: false
}).then(function(result) {
var jsonData = result.response ? JSON.parse(result.response) : {};
//in most cases the returned object is the workspace we care about
//user didn't specify a workspace so we are at the root
//just pick the first location in the provided list
if (jsonData.Workspaces && jsonData.Workspaces.length > 0) {
return this.loadWorkspace(jsonData.Workspaces[0].Location);
}
return jsonData;
}.bind(this)).then(function(result) {
if (this.makeAbsolute) {
_normalizeLocations(result);
}
return result;
}.bind(this));
},
getWorkspace: function(resourceLocation) {
//TODO move this to server to avoid path math?
var id = resourceLocation || "";
if (id.indexOf(this.fileBase) === 0) id = id.substring(this.fileBase.length);
id = id.split("/");
if (id.length > 3 && (id[2] === "file" || id[2] === "workspace")) id = id[3];
if (id.length > 4 && (id[3] === "file" || id[3] === "workspace")) id = id[4];
if (id.length > 5 && (id[4] === "file" || id[4] === "workspace")) id = id[5];
return this.loadWorkspaces().then(function(workspaces) {
var loc = "";
workspaces.some(function(workspace) {
if (workspace.Id === id) {
loc = workspace.Location;
return true;
}
});
return this.loadWorkspace(loc);
}.bind(this));
},
createProject: function(url, projectName, serverPath, create) {
throw new Error("Not supported"); //$NON-NLS-0$
Expand Down
Expand Up @@ -208,8 +208,8 @@ define([
}
};

GitRepositoryExplorer.prototype.setDefaultPath = function(defaultPath){
this.defaultPath = defaultPath;
GitRepositoryExplorer.prototype.setWorkspace = function(workspace){
this.workspace = workspace;
};

GitRepositoryExplorer.prototype.changedItem = function() {
Expand All @@ -227,15 +227,11 @@ define([
}
var pageParams = PageUtil.matchResourceParameters();
var selection = pageParams.resource;
var path = this.defaultPath;
var relativePath = mFileUtils.makeRelative(path);

//NOTE: require.toURL needs special logic here to handle "gitapi/clone"
var gitapiCloneUrl = require.toUrl("gitapi/clone._"); //$NON-NLS-0$
gitapiCloneUrl = gitapiCloneUrl.substring(0, gitapiCloneUrl.length-2);
this.defaultPath = require.toUrl("/workspace/" + this.workspace.Id || ""); //$NON-NLS-0$

var location = relativePath[0] === "/" ? gitapiCloneUrl + relativePath : gitapiCloneUrl + "/" + relativePath; //$NON-NLS-1$ //$NON-NLS-0$
this.display(location, selection, processURLs);
var reposLocation = require.toUrl("gitapi/clone/workspace/" + this.workspace.Id || ""); //$NON-NLS-0$
this.display(reposLocation, selection, processURLs);
};

GitRepositoryExplorer.prototype.destroyRepositories = function() {
Expand Down
4 changes: 2 additions & 2 deletions bundles/org.eclipse.orion.client.ui/web/compare/compare.js
Expand Up @@ -77,8 +77,8 @@ define(['orion/browserCompatibility', 'orion/bootstrap', 'orion/Deferred', 'orio
});
} else {
resolveFileNames = diffProvider.getComplexFileURL(compareParams.resource).then(function (json){
if(json.New) {
return Deferred.all([fileClient.read(json.New, true)],
if(json.New || json.NewLocation) {
return Deferred.all([fileClient.read(json.New || json.NewLocation, true)],
function(/*error*/) {
startWithFileNames(null, compareParams);
}).then( function(metadatas) {
Expand Down
19 changes: 4 additions & 15 deletions bundles/org.eclipse.orion.client.ui/web/css/layout_common.css
Expand Up @@ -717,32 +717,21 @@ and (max-device-width : 1024px) {
}

.menuScrollButton {
background-color: rgba(0,0,0,0) !important;
color: #3B4B54 !important;
background: linear-gradient(rgba(1,1,1,.2), white) !important;
color: black !important;
display: none;
cursor: pointer;
height: 24px;
opacity: 0.5;
height: 20px;
position: absolute;
outline: none; /* these button must not take focus*/
width: 100%;
max-width: 125px;
z-index: 200;
}

.menuTopScrollButton {
-webkit-transform: rotate(180deg); /* Safari */
transform: rotate(180deg);
}

button.menuScrollButton.menuTopScrollButton.core-sprite-openarrow::before {
font-size: larger;
padding-right: 90px;
}

button.menuScrollButton.menuBottomScrollButton.core-sprite-openarrow::before {
font-size: larger;
padding-left: 90px;
}
/* End of dropdown menu scroll buttons */

/* icon links */
Expand Down

0 comments on commit 4e97242

Please sign in to comment.