-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aho Henri
committed
Dec 20, 2023
1 parent
7d7e838
commit 3a05363
Showing
17 changed files
with
630 additions
and
1 deletion.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
bundles/framework/publisher2/handler/AdditionalToolsHandler.js
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,37 @@ | ||
import { controllerMixin } from 'oskari-ui/util'; | ||
import { ToolPanelHandler } from './ToolPanelHandler'; | ||
import '../tools/SwipeTool.js'; | ||
|
||
class UIHandler extends ToolPanelHandler { | ||
constructor (tools, sandbox, consumer) { | ||
// ToolPanelHandler adds tools to state so we can reference it here | ||
super(tools, consumer); | ||
this.sandbox = sandbox; | ||
this.updateState({ | ||
tools: [] | ||
}); | ||
}; | ||
|
||
init (data) { | ||
const hasTools = super.init(data); | ||
return hasTools; | ||
} | ||
|
||
stop () { | ||
const { tools } = this.getState(); | ||
tools.forEach(tool => { | ||
try { | ||
tool.publisherTool.stop(); | ||
} catch (e) { | ||
Oskari.log('Publisher.AdditionalToolsHandler') | ||
.error('Error stopping publisher tool:', tool.getTool().id); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
const wrapped = controllerMixin(UIHandler, [ | ||
'setToolEnabled' | ||
]); | ||
|
||
export { wrapped as AdditionalToolsHandler }; |
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,50 @@ | ||
import { StateHandler, controllerMixin } from 'oskari-ui/util'; | ||
|
||
class UIHandler extends StateHandler { | ||
constructor (tool) { | ||
super(); | ||
this.tool = tool; | ||
this.sandbox = tool.getSandbox(); | ||
this.setState({ | ||
autoStart: false, | ||
hideUI: false | ||
}); | ||
}; | ||
init (pluginConfig) { | ||
this.updateState({ | ||
...pluginConfig | ||
}); | ||
} | ||
|
||
clearState () { | ||
// plugin is created again on startup, so it's state doesn't need to be cleare | ||
this.setState({ | ||
autoStart: false, | ||
hideUI: false | ||
}); | ||
} | ||
|
||
setAutoStart (value) { | ||
this.tool.getPlugin().setAutoStart(value); | ||
this.updateConfig2State(); | ||
} | ||
|
||
setHideUI (value) { | ||
this.tool.getPlugin().setHideUI(value); | ||
this.updateConfig2State(); | ||
} | ||
|
||
updateConfig2State () { | ||
const newConfig = this.tool?.getPlugin()?.getConfig() || {}; | ||
this.updateState({ | ||
...newConfig | ||
}); | ||
} | ||
} | ||
|
||
const wrapped = controllerMixin(UIHandler, [ | ||
'setAutoStart', | ||
'setHideUI' | ||
]); | ||
|
||
export { wrapped as SwipeToolhandler }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* @class Oskari.mapframework.publisher.tool.AdditionalTool | ||
* This clazz documentates publisher2 react tool definations. | ||
* Protocol/interface declaration for Publisher2 react tool. | ||
* Provides an interface for bundles to add react tools to publisher2. | ||
*/ | ||
|
||
Oskari.clazz.define('Oskari.mapframework.publisher.tool.AdditionalTool', | ||
function (sandbox, mapmodule, localization) { | ||
this._log = Oskari.log('publisher.AdditionalTool'); | ||
// sandbox | ||
this.__sandbox = sandbox; | ||
// mapmodule | ||
this.__mapmodule = mapmodule; | ||
// localization | ||
this.__loc = localization; | ||
// plugin | ||
this.__plugin = null; | ||
}, { | ||
group: 'additional', | ||
/** | ||
* Initialize tool | ||
* Override | ||
* @method init | ||
* @param pdata Publisher data. Includes tools' getValues return values | ||
* @public | ||
*/ | ||
init: function (pdata) { | ||
this._log.error('Override init function for Tool ' + this.getTool().id); | ||
}, | ||
/** | ||
* Get tool object. | ||
* @method getComponent | ||
* @private | ||
* | ||
* @returns {Object} | ||
*/ | ||
getComponent: function () { | ||
this._log.error('Override getComponent function for Tool ' + this.getTool().id); | ||
}, | ||
/** | ||
* Get name. | ||
* @method getName | ||
* @public | ||
* | ||
* @returns {String} tool name | ||
*/ | ||
getName: function () { | ||
|
||
}, | ||
/** | ||
* Is displayed. | ||
* @method isDisplayed | ||
* @public | ||
* | ||
* @returns {Boolean} is tool displayed | ||
*/ | ||
isDisplayed: function () { | ||
return true; | ||
}, | ||
/** | ||
* Get values. | ||
* @method getValues | ||
* @public | ||
* | ||
* @returns {Object} tool value object | ||
*/ | ||
getValues: function () { | ||
return null; | ||
} | ||
}, { | ||
'protocol': ['Oskari.mapframework.publisher.AdditionalTool'] | ||
}); |
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,60 @@ | ||
import { AbstractPublisherTool } from './AbstractPublisherTool'; | ||
import { SwipeToolhandler } from '../handler/SwipeToolHandler'; | ||
import { SwipeToolComponent } from '../view/swipe/SwipeToolComponent'; | ||
|
||
export const SWIPE_ID = 'Oskari.mapframework.bundle.layerswipe.plugin.LayerSwipePlugin'; | ||
|
||
class SwipeTool extends AbstractPublisherTool { | ||
constructor (...args) { | ||
super(...args); | ||
this.index = 5; | ||
this.group = 'additional'; | ||
this.handler = new SwipeToolhandler(this); | ||
} | ||
getTool () { | ||
return { | ||
id: SWIPE_ID, | ||
title: Oskari.getMsg('Publisher2', 'BasicView.maptools.swipe.label'), | ||
config: this.state.pluginConfig || {} | ||
}; | ||
} | ||
getComponent () { | ||
return { | ||
component: SwipeToolComponent, | ||
handler: this.handler | ||
}; | ||
} | ||
init (data) { | ||
super.init(data); | ||
// restore state to handler -> passing init data to it | ||
this.handler.init(this.getTool().config); | ||
} | ||
getValues () { | ||
if (!this.isEnabled()) { | ||
return null; | ||
} | ||
const pluginConfig = this.getPlugin().getConfig(); | ||
const value = { | ||
configuration: { | ||
mapfull: { | ||
conf: { | ||
plugins: [{ id: this.getTool().id, config: pluginConfig }] | ||
} | ||
} | ||
} | ||
}; | ||
return value; | ||
} | ||
stop () { | ||
super.stop(); | ||
this.handler.clearState(); | ||
} | ||
} | ||
|
||
// Attach protocol to make this discoverable by Oskari publisher | ||
Oskari.clazz.defineES('Oskari.publisher.SwipeTool', | ||
SwipeTool, | ||
{ | ||
'protocol': ['Oskari.mapframework.publisher.AdditionalTool'] | ||
} | ||
); |
Oops, something went wrong.