Skip to content

Commit

Permalink
Merge pull request #2695 from DenverCoder544/publisher_tools_reactifi…
Browse files Browse the repository at this point in the history
…cation

Publisher tools reactification
  • Loading branch information
ZakarFin authored Oct 17, 2024
2 parents 4cfe26e + 699b753 commit 1810841
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 142 deletions.
1 change: 0 additions & 1 deletion bundles/framework/publisher2/resources/locale/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ Oskari.registerLocalization(
"label": "Tools",
"tooltip": "Select available map tools. Check a placement in the map preview.",
"AnnouncementsPlugin": "Announcements",
"ScaleBarPlugin": "Scale bar",
"TimeseriesControlPlugin": "Time series player",
"IndexMapPlugin": "Index map",
"PanButtons": "Move to the original map view",
Expand Down
1 change: 0 additions & 1 deletion bundles/framework/publisher2/resources/locale/fi.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ Oskari.registerLocalization(
"label": "Kartalla näytettävät työkalut",
"tooltip": "Valitse kartalla käytettävissä olevat työkalut. Tarkista asettelu esikatselukartasta.",
"AnnouncementsPlugin": "Ilmoitukset",
"ScaleBarPlugin": "Mittakaavajana",
"TimeseriesControlPlugin": "Aikasarjatoistin",
"IndexMapPlugin": "Indeksikartta",
"PanButtons": "Palaa alkutilaan",
Expand Down
1 change: 0 additions & 1 deletion bundles/framework/publisher2/resources/locale/sv.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ Oskari.registerLocalization(
"label": "Verktyg",
"tooltip": "Välj verktygen som visas på kartan. Du kan se deras placering på den förhandsvisade kartan.",
"AnnouncementsPlugin": "Aviseringar",
"ScaleBarPlugin": "Skalstock",
"TimeseriesControlPlugin": "Tidseriespelare",
"IndexMapPlugin": "Indexkarta",
"PanButtons": "Gå tillbaka till standardvyn för kartvyn",
Expand Down
25 changes: 22 additions & 3 deletions bundles/framework/publisher2/tools/AbstractPublisherTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export class AbstractPublisherTool {
config: this.state.pluginConfig || {}
};
}

// override when the tool has a component / handler
getComponent () {
return {};
};

// deprecated - new (React based) tools should use getTool().title instead
getTitle () {
const toolTitle = this.getTool().title;
Expand All @@ -45,9 +51,11 @@ export class AbstractPublisherTool {
}
return this.__loc[toolTitle];
}

getGroup () {
return this.group;
}

getIndex () {
return this.index;
}
Expand All @@ -57,11 +65,13 @@ export class AbstractPublisherTool {
// assume it's in mapfull bundles plugins array as most of the default tools are stored there
return data?.configuration?.mapfull?.conf?.plugins?.find(plugin => toolId === plugin.id);
}

storePluginConf (conf) {
this.state.pluginConfig = conf || {};
}

setEnabled (enabled) {
var tool = this.getTool();
const tool = this.getTool();

// state actually hasn't changed -> do nothing
if (this.isEnabled() === enabled) {
Expand All @@ -81,23 +91,25 @@ export class AbstractPublisherTool {
// Stop checks if we are already disabled so toggle the value after
this.state.enabled = enabled;
// notify publisher tool layout panel in case tool placement dragging needs to be toggled
var event = Oskari.eventBuilder('Publisher2.ToolEnabledChangedEvent')(this);
const event = Oskari.eventBuilder('Publisher2.ToolEnabledChangedEvent')(this);
this.getSandbox().notifyAll(event);
return true;
}

isEnabled () {
return !!this.state.enabled;
}

getValues () {
// override
return null;
}

stop () {
if (!this.isEnabled()) {
return;
}
var tool = this.getTool();
const tool = this.getTool();
if (tool.hasNoPlugin !== true) {
const plugin = this.getPlugin();
if (!plugin) {
Expand All @@ -110,6 +122,7 @@ export class AbstractPublisherTool {
this.__plugin = null;
}
}

/**
* Is displayed. We can use this to tell when tool is displayed.
* For example if stats layers are added to map when opening publisher we can tell at then this tool need to be shown (ShowStatsTableTool).
Expand All @@ -123,6 +136,7 @@ export class AbstractPublisherTool {
isDisplayed () {
return true;
}

/**
* Is this tool available.
* @method isDisabled
Expand All @@ -133,6 +147,7 @@ export class AbstractPublisherTool {
isDisabled (data) {
return false;
}

validate () {
// always valid by default
// could return false if there's something wrong that should require stopping the user from saving
Expand All @@ -142,15 +157,19 @@ export class AbstractPublisherTool {
getPlugin () {
return this.__plugin;
}

getSandbox () {
return this.__sandbox;
}

getMapmodule () {
return this.__mapmodule;
}

getAllowedLocations () {
return this.allowedLocations;
}

// old tools return jQuery object that renders the extra options for this tool
getExtraOptions () {
return null;
Expand Down
75 changes: 0 additions & 75 deletions bundles/framework/publisher2/tools/LogoTool.js

This file was deleted.

56 changes: 0 additions & 56 deletions bundles/framework/publisher2/tools/ScalebarTool.js

This file was deleted.

87 changes: 87 additions & 0 deletions bundles/mapping/mapmodule/plugin/logo/publisher/LogoTool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { AbstractPublisherTool } from '../../../../../framework/publisher2/tools/AbstractPublisherTool';

class LogoTool extends AbstractPublisherTool {
constructor (...args) {
super(...args);
this.index = 1;
this.group = 'additional';
this.config = null;
}

init (data) {
const plugin = this.findPluginFromInitData(data);
if (plugin) {
this.storePluginConf(plugin.config);
// when we enter publisher:
// restore saved location for plugin that is not stopped nor started
this.getPlugin().setLocation(plugin.config?.location?.classes);
}
}

getTool () {
return {
id: 'Oskari.mapframework.bundle.mapmodule.plugin.LogoPlugin',
title: 'LogoPlugin',
config: this.state.pluginConfig || {}
};
}

// not displayed on tool panels so user can't disable it
isDisplayed () {
return false;
}

getPlugin () {
// always use the instance on map, not a new copy
return this.getMapmodule().getPluginInstances('LogoPlugin');
}

// always enabled, use the instance that is on map
isEnabled () {
return true;
}

stop () {
// when we exit publisher:
// move plugin back to bottom left if it was dragged during publisher
this.getPlugin()?.setLocation('bottom left');
}

/**
* Get values.
* @method getValues
* @public
*
* @returns {Object} tool value object
*/
getValues () {
const plugin = this.getPlugin();
if (!plugin) {
return null;
}
return {
configuration: {
mapfull: {
conf: {
plugins: [{
id: this.getTool().id,
config: {
location: plugin.getConfig()?.location
}
}]
}
}
}
};
}
}

// Attach protocol to make this discoverable by Oskari publisher
Oskari.clazz.defineES('Oskari.publisher.LogoTool',
LogoTool,
{
protocol: ['Oskari.mapframework.publisher.Tool']
}
);

export { LogoTool };
Loading

0 comments on commit 1810841

Please sign in to comment.