Skip to content

Commit c9650d6

Browse files
authored
Merge pull request #2337 from nextcloud/techdebt/noid/use-filelist-for-dir
Use file list instead of dir attribute
2 parents bc1b490 + 893fb2a commit c9650d6

4 files changed

Lines changed: 42 additions & 6 deletions

File tree

src/helpers/filesApp.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* @copyright Copyright (c) 2022 Julius Härtl <[email protected]>
3+
*
4+
* @author Julius Härtl <[email protected]>
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+
*/
22+
23+
/**
24+
* @returns {string}
25+
*/
26+
export const getCurrentDirectory = () => {
27+
if (OCA.Sharing?.PublicApp) {
28+
return OCA.Sharing.PublicApp.fileList.getCurrentDirectory()
29+
}
30+
31+
return OCA.Files.App.currentFileList.getCurrentDirectory()
32+
}

src/services/api.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222

2323
import axios from '@nextcloud/axios'
2424
import { generateOcsUrl } from '@nextcloud/router'
25+
import { getCurrentDirectory } from '../helpers/filesApp'
2526

2627
export const createEmptyFile = async(mimeType, fileName) => {
2728
const shareToken = document.getElementById('sharingToken')?.value
28-
const directoryPath = document.getElementById('dir')?.value
29+
const directoryPath = getCurrentDirectory()
2930

3031
const response = await axios.post(generateOcsUrl('apps/richdocuments/api/v1', 2) + 'file', {
3132
mimeType,

src/view/FilesAppIntegration.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import { generateUrl, generateRemoteUrl, getRootUrl } from '@nextcloud/router'
2424
import { getCurrentUser } from '@nextcloud/auth'
2525
import moment from '@nextcloud/moment'
26+
import { getCurrentDirectory } from '../helpers/filesApp'
2627

2728
const isPublic = document.getElementById('isPublic') && document.getElementById('isPublic').value === '1'
2829

@@ -549,8 +550,7 @@ export default {
549550
if (type === 'text') {
550551
type = 'document'
551552
}
552-
const dir = parent.$('#dir').val()
553-
const url = generateUrl('/apps/files/?dir=' + dir + '&richdocuments_create=' + type + '&richdocuments_filename=' + encodeURI(value))
553+
const url = generateUrl('/apps/files/?dir=' + getCurrentDirectory() + '&richdocuments_create=' + type + '&richdocuments_filename=' + encodeURI(value))
554554
window.open(url, '_blank')
555555
}
556556
},

src/view/NewFileMenu.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*
2121
*/
2222

23+
import { getCurrentDirectory } from '../helpers/filesApp'
2324
import Types from '../helpers/types'
2425
import { createEmptyFile } from '../services/api'
2526
import { generateUrl, generateFilePath, generateOcsUrl } from '@nextcloud/router'
@@ -91,7 +92,7 @@ const NewFileMenu = {
9192
const fileAction = OCA.Files.fileActions.getDefaultFileAction(fileModel.get('mimetype'), 'file', OC.PERMISSION_ALL)
9293
fileAction.action(filename, {
9394
$file: null,
94-
dir: FileList.getCurrentDirectory(),
95+
dir: getCurrentDirectory(),
9596
FileList,
9697
fileActions: FileList.fileActions,
9798
})
@@ -102,16 +103,18 @@ const NewFileMenu = {
102103
},
103104

104105
_createDocumentFromTemplate(templateId, mimetype, filename) {
106+
const dir = getCurrentDirectory()
105107
OCA.Files.Files.isFileNameValid(filename)
106108
filename = FileList.getUniqueName(filename)
109+
107110
$.post(
108111
generateUrl('apps/richdocuments/ajax/documents/create'),
109-
{ mimetype, filename, dir: document.getElementById('dir').value },
112+
{ mimetype, filename, dir },
110113
function(response) {
111114
if (response && response.status === 'success') {
112115
FileList.add(response.data, { animate: false, scrollTo: false })
113116
const fileModel = FileList.getModelForFile(filename)
114-
const path = document.getElementById('dir').value + '/' + filename
117+
const path = dir + '/' + filename
115118
OCA.RichDocuments.openWithTemplate({
116119
fileId: -1,
117120
path,

0 commit comments

Comments
 (0)