Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 32 additions & 0 deletions src/helpers/filesApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* @copyright Copyright (c) 2022 Julius Härtl <[email protected]>
*
* @author Julius Härtl <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
* @returns {string}
*/
export const getCurrentDirectory = () => {
if (OCA.Sharing?.PublicApp) {
return OCA.Sharing.PublicApp.fileList.getCurrentDirectory()
}

return OCA.Files.App.currentFileList.getCurrentDirectory()
}
3 changes: 2 additions & 1 deletion src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@

import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { getCurrentDirectory } from '../helpers/filesApp'

export const createEmptyFile = async(mimeType, fileName) => {
const shareToken = document.getElementById('sharingToken')?.value
const directoryPath = document.getElementById('dir')?.value
const directoryPath = getCurrentDirectory()

const response = await axios.post(generateOcsUrl('apps/richdocuments/api/v1', 2) + 'file', {
mimeType,
Expand Down
4 changes: 2 additions & 2 deletions src/view/FilesAppIntegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import { generateUrl, generateRemoteUrl, getRootUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import moment from '@nextcloud/moment'
import { getCurrentDirectory } from '../helpers/filesApp'

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

Expand Down Expand Up @@ -549,8 +550,7 @@ export default {
if (type === 'text') {
type = 'document'
}
const dir = parent.$('#dir').val()
const url = generateUrl('/apps/files/?dir=' + dir + '&richdocuments_create=' + type + '&richdocuments_filename=' + encodeURI(value))
const url = generateUrl('/apps/files/?dir=' + getCurrentDirectory() + '&richdocuments_create=' + type + '&richdocuments_filename=' + encodeURI(value))
window.open(url, '_blank')
}
},
Expand Down
9 changes: 6 additions & 3 deletions src/view/NewFileMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
*/

import { getCurrentDirectory } from '../helpers/filesApp'
import Types from '../helpers/types'
import { createEmptyFile } from '../services/api'
import { generateUrl, generateFilePath, generateOcsUrl } from '@nextcloud/router'
Expand Down Expand Up @@ -91,7 +92,7 @@ const NewFileMenu = {
const fileAction = OCA.Files.fileActions.getDefaultFileAction(fileModel.get('mimetype'), 'file', OC.PERMISSION_ALL)
fileAction.action(filename, {
$file: null,
dir: FileList.getCurrentDirectory(),
dir: getCurrentDirectory(),
FileList,
fileActions: FileList.fileActions,
})
Expand All @@ -102,16 +103,18 @@ const NewFileMenu = {
},

_createDocumentFromTemplate(templateId, mimetype, filename) {
const dir = getCurrentDirectory()
OCA.Files.Files.isFileNameValid(filename)
filename = FileList.getUniqueName(filename)

$.post(
generateUrl('apps/richdocuments/ajax/documents/create'),
{ mimetype, filename, dir: document.getElementById('dir').value },
{ mimetype, filename, dir },
function(response) {
if (response && response.status === 'success') {
FileList.add(response.data, { animate: false, scrollTo: false })
const fileModel = FileList.getModelForFile(filename)
const path = document.getElementById('dir').value + '/' + filename
const path = dir + '/' + filename
OCA.RichDocuments.openWithTemplate({
fileId: -1,
path,
Expand Down