Skip to content

Commit

Permalink
Implement new format workspace key {namespace}/{workspaceName} or {wo…
Browse files Browse the repository at this point in the history
…rkspaceId} (eclipse-che#4073)

* CHE-4061 Rework workspace key to new format where namespace can contain `/` symbols

Impemented new format workspace key:
1. {workspaceId}
2. {namespace}/{workspaceName}
Note that namespace can contains '/' symbol so workspace key can looks like {namespace_part1}/{namespace_part2}/.../{namespace_partN}/{workspaceName}.

* CHE-4061 Adapt IDE to work with workspace key in new format

According to new workspace key format changes URL
to IDE looks like {HOST}/namespace/namespace_part_2/workspaceName


* CHE-4061 Adapt dashboard to work with workspace key in new format

According to new workspace key format changes URL to
dashboard workspace details team looks like
{HOST}/dashboard/#/workspace/namespace/namespace_part_2/workspaceName
  • Loading branch information
Sergii Leschenko authored Feb 10, 2017
1 parent f0b042d commit 9f60c6f
Show file tree
Hide file tree
Showing 24 changed files with 296 additions and 337 deletions.
2 changes: 1 addition & 1 deletion dashboard/src/app/ide/ide-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class IdeConfig {
// config routes
register.app.config(function ($routeProvider) {
$routeProvider.accessWhen('/ide', ideProvider)
.accessWhen('/ide/:namespace/:workspaceName', ideProvider);
.accessWhen('/ide/:namespace*/:workspaceName', ideProvider);

});
}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/app/projects/projects-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class ProjectsConfig {

// config routes
register.app.config(function ($routeProvider) {
$routeProvider.accessWhen('/project/:namespace/:workspaceName/:projectName', {
$routeProvider.accessWhen('/project/:namespace*/:workspaceName/:projectName', {
title: (params) => {return params.workspaceName + ' | ' + params.projectName},
templateUrl: 'app/projects/project-details/project-details.html',
controller: 'ProjectDetailsController',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class WorkspaceDetailsController {
if (this.cheWorkspace.getWorkspaceByName(this.namespace, this.workspaceName)) {
defer.resolve();
} else {
this.cheWorkspace.fetchWorkspaceDetails(this.namespace + ':' + this.workspaceName).then(() => {
this.cheWorkspace.fetchWorkspaceDetails(this.namespace + '/' + this.workspaceName).then(() => {
defer.resolve();
}, (error: any) => {
if (error.status === 304) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class WorkspaceDetailsProjectsCtrl {

this.namespace = $route.current.params.namespace;
this.workspaceName = $route.current.params.workspaceName;
this.workspaceKey = this.namespace + ':' + this.workspaceName;
this.workspaceKey = this.namespace + '/' + this.workspaceName;

let preferences = cheAPI.getPreferences().getPreferences();

Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/app/workspaces/workspaces-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ export class WorkspacesConfig {
controller: 'ListWorkspacesCtrl',
controllerAs: 'listWorkspacesCtrl'
})
.accessWhen('/workspace/:namespace/:workspaceName', locationProvider)
.accessWhen('/workspace/:namespace/:workspaceName/:page', locationProvider)
.accessWhen('/workspace/:namespace*/:workspaceName', locationProvider)
.accessWhen('/workspace/:namespace*/:workspaceName/:page', locationProvider)
.accessWhen('/create-workspace', {
title: 'New Workspace',
templateUrl: 'app/workspaces/workspace-details/workspace-details.html',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ public interface WorkspaceServiceClient {
/**
* Gets users workspace by key.
*
* @param wsId
* workspace ID
* @param key
* composite key can be just workspace ID or in the namespace/workspace_name form
* @return a promise that resolves to the {@link WorkspaceDto}, or rejects with an error
* @see WorkspaceService#getByKey(String)
*/
Promise<WorkspaceDto> getWorkspace(String wsId);
Promise<WorkspaceDto> getWorkspace(String key);

/**
* Gets workspace by namespace and name
*
* @param namespace
* namespace
* @param workspaceName
* @param workspaceName
* workspace name
* @return a promise that resolves to the {@link WorkspaceDto}, or rejects with an error
* @see WorkspaceService#getByKey(String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public class AppContextImpl implements AppContext,

private static final Project[] NO_PROJECTS = {};

private final BrowserQueryFieldRenderer browserQueryFieldRenderer;
private final List<String> projectsInImport;
private final QueryParameters queryParameters;
private final List<String> projectsInImport;

private Workspace usersWorkspace;
private CurrentUser currentUser;
Expand All @@ -106,12 +106,12 @@ public class AppContextImpl implements AppContext,

@Inject
public AppContextImpl(EventBus eventBus,
BrowserQueryFieldRenderer browserQueryFieldRenderer,
QueryParameters queryParameters,
ResourceManager.ResourceManagerFactory resourceManagerFactory,
Provider<EditorAgent> editorAgentProvider,
Provider<AppStateManager> appStateManager) {
this.eventBus = eventBus;
this.browserQueryFieldRenderer = browserQueryFieldRenderer;
this.queryParameters = queryParameters;
this.resourceManagerFactory = resourceManagerFactory;
this.editorAgentProvider = editorAgentProvider;
this.appStateManager = appStateManager;
Expand Down Expand Up @@ -206,8 +206,6 @@ public void initResourceManager(final Callback<ResourceManager, Exception> callb
callback.onFailure(new NullPointerException("Dev machine is not initialized"));
}

browserQueryFieldRenderer.setProjectName("");

if (projects != null) {
for (Project project : projects) {
eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(project, REMOVED)));
Expand Down Expand Up @@ -325,8 +323,6 @@ public void onSelectionChanged(SelectionChangedEvent event) {
return;
}

browserQueryFieldRenderer.setProjectName("");

currentResource = null;
currentResources = null;

Expand Down Expand Up @@ -464,7 +460,6 @@ public void onWorkspaceStopped(WorkspaceStoppedEvent event) {
appStateManager.get().persistWorkspaceState(getWorkspaceId()).then(new Operation<Void>() {
@Override
public void apply(Void arg) throws OperationException {
browserQueryFieldRenderer.setProjectName("");
for (Project project : projects) {
eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(project, REMOVED)));
}
Expand All @@ -489,7 +484,7 @@ public void onWindowClosed(WindowActionEvent event) {

@Override
public String getMasterEndpoint() {
String fromUrl = this.browserQueryFieldRenderer.getParameterFromURLByName("master");
String fromUrl = queryParameters.getByName("master");
if(fromUrl == null || fromUrl.isEmpty())
return masterFromIDEConfig();
else
Expand All @@ -498,7 +493,7 @@ public String getMasterEndpoint() {

@Override
public String getDevAgentEndpoint() {
String fromUrl = this.browserQueryFieldRenderer.getParameterFromURLByName("agent");
String fromUrl = queryParameters.getByName("agent");
if(fromUrl == null || fromUrl.isEmpty())
return runtime.getDevMachine().getWsAgentBaseUrl();
else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.context;

import com.google.gwt.user.client.Window;
import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.eclipse.che.ide.api.ProductInfoDataProvider;

/**
* Helps to update address and extract information from current address.
*
* @author Alexander Andrienko
* @author Sergii Leschenko
*/
@Singleton
public class BrowserAddress {
private static final int NAMESPACE_START_SEGMENT = 1;

private final ProductInfoDataProvider productInfoDataProvider;

@Inject
public BrowserAddress(ProductInfoDataProvider productInfoDataProvider) {
this.productInfoDataProvider = productInfoDataProvider;
}

/**
* Updates browser's address along with tab title in accordance to current running workspace.
*
* @param namespace
* namespace of workspace
* @param workspaceName
* name of the current running workspace. Can be null or empty if workspace was stopped.
*/
public void setAddress(String namespace, String workspaceName) {
String browserUrl = Window.Location.getPath();
int currentSlashIndex = 0;
int currentSlashNumber = 0;
while (currentSlashNumber < NAMESPACE_START_SEGMENT) {
currentSlashIndex = browserUrl.indexOf('/', currentSlashIndex);
currentSlashNumber++;
}

String baseUrl = browserUrl.substring(0, currentSlashIndex) + "/" + namespace + "/" + workspaceName;

String title;
if (workspaceName == null || workspaceName.isEmpty()) {
title = productInfoDataProvider.getDocumentTitle();
} else {
title = productInfoDataProvider.getDocumentTitle(workspaceName);
}
doSetAddress(baseUrl, title);
}

/**
* Returns workspace name from current address
* or empty string when it is undefined.
*/
public String getWorkspaceName() {
String workspaceKey = getWorkspaceKey();
String[] split = workspaceKey.split("/", 2);
if (split.length != 2) {
return "";
}
return workspaceKey.substring(workspaceKey.lastIndexOf("/") + 1);
}

/**
* Returns workspace key from current address
* or empty string when it is undefined.
*
* @see org.eclipse.che.ide.api.workspace.WorkspaceServiceClient#getWorkspace(String)
*/
public String getWorkspaceKey() {
String browserUrl = Window.Location.getPath();
String[] urlParts = browserUrl.split("/", NAMESPACE_START_SEGMENT + 1);
if (urlParts.length < NAMESPACE_START_SEGMENT) {
return "";
} else {
return urlParts[NAMESPACE_START_SEGMENT];
}
}

private native void doSetAddress(String url, String title) /*-{
try {
var window = $wnd;
if (!window["_history_relocation_id"]) {
window["_history_relocation_id"] = 0;
}
window.top.document.title = title;
window.history.pushState(window["_history_relocation_id"], window.top.document.title, url);
window["_history_relocation_id"]++;
} catch (e) {
console.log(e.message);
}
}-*/;
}
Loading

0 comments on commit 9f60c6f

Please sign in to comment.