diff --git a/src/js_tests/wirecloud/coreSpec.js b/src/js_tests/wirecloud/coreSpec.js index 78014111e..107f74732 100644 --- a/src/js_tests/wirecloud/coreSpec.js +++ b/src/js_tests/wirecloud/coreSpec.js @@ -52,7 +52,8 @@ name: "home", title: "Home", contextManager: { - addCallback: jasmine.createSpy() + addCallback: jasmine.createSpy(), + modify: jasmine.createSpy() } }; Wirecloud.workspaceInstances = {1: initworkspace}; @@ -170,7 +171,8 @@ workspace_name: "home", workspace_title: "Home", view: "workspace", - tab: "MyTab" + tab: "MyTab", + params: {} }); expect(Wirecloud.activeWorkspace).toBe(initworkspace); expect(workspace).toBe(initworkspace); @@ -195,7 +197,8 @@ workspace_owner: "wirecloud", workspace_name: "home", workspace_title: "Home", - view: "workspace" + view: "workspace", + params: {} }); expect(Wirecloud.activeWorkspace).toBe(initworkspace); expect(workspace).toBe(initworkspace); diff --git a/src/js_tests/wirecloud/ui/WiringEditorSpec.js b/src/js_tests/wirecloud/ui/WiringEditorSpec.js index 482eb9768..15601c880 100644 --- a/src/js_tests/wirecloud/ui/WiringEditorSpec.js +++ b/src/js_tests/wirecloud/ui/WiringEditorSpec.js @@ -1687,7 +1687,10 @@ spyOn(Wirecloud.HistoryManager, "getCurrentState").and.returnValue({ "workspace_owner": "workspace_owner", "workspace_name": "workspace_name", - "view": "workspace" + "view": "workspace", + "params": { + "testParam": "testValue" + } }); const editor = new ns.WiringEditor(1); @@ -1696,7 +1699,10 @@ expect(state).toEqual({ "workspace_owner": "workspace_owner", "workspace_name": "workspace_name", - "view": "wiring" + "view": "wiring", + "params": { + "testParam": "testValue" + } }); expect(Wirecloud.HistoryManager.getCurrentState).toHaveBeenCalledWith(); }); diff --git a/src/js_tests/wirecloud/ui/WorkspaceViewSpec.js b/src/js_tests/wirecloud/ui/WorkspaceViewSpec.js index 50a87f812..3c95525e2 100644 --- a/src/js_tests/wirecloud/ui/WorkspaceViewSpec.js +++ b/src/js_tests/wirecloud/ui/WorkspaceViewSpec.js @@ -1015,10 +1015,13 @@ view.onHistoryChange({ workspace_owner: "user", - workspace_name: "dashboard" + workspace_name: "dashboard", + params: { + test: "test" + } }); - expect(Wirecloud.changeActiveWorkspace).toHaveBeenCalledWith(workspace, {initialtab: undefined, history: 'ignore'}); + expect(Wirecloud.changeActiveWorkspace).toHaveBeenCalledWith(workspace, {initialtab: undefined, history: 'ignore', params: {test: "test"}}); }); it("should handle tab changes", () => { diff --git a/src/wirecloud/platform/core/plugins.py b/src/wirecloud/platform/core/plugins.py index 0c72e3edc..44ea57848 100644 --- a/src/wirecloud/platform/core/plugins.py +++ b/src/wirecloud/platform/core/plugins.py @@ -395,7 +395,11 @@ def get_workspace_context_definitions(self): 'longdescription': { 'label': _('Long description'), 'description': _("Detailed workspace's description. This description can contain formatting."), - } + }, + "params": { + "description": _("Dictionary with the parameters of the workspace"), + "label": _("Params"), + }, } def get_workspace_preferences(self): diff --git a/src/wirecloud/platform/static/js/wirecloud/HistoryManager.js b/src/wirecloud/platform/static/js/wirecloud/HistoryManager.js index 87a292181..54b6fb95a 100644 --- a/src/wirecloud/platform/static/js/wirecloud/HistoryManager.js +++ b/src/wirecloud/platform/static/js/wirecloud/HistoryManager.js @@ -50,6 +50,9 @@ data.title = document.title; } for (const key in data) { + if (typeof data[key] === 'object') { + continue; + } data[key] = "" + data[key]; } return data; @@ -66,11 +69,17 @@ url.search = window.location.search; for (key in data) { - if (['workspace_name', 'workspace_owner', 'workspace_title', 'tab_id', 'title'].indexOf(key) !== -1) { + if (['workspace_name', 'workspace_owner', 'workspace_title', 'tab_id', 'title', 'params'].indexOf(key) !== -1) { continue; } hash += '&' + encodeURIComponent(key) + '=' + encodeURIComponent(data[key]); } + if ("params" in data) { + for (key in data.params) { + hash += '&' + encodeURIComponent(key) + '=' + encodeURIComponent(data.params[key]); + } + } + url.hash = '#' + hash.substr(1); return url; diff --git a/src/wirecloud/platform/static/js/wirecloud/core.js b/src/wirecloud/platform/static/js/wirecloud/core.js index 9753f4d9d..8fb267cf9 100644 --- a/src/wirecloud/platform/static/js/wirecloud/core.js +++ b/src/wirecloud/platform/static/js/wirecloud/core.js @@ -50,6 +50,30 @@ }); }; + const get_hash_parameters = function get_hash_parameters() { + + const hash = window.location.hash; + const hash_parameters = {}; + + if (hash.length > 1) { + hash.substring(1).split('&').forEach(function (param) { + const parts = param.split('='); + hash_parameters[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]); + }); + } + + if ('view' in hash_parameters) { + delete hash_parameters.view; + } + + if ('tab' in hash_parameters) { + delete hash_parameters.tab; + } + + return hash_parameters; + + }; + const switch_active_workspace = function switch_active_workspace(options, workspace) { return new Wirecloud.Task(gettext("Switching active workspace"), (resolve, reject) => { @@ -58,9 +82,14 @@ workspace_owner: workspace.owner, workspace_name: workspace.name, workspace_title: workspace.title, - view: "workspace" + view: "workspace", + params: {} }; + if ('params' in options) { + state.params = options.params; + } + if (options.initialtab != null) { state.tab = options.initialtab; } @@ -73,6 +102,10 @@ Wirecloud.HistoryManager.replaceState(state); } + workspace.contextManager.modify({ + params: state.params + }); + if (this.activeWorkspace) { this.activeWorkspace.unload(); this.activeWorkspace = null; @@ -316,7 +349,8 @@ name: state.workspace_name }, { initialtab: state.tab, - history: "replace" + history: "replace", + params: get_hash_parameters() } ); }, (error) => { diff --git a/src/wirecloud/platform/static/js/wirecloud/ui/MarketplaceView.js b/src/wirecloud/platform/static/js/wirecloud/ui/MarketplaceView.js index 41f6964b8..51af1f6f2 100644 --- a/src/wirecloud/platform/static/js/wirecloud/ui/MarketplaceView.js +++ b/src/wirecloud/platform/static/js/wirecloud/ui/MarketplaceView.js @@ -192,7 +192,8 @@ const data = { workspace_owner: currentState.workspace_owner, workspace_name: currentState.workspace_name, - view: 'marketplace' + view: 'marketplace', + params: currentState.params }; if (this.loading === false && this.error === false && this.alternatives.getCurrentAlternative() !== this.emptyAlternative) { diff --git a/src/wirecloud/platform/static/js/wirecloud/ui/MyResourcesView.js b/src/wirecloud/platform/static/js/wirecloud/ui/MyResourcesView.js index 96abac576..d15cb5ccd 100644 --- a/src/wirecloud/platform/static/js/wirecloud/ui/MyResourcesView.js +++ b/src/wirecloud/platform/static/js/wirecloud/ui/MyResourcesView.js @@ -102,7 +102,8 @@ workspace_owner: currentState.workspace_owner, workspace_name: currentState.workspace_name, view: 'myresources', - subview: 'search' + subview: 'search', + params: currentState.params }; const subview = this.alternatives.getCurrentAlternative(); diff --git a/src/wirecloud/platform/static/js/wirecloud/ui/WiringEditor.js b/src/wirecloud/platform/static/js/wirecloud/ui/WiringEditor.js index b2e620bcd..2557b9516 100644 --- a/src/wirecloud/platform/static/js/wirecloud/ui/WiringEditor.js +++ b/src/wirecloud/platform/static/js/wirecloud/ui/WiringEditor.js @@ -760,11 +760,11 @@ Wirecloud.ui = Wirecloud.ui || {}; buildStateData() { const currentState = Wirecloud.HistoryManager.getCurrentState(); - return { workspace_owner: currentState.workspace_owner, workspace_name: currentState.workspace_name, - view: this.view_name + view: this.view_name, + params: currentState.params }; } diff --git a/src/wirecloud/platform/static/js/wirecloud/ui/WorkspaceView.js b/src/wirecloud/platform/static/js/wirecloud/ui/WorkspaceView.js index 882a675ed..374786adb 100644 --- a/src/wirecloud/platform/static/js/wirecloud/ui/WorkspaceView.js +++ b/src/wirecloud/platform/static/js/wirecloud/ui/WorkspaceView.js @@ -449,7 +449,8 @@ workspace_owner: currentState.workspace_owner, workspace_name: currentState.workspace_name, workspace_title: currentState.workspace_title, - view: 'workspace' + view: 'workspace', + params: currentState.params }; } @@ -540,7 +541,7 @@ this.layout.slideOut().content.clear().appendChild(alert_msg); Wirecloud.dispatchEvent('viewcontextchanged'); } else if (Wirecloud.activeWorkspace == null || (nextWorkspace.id !== Wirecloud.activeWorkspace.id)) { - Wirecloud.changeActiveWorkspace(nextWorkspace, {initialtab: newState.tab, history: 'ignore'}); + Wirecloud.changeActiveWorkspace(nextWorkspace, {initialtab: newState.tab, history: 'ignore', params: newState.params}); } else if (newState.tab != null) { target_tab = this.findTab(newState.tab_id); this.notebook.goToTab(target_tab);