Skip to content

Commit

Permalink
Merge pull request #1147 from nextcloud/track-menu-download-button
Browse files Browse the repository at this point in the history
added "Download Track" button to AppNavigationTrackItem
  • Loading branch information
tacruc authored Oct 23, 2023
2 parents 75fe278 + 57bf595 commit 5cb5b0a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/Controller/PublicTracksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
use OCA\Maps\Service\TracksService;
use OCP\Share\IManager as ShareManager;


/**
* @param string $text
* @return string
Expand Down Expand Up @@ -151,19 +152,21 @@ private function getShareNode() {
*/
public function getTracks(): DataResponse {
$share = $this->getShare();
$hideDownload = (bool) $share->getHideDownload();
$permissions = $share->getPermissions();
$folder = $this->getShareNode();
$isReadable = (bool) ($permissions & (1 << 0));
if ($isReadable) {
$owner = $share->getShareOwner();
$pre_path = $this->root->getUserFolder($owner)->getPath();
$tracks = $this->tracksService->getTracksFromDB($owner, $folder, true, false, false);
$new_tracks = array_map(function ($track) use ($folder, $permissions, $pre_path) {
$new_tracks = array_map(function ($track) use ($folder, $permissions, $pre_path, $hideDownload) {
$track['isCreatable'] = ($permissions & (1 << 2)) && $track['isCreatable'];
$track['isUpdateable'] = ($permissions & (1 << 1)) && $track['isUpdateable'];
$track['isDeletable'] = ($permissions & (1 << 3)) && $track['isDeletable'];
$track['path'] = $folder->getRelativePath($pre_path.$track['path']);
$track['filename'] = $track['path'];
$track['hideDownload'] = $hideDownload;
return $track;
}, $tracks);
} else {
Expand Down
26 changes: 25 additions & 1 deletion src/components/AppNavigationTrackItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,39 @@
@click="$emit('add-to-map-track', track)">
{{ t('maps', 'Copy to map') }}
</NcActionButton>
<NcActionLink v-if="parentEnabled && track.enabled && !isPublic()"
target="_self"
:href="downloadTrackUrl"
icon="icon-download"
:close-after-click="true">
{{ t('maps', 'Download track') }}
</NcActionLink>
<NcActionLink v-if="parentEnabled && track.enabled && isPublic() && !(track.hideDownload)"
target="_self"
:href="downloadTrackShareUrl"
icon="icon-download"
:close-after-click="true">
{{ t('maps', 'Download track') }}
</NcActionLink>

</template>
</NcAppNavigationItem>
</template>

<script>
import NcAppNavigationItem from '@nextcloud/vue/dist/Components/NcAppNavigationItem'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton'
import {isPublic} from "../utils/common";
import NcActionLink from '@nextcloud/vue/dist/Components/NcActionLink'
import {isPublic, getToken} from "../utils/common";
import { generateUrl } from "@nextcloud/router";
export default {
name: 'AppNavigationTrackItem',
components: {
NcAppNavigationItem,
NcActionButton,
NcActionLink,
},
props: {
Expand All @@ -94,6 +112,12 @@ export default {
},
computed: {
downloadTrackUrl() {
return OCA.Files.App.fileList.filesClient.getBaseUrl() + this.track.file_path
},
downloadTrackShareUrl() {
return generateUrl('s/' + getToken() + '/download' + '?path=/&files=' + this.track.file_name )
},
},
methods: {
Expand Down
40 changes: 39 additions & 1 deletion src/components/map/TrackLayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@
@click="$emit('add-to-map-track', track)">
{{ t('maps', 'Copy to map') }}
</NcActionButton>
<NcActionLink v-if="!isPublic()"
:href="downloadTrackUrl"
target="_self"
icon="icon-download"
:close-after-click="true"
@click="closeafterclickworkaround">
<!--
looks like close-after-click not working in this popovermenu
therefore added workaround closeafterclickworkaround
-->
{{ t('maps', 'Download track') }}
</NcActionLink>
<NcActionLink v-if="isPublic() && !(track.hideDownload)"
target="_self"
:href="downloadTrackShareUrl"
icon="icon-download"
:close-after-click="true"
@click="closeafterclickworkaround">
<!--
looks like close-after-click not working in this popovermenu
therefore added workaround closeafterclickworkaround
-->
{{ t('maps', 'Download track') }}
</NcActionLink>
</LPopup>
<LTooltip :options="tooltipOptions">
<div class="tooltip-track-wrapper"
Expand Down Expand Up @@ -57,10 +81,12 @@ import L from 'leaflet'
import { LMarker, LTooltip, LPopup, LFeatureGroup, LPolyline } from 'vue2-leaflet'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton'
import NcActionLink from '@nextcloud/vue/dist/Components/NcActionLink'
import moment from '@nextcloud/moment'
import { generateUrl } from "@nextcloud/router";
import optionsController from '../../optionsController'
import {binSearch, isPublic} from '../../utils/common'
import {binSearch, isPublic, getToken} from '../../utils/common'
const TRACK_MARKER_VIEW_SIZE = 40
const WAYPOINT_MARKER_VIEW_SIZE = 30
Expand All @@ -74,6 +100,7 @@ export default {
LFeatureGroup,
LPolyline,
NcActionButton,
NcActionLink,
},
props: {
Expand Down Expand Up @@ -116,6 +143,12 @@ export default {
},
computed: {
downloadTrackUrl() {
return OCA.Files.App.fileList.filesClient.getBaseUrl() + this.track.file_path
},
downloadTrackShareUrl() {
return generateUrl('s/' + getToken() + '/download' + '?path=/&files=' + this.track.file_name )
},
dateBegin() {
return this.track.metadata?.begin
? moment.unix(this.track.metadata.begin).format('LLL')
Expand Down Expand Up @@ -233,6 +266,11 @@ export default {
},
methods: {
// looks like close-after-click not working for NcAcionLink
// added working closeafterclickworkaround
closeafterclickworkaround() {
this.$refs.featgroup.mapObject.closePopup()
},
onFGReady(f) {
// avoid left click popup
L.DomEvent.on(f, 'click', (ev) => {
Expand Down

0 comments on commit 5cb5b0a

Please sign in to comment.