Skip to content
Snippets Groups Projects
Commit 55cfc98c authored by uhensler's avatar uhensler
Browse files

OO-3940: Show document always as read-only, start editing with the menu command

parent 3c9ed9a2
No related branches found
No related tags found
No related merge requests found
Showing
with 211 additions and 43 deletions
......@@ -49,12 +49,18 @@ public class VFSLeafEditorController extends BasicController {
public VFSLeafEditorController(UserRequest ureq, WindowControl wControl, VFSLeaf vfsLeaf,
FolderComponent folderComponent, VFSLeafEditorSecurityCallback secCallback) {
this(ureq, wControl, vfsLeaf, folderComponent, secCallback, null);
}
public VFSLeafEditorController(UserRequest ureq, WindowControl wControl, VFSLeaf vfsLeaf,
FolderComponent folderComponent, VFSLeafEditorSecurityCallback secCallback, String cssClass) {
super(ureq, wControl);
this.vfsLeaf = vfsLeaf;
this.folderComponent = folderComponent;
this.secCallback = secCallback;
mainVC = createVelocityContainer("editor_main");
mainVC.contextPut("cssClass", cssClass);
configCtrl = new VFSLeafConfigController(ureq, wControl, vfsLeaf, secCallback);
listenTo(configCtrl);
......
<div class="o_vfseditor">
<div class="o_vfseditor $!cssClass">
$r.render("config")
#if($r.available("editor"))
$r.render("editor")
......
......@@ -31,10 +31,10 @@ import org.olat.fileresource.types.XlsFileResource;
* @author uhensler, urs.hensler@frentix.com, http://www.frentix.com
*
*/
public class ExcelCreateDelegate extends AbstractCreateDelegate {
public class ExcelVFSEditorDelegateType implements VFSEditorDelegateType {
@Override
protected OLATResourceable getOLATResourceable() {
public OLATResourceable getOLATResourceable() {
return new XlsFileResource();
}
......@@ -44,12 +44,12 @@ public class ExcelCreateDelegate extends AbstractCreateDelegate {
}
@Override
protected String getSuffix() {
public String getSuffix() {
return "xlsx";
}
@Override
protected InputStream getContent() {
public InputStream getContent() {
return ContentProviderFactory.emptyXlsx().getContent();
}
......
......@@ -79,8 +79,11 @@ public class RepositoryHandlerFactory {
registerHandler(new GlossaryHandler(), 41);
registerHandler(new PortfolioHandler(), 42);
registerHandler(new WebDocumentHandler(DocFileResource.TYPE_NAME, new WordCreateDelegate()), 10001);
registerHandler(new WebDocumentHandler(XlsFileResource.TYPE_NAME, new ExcelCreateDelegate()), 10002);
VFSEditorDelegate wordDelegate = new VFSEditorDelegate(new WordVFSEditorDelegateType());
registerHandler(new WebDocumentHandler(DocFileResource.TYPE_NAME, wordDelegate, wordDelegate), 10001);
VFSEditorDelegate excelDelegate = new VFSEditorDelegate(new ExcelVFSEditorDelegateType());
registerHandler(new WebDocumentHandler(XlsFileResource.TYPE_NAME, excelDelegate, excelDelegate), 10002);
registerHandler(new WebDocumentHandler(PowerpointFileResource.TYPE_NAME), 10003);
registerHandler(new WebDocumentHandler(PdfFileResource.TYPE_NAME), 10010);
registerHandler(new WebDocumentHandler(ImageFileResource.TYPE_NAME), 10011);
......
......@@ -20,19 +20,29 @@
package org.olat.repository.handlers;
import java.io.File;
import java.io.InputStream;
import java.util.Locale;
import org.olat.core.CoreSpringFactory;
import org.olat.core.commons.persistence.DBFactory;
import org.olat.core.commons.services.vfs.VFSLeafEditorSecurityCallback;
import org.olat.core.commons.services.vfs.VFSLeafEditorSecurityCallbackBuilder;
import org.olat.core.commons.services.vfs.VFSRepositoryService;
import org.olat.core.commons.services.vfs.ui.editor.VFSLeafEditorController;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.stack.TooledStackedPanel;
import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.id.Identity;
import org.olat.core.id.OLATResourceable;
import org.olat.core.id.Organisation;
import org.olat.core.logging.AssertException;
import org.olat.core.util.FileUtils;
import org.olat.core.util.vfs.LocalFileImpl;
import org.olat.core.util.vfs.LocalImpl;
import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSItem;
import org.olat.core.util.vfs.VFSLeaf;
import org.olat.core.util.vfs.VFSManager;
import org.olat.core.util.vfs.filters.VFSSystemItemFilter;
import org.olat.fileresource.FileResourceManager;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryEntryStatusEnum;
......@@ -46,35 +56,75 @@ import org.olat.resource.OLATResourceManager;
* @author uhensler, urs.hensler@frentix.com, http://www.frentix.com
*
*/
public abstract class AbstractCreateDelegate implements WebDocumentCreateDelegate {
public class VFSEditorDelegate implements WebDocumentCreateDelegate, WebDocumentEditDelegate {
protected abstract OLATResourceable getOLATResourceable();
protected abstract String getSuffix();
protected abstract InputStream getContent();
private VFSEditorDelegateType type;
public VFSEditorDelegate(VFSEditorDelegateType type) {
this.type = type;
}
@Override
public String getCreateLabelI18nKey() {
return type.getCreateLabelI18nKey();
}
@Override
public boolean supportCreate() {
return hasEditor();
}
private boolean hasEditor() {
VFSRepositoryService vfsService = CoreSpringFactory.getImpl(VFSRepositoryService.class);
return vfsService.hasEditor(getSuffix());
return vfsService.hasEditor(type.getSuffix());
}
@Override
public RepositoryEntry createResource(Identity initialAuthor, String displayname, String description,
Object createObject, Organisation organisation, Locale locale) {
OLATResource resource = OLATResourceManager.getInstance().createAndPersistOLATResourceInstance(getOLATResourceable());
OLATResource resource = OLATResourceManager.getInstance().createAndPersistOLATResourceInstance(type.getOLATResourceable());
File fResourceFileroot = FileResourceManager.getInstance().getFileResourceRootImpl(resource).getBasefile();
String filename = FileUtils.cleanFilename(displayname.toLowerCase()) + "." + getSuffix();
String filename = FileUtils.cleanFilename(displayname.toLowerCase()) + "." + type.getSuffix();
File target = new File(fResourceFileroot, filename);
VFSLeaf vfsLeaf = new LocalFileImpl(target);
VFSManager.copyContent(getContent(), vfsLeaf);
VFSManager.copyContent(type.getContent(), vfsLeaf);
RepositoryEntry re = CoreSpringFactory.getImpl(RepositoryService.class).create(initialAuthor, null, "", displayname,
description, resource, RepositoryEntryStatusEnum.preparation, organisation);
DBFactory.getInstance().commit();
return re;
}
@Override
public EditionSupport supportsEdit() {
return hasEditor()? EditionSupport.yes: EditionSupport.no;
}
@Override
public Controller createEditorController(RepositoryEntry re, UserRequest ureq, WindowControl wControl,
TooledStackedPanel toolbar) {
OLATResource resource = re.getOlatResource();
VFSContainer fResourceFileroot = FileResourceManager.getInstance().getFileResourceRootImpl(resource);
LocalFileImpl document = null;
for(VFSItem item:fResourceFileroot.getItems(new VFSSystemItemFilter())) {
if(item instanceof VFSLeaf && item instanceof LocalImpl) {
document = (LocalFileImpl)item;
}
}
if (document == null) {
throw new AssertException("Web document not found! " + re);
}
VFSLeafEditorSecurityCallback secCallback = VFSLeafEditorSecurityCallbackBuilder.builder()
.canEdit(true)
.canClose(false)
.build();
// FolderComponent should be initialized to be safe. As of today the internal
// editor does not support these file types.
return new VFSLeafEditorController(ureq, wControl, document, null, secCallback, "o_web_document_edit");
}
}
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.repository.handlers;
import java.io.InputStream;
import org.olat.core.id.OLATResourceable;
/**
*
* Initial date: 27 Mar 2019<br>
* @author uhensler, urs.hensler@frentix.com, http://www.frentix.com
*
*/
public interface VFSEditorDelegateType {
public String getCreateLabelI18nKey();
public OLATResourceable getOLATResourceable();
public String getSuffix();
public InputStream getContent();
}
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.repository.handlers;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.stack.TooledStackedPanel;
import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.WindowControl;
import org.olat.repository.RepositoryEntry;
/**
*
* Initial date: 27 Mar 2019<br>
* @author uhensler, urs.hensler@frentix.com, http://www.frentix.com
*
*/
public interface WebDocumentEditDelegate {
public EditionSupport supportsEdit();
public Controller createEditorController(RepositoryEntry re, UserRequest ureq, WindowControl wControl, TooledStackedPanel toolbar);
}
......@@ -84,14 +84,16 @@ public class WebDocumentHandler extends FileHandler {
private static final OLog log = Tracing.createLoggerFor(WebDocumentHandler.class);
private final String supportedType;
private final WebDocumentCreateDelegate createDelegate;
private final WebDocumentEditDelegate editDelegate;
public WebDocumentHandler(String type) {
this(type, new NullCreateDelegate());
this(type, new NullCreateDelegate(), new NullEditDelegate());
}
public WebDocumentHandler(String type, WebDocumentCreateDelegate createDelegate) {
public WebDocumentHandler(String type, WebDocumentCreateDelegate createDelegate, WebDocumentEditDelegate editDelegate) {
this.supportedType = type;
this.createDelegate = createDelegate;
this.editDelegate = editDelegate;
}
@Override
......@@ -234,7 +236,7 @@ public class WebDocumentHandler extends FileHandler {
@Override
public EditionSupport supportsEdit(OLATResourceable resource) {
return EditionSupport.no;
return editDelegate.supportsEdit();
}
@Override
......@@ -262,7 +264,7 @@ public class WebDocumentHandler extends FileHandler {
@Override
public Controller createEditorController(RepositoryEntry re, UserRequest ureq, WindowControl wControl, TooledStackedPanel toolbar) {
throw new AssertException("a web document is not editable!!! res-id:"+re.getResourceableId());
return editDelegate.createEditorController(re, ureq, wControl, toolbar);
}
@Override
......@@ -318,4 +320,19 @@ public class WebDocumentHandler extends FileHandler {
}
}
private static class NullEditDelegate implements WebDocumentEditDelegate {
@Override
public EditionSupport supportsEdit() {
return EditionSupport.no;
}
@Override
public Controller createEditorController(RepositoryEntry re, UserRequest ureq, WindowControl wControl,
TooledStackedPanel toolbar) {
throw new AssertException("This web document is not editable!!! res-id: " + re.getResourceableId());
}
}
}
......@@ -31,7 +31,7 @@ import org.olat.fileresource.types.DocFileResource;
* @author uhensler, urs.hensler@frentix.com, http://www.frentix.com
*
*/
public class WordCreateDelegate extends AbstractCreateDelegate {
public class WordVFSEditorDelegateType implements VFSEditorDelegateType {
@Override
public String getCreateLabelI18nKey() {
......@@ -39,17 +39,17 @@ public class WordCreateDelegate extends AbstractCreateDelegate {
}
@Override
protected OLATResourceable getOLATResourceable() {
public OLATResourceable getOLATResourceable() {
return new DocFileResource();
}
@Override
protected String getSuffix() {
public String getSuffix() {
return "docx";
}
@Override
protected InputStream getContent() {
public InputStream getContent() {
return ContentProviderFactory.emptyDocx().getContent();
}
......
......@@ -104,14 +104,14 @@ public class WebDocumentRunController extends BasicController {
}
} else if (vfsService.hasEditor(extension)) {
VFSLeafEditorSecurityCallback secCallback = VFSLeafEditorSecurityCallbackBuilder.builder()
.canEdit(reSecurity.isOwner() || reSecurity.isCoach())
.canEdit(false)
.canClose(false)
.build();
List<VFSLeafEditor> editors = vfsService.getEditors(document);
if (editors.size() >= 1) {
// FolderComponent should be initialized to be safe. As of today the internal
// editor does not support these file types.
Controller editCtrl = new VFSLeafEditorController(ureq, wControl, document, null, secCallback);
Controller editCtrl = new VFSLeafEditorController(ureq, wControl, document, null, secCallback, "o_web_document");
listenTo(editCtrl);
mainVC.put("content", editCtrl.getInitialComponent());
}
......
......@@ -8,16 +8,26 @@
border-width: 1px;
}
}
}
.o_web_content {
.o_collabora {
iframe {
width: 100%;
height: calc(100vh - 355px); // 387px would be good to avoid scroll bars if editor selection is shown
margin-top: 10px;
margin-bottom: 20px;
border-width: 1px;
&.o_web_document {
.o_collabora {
iframe {
width: 100%;
height: calc(100vh - 355px); // editor selection is not taken
margin-top: 10px;
border-width: 1px;
}
}
}
&.o_web_document_edit {
.o_collabora {
iframe {
width: 100%;
height: calc(100vh - 310px); // editor selection is not taken
margin-top: 10px;
margin-bottom: 35px;
border-width: 1px;
}
}
}
}
\ No newline at end of file
source diff could not be displayed: it is too large. Options to address this: view the blob.
source diff could not be displayed: it is too large. Options to address this: view the blob.
source diff could not be displayed: it is too large. Options to address this: view the blob.
source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment