From 31e14040dc63042996fc737357d1b2b0ca563323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 16 Apr 2024 10:12:06 +0200 Subject: [PATCH 1/2] fix: Load public share link file creation again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/AppInfo/Application.php | 8 ++-- src/document.js | 2 +- src/files.js | 75 +++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 6 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index f0d2ceabf..18ed9e60c 100755 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -27,11 +27,10 @@ use OC\Files\Type\Detection; use OC\Security\CSP\ContentSecurityPolicy; use OCA\Federation\TrustedServers; -use OCA\Files\Event\LoadAdditionalScriptsEvent; -use OCA\Files_Sharing\Listener\LoadAdditionalListener; +use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent; use OCA\Officeonline\Capabilities; use OCA\Officeonline\Hooks\WopiLockHooks; -use OCA\Officeonline\Listener\FilesScriptListener; +use OCA\Officeonline\Listener\SharingLoadAdditionalScriptsListener; use OCA\Officeonline\Listener\LoadViewerListener; use OCA\Officeonline\Middleware\WOPIMiddleware; use OCA\Officeonline\PermissionManager; @@ -63,8 +62,7 @@ public function __construct(array $urlParams = []) { public function register(IRegistrationContext $context): void { $context->registerCapability(Capabilities::class); $context->registerMiddleWare(WOPIMiddleware::class); - $context->registerEventListener(LoadAdditionalScriptsEvent::class, FilesScriptListener::class); - $context->registerEventListener(LoadAdditionalListener::class, FilesScriptListener::class); + $context->registerEventListener(BeforeTemplateRenderedEvent::class, SharingLoadAdditionalScriptsListener::class); $context->registerEventListener(LoadViewer::class, LoadViewerListener::class); } diff --git a/src/document.js b/src/document.js index e8d275927..3b7774b45 100644 --- a/src/document.js +++ b/src/document.js @@ -283,7 +283,7 @@ const documentsMain = { }, 45000) }) - $('#loleafletframe').load(function() { + $('#loleafletframe').on('load', function() { const ViewerToLool = [ 'Action_FollowUser', 'Host_VersionRestore', diff --git a/src/files.js b/src/files.js index f822a15f9..bcd964ccb 100644 --- a/src/files.js +++ b/src/files.js @@ -1,3 +1,5 @@ +import Types from './helpers/types' +import axios from '@nextcloud/axios' import { getCapabilities } from '@nextcloud/capabilities' import './viewer.js' import Vue from 'vue' @@ -16,6 +18,77 @@ Vue.prototype.n = window.n Vue.prototype.OC = window.OC Vue.prototype.OCA = window.OCA +const NewFilePlugin = { + attach: function(newFileMenu) { + const self = this + const document = Types.getFileType('document') + const spreadsheet = Types.getFileType('spreadsheet') + const presentation = Types.getFileType('presentation') + + newFileMenu.addMenuEntry({ + id: 'add-' + document.extension, + displayName: t('officeonline', 'New Document'), + templateName: t('officeonline', 'New Document') + '.' + document.extension, + iconClass: 'icon-filetype-document', + fileType: 'x-office-document', + actionHandler: function(filename) { + self._createDocument(document.mime, filename) + }, + }) + + newFileMenu.addMenuEntry({ + id: 'add-' + spreadsheet.extension, + displayName: t('officeonline', 'New Spreadsheet'), + templateName: t('officeonline', 'New Spreadsheet') + '.' + spreadsheet.extension, + iconClass: 'icon-filetype-spreadsheet', + fileType: 'x-office-spreadsheet', + actionHandler: function(filename) { + self._createDocument(spreadsheet.mime, filename) + }, + }) + + newFileMenu.addMenuEntry({ + id: 'add-' + presentation.extension, + displayName: t('officeonline', 'New Presentation'), + templateName: t('officeonline', 'New Presentation') + '.' + presentation.extension, + iconClass: 'icon-filetype-presentation', + fileType: 'x-office-presentation', + actionHandler: function(filename) { + self._createDocument(presentation.mime, filename) + }, + }) + }, + + _createDocument: function(mimetype, filename) { + const dir = document.getElementById('dir') ? document.getElementById('dir').value : window.FileList.getCurrentDirectory() + try { + OCA.Files.Files.isFileNameValid(filename) + } catch (e) { + window.OC.dialogs.alert(e, t('core', 'Could not create file')) + return + } + filename = FileList.getUniqueName(filename) + const path = dir + '/' + filename + + const isPublic = document.getElementById('isPublic') ? document.getElementById('isPublic').value === '1' : false + if (isPublic) { + return window.FileList.createFile(filename).then(function() { + OCA.Viewer.open({ path }) + }) + } + + axios.post(OC.generateUrl('apps/officeonline/ajax/documents/create'), { mimetype, filename, dir }).then(({ data }) => { + console.debug(data) + if (data && data.status === 'success') { + window.FileList.add(data.data, { animate: true, scrollTo: true }) + window.OCA.Viewer.open({ path }) + } else { + window.OC.dialogs.alert(data.data.message, t('core', 'Could not create file')) + } + }) + }, +} + document.addEventListener('DOMContentLoaded', () => { // PUBLIC SHARE LINK HANDLING const isPublic = document.getElementById('isPublic') ? document.getElementById('isPublic').value === '1' : false @@ -29,4 +102,6 @@ document.addEventListener('DOMContentLoaded', () => { render: h => h(Office, { props: { fileName: document.getElementById('filename').value } }), }).$mount('#imgframe') } + + OC.Plugins.register('OCA.Files.NewFileMenu', NewFilePlugin) }) From 89a49ac15a6ed883fe6499d202f7162625255bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 16 Apr 2024 11:02:20 +0200 Subject: [PATCH 2/2] chore: Bump php version in tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .github/workflows/lint-php.yml | 2 +- .github/workflows/phpunit-mysql.yml | 2 +- .github/workflows/phpunit-oci.yml | 2 +- .github/workflows/phpunit-pgsql.yml | 2 +- .github/workflows/phpunit-sqlite.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint-php.yml b/.github/workflows/lint-php.yml index 22f861242..99813d199 100644 --- a/.github/workflows/lint-php.yml +++ b/.github/workflows/lint-php.yml @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: [ "8.0", "8.1", "8.2" ] + php-versions: [ "8.1", "8.2" ] name: php-lint diff --git a/.github/workflows/phpunit-mysql.yml b/.github/workflows/phpunit-mysql.yml index 13627a21d..0a64c41aa 100644 --- a/.github/workflows/phpunit-mysql.yml +++ b/.github/workflows/phpunit-mysql.yml @@ -38,7 +38,7 @@ jobs: strategy: matrix: - php-versions: ['8.0', '8.1', '8.2'] + php-versions: ['8.1', '8.2'] server-versions: ['master', 'stable29', 'stable28'] services: diff --git a/.github/workflows/phpunit-oci.yml b/.github/workflows/phpunit-oci.yml index 129f848cc..26163d8fb 100644 --- a/.github/workflows/phpunit-oci.yml +++ b/.github/workflows/phpunit-oci.yml @@ -38,7 +38,7 @@ jobs: strategy: matrix: - php-versions: ['8.0'] + php-versions: ['8.1'] server-versions: ['master'] services: diff --git a/.github/workflows/phpunit-pgsql.yml b/.github/workflows/phpunit-pgsql.yml index c944d35c5..476efd6bd 100644 --- a/.github/workflows/phpunit-pgsql.yml +++ b/.github/workflows/phpunit-pgsql.yml @@ -38,7 +38,7 @@ jobs: strategy: matrix: - php-versions: ['8.0'] + php-versions: ['8.1'] server-versions: ['master'] services: diff --git a/.github/workflows/phpunit-sqlite.yml b/.github/workflows/phpunit-sqlite.yml index 35463b0dc..fc4dd3e45 100644 --- a/.github/workflows/phpunit-sqlite.yml +++ b/.github/workflows/phpunit-sqlite.yml @@ -38,7 +38,7 @@ jobs: strategy: matrix: - php-versions: ['8.0'] + php-versions: ['8.1'] server-versions: ['master'] steps: