forked from eclipse-che/che
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement new format workspace key {namespace}/{workspaceName} or {wo…
…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
Showing
24 changed files
with
296 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/context/BrowserAddress.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}-*/; | ||
} |
Oops, something went wrong.