diff --git a/appinfo/info.xml b/appinfo/info.xml index 12165f594..ab734482d 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -3,7 +3,7 @@ gpxpod GpxPod - 6.0.0 + 7.0.0 agpl Julien Veyssier (@julien-nc) GpxPod diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index c320ca133..c4caff1aa 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -126,8 +126,8 @@ public function index(): TemplateResponse { 'path' => $dir['path'], 'isOpen' => $dir['isOpen'], 'sortOrder' => $dir['sortOrder'], - 'sortAsc' => $dir['sortAsc'], - 'recursive' => $dir['recursive'], + 'sortAscending' => $dir['sortAscending'], + 'displayRecursive' => $dir['displayRecursive'], 'tracks' => [], 'pictures' => [], 'loading' => false, @@ -292,8 +292,8 @@ private function getPublicTemplate(IShare $share, ?string $password, ?string $pa 'path' => $this->l10n->t('Public link'), 'isOpen' => true, 'sortOrder' => 0, - 'sortAsc' => true, - 'recursive' => false, + 'sortAscending' => true, + 'displayRecursive' => false, 'tracks' => [ '0' => $this->getPublicTrack($share, $shareNode), ], @@ -315,8 +315,8 @@ private function getPublicTemplate(IShare $share, ?string $password, ?string $pa 'path' => $shareNode->getName(), 'isOpen' => true, 'sortOrder' => 0, - 'sortAsc' => true, - 'recursive' => false, + 'sortAscending' => true, + 'displayRecursive' => false, 'tracks' => $this->getPublicDirectoryTracks($share, $shareNode), 'pictures' => [], 'loading' => false, @@ -338,8 +338,8 @@ private function getPublicTemplate(IShare $share, ?string $password, ?string $pa 'path' => $this->l10n->t('Public link'), 'isOpen' => true, 'sortOrder' => 0, - 'sortAsc' => true, - 'recursive' => false, + 'sortAscending' => true, + 'displayRecursive' => false, 'tracks' => [ '0' => $this->getPublicTrack($share, $targetNode), ], @@ -359,8 +359,8 @@ private function getPublicTemplate(IShare $share, ?string $password, ?string $pa 'path' => $shareNode->getName() . '/' . ltrim($path, '/'), 'isOpen' => true, 'sortOrder' => 0, - 'sortAsc' => true, - 'recursive' => false, + 'sortAscending' => true, + 'displayRecursive' => false, 'tracks' => $this->getPublicDirectoryTracks($share, $targetNode), 'pictures' => [], 'loading' => false, @@ -675,17 +675,17 @@ private function getDefaultSettings(array $settings): array { * @param int $id * @param bool $isOpen * @param int|null $sortOrder - * @param bool|null $sortAsc - * @param bool|null $recursive + * @param bool|null $sortAscending + * @param bool|null $displayRecursive * @return DataResponse * @throws \OCP\DB\Exception */ #[NoAdminRequired] public function updateDirectory( int $id, ?bool $isOpen = null, ?int $sortOrder = null, - ?bool $sortAsc = null, ?bool $recursive = null, + ?bool $sortAscending = null, ?bool $displayRecursive = null, ): DataResponse { - $this->directoryMapper->updateDirectory($id, $this->userId, null, $isOpen, $sortOrder, $sortAsc, $recursive); + $this->directoryMapper->updateDirectory($id, $this->userId, null, $isOpen, $sortOrder, $sortAscending, $displayRecursive); return new DataResponse(); } @@ -717,7 +717,7 @@ public function updateDirectoryTracks(int $id, ?bool $isEnabled = null): DataRes * no CSRF because this can be called from the files app * * @param string $path - * @param bool $recursive + * @param bool $displayRecursive * @return DataResponse * @throws NoUserException * @throws NotFoundException @@ -725,8 +725,8 @@ public function updateDirectoryTracks(int $id, ?bool $isEnabled = null): DataRes */ #[NoAdminRequired] #[NoCSRFRequired] - public function addDirectory(string $path, bool $recursive = false): DataResponse { - if ($recursive) { + public function addDirectory(string $path, bool $displayRecursive = false): DataResponse { + if ($displayRecursive) { return $this->addDirectoryRecursive($path); } $userFolder = $this->root->getUserFolder($this->userId); @@ -1004,7 +1004,7 @@ public function getTrackMarkersJson(int $id, string $directoryPath, bool $proces return new DataResponse(['error' => 'This directory is not a directory'], Http::STATUS_BAD_REQUEST); } - $recursive = $dbDir->getRecursive(); + $displayRecursive = $dbDir->getDisplayRecursive() === 1; $optionValues = $this->processService->getSharedMountedOptionValue($this->userId); $sharedAllowed = $optionValues['sharedAllowed']; $mountedAllowed = $optionValues['mountedAllowed']; @@ -1022,7 +1022,7 @@ public function getTrackMarkersJson(int $id, string $directoryPath, bool $proces $filesByExtension[$ext] = []; } - if ($recursive) { + if ($displayRecursive) { $extensions = array_keys(ConversionService::fileExtToGpsbabelFormat); $files = $this->processService->searchFilesWithExt($userFolder->get($directoryPath), $sharedAllowed, $mountedAllowed, $extensions); foreach ($files as $file) { @@ -1048,7 +1048,7 @@ public function getTrackMarkersJson(int $id, string $directoryPath, bool $proces $this->conversionService->convertFiles($userFolder, $directoryPath, $this->userId, $filesByExtension); // PROCESS gpx files and fill DB - $this->processService->processGpxFiles($this->userId, $dbDir->getId(), $sharedAllowed, $mountedAllowed, $processAll, $recursive); + $this->processService->processGpxFiles($this->userId, $dbDir->getId(), $sharedAllowed, $mountedAllowed, $processAll, $displayRecursive); // build tracks array $dbTracks = $this->trackMapper->getDirectoryTracksOfUser($this->userId, $dbDir->getId()); diff --git a/lib/Db/Directory.php b/lib/Db/Directory.php index aa5d10bc7..db9184279 100644 --- a/lib/Db/Directory.php +++ b/lib/Db/Directory.php @@ -36,10 +36,10 @@ * @method void setIsOpen(int $isOpen) * @method int getSortOrder() * @method void setSortOrder(int $sortOrder) - * @method bool|null getSortAsc() - * @method void setSortAsc(bool|null $sortAsc) - * @method bool|null getRecursive() - * @method void setRecursive(bool|null $recursive) + * @method int getSortAscending() + * @method void setSortAscending(int $sortAscending) + * @method int getDisplayRecursive() + * @method void setDisplayRecursive(int $displayRecursive) */ class Directory extends Entity implements \JsonSerializable { @@ -47,16 +47,16 @@ class Directory extends Entity implements \JsonSerializable { protected string $path = ''; protected int $isOpen = 0; protected int $sortOrder = 0; - protected ?bool $sortAsc = null; - protected ?bool $recursive = false; + protected int $sortAscending = 1; + protected int $displayRecursive = 0; public function __construct() { $this->addType('user', 'string'); $this->addType('path', 'string'); $this->addType('is_open', 'integer'); $this->addType('sort_order', 'integer'); - $this->addType('sort_asc', 'boolean'); - $this->addType('recursive', 'boolean'); + $this->addType('sort_ascending', 'boolean'); + $this->addType('display_recursive', 'boolean'); } #[\ReturnTypeWillChange] @@ -67,8 +67,8 @@ public function jsonSerialize() { 'path' => $this->getPath(), 'isOpen' => $this->getIsOpen() === 1, 'sortOrder' => $this->getSortOrder(), - 'sortAsc' => $this->getSortAsc(), - 'recursive' => $this->getRecursive(), + 'sortAscending' => $this->getSortAscending() === 1, + 'displayRecursive' => $this->getDisplayRecursive() === 1, ]; } } diff --git a/lib/Db/DirectoryMapper.php b/lib/Db/DirectoryMapper.php index f438c0d28..b7469c303 100644 --- a/lib/Db/DirectoryMapper.php +++ b/lib/Db/DirectoryMapper.php @@ -155,13 +155,15 @@ public function deleteAndCleanup(int $id, string $userId): int { * @param string $user * @param bool $isOpen * @param int $sortOrder - * @param bool $sortAsc - * @param bool $recursive + * @param bool $sortAscending + * @param bool $displayRecursive * @return Directory * @throws Exception */ - public function createDirectory(string $path, string $user, bool $isOpen = false, int $sortOrder = 0, - bool $sortAsc = true, bool $recursive = false): Directory { + public function createDirectory( + string $path, string $user, bool $isOpen = false, int $sortOrder = 0, + bool $sortAscending = true, bool $displayRecursive = false + ): Directory { try { // do not create if one with same path/userId already exists $dir = $this->getDirectoryOfUserByPath($path, $user); @@ -178,8 +180,8 @@ public function createDirectory(string $path, string $user, bool $isOpen = false $dir->setUser($user); $dir->setIsOpen($isOpen ? 1 : 0); $dir->setSortOrder($sortOrder); - $dir->setSortAsc($sortAsc); - $dir->setRecursive($recursive); + $dir->setSortAscending($sortAscending ? 1 : 0); + $dir->setDisplayRecursive($displayRecursive ? 1 : 0); /** @var Directory $directory */ $createdDirectory = $this->insert($dir); return $createdDirectory; @@ -191,17 +193,17 @@ public function createDirectory(string $path, string $user, bool $isOpen = false * @param string|null $path * @param bool|null $isOpen * @param int|null $sortOrder - * @param bool|null $sortAsc - * @param bool|null $recursive + * @param bool|null $sortAscending + * @param bool|null $displayRecursive * @return Directory|null * @throws Exception */ public function updateDirectory( int $id, string $userId, ?string $path = null, ?bool $isOpen = null, ?int $sortOrder = null, - ?bool $sortAsc = null, ?bool $recursive = null, + ?bool $sortAscending = null, ?bool $displayRecursive = null, ): ?Directory { - if ($path === null && $isOpen === null && $sortOrder === null && $sortAsc === null && $recursive === null) { + if ($path === null && $isOpen === null && $sortOrder === null && $sortAscending === null && $displayRecursive === null) { return null; } try { @@ -218,11 +220,11 @@ public function updateDirectory( if ($sortOrder !== null) { $dir->setSortOrder($sortOrder); } - if ($sortAsc !== null) { - $dir->setSortAsc($sortAsc); + if ($sortAscending !== null) { + $dir->setSortAscending($sortAscending ? 1 : 0); } - if ($recursive !== null) { - $dir->setRecursive($recursive); + if ($displayRecursive !== null) { + $dir->setDisplayRecursive($displayRecursive ? 1 : 0); } /** @var Directory $directory */ $updatedDirectory = $this->update($dir); diff --git a/lib/Migration/Version070000Date20240923181142.php b/lib/Migration/Version070000Date20240923181142.php new file mode 100644 index 000000000..e2089c979 --- /dev/null +++ b/lib/Migration/Version070000Date20240923181142.php @@ -0,0 +1,71 @@ +getTable('gpxpod_directories'); + if (!$table->hasColumn('sort_ascending')) { + $table->addColumn('sort_ascending', Types::SMALLINT, [ + 'notnull' => true, + 'default' => 1, + ]); + $schemaChanged = true; + } + if (!$table->hasColumn('display_recursive')) { + $table->addColumn('display_recursive', Types::SMALLINT, [ + 'notnull' => true, + 'default' => 0, + ]); + $schemaChanged = true; + } + if ($table->hasColumn('sort_asc')) { + $table->dropColumn('sort_asc'); + $schemaChanged = true; + } + if ($table->hasColumn('recursive')) { + $table->dropColumn('recursive'); + $schemaChanged = true; + } + + return $schemaChanged ? $schema : null; + } + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + */ + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { + } +} diff --git a/src/App.vue b/src/App.vue index 97a47b783..9aa828080 100644 --- a/src/App.vue +++ b/src/App.vue @@ -452,7 +452,7 @@ export default { onDirectoryAddRecursive(path) { const req = { path, - recursive: true, + displayRecursive: true, } const url = generateUrl('/apps/gpxpod/directories') axios.post(url, req).then((response) => { @@ -575,20 +575,20 @@ export default { this.loadDirectory(dirId, true, true) }, onDirectoryRecursiveChanged(dirId) { - this.state.directories[dirId].recursive = !this.state.directories[dirId].recursive - this.updateDirectory(dirId, { recursive: this.state.directories[dirId].recursive }) + this.state.directories[dirId].displayRecursive = !this.state.directories[dirId].displayRecursive + this.updateDirectory(dirId, { displayRecursive: this.state.directories[dirId].displayRecursive }) .then(() => { this.loadDirectory(dirId, true, true) }) }, - onDirectorySortChanged({ dirId, sortOrder, sortAsc }) { + onDirectorySortChanged({ dirId, sortOrder, sortAscending }) { if (sortOrder !== undefined) { this.state.directories[dirId].sortOrder = sortOrder this.updateDirectory(dirId, { sortOrder }) } - if (sortAsc !== undefined) { - this.state.directories[dirId].sortAsc = sortAsc - this.updateDirectory(dirId, { sortAsc }) + if (sortAscending !== undefined) { + this.state.directories[dirId].sortAscending = sortAscending + this.updateDirectory(dirId, { sortAscending }) } }, updateDirectory(dirId, values) { diff --git a/src/components/NavigationDirectoryItem.vue b/src/components/NavigationDirectoryItem.vue index e96a4caa7..4f0cdc91b 100644 --- a/src/components/NavigationDirectoryItem.vue +++ b/src/components/NavigationDirectoryItem.vue @@ -45,15 +45,15 @@ + name="sortAscending" + :checked="directory.sortAscending === true" + @change="onSortAscendingChange(true)"> ⬇ {{ t('gpxpod', 'Sort ascending') }} + name="sortAscending" + :checked="directory.sortAscending !== true" + @change="onSortAscendingChange(false)"> ⬆ {{ t('gpxpod', 'Sort descending') }} @@ -96,7 +96,7 @@ {{ t('gpxpod', 'Display recursively') }} @@ -346,7 +346,7 @@ export default { if (!this.compact) { return [] } - return sortTracks(Object.values(this.directory.tracks), this.directory.sortOrder, this.directory.sortAsc) + return sortTracks(Object.values(this.directory.tracks), this.directory.sortOrder, this.directory.sortAscending) }, }, beforeMount() { @@ -372,8 +372,8 @@ export default { onSortOrderChange(sortOrder) { emit('directory-sort-changed', { dirId: this.directory.id, sortOrder }) }, - onSortAscChange(sortAsc) { - emit('directory-sort-changed', { dirId: this.directory.id, sortAsc }) + onSortAscendingChange(sortAscending) { + emit('directory-sort-changed', { dirId: this.directory.id, sortAscending }) }, onZoomToBounds() { emit('directory-zoom', this.directory.id) diff --git a/src/components/TrackList.vue b/src/components/TrackList.vue index 4abb6aa19..731a4a35e 100644 --- a/src/components/TrackList.vue +++ b/src/components/TrackList.vue @@ -107,7 +107,7 @@ export default { return this.sortedTracks.length }, sortedTracks() { - return sortTracks(this.filteredTracks, this.directory.sortOrder, this.directory.sortAsc) + return sortTracks(this.filteredTracks, this.directory.sortOrder, this.directory.sortAscending) }, filteredTracks() { if (this.filterQuery === '') { diff --git a/src/utils.js b/src/utils.js index f8ba1a14b..ff7c3ea78 100644 --- a/src/utils.js +++ b/src/utils.js @@ -318,9 +318,9 @@ export function formatExtensionValue(key, value, unit = 'metric') { : value } -export function sortTracks(tracks, sortOrder, sortAsc = true) { +export function sortTracks(tracks, sortOrder, sortAscending = true) { if (sortOrder === TRACK_SORT_ORDER.name.value) { - const sortFunction = sortAsc + const sortFunction = sortAscending ? (ta, tb) => { return strcmp(ta.name, tb.name) } @@ -330,7 +330,7 @@ export function sortTracks(tracks, sortOrder, sortAsc = true) { return tracks.sort(sortFunction) } if (sortOrder === TRACK_SORT_ORDER.date.value) { - const sortFunction = sortAsc + const sortFunction = sortAscending ? (ta, tb) => { const tsA = ta.date_begin const tsB = tb.date_begin @@ -352,7 +352,7 @@ export function sortTracks(tracks, sortOrder, sortAsc = true) { return tracks.sort(sortFunction) } if (sortOrder === TRACK_SORT_ORDER.distance.value) { - const sortFunction = sortAsc + const sortFunction = sortAscending ? (ta, tb) => { return ta.total_distance > tb.total_distance ? 1 @@ -370,7 +370,7 @@ export function sortTracks(tracks, sortOrder, sortAsc = true) { return tracks.sort(sortFunction) } if (sortOrder === TRACK_SORT_ORDER.duration.value) { - const sortFunction = sortAsc + const sortFunction = sortAscending ? (ta, tb) => { return ta.total_duration > tb.total_duration ? 1 @@ -388,7 +388,7 @@ export function sortTracks(tracks, sortOrder, sortAsc = true) { return tracks.sort(sortFunction) } if (sortOrder === TRACK_SORT_ORDER.elevationGain.value) { - const sortFunction = sortAsc + const sortFunction = sortAscending ? (ta, tb) => { return ta.positive_elevation_gain > tb.positive_elevation_gain ? 1