| 1 | /******/ (() => { // webpackBootstrap
|
|---|
| 2 | /******/ "use strict";
|
|---|
| 3 | var __webpack_exports__ = {};
|
|---|
| 4 |
|
|---|
| 5 | ;// CONCATENATED MODULE: ../mods/markers/mapComponent.js
|
|---|
| 6 | /* eslint-disable react/prop-types */
|
|---|
| 7 |
|
|---|
| 8 | function MarkersComponent({
|
|---|
| 9 | map,
|
|---|
| 10 | React,
|
|---|
| 11 | HTTP,
|
|---|
| 12 | checkPermission,
|
|---|
| 13 | useQuery,
|
|---|
| 14 | LayerGroup,
|
|---|
| 15 | LayersControl,
|
|---|
| 16 | Marker,
|
|---|
| 17 | Tooltip,
|
|---|
| 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 | }
|
|---|
| 48 | }, /*#__PURE__*/React.createElement(Tooltip, null, marker.name));
|
|---|
| 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
|
|---|
| 65 | function _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 |
|
|---|
| 68 | function 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
|
|---|
| 85 | },
|
|---|
| 86 | setValue
|
|---|
| 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', {
|
|---|
| 95 | name: data.name,
|
|---|
| 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}`, {
|
|---|
| 109 | name: data.name,
|
|---|
| 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 | });
|
|---|
| 120 | const canDeleteRows = checkPermission({
|
|---|
| 121 | module: 'webapi.Markers',
|
|---|
| 122 | method: 'DELETE'
|
|---|
| 123 | });
|
|---|
| 124 | const columnDef = [{
|
|---|
| 125 | field: 'id',
|
|---|
| 126 | filter: 'agTextColumnFilter',
|
|---|
| 127 | flex: 1
|
|---|
| 128 | }, {
|
|---|
| 129 | field: 'name',
|
|---|
| 130 | filter: 'agTextColumnFilter',
|
|---|
| 131 | flex: 1
|
|---|
| 132 | }, {
|
|---|
| 133 | field: 'x',
|
|---|
| 134 | filter: 'agNumberColumnFilter',
|
|---|
| 135 | flex: 0.25,
|
|---|
| 136 | sort: 'asc'
|
|---|
| 137 | }, {
|
|---|
| 138 | field: 'y',
|
|---|
| 139 | filter: 'agNumberColumnFilter',
|
|---|
| 140 | flex: 0.25,
|
|---|
| 141 | sort: 'asc'
|
|---|
| 142 | }, {
|
|---|
| 143 | field: 'icon',
|
|---|
| 144 | filter: 'agTextColumnFilter',
|
|---|
| 145 | flex: 1
|
|---|
| 146 | }];
|
|---|
| 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) {
|
|---|
| 178 | if (!checkPermission({
|
|---|
| 179 | module: 'webapi.Markers',
|
|---|
| 180 | method: 'POST'
|
|---|
| 181 | })) {
|
|---|
| 182 | return;
|
|---|
| 183 | }
|
|---|
| 184 | createMarker(data);
|
|---|
| 185 | }
|
|---|
| 186 | async function handleEdit(data) {
|
|---|
| 187 | if (!checkPermission({
|
|---|
| 188 | module: 'webapi.Markers',
|
|---|
| 189 | method: 'PUT'
|
|---|
| 190 | })) {
|
|---|
| 191 | return;
|
|---|
| 192 | }
|
|---|
| 193 | updateMarker(data);
|
|---|
| 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 | }
|
|---|
| 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 | };
|
|---|
| 210 | return /*#__PURE__*/React.createElement("div", {
|
|---|
| 211 | style: {
|
|---|
| 212 | flexDirection: 'row',
|
|---|
| 213 | height: '80vh'
|
|---|
| 214 | }
|
|---|
| 215 | }, /*#__PURE__*/React.createElement(EditableTable, {
|
|---|
| 216 | columnDef: columnDef,
|
|---|
| 217 | rowData: data,
|
|---|
| 218 | reloadFn: refetch,
|
|---|
| 219 | deleteRowFn: cellDeleted,
|
|---|
| 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)
|
|---|
| 228 | }));
|
|---|
| 229 | }
|
|---|
| 230 | ;// CONCATENATED MODULE: ../mods/markers/index.js
|
|---|
| 231 | /* eslint-disable react/prop-types */
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 | const modId = 'TFP_MarkersExample';
|
|---|
| 235 | const Markers = {
|
|---|
| 236 | about: `This mod manages markers on a Leaflet map.`,
|
|---|
| 237 | routes: {},
|
|---|
| 238 | settings: {
|
|---|
| 239 | 'Map markers': MarkersSettings
|
|---|
| 240 | },
|
|---|
| 241 | mapComponents: [MarkersComponent]
|
|---|
| 242 | };
|
|---|
| 243 | window[modId] = Markers;
|
|---|
| 244 | window.dispatchEvent(new Event(`mod:${modId}:ready`));
|
|---|
| 245 | /******/ })()
|
|---|
| 246 | ;
|
|---|