Skip to content

Commit 8e5ca61

Browse files
copy myplacesimport to new bundle and rename stuff and call new action route
1 parent 22f73f9 commit 8e5ca61

28 files changed

+2145
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { Message } from 'oskari-ui';
4+
import { Table, getSorterFor, ToolsContainer } from 'oskari-ui/components/Table';
5+
import { EditOutlined } from '@ant-design/icons';
6+
import { IconButton, DeleteButton } from 'oskari-ui/components/buttons';
7+
8+
const EDIT_ICON_STYLE = {
9+
fontSize: '16px'
10+
};
11+
12+
export const MyFeaturesList = ({ data = [], controller, loading }) => {
13+
const columnSettings = [
14+
{
15+
align: 'left',
16+
title: <Message messageKey='tab.grid.name' />,
17+
dataIndex: 'name',
18+
sorter: getSorterFor('name'),
19+
defaultSortOrder: 'ascend',
20+
render: (title, item) => {
21+
return (
22+
<a onClick={() => controller.openLayer(item.key)}>{title}</a>
23+
);
24+
}
25+
},
26+
{
27+
align: 'left',
28+
title: <Message messageKey='tab.grid.desc' />,
29+
dataIndex: 'desc',
30+
sorter: getSorterFor('description')
31+
},
32+
{
33+
align: 'left',
34+
title: <Message messageKey='tab.grid.source' />,
35+
dataIndex: 'source',
36+
sorter: getSorterFor('source')
37+
},
38+
{
39+
align: 'left',
40+
title: <Message messageKey='tab.grid.createDate' />,
41+
dataIndex: 'created',
42+
sorter: getSorterFor('created'),
43+
width: 135,
44+
render: title => Oskari.util.formatDate(title)
45+
},
46+
{
47+
align: 'left',
48+
title: <Message messageKey='tab.grid.actions' />,
49+
dataIndex: 'key',
50+
width: 100,
51+
render: (title, item) => {
52+
return (
53+
<ToolsContainer>
54+
<IconButton
55+
className='t_edit'
56+
title={<Message messageKey='tab.grid.edit' />}
57+
icon={<EditOutlined style={EDIT_ICON_STYLE} />}
58+
onClick={() => controller.editMyFeatures(item.key)}
59+
/>
60+
<DeleteButton
61+
type='icon'
62+
title={<Message messageKey='tab.confirmDeleteMsg' messageArgs={{ name: item.name }} />}
63+
onConfirm={() => controller.deleteMyFeature(item.key)}
64+
/>
65+
</ToolsContainer>
66+
);
67+
}
68+
}
69+
];
70+
71+
return (
72+
<Table
73+
columns={columnSettings}
74+
dataSource={data.map(item => ({
75+
key: item.getId(),
76+
created: item.getCreated(),
77+
...item.getLocaleValues()
78+
}))}
79+
pagination={false}
80+
loading={loading}
81+
/>
82+
);
83+
};
84+
85+
MyFeaturesList.propTypes = {
86+
data: PropTypes.arrayOf(PropTypes.object),
87+
controller: PropTypes.object.isRequired,
88+
loading: PropTypes.bool
89+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { MyFeaturesList } from './MyFeaturesList';
4+
import { LocaleProvider } from 'oskari-ui/util';
5+
6+
const BUNDLE_KEY = 'MyFeatures';
7+
8+
export const MyFeaturesTab = ({ controller, state }) => {
9+
return (
10+
<LocaleProvider value={{ bundleKey: BUNDLE_KEY }}>
11+
<MyFeaturesList
12+
controller={controller}
13+
data={state.data}
14+
loading={state.loading}
15+
/>
16+
</LocaleProvider>
17+
);
18+
};
19+
20+
MyFeaturesTab.propTypes = {
21+
controller: PropTypes.object.isRequired,
22+
state: PropTypes.object.isRequired
23+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export const BUNDLE_NAME = 'MyFeatures';
2+
export const LAYER_TYPE = 'userlayer';
3+
export const MAX_SIZE = 10;
4+
5+
export const TOOL = {
6+
NAME: 'import2',
7+
GROUP: 'myplaces',
8+
ICON: 'upload-material'
9+
};
10+
11+
export const FILE_INPUT_PROPS = {
12+
multiple: false,
13+
allowedTypes: ['application/zip', 'application/octet-stream', 'application/x-zip-compressed', 'multipart/x-zip'],
14+
allowedExtensions: ['zip']
15+
};
16+
17+
export const ERRORS = {
18+
GENERIC: 'generic',
19+
PARSER: 'parser_error',
20+
NO_SRS: 'unknown_projection',
21+
FORMAT: 'format_failure'
22+
};
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import { StateHandler, controllerMixin } from 'oskari-ui/util';
2+
import { showLayerForm } from '../view/LayerForm';
3+
import { MAX_SIZE, ERRORS } from '../constants';
4+
5+
class MyFeaturesHandler extends StateHandler {
6+
constructor (instance) {
7+
super();
8+
this.instance = instance;
9+
this.sandbox = Oskari.getSandbox();
10+
this.setState({
11+
data: [],
12+
loading: false
13+
});
14+
this.popupControls = null;
15+
this.loc = Oskari.getMsg.bind(null, 'MyFeatures');
16+
this.eventHandlers = this.createEventHandlers();
17+
this.layerMetaType = 'USERLAYER';
18+
this.refreshLayersList();
19+
};
20+
21+
popupCleanup () {
22+
if (this.popupControls) this.popupControls.close();
23+
this.popupControls = null;
24+
}
25+
26+
getName () {
27+
return 'MyFeaturesHandler';
28+
}
29+
30+
showLayerDialog (values) {
31+
const { id } = values;
32+
const isImport = !id;
33+
if (this.popupControls) {
34+
// already opened
35+
if (this.popupControls.id === id) {
36+
this.popupControls.bringToTop();
37+
return;
38+
}
39+
// remove previous popup
40+
this.popupCleanup();
41+
}
42+
const conf = {
43+
maxSize: this.getMaxSize(),
44+
unzippedMaxSize: this.getMaxSize() * 15,
45+
isImport
46+
};
47+
const onSuccess = () => this.popupCleanup();
48+
const onError = (error = ERRORS.GENERIC, values) => {
49+
if (this.popupControls) {
50+
this.popupControls.update(error, values);
51+
}
52+
};
53+
const save = values => {
54+
this.updateState({
55+
loading: true
56+
});
57+
this.instance.getService().submitMyFeatures(values, onSuccess, (err) => onError(err, values));
58+
};
59+
const update = values => {
60+
this.updateState({
61+
loading: true
62+
});
63+
this.instance.getService().updateMyFeatures(id, values, onSuccess, (err) => onError(err, values));
64+
};
65+
const onOk = isImport ? save : update;
66+
this.popupControls = showLayerForm(values, conf, onOk, () => this.popupCleanup());
67+
}
68+
69+
getMaxSize () {
70+
const confMax = this.instance.conf?.maxFileSizeMb;
71+
return isNaN(confMax) ? MAX_SIZE : parseInt(confMax);
72+
}
73+
74+
openLayer (id) {
75+
const addMLrequestBuilder = Oskari.requestBuilder('AddMapLayerRequest');
76+
const addMlRequest = addMLrequestBuilder(id, {
77+
zoomContent: true
78+
});
79+
this.sandbox.request(this.instance, addMlRequest);
80+
}
81+
82+
refreshLayersList () {
83+
this.updateState({
84+
loading: true
85+
});
86+
const layers = this.instance.getMapLayerService().getAllLayersByMetaType(this.layerMetaType);
87+
this.updateState({
88+
data: layers,
89+
loading: false
90+
});
91+
}
92+
93+
editMyFeature (id) {
94+
const layer = this.instance.getMapLayerService().findMapLayer(id);
95+
const values = {
96+
locale: layer.getLocale(),
97+
style: layer.getCurrentStyle().getFeatureStyle(),
98+
id
99+
};
100+
this.showLayerDialog(values);
101+
}
102+
103+
deleteMyFeature (id) {
104+
this.updateState({
105+
loading: true
106+
});
107+
this.instance.getService().deleteMyFeature(id);
108+
}
109+
110+
createEventHandlers () {
111+
const handlers = {
112+
MapLayerEvent: (event) => {
113+
const operation = event.getOperation();
114+
if (operation === 'add' || operation === 'update' || operation === 'remove') {
115+
this.refreshLayersList();
116+
}
117+
}
118+
};
119+
Object.getOwnPropertyNames(handlers).forEach(p => this.sandbox.registerForEventByName(this, p));
120+
return handlers;
121+
}
122+
123+
onEvent (e) {
124+
const handler = this.eventHandlers[e.getName()];
125+
if (!handler) {
126+
return;
127+
}
128+
129+
return handler.apply(this, [e]);
130+
}
131+
}
132+
133+
const wrapped = controllerMixin(MyFeaturesHandler, [
134+
'editMyFeature',
135+
'deleteMyFeature',
136+
'openLayer'
137+
]);
138+
139+
export { wrapped as MyFeaturesHandler };
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import './instance';
2+
3+
// register create function for bundleid
4+
Oskari.bundle('myfeatures', () => Oskari.clazz.create('Oskari.mapframework.bundle.myfeatures.MyFeaturesBundleInstance'));

0 commit comments

Comments
 (0)