source: TFP-WebServer/MarkersMod/WebMod/bundle.js@ 501

Last change on this file since 501 was 487, checked in by alloc, 6 months ago

1.1.0.1 Release for V 1.0

File size: 6.6 KB
RevLine 
[485]1/******/ (() => { // webpackBootstrap
2/******/ "use strict";
3var __webpack_exports__ = {};
4
5;// CONCATENATED MODULE: ../mods/markers/mapComponent.js
6/* eslint-disable react/prop-types */
7
8function MarkersComponent({
9 map,
10 React,
11 HTTP,
12 checkPermission,
13 useQuery,
14 LayerGroup,
15 LayersControl,
16 Marker,
[487]17 Tooltip,
[485]18 HideBasedOnAuth,
19 L
20}) {
21 const [markers, setMarkers] = React.useState([]);
22 const {
23 data
24 } = useQuery('markers', async () => HTTP.get('/api/markers'));
25 React.useEffect(() => {
26 async function getMarkers() {
27 if (checkPermission({
28 module: 'webapi.Markers',
29 method: 'GET'
30 })) {
31 const markerComponents = data.map(marker => {
32 const {
33 x,
34 y,
35 icon = 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/11/Blue_question_mark_icon.svg/1200px-Blue_question_mark_icon.svg.png'
36 } = marker;
37 const iconComponent = L.icon({
38 iconSize: [25, 25],
39 iconUrl: icon
40 });
41 return /*#__PURE__*/React.createElement(Marker, {
42 key: marker.id,
43 icon: iconComponent,
44 position: {
45 lat: x,
46 lng: y
47 }
[487]48 }, /*#__PURE__*/React.createElement(Tooltip, null, marker.name));
[485]49 });
50 setMarkers(markerComponents);
51 }
52 }
53 getMarkers();
54 }, [data]);
55 return /*#__PURE__*/React.createElement(HideBasedOnAuth, {
56 requiredPermission: {
57 module: 'webapi.Markers',
58 method: 'GET'
59 }
60 }, /*#__PURE__*/React.createElement(LayersControl.Overlay, {
61 name: "Markers"
62 }, /*#__PURE__*/React.createElement(LayerGroup, null, markers)));
63}
64;// CONCATENATED MODULE: ../mods/markers/settings.js
65function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
66/* eslint-disable react/prop-types */
67
68function MarkersSettings({
69 React,
70 styled,
71 HTTP,
72 EditableTable,
73 FormElements,
74 TfpForm,
75 useForm,
76 useQuery,
77 useMutation,
78 checkPermission
79}) {
80 const {
81 register,
82 handleSubmit,
83 formState: {
84 errors
[487]85 },
86 setValue
[485]87 } = useForm();
88 const {
89 data,
90 refetch
91 } = useQuery('markers', async () => HTTP.get('/api/markers'));
92 const {
93 mutate: createMarker
94 } = useMutation('createMarker', data => HTTP.post('/api/markers', {
[487]95 name: data.name,
[485]96 x: parseInt(data.x, 10),
97 y: parseInt(data.y, 10)
98 }), {
99 onSuccess: () => refetch()
100 });
101 const {
102 mutate: deleteMarker
103 } = useMutation('deleteMarker', id => HTTP.delete(`/api/markers/${id}`), {
104 onSuccess: () => refetch()
105 });
106 const {
107 mutate: updateMarker
108 } = useMutation('updateMarker', data => HTTP.put(`/api/markers/${data.id}`, {
[487]109 name: data.name,
[485]110 x: parseInt(data.x, 10),
111 y: parseInt(data.y, 10),
112 icon: data.icon
113 }), {
114 onSuccess: () => refetch()
115 });
116 const canEditRows = checkPermission({
117 module: 'webapi.Markers',
118 method: 'PUT'
119 });
[487]120 const canDeleteRows = checkPermission({
121 module: 'webapi.Markers',
122 method: 'DELETE'
123 });
[485]124 const columnDef = [{
125 field: 'id',
126 filter: 'agTextColumnFilter',
[487]127 flex: 1
[485]128 }, {
[487]129 field: 'name',
130 filter: 'agTextColumnFilter',
131 flex: 1
132 }, {
[485]133 field: 'x',
134 filter: 'agNumberColumnFilter',
[487]135 flex: 0.25,
136 sort: 'asc'
[485]137 }, {
138 field: 'y',
139 filter: 'agNumberColumnFilter',
[487]140 flex: 0.25,
141 sort: 'asc'
[485]142 }, {
143 field: 'icon',
144 filter: 'agTextColumnFilter',
145 flex: 1
146 }];
[487]147 const Form = /*#__PURE__*/React.createElement(TfpForm, {
148 id: "markers-form",
149 error: errors
150 }, /*#__PURE__*/React.createElement(FormElements.StyledFormItem, null, /*#__PURE__*/React.createElement(FormElements.FormLabel, {
151 htmlFor: "input-id"
152 }, "ID"), /*#__PURE__*/React.createElement(FormElements.FormInput, _extends({
153 key: "id",
154 id: "input-id"
155 }, register('id'), {
156 disabled: true
157 }))), /*#__PURE__*/React.createElement(FormElements.StyledFormItem, null, /*#__PURE__*/React.createElement(FormElements.FormLabel, {
158 htmlFor: "input-name"
159 }, "Name"), /*#__PURE__*/React.createElement(FormElements.FormInput, _extends({
160 key: "name",
161 id: "input-name"
162 }, register('name')))), /*#__PURE__*/React.createElement(FormElements.StyledFormItem, null, /*#__PURE__*/React.createElement(FormElements.FormLabel, {
163 htmlFor: "input-x"
164 }, "X"), /*#__PURE__*/React.createElement(FormElements.FormInput, _extends({
165 key: "x",
166 id: "input-x"
167 }, register('x', {
168 required: true
169 })))), /*#__PURE__*/React.createElement(FormElements.StyledFormItem, null, /*#__PURE__*/React.createElement(FormElements.FormLabel, {
170 htmlFor: "input-y"
171 }, "Y"), /*#__PURE__*/React.createElement(FormElements.FormInput, _extends({
172 key: "y",
173 id: "input-y"
174 }, register('y', {
175 required: true
176 })))));
177 async function handleCreate(data) {
[485]178 if (!checkPermission({
179 module: 'webapi.Markers',
180 method: 'POST'
181 })) {
[487]182 return;
[485]183 }
[487]184 createMarker(data);
185 }
186 async function handleEdit(data) {
[485]187 if (!checkPermission({
188 module: 'webapi.Markers',
189 method: 'PUT'
190 })) {
191 return;
192 }
[487]193 updateMarker(data);
[485]194 }
195 async function cellDeleted(row) {
196 if (!checkPermission({
197 module: 'webapi.Markers',
198 method: 'DELETE'
199 })) {
200 return;
201 }
202 deleteMarker(row.id);
203 }
[487]204 const setDefaultValues = data => {
205 setValue('id', data.id);
206 setValue('name', data.name);
207 setValue('x', data.x);
208 setValue('y', data.y);
209 };
[485]210 return /*#__PURE__*/React.createElement("div", {
211 style: {
212 flexDirection: 'row',
213 height: '80vh'
214 }
[487]215 }, /*#__PURE__*/React.createElement(EditableTable, {
[485]216 columnDef: columnDef,
217 rowData: data,
218 reloadFn: refetch,
219 deleteRowFn: cellDeleted,
[487]220 canDeleteRows: canDeleteRows,
221 height: '90%',
222 editRowFn: handleSubmit(handleEdit),
223 editForm: Form,
224 setDefaultValues: setDefaultValues,
225 canEditRows: canEditRows,
226 canCreateRows: canEditRows,
227 createRowFn: handleSubmit(handleCreate)
[485]228 }));
229}
230;// CONCATENATED MODULE: ../mods/markers/index.js
231/* eslint-disable react/prop-types */
232
233
234const modId = 'TFP_MarkersExample';
235const Markers = {
236 about: `This mod manages markers on a Leaflet map.`,
237 routes: {},
238 settings: {
239 'Map markers': MarkersSettings
240 },
241 mapComponents: [MarkersComponent]
242};
243window[modId] = Markers;
244window.dispatchEvent(new Event(`mod:${modId}:ready`));
245/******/ })()
246;
Note: See TracBrowser for help on using the repository browser.