mirror of
https://github.com/nextcloud/richdocuments.git
synced 2025-12-18 05:20:43 +01:00
chore: remove new file entry workaround
Signed-off-by: Elizabeth Danzberger <elizabeth@elzody.dev>
This commit is contained in:
parent
5284e3e704
commit
8f923018d4
3 changed files with 1 additions and 124 deletions
|
|
@ -10,15 +10,12 @@ import {
|
||||||
isDownloadHidden,
|
isDownloadHidden,
|
||||||
} from './helpers/index.js'
|
} from './helpers/index.js'
|
||||||
import { getCapabilities } from './services/capabilities.ts'
|
import { getCapabilities } from './services/capabilities.ts'
|
||||||
import { registerNewFileMenuEntries } from './view/NewFileMenu.js'
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
if (!isPublicShare() || !OCA.Viewer) {
|
if (!isPublicShare() || !OCA.Viewer) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
registerNewFileMenuEntries()
|
|
||||||
|
|
||||||
const isEnabledFilesPdfViewer = getCapabilities().mimetypesNoDefaultOpen.includes('application/pdf')
|
const isEnabledFilesPdfViewer = getCapabilities().mimetypesNoDefaultOpen.includes('application/pdf')
|
||||||
|
|
||||||
if ((isDownloadHidden() || !isEnabledFilesPdfViewer) && isPdf()) {
|
if ((isDownloadHidden() || !isEnabledFilesPdfViewer) && isPdf()) {
|
||||||
|
|
|
||||||
|
|
@ -4,22 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import axios from '@nextcloud/axios'
|
import axios from '@nextcloud/axios'
|
||||||
import { generateOcsUrl, generateFilePath } from '@nextcloud/router'
|
import { generateFilePath } from '@nextcloud/router'
|
||||||
import { getSharingToken } from '@nextcloud/sharing/public'
|
|
||||||
|
|
||||||
export const createEmptyFile = async (context, mimeType, fileName, templateId = null) => {
|
|
||||||
const shareToken = getSharingToken()
|
|
||||||
|
|
||||||
const response = await axios.post(generateOcsUrl('apps/richdocuments/api/v1/file', 2), {
|
|
||||||
mimeType,
|
|
||||||
fileName,
|
|
||||||
directoryPath: context.dirname,
|
|
||||||
shareToken,
|
|
||||||
templateId,
|
|
||||||
})
|
|
||||||
|
|
||||||
return response.data
|
|
||||||
}
|
|
||||||
|
|
||||||
export const savePersonalSetting = (data) => {
|
export const savePersonalSetting = (data) => {
|
||||||
return axios.post(generateFilePath('richdocuments', 'ajax', 'personal.php'), data)
|
return axios.post(generateFilePath('richdocuments', 'ajax', 'personal.php'), data)
|
||||||
|
|
|
||||||
|
|
@ -1,105 +0,0 @@
|
||||||
/**
|
|
||||||
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
import axios from '@nextcloud/axios'
|
|
||||||
import { emit } from '@nextcloud/event-bus'
|
|
||||||
import Types from '../helpers/types.js'
|
|
||||||
import { createEmptyFile } from '../services/api.js'
|
|
||||||
import { generateOcsUrl } from '@nextcloud/router'
|
|
||||||
import { showError, spawnDialog } from '@nextcloud/dialogs'
|
|
||||||
import { getCapabilities } from '../services/capabilities.ts'
|
|
||||||
import { File, addNewFileMenuEntry, isFilenameValid, getUniqueName } from '@nextcloud/files'
|
|
||||||
import TemplatePicker from '../components/Modal/TemplatePicker.vue'
|
|
||||||
|
|
||||||
const createFileTypeEntry = (type, displayName, iconClass, index) => ({
|
|
||||||
id: 'add-' + type.extension,
|
|
||||||
displayName: t('richdocuments', displayName),
|
|
||||||
iconClass,
|
|
||||||
order: 10 + index,
|
|
||||||
async handler(context, content) {
|
|
||||||
const filename = t('richdocuments', displayName) + '.' + type.extension
|
|
||||||
if (getCapabilities().templates) {
|
|
||||||
await openTemplatePicker(context, type.name, type.mime, filename, content)
|
|
||||||
} else {
|
|
||||||
await createDocument(context, type.mime, filename, null, content)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
export const registerNewFileMenuEntries = () => {
|
|
||||||
const fileTypes = [
|
|
||||||
{ type: Types.getFileType('document'), displayName: 'New document', iconClass: 'icon-filetype-document' },
|
|
||||||
{ type: Types.getFileType('spreadsheet'), displayName: 'New spreadsheet', iconClass: 'icon-filetype-spreadsheet' },
|
|
||||||
{ type: Types.getFileType('presentation'), displayName: 'New presentation', iconClass: 'icon-filetype-presentation' },
|
|
||||||
{ type: Types.getFileType('drawing'), displayName: 'New drawing', iconClass: 'icon-filetype-draw' },
|
|
||||||
]
|
|
||||||
|
|
||||||
fileTypes.forEach(({ type, displayName, iconClass }, index) => {
|
|
||||||
addNewFileMenuEntry(createFileTypeEntry(type, displayName, iconClass, index))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const createDocument = async (context, mimetype, filename, templateId = null, content = []) => {
|
|
||||||
if (!isFilenameValid(filename)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
filename = getUniqueName(
|
|
||||||
filename,
|
|
||||||
content.map((n) => n.basename),
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await createEmptyFile(context, mimetype, filename, templateId)
|
|
||||||
const { data } = response
|
|
||||||
|
|
||||||
const file = new File({
|
|
||||||
source: context.source + '/' + filename,
|
|
||||||
basename: filename,
|
|
||||||
id: data.id,
|
|
||||||
mtime: new Date(data.mtime),
|
|
||||||
mime: data.mimetype,
|
|
||||||
owner: null,
|
|
||||||
permissions: data.permissions,
|
|
||||||
root: context?.root,
|
|
||||||
})
|
|
||||||
emit('files:node:created', file)
|
|
||||||
|
|
||||||
if (response && response.status === 'success') {
|
|
||||||
OCA.Viewer.open({ path: context.dirname + '/' + filename })
|
|
||||||
} else {
|
|
||||||
showError(t('core', 'Could not create file') + ': ' + response.data.message)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
showError(t('core', 'Could not create file'))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const openTemplatePicker = async (context, type, mimetype, filename, content = []) => {
|
|
||||||
try {
|
|
||||||
const { data: response } = await axios.get(generateOcsUrl(`apps/richdocuments/api/v1/templates/${type}`, 2))
|
|
||||||
const templates = response.ocs.data
|
|
||||||
|
|
||||||
if (templates.length === 1) {
|
|
||||||
await createDocument(context, mimetype, filename, templates[0].id, content)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
await spawnDialog(TemplatePicker, {
|
|
||||||
templates,
|
|
||||||
suggestedFilename: filename,
|
|
||||||
content,
|
|
||||||
initialTemplateId: templates[0]?.id,
|
|
||||||
}, (templateId, filename) => {
|
|
||||||
if (templateId) {
|
|
||||||
createDocument(context, mimetype, filename, templateId, content)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
showError(t('core', 'Could not load templates'))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue