Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added "Download Track" button to AppNavigationTrackItem #1147

Merged
merged 4 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading