java-spring: add createUrl to editorConfig and creating from templates

This commit is contained in:
Oleg Sinizin
2021-07-29 13:30:49 +03:00
parent d5f5079c22
commit 2d51ddde3d
5 changed files with 88 additions and 1 deletions

View File

@ -33,12 +33,15 @@ import com.onlyoffice.integration.entities.enums.Type;
import com.onlyoffice.integration.util.documentManagers.DocumentManagerExts;
import com.onlyoffice.integration.util.fileUtilities.FileUtility;
import com.onlyoffice.integration.util.documentManagers.DocumentManager;
import com.onlyoffice.integration.util.objects.Template;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@Component
@Scope("prototype")
@ -57,11 +60,13 @@ public class EditorConfig {
private HashMap<String, Object> actionLink = null;
private String callbackUrl;
private String createUrl;
private Customization customization;
private Embedded embedded;
private Language lang;
private Mode mode;
private User user;
private List<Template> templates;
public void configure(com.onlyoffice.integration.entities.User user,
String fileName,
@ -77,7 +82,9 @@ public class EditorConfig {
e.printStackTrace();
}
}
this.setTemplatesData(fileName);
this.callbackUrl = documentManager.getCallback(fileName);
this.createUrl = documentManager.getCreateUrl(fileName, false);
this.lang = lang;
Boolean canEdit = documentManagerExts.getEditedExts().contains(fileUtility.getFileExtension(fileName));
this.customization = applicationContext.getBean(Customization.class);
@ -98,6 +105,12 @@ public class EditorConfig {
this.embedded = embedded;
}
private void setTemplatesData(String fileName){
this.templates = new ArrayList<>();
templates.add(new Template("", "Blank", documentManager.getCreateUrl(fileName, false)));
templates.add(new Template(documentManager.getTemplateImageUrl(fileName), "With sample content", documentManager.getCreateUrl(fileName, true)));
}
public HashMap<String, Object> getActionLink() {
return actionLink;
}
@ -153,4 +166,20 @@ public class EditorConfig {
public void setUser(User user) {
this.user = user;
}
public String getCreateUrl() {
return createUrl;
}
public void setCreateUrl(String createUrl) {
this.createUrl = createUrl;
}
public List<Template> getTemplates(){
return templates;
}
public void setTemplates(List<Template> templates){
this.templates = templates;
}
}

View File

@ -49,4 +49,6 @@ public interface DocumentManager {
public ArrayList<Map<String, Object>> getFilesInfo();
public ArrayList<Map<String, Object>> getFilesInfo(String fileId);
public String createDemo(String fileExt,Boolean sample,String uid,String uname) throws Exception;
public String getTemplateImageUrl(String fileName);
public String getCreateUrl(String fileName, Boolean sample);
}

View File

@ -18,6 +18,7 @@
package com.onlyoffice.integration.util.documentManagers;
import com.onlyoffice.integration.entities.enums.DocumentType;
import com.onlyoffice.integration.util.fileUtilities.FileUtility;
import com.onlyoffice.integration.util.serviceConverter.ServiceConverter;
import org.json.simple.JSONObject;
@ -91,6 +92,25 @@ public class DocumentManagerImpl implements DocumentManager {
return userAddress.replaceAll("[^0-9a-zA-Z.=]", "_");
}
public String getTemplateImageUrl(String fileName){
DocumentType fileType = fileUtility.getDocumentType(fileName);
String path = getServerUrl(true);
if(fileType.equals(DocumentType.word)){
return path + "/css/img/file_docx.svg";
} else if(fileType.equals(DocumentType.slide)){
return path + "/css/img/file_pptx.svg";
} else if(fileType.equals(DocumentType.cell)){
return path + "/css/img/file_xlsx.svg";
}
return path + "/css/img/file_docx.svg";
}
public String getCreateUrl(String fileName, Boolean sample){
String fileExt = fileName.substring(fileName.length() - 4);
String url = getServerUrl(true) + "/create?fileExt=" + fileExt + "&sample=" + sample;
return url;
}
public void createDirectory(Path path){
try {
Files.createDirectories(path);

View File

@ -0,0 +1,37 @@
package com.onlyoffice.integration.util.objects;
public class Template {
private String image;
private String title;
private String url;
public Template(String image, String title, String url) {
this.image = image;
this.title = title;
this.url = url;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}

View File

@ -123,7 +123,6 @@
var hist = JSON.parse(histArray[0]);
var historyData = JSON.parse(histArray[1]);
var usersForMentions = [[${usersForMentions}]];
console.log(hist);
if (hist && historyData) {
config.events['onRequestHistory'] = function () {