Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ONHOLD/WIP: POC allow customizing supported formats via app config #459

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
107 changes: 42 additions & 65 deletions js/viewer/viewer.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,29 @@
/* globals FileList, OCA.Files.fileActions, oc_debug */
var odfViewer = {
isDocuments : false,
supportedMimes: [
'application/pdf',
'application/vnd.oasis.opendocument.text',
'application/vnd.oasis.opendocument.spreadsheet',
'application/vnd.oasis.opendocument.graphics',
'application/vnd.oasis.opendocument.presentation',
'application/vnd.oasis.opendocument.text-flat-xml',
'application/vnd.oasis.opendocument.spreadsheet-flat-xml',
'application/vnd.oasis.opendocument.graphics-flat-xml',
'application/vnd.oasis.opendocument.presentation-flat-xml',
'application/vnd.lotus-wordpro',
'image/svg+xml',
'application/vnd.visio',
'application/vnd.wordperfect',
'application/msonenote',
'application/msword',
'application/rtf',
'text/rtf',
'text/plain',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'application/vnd.ms-word.document.macroEnabled.12',
'application/vnd.ms-word.template.macroEnabled.12',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
'application/vnd.ms-excel.sheet.macroEnabled.12',
'application/vnd.ms-excel.template.macroEnabled.12',
'application/vnd.ms-excel.addin.macroEnabled.12',
'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
'application/vnd.ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.openxmlformats-officedocument.presentationml.template',
'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'application/vnd.ms-powerpoint.template.macroEnabled.12',
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'
],

loadSettings: function () {
return new Promise(function (resolve, reject) {
$.ajax({
type: "get",
url: OC.filePath('richdocuments', 'ajax', 'settings.php'),
success: function(data) {
resolve(data);
},
error: function(xhr, status) {
reject(Error(status));
}
});
});
},

isSupportedMimeType: function(mimetype) {
return (odfViewer.supportedMimes.indexOf(mimetype) !== -1);
},

register : function() {
for (var i = 0; i < odfViewer.supportedMimes.length; ++i) {
var mime = odfViewer.supportedMimes[i];
register : function(settings) {
for (var i = 0; i < settings.supported_mimetypes.length; ++i) {
var mime = settings.supported_mimetypes[i];

if(!$("#isPublic").val() &&
OC.appConfig.richdocuments &&
Expand Down Expand Up @@ -117,8 +93,8 @@ var odfViewer = {

},

registerFilesMenu: function(response) {
var ooxml = response.doc_format === 'ooxml';
registerFilesMenu: function(settings) {
var ooxml = settings.doc_format === 'ooxml';

var docExt, spreadsheetExt, presentationExt;
var docMime, spreadsheetMime, presentationMime;
Expand Down Expand Up @@ -245,28 +221,29 @@ $(document).ready(function() {
&& typeof OCA.Files !== 'undefined'
&& typeof OCA.Files.fileActions !== 'undefined'
) {
odfViewer.register();

// Check if public file share button
var mimetype = $("#mimetype").val();
if (odfViewer.supportedMimes.indexOf(mimetype) !== -1 && $("#isPublic").val()){
// Single file public share, add button to allow view or edit
var button = document.createElement("a");
button.href = OC.generateUrl("apps/richdocuments/public?fileId={file_id}&shareToken={shareToken}", { file_id: null, shareToken: encodeURIComponent($("#sharingToken").val()) });
button.className = "button";
button.innerText = t('richdocuments', 'View/Edit in Collabora');

$("#preview").append(button);
}

if (!$("#isPublic").val()) {
// Dont register file menu with public links
$.get(
OC.filePath('richdocuments', 'ajax', 'settings.php'),
{},
odfViewer.registerFilesMenu
);
}
odfViewer.loadSettings().then(function (settings) {
odfViewer.register(settings);

// Check if public file share button
var mimetype = $("#mimetype").val();
if (settings.supported_mimetypes.indexOf(mimetype) !== -1 && $("#isPublic").val()){
// Single file public share, add button to allow view or edit
var button = document.createElement("a");
button.href = OC.generateUrl("apps/richdocuments/public?fileId={file_id}&shareToken={shareToken}", { file_id: null, shareToken: encodeURIComponent($("#sharingToken").val()) });
button.className = "button";
button.innerText = t('richdocuments', 'View/Edit in Collabora');

$("#preview").append(button);
}

if (!$("#isPublic").val()) {
odfViewer.registerFilesMenu(settings);
}
}, function (error) {
console.error(error);
});

}

if ($('#odf_close').length) {
Expand Down
50 changes: 50 additions & 0 deletions lib/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,45 @@ class AppConfig {
'open_in_new_tab' => 'true',
'start_grace_period' => 'false',
];
private $defaultMimetypes = [
'application/pdf',
'application/vnd.oasis.opendocument.text',
'application/vnd.oasis.opendocument.spreadsheet',
'application/vnd.oasis.opendocument.graphics',
'application/vnd.oasis.opendocument.presentation',
'application/vnd.oasis.opendocument.text-flat-xml',
'application/vnd.oasis.opendocument.spreadsheet-flat-xml',
'application/vnd.oasis.opendocument.graphics-flat-xml',
'application/vnd.oasis.opendocument.presentation-flat-xml',
'application/vnd.lotus-wordpro',
'image/svg+xml',
'application/vnd.visio',
'application/vnd.wordperfect',
'application/msonenote',
'application/msword',
'application/rtf',
'text/rtf',
'text/plain',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'application/vnd.ms-word.document.macroEnabled.12',
'application/vnd.ms-word.template.macroEnabled.12',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
'application/vnd.ms-excel.sheet.macroEnabled.12',
'application/vnd.ms-excel.template.macroEnabled.12',
'application/vnd.ms-excel.addin.macroEnabled.12',
'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
'application/vnd.ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.openxmlformats-officedocument.presentationml.template',
'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'application/vnd.ms-powerpoint.template.macroEnabled.12',
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'
];

private $config;
private $appManager;
Expand Down Expand Up @@ -165,4 +204,15 @@ public function secureViewHasWatermarkDefaultEnabled() {
public function openInNewTabEnabled() {
return \filter_var($this->getAppValue('open_in_new_tab'), FILTER_VALIDATE_BOOLEAN);
}

/**
* @return bool
*/
public function getSupportedMimetypes() {
$supportedMimetypes = \json_decode($this->getAppValue('supported_mimetypes'));
if (!$supportedMimetypes) {
return $this->defaultMimetypes;
}
return $supportedMimetypes;
}
}
1 change: 1 addition & 0 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function getSettings() {
'wopi_url' => $this->appConfig->getAppValue('wopi_url'),
'test_wopi_url' => $this->appConfig->getAppValue('test_wopi_url'),
'test_server_groups' => $this->appConfig->getAppValue('test_server_groups'),
'supported_mimetypes' => $this->appConfig->getSupportedMimetypes(),
];
}

Expand Down