Skip to content

Commit 1dd48da

Browse files
committed
clean some code
Signed-off-by: Théo Lallement <lallement.theo@gmail.com>
1 parent 735de9d commit 1dd48da

7 files changed

Lines changed: 162 additions & 83 deletions

File tree

appinfo/routes.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
['name' => 'utils#saveOptionValue', 'url' => '/saveOptionValue', 'verb' => 'POST'],
2626
['name' => 'utils#setRoutingSettings', 'url' => '/setRoutingSettings', 'verb' => 'POST'],
2727
['name' => 'utils#getTrafficStyle', 'url' => '/style/traffic', 'verb' => 'GET'],
28-
['name' => 'utils#copyFile', 'url' => '/copy-file', 'verb' => 'POST'],
2928
['name' => 'PublicUtils#getOptionsValues', 'url' => '/s/{token}/getOptionsValues', 'verb' => 'GET'],
3029
['name' => 'PublicUtils#saveOptionValue', 'url' => '/s/{token}/saveOptionValue', 'verb' => 'POST'],
3130
['name' => 'PublicUtils#setRoutingSettings', 'url' => '/s/{token}/setRoutingSettings', 'verb' => 'POST'],

lib/Controller/UtilsController.php

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -246,63 +246,4 @@ public function getTrafficStyle(): DataResponse {
246246
];
247247
return new DataResponse($style);
248248
}
249-
250-
/**
251-
* Copy a file from one path to another inside a share
252-
*
253-
* @PublicPage
254-
* @param string $from Relative path from the share root
255-
* @param string $to Relative destination path inside the share
256-
* @NoAdminRequired
257-
* @NoCSRFRequired
258-
* @return DataResponse
259-
* @throws NotFoundException
260-
* @throws GenericFileException
261-
* @throws InvalidPathException
262-
* @throws NotPermittedException
263-
*/
264-
public function copyFile($from = null, $to = null): DataResponse {
265-
if (!$from || !$to) {
266-
return new DataResponse(['status' => 'error', 'message' => 'Missing from/to parameters'], 400);
267-
}
268-
269-
// Remove leading slashes
270-
$from = ltrim($from, '/');
271-
$to = ltrim($to, '/');
272-
273-
$userFolder = $this->root->getUserFolder($this->userId);
274-
275-
$nodes = $userFolder->getDirectoryListing();
276-
foreach ($nodes as $n) {
277-
\OC::$server->getLogger()->info('Node: ' . $n->getName());
278-
}
279-
280-
if (!$userFolder->nodeExists($from)) {
281-
return new DataResponse(['status' => 'error', 'message' => 'Source file does not exist: ' . $from], 404);
282-
}
283-
284-
try {
285-
$sourceNode = $userFolder->get($from);
286-
287-
$destinationParts = explode('/', $to);
288-
$destFileName = array_pop($destinationParts);
289-
$destFolder = $userFolder;
290-
291-
foreach ($destinationParts as $part) {
292-
if (!$destFolder->nodeExists($part)) {
293-
$destFolder = $destFolder->newFolder($part);
294-
} else {
295-
$destFolder = $destFolder->get($part);
296-
}
297-
}
298-
299-
// Copy the file to destination
300-
$sourceNode->copy($destFolder->getPath() . '/' . $destFileName);
301-
302-
} catch (\Exception $e) {
303-
return new DataResponse(['status' => 'error', 'message' => $e->getMessage()], 500);
304-
}
305-
306-
return new DataResponse(['status' => 'success']);
307-
}
308249
}

src/components/Map.vue

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ export default {
259259
this.leafletOverlays = {}
260260
},
261261
mounted() {
262-
// 1. Initialize Pure Leaflet Map
263262
this.map = L.map(this.$refs.mapContainer, {
264263
center: this.mapOptions.center,
265264
zoom: this.mapOptions.zoom,
@@ -273,35 +272,29 @@ export default {
273272
contextmenuItems: this.getContextmenuItems(),
274273
});
275274
276-
// 2. Set bounds if they exist
277275
if (this.mapOptions.bounds) {
278276
this.map.fitBounds(this.mapOptions.bounds);
279277
}
280278
281-
// 3. Add standard controls natively
282279
L.control.zoom({ position: 'bottomright' }).addTo(this.map);
283280
L.control.scale({
284281
position: 'bottomleft',
285282
imperial: this.mapOptions.scaleControlShouldUseImperial,
286283
metric: !this.mapOptions.scaleControlShouldUseImperial
287284
}).addTo(this.map);
288285
289-
// 4. Bind native Leaflet events back to Vue methods
290286
this.map.on('moveend zoomend', () => this.onUpdateBounds(this.map.getBounds()));
291287
this.map.on('baselayerchange', this.onBaselayerchange);
292288
this.map.on('click', this.onMapClick);
293289
this.map.on('contextmenu', this.onMapContextmenu);
294290
295-
// 5. Initialize custom layers & loc control
296291
this.initLocControl(this.map);
297292
this.initLayers(this.map);
298293
299-
// Force container to resize correctly (fixes grey screen on load)
300294
this.$nextTick(() => {
301295
this.map.invalidateSize();
302296
});
303297
304-
// 6. Trigger reactivity for children
305298
this.isMapReady = true;
306299
},
307300
beforeUnmount() {

src/components/MapContainer.vue

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
<!--
2+
- @copyright Copyright (c) 2019 Paul Schwörer <hello@paulschwoerer.de>
3+
-
4+
- @author Paul Schwörer <hello@paulschwoerer.de>
5+
-
6+
- @license GNU AGPL version 3 or any later version
7+
-
8+
- This program is free software: you can redistribute it and/or modify
9+
- it under the terms of the GNU Affero General Public License as
10+
- published by the Free Software Foundation, either version 3 of the
11+
- License, or (at your option) any later version.
12+
-
13+
- This program is distributed in the hope that it will be useful,
14+
- but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
- GNU Affero General Public License for more details.
17+
-
18+
- You should have received a copy of the GNU Affero General Public License
19+
- along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
-->
21+
122
<template>
223
<div class="map-container">
324
<div ref="mapContainer" style="width: 100%; height: 100%;"></div>
@@ -115,7 +136,6 @@ export default {
115136
},
116137
117138
mounted() {
118-
// 1. Initialize Map
119139
this.map = L.map(this.$refs.mapContainer, {
120140
center: this.mapOptions.center,
121141
zoom: this.mapOptions.zoom,
@@ -124,21 +144,18 @@ export default {
124144
zoomControl: false,
125145
});
126146
127-
// 2. Add Controls
128147
L.control.zoom({ position: 'bottomright' }).addTo(this.map);
129148
L.control.scale({
130149
position: 'bottomleft',
131150
imperial: this.mapOptions.scaleControlShouldUseImperial,
132151
metric: !this.mapOptions.scaleControlShouldUseImperial
133152
}).addTo(this.map);
134153
135-
// 3. Add Tile Layer
136154
L.tileLayer(this.activeLayer.url, {
137155
attribution: this.activeLayer.attribution,
138156
...this.activeLayer.options
139157
}).addTo(this.map);
140158
141-
// 4. Setup Cluster Group
142159
this.clusterGroup = L.markerClusterGroup({
143160
showCoverageOnHover: false,
144161
zoomToBoundsOnClick: true,
@@ -147,7 +164,6 @@ export default {
147164
});
148165
this.map.addLayer(this.clusterGroup);
149166
150-
// 5. Events
151167
this.map.on('click', this.handleMapClick);
152168
this.map.on('popupclose', this.handlePopupCloseEvent);
153169
@@ -281,7 +297,6 @@ export default {
281297
@import '~leaflet.markercluster/dist/MarkerCluster.css';
282298
@import '~leaflet.markercluster/dist/MarkerCluster.Default.css';
283299
284-
/* ... Keep all existing styles from MapContainer.vue exactly as they were ... */
285300
.leaflet-tooltip { white-space: normal !important; }
286301
.leaflet-container { background: var(--color-main-background); }
287302
.leaflet-marker-favorite, .leaflet-marker-favorite-cluster {

src/components/map/ClickSearchPopup.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,8 @@ export default {
8989
},
9090
9191
mounted() {
92-
// 1. Create the marker natively
9392
this.marker = L.marker(this.latLng, { icon: this.icon }).addTo(this.map)
9493
95-
// 2. Bind THIS component's HTML to the popup natively
9694
this.marker.bindPopup(this.$el, {
9795
closeButton: false,
9896
offset: L.point(-1, 42)
@@ -102,7 +100,6 @@ export default {
102100
},
103101
104102
beforeUnmount() {
105-
// 3. Clean up the native Leaflet marker
106103
if (this.marker && this.map) {
107104
this.map.removeLayer(this.marker)
108105
}

src/components/map/PoiMarker.vue

Lines changed: 119 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,142 @@ export default {
2929
name: 'PoiMarker',
3030
props: {
3131
poi: { type: Object, required: true },
32-
map: { type: Object, required: true }, // Pass map instance
32+
map: { type: Object, required: true },
3333
},
3434
data() {
35-
return { /* keep existing data */ }
35+
return {
36+
recentImagePath: imagePath('maps', 'recent.svg'),
37+
triangleSimagePath: imagePath('maps', 'triangle-s.svg'),
38+
triangleEPath: imagePath('maps', 'triangle-e.svg'),
39+
mailImagePath: imagePath('maps', 'mail.svg'),
40+
linkImagePath: imagePath('maps', 'link.svg'),
41+
ohOpen: false,
42+
}
3643
},
37-
computed: { /* keep existing computeds */ },
44+
computed: {
45+
tooltipContent() {
46+
return this.poi.namedetails?.name || this.poi.display_name
47+
},
48+
// OPENING HOURS
49+
myOpeningHours() {
50+
return this.poi.extratags?.opening_hours
51+
? new OpeningHours(this.poi.extratags.opening_hours, this.poi)
52+
: null
53+
},
54+
ohChangeDt() {
55+
return this.myOpeningHours?.getNextChange()
56+
},
57+
formattedOhChangeDt() {
58+
return moment(this.ohChangeDt).format('HH:mm')
59+
},
60+
ohDtDiff() {
61+
const currentDt = new Date()
62+
return (this.ohChangeDt.getTime() - currentDt) / 60000
63+
},
64+
ohIsCurrentlyOpen() {
65+
return this.myOpeningHours.getState()
66+
},
67+
ohIntervals() {
68+
const todayStart = new Date()
69+
todayStart.setHours(0)
70+
todayStart.setMinutes(0)
71+
todayStart.setSeconds(0)
72+
const sevDaysEnd = new Date(todayStart)
73+
const sevDaysMs = 7 * 24 * 60 * 60 * 1000
74+
sevDaysEnd.setTime(sevDaysEnd.getTime() + sevDaysMs)
75+
const intervals = this.myOpeningHours.getOpenIntervals(todayStart, sevDaysEnd)
76+
// intervals should be 7, if 8, then first entry is interval after 00:00:00 from last day
77+
if (intervals.length === 8) {
78+
// set end time of last element to end time of first element and remove it
79+
intervals[7][1] = intervals[0][1]
80+
intervals.splice(0, 1)
81+
}
82+
const resultIntervals = intervals.map((interval) => {
83+
return {
84+
startTime: moment(interval[0]).format('HH:mm'),
85+
endTime: moment(interval[1]).format('HH:mm'),
86+
day: moment(interval[1]).format('dddd'),
87+
selected: false,
88+
}
89+
})
90+
resultIntervals[0].selected = true
91+
return resultIntervals
92+
},
93+
// ADDRESS
94+
city() {
95+
const poi = this.poi
96+
return (poi.address.city || poi.address.town || poi.address.village)
97+
? poi.address.city
98+
? poi.address.city
99+
: poi.address.town
100+
? poi.address.town
101+
: poi.address.village
102+
? poi.address.village
103+
: ''
104+
: ''
105+
},
106+
road() {
107+
let road = this.poi.address?.road || ''
108+
if (road && this.poi.address?.house_number) {
109+
road += ' ' + this.poi.address.house_number
110+
}
111+
return road
112+
},
113+
header() {
114+
return this.poi.namedetails?.name || this.road || this.city
115+
},
116+
desc() {
117+
const poi = this.poi
118+
let desc = ''
119+
let needSeparator = false
120+
// add road to desc if it is not heading and exists (isn't heading, if 'name' is set)
121+
if (poi.namedetails?.name && this.road) {
122+
desc = this.road
123+
needSeparator = true
124+
}
125+
if (poi.address.postcode) {
126+
if (needSeparator) {
127+
desc += ', '
128+
needSeparator = false
129+
}
130+
desc += poi.address.postcode
131+
}
132+
if (this.city) {
133+
if (needSeparator) {
134+
desc += ', '
135+
needSeparator = false
136+
} else if (desc.length > 0) {
137+
desc += ' '
138+
}
139+
desc += this.city
140+
}
141+
// assume that state is only important for us addresses
142+
if (poi.address?.state && poi.address?.country_code === 'us') {
143+
if (desc.length > 0) {
144+
desc += ' '
145+
}
146+
desc += '(' + poi.address.state + ')'
147+
}
148+
return desc
149+
},
150+
},
38151
created() {
39152
this.marker = null; // Non-reactive
40153
},
41154
mounted() {
42-
// 1. Create the marker
43155
this.marker = L.marker([this.poi.lat, this.poi.lon]).addTo(this.map);
44156
45-
// 2. Bind the tooltip
46157
this.marker.bindTooltip(this.tooltipContent);
47158
48-
// 3. Bind THIS Vue component's HTML element as the popup content!
49159
this.marker.bindPopup(this.$el);
50160
},
51161
beforeUnmount() {
52162
if (this.marker && this.map) {
53163
this.map.removeLayer(this.marker);
54164
}
55165
},
56-
methods: { /* keep existing methods */ }
166+
methods: {
167+
168+
}
57169
}
58170
</script>

src/services/FileInfo.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
3+
*
4+
* @author John Molakvoæ <skjnldsv@protonmail.com>
5+
*
6+
* @license AGPL-3.0-or-later
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
123
import axios from '@nextcloud/axios'
224

325
/**

0 commit comments

Comments
 (0)