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

Last change on this file since 485 was 485, checked in by alloc, 9 months ago

22.0.0.0 Commands release

  • Only A22 compatibility fix

22.0.0.0 MapRendering release (no code changes)

22.0.1.0 WebServer release

  • Updated to dashboard files 0.8.5
  • Added API 'EntityClass'
  • Changed API 'Command' default permissions
  • Added some A22 compatibility changes
  • Fixed some OpenAPI docs

22.0.1.0 MarkersMod release

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