Skip to content

Commit

Permalink
Migrate remaining instances of UploadPicker
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge authored and Pytal committed Jan 30, 2024
1 parent 0baea86 commit 8f1a989
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 36 deletions.
25 changes: 1 addition & 24 deletions lib/Controller/AlbumsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\Constants;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
Expand Down Expand Up @@ -110,36 +109,14 @@ private function formatData(iterable $nodes): array {
'mime' => $node->getMimetype(),
'size' => $node->getSize(),
'type' => $node->getType(),
'permissions' => $this->formatPermissions($node->getPermissions()),
'permissions' => $node->getPermissions(),
'hasPreview' => $this->previewManager->isAvailable($node),
];
}

return $result;
}

private function formatPermissions(int $permissions): string {
$strPermissions = '';
if ($permissions) {
if ($permissions & Constants::PERMISSION_CREATE) {
$strPermissions .= 'CK';
}
if ($permissions & Constants::PERMISSION_READ) {
$strPermissions .= 'G';
}
if ($permissions & Constants::PERMISSION_UPDATE) {
$strPermissions .= 'W';
}
if ($permissions & Constants::PERMISSION_DELETE) {
$strPermissions .= 'D';
}
if ($permissions & Constants::PERMISSION_SHARE) {
$strPermissions .= 'R';
}
}
return $strPermissions;
}

private function scanCurrentFolder(Folder $folder, bool $shared): iterable {
$nodes = $folder->getDirectoryListing();

Expand Down
2 changes: 1 addition & 1 deletion src/components/FilesPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<div class="photos-picker__actions">
<UploadPicker :accept="allowedMimes"
:context="uploadContext"
:destination="photosLocation"
:destination="photosLocationFolder"
:multiple="true"
@uploaded="refreshFiles" />
<NcButton type="primary" :disabled="loading || selectedFileIds.length === 0" @click="emitPickedEvent">
Expand Down
8 changes: 7 additions & 1 deletion src/mixins/UserConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@

import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
import { generateUrl } from '@nextcloud/router'
import { davGetClient, davGetDefaultPropfind, davResultToNode, davRootPath } from '@nextcloud/files'
import { loadState } from '@nextcloud/initial-state'
import axios from '@nextcloud/axios'
import { joinPaths } from '@nextcloud/paths'

const eventName = 'photos:user-config-changed'

Expand All @@ -36,11 +38,15 @@ export default {
? croppedLayoutLocalStorage === 'true'
: loadState('photos', 'croppedLayout', 'false') === 'true',
photosLocation: loadState('photos', 'photosLocation', ''),
photosLocationFolder: null,
}
},

created() {
async created() {
subscribe(eventName, this.updateLocalSetting)
const davClient = davGetClient()
const stat = await davClient.stat(joinPaths(davRootPath, this.photosLocation), { details: true, data: davGetDefaultPropfind() })
this.photosLocationFolder = davResultToNode(stat.data)
},

beforeDestroy() {
Expand Down
25 changes: 15 additions & 10 deletions src/views/Folders.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
:root-title="rootTitle"
@refresh="onRefresh">
<UploadPicker :accept="allowedMimes"
:destination="path"
:destination="folderAsFolder"
:multiple="true"
@uploaded="onUpload" />
</HeaderNavigation>
Expand All @@ -69,7 +69,8 @@
<script>
import { mapGetters } from 'vuex'
import { UploadPicker, getUploader } from '@nextcloud/upload'
import { Upload, UploadPicker, getUploader } from '@nextcloud/upload'
import { Folder as NcFolder } from '@nextcloud/files'
import { NcEmptyContent } from '@nextcloud/vue'
import VirtualGrid from 'vue-virtual-grid'
Expand Down Expand Up @@ -142,6 +143,12 @@ export default {
folder() {
return this.files[this.folderId]
},
folderAsFolder() {
return new NcFolder({
...this.folder,
source: decodeURI(this.folder.source),
})
},
folderContent() {
return this.folders[this.folderId]
},
Expand Down Expand Up @@ -273,15 +280,13 @@ export default {
/**
* Fetch file Info and add them into the store
*
* @param {Upload[]} uploads the newly uploaded files
* @param {Upload} upload the newly uploaded files
*/
onUpload(uploads) {
uploads.forEach(async upload => {
const relPath = upload.path.split(prefixPath).pop()
const file = await getFileInfo(relPath)
this.$store.dispatch('appendFiles', [file])
this.$store.dispatch('addFilesToFolder', { fileid: this.folderId, files: [file] })
})
async onUpload(upload) {
const relPath = upload.source.split(prefixPath).pop()
const file = await getFileInfo(relPath)
this.$store.dispatch('appendFiles', [file])
this.$store.dispatch('addFilesToFolder', { fileid: this.folderId, files: [file] })
},
},
Expand Down

0 comments on commit 8f1a989

Please sign in to comment.