Add support for adding canonical webroot (#157)
See cc42c7f46c
for details
This commit is contained in:
Родитель
fec3a73943
Коммит
a08c0b7a5e
|
@ -1,3 +1,6 @@
|
|||
.rd-settings-documentation {
|
||||
max-width: 50em;
|
||||
};
|
||||
#richdocuments h2 {
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
26
js/admin.js
26
js/admin.js
|
@ -72,6 +72,16 @@ var documentsSettings = {
|
|||
);
|
||||
},
|
||||
|
||||
saveWebroot: function(value) {
|
||||
var data = {
|
||||
'canonical_webroot': value
|
||||
};
|
||||
$.post(
|
||||
OC.filePath('richdocuments', 'ajax', 'admin.php'),
|
||||
data
|
||||
);
|
||||
},
|
||||
|
||||
afterSaveExternalApps: function(response) {
|
||||
OC.msg.finishedAction('#enable-external-apps-section-msg', response);
|
||||
},
|
||||
|
@ -233,6 +243,22 @@ var documentsSettings = {
|
|||
$select.change();
|
||||
});
|
||||
|
||||
$(document).on('change', '#enable_canonical_webroot_cb-richdocuments', function() {
|
||||
var page = $(this).parent();
|
||||
|
||||
page.find('#enable-canonical-webroot-section').toggleClass('hidden', !this.checked);
|
||||
if (!this.checked) {
|
||||
documentsSettings.saveWebroot('');
|
||||
} else {
|
||||
var val = $('#canonical-webroot').val();
|
||||
if (val)
|
||||
documentsSettings.saveWebroot();
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('change', '#canonical-webroot', function() {
|
||||
documentsSettings.saveWebroot(this.value);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
197
js/documents.js
197
js/documents.js
|
@ -71,6 +71,19 @@ var documentsMain = {
|
|||
renderComplete: false, // false till page is rendered with all required data about the document(s)
|
||||
toolbar : '<div id="ocToolbar"><div id="ocToolbarInside"></div><span id="toolbar" class="claro"></span></div>',
|
||||
|
||||
// generates docKey for given fileId
|
||||
_generateDocKey: function(wopiFileId) {
|
||||
var ocurl = OC.generateUrl('apps/richdocuments/wopi/files/{file_id}', {file_id: wopiFileId});
|
||||
if (richdocuments_canonical_webroot) {
|
||||
if (!richdocuments_canonical_webroot.startsWith('/'))
|
||||
richdocuments_canonical_webroot = '/' + richdocuments_canonical_webroot;
|
||||
|
||||
ocurl = ocurl.replace(OC.webroot, richdocuments_canonical_webroot);
|
||||
}
|
||||
|
||||
return ocurl;
|
||||
},
|
||||
|
||||
UI : {
|
||||
/* Editor wrapper HTML */
|
||||
container : '<div id="mainContainer" class="claro">' +
|
||||
|
@ -115,189 +128,9 @@ var documentsMain = {
|
|||
$('#revViewerContainer').prepend($('<div id="revViewer">'));
|
||||
}
|
||||
|
||||
var ocurl = documentsMain._generateDocKey(fileId);
|
||||
// WOPISrc - URL that loolwsd will access (ie. pointing to ownCloud)
|
||||
var wopiurl = window.location.protocol + '//' + window.location.host + OC.generateUrl('apps/richdocuments/wopi/files/{file_id}', {file_id: fileId});
|
||||
var wopisrc = encodeURIComponent(wopiurl);
|
||||
|
||||
// urlsrc - the URL from discovery xml that we access for the particular
|
||||
// document; we add various parameters to that.
|
||||
// The discovery is available at
|
||||
// https://<loolwsd-server>:9980/hosting/discovery
|
||||
var urlsrc = documentsMain.urlsrc +
|
||||
"WOPISrc=" + wopisrc +
|
||||
"&title=" + encodeURIComponent(title) +
|
||||
"&lang=" + OC.getLocale().replace('_', '-') + // loleaflet expects a BCP47 language tag syntax
|
||||
"&permission=readonly";
|
||||
|
||||
// access_token - must be passed via a form post
|
||||
var access_token = encodeURIComponent(documentsMain.token);
|
||||
|
||||
// form to post the access token for WOPISrc
|
||||
var form = '<form id="loleafletform_viewer" name="loleafletform_viewer" target="loleafletframe_viewer" action="' + urlsrc + '" method="post">' +
|
||||
'<input name="access_token" value="' + access_token + '" type="hidden"/></form>';
|
||||
|
||||
// iframe that contains the Collabora Online Viewer
|
||||
var frame = '<iframe id="loleafletframe_viewer" name= "loleafletframe_viewer" style="width:100%;height:100%;position:absolute;"/>';
|
||||
|
||||
$('#revViewer').append(form);
|
||||
$('#revViewer').append(frame);
|
||||
|
||||
// submit that
|
||||
$('#loleafletform_viewer').submit();
|
||||
documentsMain.isViewerMode = true;
|
||||
|
||||
// for closing revision mode
|
||||
$('#revPanelHeader .closeButton').click(function(e) {
|
||||
e.preventDefault();
|
||||
documentsMain.onCloseViewer();
|
||||
});
|
||||
},
|
||||
|
||||
addRevision: function(fileId, version, relativeTimestamp, documentPath) {
|
||||
var formattedTimestamp = OC.Util.formatDate(parseInt(version) * 1000);
|
||||
var fileName = documentsMain.fileName.substring(0, documentsMain.fileName.indexOf('.'));
|
||||
var downloadUrl, restoreUrl;
|
||||
if (version === 0) {
|
||||
formattedTimestamp = t('richdocuments', 'Latest revision');
|
||||
downloadUrl = OC.generateUrl('apps/files/download'+ documentPath);
|
||||
} else {
|
||||
downloadUrl = OC.generateUrl('apps/files_versions/download.php?file={file}&revision={revision}',
|
||||
{file: documentPath, revision: version});
|
||||
fileId = fileId + '_' + version;
|
||||
restoreUrl = OC.generateUrl('apps/files_versions/ajax/rollbackVersion.php?file={file}&revision={revision}',
|
||||
{file: documentPath, revision: version});
|
||||
}
|
||||
|
||||
var revHistoryItemTemplate = Handlebars.compile(documentsMain.UI.revHistoryItemTemplate);
|
||||
var html = revHistoryItemTemplate({
|
||||
downloadUrl: downloadUrl,
|
||||
downloadIconUrl: OC.imagePath('core', 'actions/download'),
|
||||
restoreUrl: restoreUrl,
|
||||
restoreIconUrl: OC.imagePath('core', 'actions/history'),
|
||||
relativeTimestamp: relativeTimestamp,
|
||||
formattedTimestamp: formattedTimestamp
|
||||
});
|
||||
|
||||
html = $(html).attr('data-fileid', fileId)
|
||||
.attr('data-title', fileName + ' - ' + formattedTimestamp);
|
||||
$('#revisionsContainer ul').append(html);
|
||||
},
|
||||
|
||||
fetchAndFillRevisions: function(documentPath) {
|
||||
// fill #rev-history with file versions
|
||||
$.get(OC.generateUrl('apps/files_versions/ajax/getVersions.php?source={documentPath}&start={start}',
|
||||
{ documentPath: documentPath, start: documentsMain.UI.revisionsStart }),
|
||||
function(result) {
|
||||
for(var key in result.data.versions) {
|
||||
documentsMain.UI.addRevision(documentsMain.fileId,
|
||||
result.data.versions[key].version,
|
||||
result.data.versions[key].humanReadableTimestamp,
|
||||
documentPath);
|
||||
}
|
||||
|
||||
// owncloud only gives 5 version at max in one go
|
||||
documentsMain.UI.revisionsStart += 5;
|
||||
|
||||
if (result.data.endReached) {
|
||||
// Remove 'More versions' button
|
||||
$('#show-more-versions').addClass('hidden');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
showRevHistory: function(documentPath) {
|
||||
$(document.body).prepend(documentsMain.UI.viewContainer);
|
||||
|
||||
var revHistoryContainerTemplate = Handlebars.compile(documentsMain.UI.revHistoryContainerTemplate);
|
||||
var revHistoryContainer = revHistoryContainerTemplate({
|
||||
filename: documentsMain.fileName,
|
||||
moreVersionsLabel: t('richdocuments', 'More versions…'),
|
||||
closeButtonUrl: OC.imagePath('core', 'actions/close')
|
||||
});
|
||||
$('#revViewerContainer').prepend(revHistoryContainer);
|
||||
|
||||
documentsMain.UI.revisionsStart = 0;
|
||||
|
||||
// append current document first
|
||||
documentsMain.UI.addRevision(documentsMain.fileId, 0, t('richdocuments', 'Just now'), documentPath);
|
||||
|
||||
// add "Show more versions" button
|
||||
$('#show-more-versions').click(function(e) {
|
||||
e.preventDefault();
|
||||
documentsMain.UI.fetchAndFillRevisions(documentPath);
|
||||
});
|
||||
|
||||
// fake click to load first 5 versions
|
||||
$('#show-more-versions').click();
|
||||
|
||||
// make these revisions clickable/attach functionality
|
||||
$('#revisionsContainer').on('click', '.versionPreview', function(e) {
|
||||
e.preventDefault();
|
||||
documentsMain.UI.showViewer(e.currentTarget.parentElement.dataset.fileid,
|
||||
e.currentTarget.parentElement.dataset.title);
|
||||
|
||||
// mark only current <li> as active
|
||||
$(e.currentTarget.parentElement.parentElement).find('li').removeClass('active');
|
||||
$(e.currentTarget.parentElement).addClass('active');
|
||||
});
|
||||
|
||||
$('#revisionsContainer').on('click', '.restoreVersion', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// close the viewer
|
||||
documentsMain.onCloseViewer();
|
||||
|
||||
// close the editor
|
||||
documentsMain.UI.hideEditor();
|
||||
|
||||
// If there are changes in the opened editor, we need to wait
|
||||
// for sometime before these changes can be saved and a revision is created for it,
|
||||
// before restoring to requested version.
|
||||
documentsMain.overlay.documentOverlay('show');
|
||||
setTimeout(function() {
|
||||
// restore selected version
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: e.currentTarget.href,
|
||||
success: function(response) {
|
||||
if (response.status === 'error') {
|
||||
documentsMain.UI.notify(t('richdocuments', 'Failed to revert the document to older version'));
|
||||
}
|
||||
|
||||
// load the file again, it should get reverted now
|
||||
window.location = OC.generateUrl('apps/richdocuments/index#{fileid}', {fileid: e.currentTarget.parentElement.dataset.fileid});
|
||||
window.location.reload();
|
||||
documentsMain.overlay.documentOverlay('hide');
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
// fake click on first revision (i.e current revision)
|
||||
$('#revisionsContainer li').first().find('.versionPreview').click();
|
||||
},
|
||||
|
||||
showEditor : function(title, fileId, action){
|
||||
if (documentsMain.loadError) {
|
||||
documentsMain.onEditorShutdown(documentsMain.loadErrorMessage + '\n' + documentsMain.loadErrorHint);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!documentsMain.renderComplete) {
|
||||
setTimeout(function() { documentsMain.UI.showEditor(title, action); }, 500);
|
||||
console.log('Waiting for page to render…');
|
||||
return;
|
||||
}
|
||||
parent.postMessage('loading', '*');
|
||||
|
||||
$(document.body).addClass("claro");
|
||||
$(document.body).prepend(documentsMain.UI.container);
|
||||
|
||||
parent.document.title = title + ' - ' + documentsMain.UI.mainTitle;
|
||||
|
||||
// WOPISrc - URL that loolwsd will access (ie. pointing to ownCloud)
|
||||
var wopiurl = window.location.protocol + '//' + window.location.host + OC.generateUrl('apps/richdocuments/wopi/files/{file_id}', {file_id: documentsMain.fileId});
|
||||
var wopisrc = encodeURIComponent(wopiurl);
|
||||
var wopiurl = window.location.protocol + '//' + window.location.host + ocurl;
|
||||
|
||||
// urlsrc - the URL from discovery xml that we access for the particular
|
||||
// document; we add various parameters to that.
|
||||
|
|
|
@ -174,6 +174,7 @@ class DocumentController extends Controller {
|
|||
'urlsrc' => $urlSrc,
|
||||
'path' => $folder->getRelativePath($item->getPath()),
|
||||
'instanceId' => $this->settings->getSystemValue('instanceid'),
|
||||
'canonical_webroot' => $this->appConfig->getAppValue('canonical_webroot'),
|
||||
];
|
||||
|
||||
$encryptionManager = \OC::$server->getEncryptionManager();
|
||||
|
|
|
@ -64,13 +64,16 @@ class SettingsController extends Controller{
|
|||
* @param string $edit_groups
|
||||
* @param string $use_groups
|
||||
* @param string $doc_format
|
||||
* @param string $external_apps
|
||||
* @param string $canonical_webroot
|
||||
* @return JSONResponse
|
||||
*/
|
||||
public function setSettings($wopi_url,
|
||||
$edit_groups,
|
||||
$edit_groups,
|
||||
$use_groups,
|
||||
$doc_format,
|
||||
$external_apps){
|
||||
$external_apps,
|
||||
$canonical_webroot) {
|
||||
$message = $this->l10n->t('Saved');
|
||||
|
||||
if ($wopi_url !== null){
|
||||
|
@ -98,6 +101,10 @@ class SettingsController extends Controller{
|
|||
$this->appConfig->setAppValue('external_apps', $external_apps);
|
||||
}
|
||||
|
||||
if ($canonical_webroot !== null) {
|
||||
$this->appConfig->setAppValue('canonical_webroot', $canonical_webroot);
|
||||
}
|
||||
|
||||
$this->discoveryManager->refretch();
|
||||
|
||||
$response = [
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
pranavk@pranavk.local.me.15425:1516137457
|
|
@ -26,7 +26,7 @@ script('richdocuments', 'admin');
|
|||
<input type="checkbox" class="doc-format-ooxml" id="doc_format_ooxml_enable-richdocuments" <?php p($_['doc_format'] === 'ooxml' ? 'checked' : '') ?> />
|
||||
<label for="doc_format_ooxml_enable-richdocuments"><?php p($l->t('Use OOXML by default for new files')) ?></label>
|
||||
<br/>
|
||||
<input type="checkbox" id="enable_external_apps_cb-richdocuments" <?php p($_['external_apps'] !== '' ? 'checked' : '') ?> />
|
||||
<input type="checkbox" id="enable_external_apps_cb-richdocuments" <?php p($_['external_apps'] != '' ? 'checked' : '') ?> />
|
||||
<label for="enable_external_apps_cb-richdocuments"><?php p($l->t('Enable access for external apps')) ?></label>
|
||||
<div id="enable-external-apps-section" class="indent <?php if ($_['external_apps'] == '') p('hidden') ?>" >
|
||||
<div id="external-apps-section">
|
||||
|
@ -36,5 +36,13 @@ script('richdocuments', 'admin');
|
|||
<button type="button" id="external-apps-save-button"><?php p($l->t('Save')) ?></button>
|
||||
<button type="button" id="external-apps-add-button"><?php p($l->t('Add')) ?></button>
|
||||
<span id="enable-external-apps-section-msg" class="msg"></span>
|
||||
</div><br/>
|
||||
|
||||
<input type="checkbox" id="enable_canonical_webroot_cb-richdocuments" <?php p($_['canonical_webroot'] != '' ? 'checked' : '') ?> />
|
||||
<label for="canonical_webroot_cb-richdocuments"><?php p($l->t('Use Canonical webroot')) ?></label>
|
||||
<div id="enable-canonical-webroot-section" class="indent <?php if ($_['canonical_webroot'] == '') p('hidden') ?>" >
|
||||
<input type="text" id="canonical-webroot" name="canonical-webroot-name" value="<?php p($_['canonical_webroot']) ?>">
|
||||
<br/>
|
||||
<p class="rd-settings-documentation"><em><?php p($l->t('Canonical webroot, in case there are multiple, for Collabora to use. Provide the one with least restrictions. Eg: Use non-shibbolized webroot if this instance is accessed by both shibbolized and non-shibbolized webroots. You can ignore this setting if only one webroot is used to access this instance.')) ?></em></p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
var richdocuments_urlsrc = '<?php p($_['urlsrc']) ?>';
|
||||
var richdocuments_path = '<?php p($_['path']) ?>';
|
||||
var instanceId = '<?php p($_['instanceId']) ?>';
|
||||
var richdocuments_canonical_webroot = '<?php p($_['canonical_webroot']) ?>';
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
|
Загрузка…
Ссылка в новой задаче