Skip to content

Commit

Permalink
reactify publisher toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
DenverCoder544 committed Nov 14, 2024
1 parent 585f1e5 commit 8725daa
Show file tree
Hide file tree
Showing 18 changed files with 220 additions and 196 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 @@ -68,7 +68,6 @@ Oskari.registerLocalization(
"TimeseriesControlPlugin": "Time series player",
"FeaturedataPlugin": "Feature data",
"GetInfoPlugin": "Feature query tool",
"PublisherToolbarPlugin": "Map tools",
"selectDrawLayer": "Select map layer",
"LayerSelectionPlugin": "Map layers menu",
"CoordinateToolPlugin": "Coordinate tool",
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 @@ -68,7 +68,6 @@ Oskari.registerLocalization(
"TimeseriesControlPlugin": "Aikasarjatoistin",
"FeaturedataPlugin": "Kohdetietotaulukko",
"GetInfoPlugin": "Kohdetietojen kyselytyökalu",
"PublisherToolbarPlugin": "Karttatyökalut",
"selectDrawLayer": "Valitse tallennustaso",
"LayerSelectionPlugin": "Karttatasovalikko",
"CoordinateToolPlugin": "Koordinaattityökalu",
Expand Down
1 change: 0 additions & 1 deletion bundles/framework/publisher2/resources/locale/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ Oskari.registerLocalization(
"TimeseriesControlPlugin": "Lecteur chronologique",
"FeaturedataPlugin": "Données de fonctionnalité",
"GetInfoPlugin": "Outil d'interrogation de fonctionnalité",
"PublisherToolbarPlugin": "Outils cartographiques",
"selectDrawLayer": "Sélectionner la couche cartographique",
"LayerSelectionPlugin": "Menu des couches cartographiques",
"CoordinateToolPlugin": "Coordonner l'outil",
Expand Down
1 change: 0 additions & 1 deletion bundles/framework/publisher2/resources/locale/is.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ Oskari.registerLocalization(
"tooltip": "Velja tiltæk kortatól. Athugaðu staðsetningu við forskoðun korts.",
"FeaturedataPlugin": "Fitjugögn",
"GetInfoPlugin": "Fyrirspurnatól fyrir fitjur",
"PublisherToolbarPlugin": "Kortatól",
"selectDrawLayer": "Velja kortalag",
"LayerSelectionPlugin": "Valmynd fyrir kortalög",
"CoordinateToolPlugin": "Hnitatól",
Expand Down
1 change: 0 additions & 1 deletion bundles/framework/publisher2/resources/locale/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ Oskari.registerLocalization(
"TimeseriesControlPlugin": "Временные ряды",
"FeaturedataPlugin": "Данные объекта",
"GetInfoPlugin": "Инструмент запроса объектов",
"PublisherToolbarPlugin": "Инструмент карты",
"selectDrawLayer": "Выбрать слой карты",
"LayerSelectionPlugin": "Меню слоев карты",
"CoordinateToolPlugin": "Инструмент координат",
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 @@ -68,7 +68,6 @@ Oskari.registerLocalization(
"TimeseriesControlPlugin": "Tidseriespelare",
"FeaturedataPlugin": "Objektuppgifter",
"GetInfoPlugin": "Frågverktyg för visande av objektuppgifter",
"PublisherToolbarPlugin": "Kartverktyg",
"selectDrawLayer": "Välj lager för nya funktioner",
"LayerSelectionPlugin": "Kartlagermeny",
"CoordinateToolPlugin": "Koordinatverktyg",
Expand Down
185 changes: 0 additions & 185 deletions bundles/framework/publisher2/tools/ToolbarTool.js

This file was deleted.

109 changes: 109 additions & 0 deletions bundles/mapping/mapmodule/publisher/toolbar/ToolbarTool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { AbstractPublisherTool } from '../../../../framework/publisher2/tools/AbstractPublisherTool';
import { ToolbarToolComponent } from './ToolbarToolComponent';
import { ToolbarToolHandler } from './ToolbarToolHandler';
class ToolbarTool extends AbstractPublisherTool {
constructor (...args) {
super(...args);
this.index = 1;
this.group = 'additional';
this.handler = new ToolbarToolHandler(this);
}

init (data) {
super.init(data);
const buttons = this.state?.pluginConfig?.buttons;
if (!buttons) {
return;
}

const handlerConfig = {
history_forward: false,
history_back: false,
measureline: false,
measurearea: false
};

const plugin = this.getPlugin();
buttons.forEach((key) => { handlerConfig[key] = true; plugin.addToolButton(key); });
this.handler.init(handlerConfig);
}

getTool () {
const state = this.handler.getState();
const buttons = Object.keys(state).filter((key) => !!state[key]);
return {
id: 'Oskari.mapframework.bundle.mapmodule.plugin.PublisherToolbarPlugin',
title: Oskari.getMsg('MapModule', 'publisherTools.PublisherToolbarPlugin.toolLabel'),
config: {
...(this.state.pluginConfig || {}),
toolbarId: 'PublisherToolbar',
buttons: buttons || {}
}
};
}

getComponent () {
return {
component: ToolbarToolComponent,
handler: this.handler
};
}

/**
* Get values.
* @method getValues
* @public
*
* @returns {Object} tool value object
*/
getValues () {
if (!this.isEnabled()) {
return null;
}

const buttons = [];
const state = this.handler.getState();
for (const toolName in state) {
if (state[toolName]) {
buttons.push(toolName);
}
}

const pluginConfig = this.getPlugin().getConfig();
pluginConfig.buttons = buttons;

const retValue = {
configuration: {
mapfull: {
conf: {
plugins: [{ id: this.getTool().id, config: pluginConfig }]
}
},
toolbar: {
conf: {
history: false,
basictools: false,
viewtools: false
}
}
}
};
return retValue;
}

hasActiveTools () {
const state = this.handler.getState();
return Object.keys(state)
.some(toolName => state[toolName] === true);
}
}

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

export { ToolbarTool };
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Message, Checkbox } from 'oskari-ui';
import styled from 'styled-components';

const Col = styled('div')`
display: flex;
flex-direction: column;
`;

export const ToolbarToolComponent = ({ state, controller }) => {
// eslint-disable-next-line camelcase
const { history_forward, history_back, measureline, measurearea } = state;
// eslint-disable-next-line camelcase
const history = (history_back || history_forward);
return <Col>
<Checkbox checked={history} onChange={evt => controller.historySelectionChanged(evt.target.checked)}>
<Message bundleKey={'Publisher2'} messageKey={'BasicView.maptools.toolbarToolNames.history'}/>
</Checkbox>
<Checkbox checked={measureline} onChange={evt => controller.selectionChanged('measureline', evt.target.checked)}>
<Message bundleKey={'Publisher2'} messageKey={'BasicView.maptools.toolbarToolNames.measureline'}/>
</Checkbox>
<Checkbox checked={measurearea} onChange={evt => controller.selectionChanged('measurearea', evt.target.checked)}>
<Message bundleKey={'Publisher2'} messageKey={'BasicView.maptools.toolbarToolNames.measurearea'}/>
</Checkbox>
</Col>;
};

ToolbarToolComponent.propTypes = {
state: PropTypes.object,
controller: PropTypes.object
};
Loading

0 comments on commit 8725daa

Please sign in to comment.