Skip to content
Snippets Groups Projects
Commit d7fa3f29 authored by Dominik Lechner's avatar Dominik Lechner
Browse files

Write document to drive and show it in preview

parent c891cbe6
No related branches found
No related tags found
No related merge requests found
Showing
with 135 additions and 18 deletions
......@@ -18,8 +18,8 @@
<title>Description</title>
</entityField>
<entityField>
<name>DOCUMENTMANAGEMENTID</name>
<valueProcess>%aditoprj%/entity/DocumentTemplate_entity/entityfields/documentmanagementid/valueProcess.js</valueProcess>
<name>DOCUMENTTEMPLATEID</name>
<valueProcess>%aditoprj%/entity/DocumentTemplate_entity/entityfields/documenttemplateid/valueProcess.js</valueProcess>
</entityField>
<entityField>
<name>DATE_NEW</name>
......@@ -52,6 +52,29 @@
<name>BINDATA</name>
<contentType>FILE</contentType>
</entityField>
<entityConsumer>
<name>Documents</name>
<fieldType>DEPENDENCY_OUT</fieldType>
<dependency>
<name>dependency</name>
<entityName>Document_entity</entityName>
<fieldName>Documents</fieldName>
</dependency>
<children>
<entityParameter>
<name>AssignmentTable_param</name>
<valueProcess>%aditoprj%/entity/DocumentTemplate_entity/entityfields/documents/children/assignmenttable_param/valueProcess.js</valueProcess>
</entityParameter>
<entityParameter>
<name>AssignmentRowId_param</name>
<valueProcess>%aditoprj%/entity/DocumentTemplate_entity/entityfields/documents/children/assignmentrowid_param/valueProcess.js</valueProcess>
</entityParameter>
<entityParameter>
<name>AssignmentName_param</name>
<valueProcess>%aditoprj%/entity/DocumentTemplate_entity/entityfields/documents/children/assignmentname_param/valueProcess.js</valueProcess>
</entityParameter>
</children>
</entityConsumer>
</entityFields>
<recordContainers>
<dbRecordContainer>
......@@ -80,10 +103,6 @@
<name>DESCRIPTION.value</name>
<recordfield>DOCUMENTTEMPLATE.DESCRIPTION</recordfield>
</dbRecordFieldMapping>
<dbRecordFieldMapping>
<name>DOCUMENTMANAGEMENTID.value</name>
<recordfield>DOCUMENTTEMPLATE.DOCUMENTTEMPLATEID</recordfield>
</dbRecordFieldMapping>
<dbRecordFieldMapping>
<name>LANGUAGE_documentmanagement.value</name>
<recordfield>DOCUMENTTEMPLATE.LANGUAGE</recordfield>
......@@ -104,6 +123,10 @@
<name>USER_NEW.value</name>
<recordfield>DOCUMENTTEMPLATE.USER_NEW</recordfield>
</dbRecordFieldMapping>
<dbRecordFieldMapping>
<name>DOCUMENTTEMPLATEID.value</name>
<recordfield>DOCUMENTTEMPLATE.DOCUMENTTEMPLATEID</recordfield>
</dbRecordFieldMapping>
</recordFieldMappings>
</dbRecordContainer>
</recordContainers>
......
import("system.vars");
import("system.result");
result.string("DOCUMENT");
\ No newline at end of file
import("system.vars");
import("system.result");
result.string(vars.get("$field.DOCUMENTTEMPLATEID"));
\ No newline at end of file
import("system.result");
result.string("DOCUMENTTEMPLATE");
\ No newline at end of file
import("system.vars");
import("system.db");
import("Document_lib");
if(vars.get("$field.BINDATA") != "")
{
DocumentUtil.writeDocumentToDrive(vars.get("$field.BINDATA"), vars.get("$field.DOCUMENTMANAGEMENTID"));
DocumentUtil.uploadDocument("DOCUMENTTEMPLATE", "DOCUMENT", vars.get("$field.DOCUMENTTEMPLATEID"), "",
vars.get("$field.BINDATA"), vars.get("$field.DOCUMENTTEMPLATEID"),
"", "", "_____SYSTEMALIAS", true);
}
\ No newline at end of file
......@@ -186,6 +186,12 @@
<fieldName>Documents</fieldName>
<isConsumer v="false" />
</entityDependency>
<entityDependency>
<name>51e40901-0132-45d3-b87d-69161cbc9fbd</name>
<entityName>DocumentTemplate_entity</entityName>
<fieldName>Documents</fieldName>
<isConsumer v="false" />
</entityDependency>
</dependencies>
<children>
<entityParameter>
......
......@@ -5,17 +5,17 @@ import("Document_lib");
var assignmentTable = vars.get("$param.AssignmentTable_param");
var assignmentName = vars.get("$param.AssignmentName_param");
var assignmentRowId = vars.get("$param.AssignmentRowId_param");
var bindata = DocumentUtil.getBindataFromUpload(vars.get("$field.BINDATA_UPLOAD"));
var uploadValue = vars.get("$field.BINDATA_UPLOAD");
var filename = vars.get("$field.NAME");
var description = vars.get("$field.DESCRIPTION");
var alias = db.getCurrentAlias();
if(bindata != '' && filename != ''){
if(uploadValue != '' && filename != ''){
var keyword = '';
if(vars.get("$field.IS_MAIN_DOCUMENT") == '1') {
keyword = 'MAINDOCUMENT';
}
db.insertBinary(assignmentTable, assignmentName, assignmentRowId, "",
bindata, filename, description, keyword, alias);
}
DocumentUtil.uploadDocument(assignmentTable, assignmentName, assignmentRowId, "",
uploadValue, filename, description, keyword, alias, false);
\ No newline at end of file
......@@ -6,6 +6,7 @@
<icon>VAADIN:FILE_FONT</icon>
<filterview>DocumentTemplateFilter_view</filterview>
<editview>DocumentTemplateEdit_view</editview>
<preview>DocumentTemplatePreview_view</preview>
<entity>DocumentTemplate_entity</entity>
<references>
<neonViewReference>
......@@ -16,5 +17,9 @@
<name>d49f9ade-9f33-4996-8482-d2520f6cb8db</name>
<view>DocumentTemplateEdit_view</view>
</neonViewReference>
<neonViewReference>
<name>c67fc6df-2511-4ddf-8638-cec8591fc9dc</name>
<view>DocumentTemplatePreview_view</view>
</neonViewReference>
</references>
</neonContext>
......@@ -16,6 +16,7 @@
<iconField>ICON</iconField>
<entryAction>downloadSingleFileAction</entryAction>
<entityField>#ENTITY</entityField>
<title>Documents</title>
</actionListViewTemplate>
</children>
</neonView>
<?xml version="1.0" encoding="UTF-8"?>
<neonView xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.1">
<name>DocumentTemplatePreview_view</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<layout>
<boxLayout>
<name>layout</name>
</boxLayout>
</layout>
<children>
<cardViewTemplate>
<name>Card</name>
<titleField>NAME</titleField>
<subtitleField>TYPE</subtitleField>
<entityField>#ENTITY</entityField>
<title>Document Template</title>
</cardViewTemplate>
<neonViewReference>
<name>772fc07a-a25b-48b1-acc4-ffd599e13def</name>
<entityField>Documents</entityField>
<view>DocumentList_view</view>
</neonViewReference>
</children>
</neonView>
......@@ -19,6 +19,41 @@ var path = vars.get("$sys.serverhome") + "/binaryfiles/"
function DocumentUtil(){
}
/**
* Utility function to write Files.
* Via parameter pWriteBlobToDrive function decides writing file to drive or in database
*
* @param {String} pAssignmentTable req Information for ASYS_BINARIES insert
* @param {String} pAssignmentName req Information for ASYS_BINARIES insert
* @param {String} pAssignmentRowId req Information for ASYS_BINARIES insert
* @param {String} pParentId opt Information for ASYS_BINARIES insert
* @param {String} pUploadValue req The value of an uploadcomponent contains filename + filedata separated by a semicolon e.g. "file1.jpg;base64data"
* @param {String} pFilename req Information for ASYS_BINARIES insert and the filename when write to drive
* @param {String} pDescription req Information for ASYS_BINARIES insert
* @param {String} pKeyword req Information for ASYS_BINARIES insert
* @param {String} pAlias req Information for ASYS_BINARIES insert
* @param {String} pWriteBlobToDrive req choose writing file to database or to drive (only the blob-value)
*
*/
DocumentUtil.uploadDocument = function(pAssignmentTable, pAssignmentName, pAssignmentRowId, pParentId, pUploadValue,
pFilename, pDescription, pKeyword, pAlias, pWriteBlobToDrive)
{
var bindata = "";
if(pWriteBlobToDrive != null && pWriteBlobToDrive == true)
{
DocumentUtil.writeDocumentToDrive(pUploadValue, pFilename);
}
else
{
bindata = DocumentUtil.getBindataFromUpload(pUploadValue);
}
//Allways insert into ASYS_BINARIES for Meta-Data
db.insertBinary(pAssignmentTable, pAssignmentName, pAssignmentRowId, pParentId,
bindata, pFilename, pDescription, pKeyword, pAlias);
}
/**
* Utility function to download all selected documents.
* Selected documents will be checked with $local.uids.
......@@ -87,15 +122,11 @@ DocumentUtil.deleteCurrentDocument = function() {
*/
DocumentUtil.writeDocumentToDrive = function(pUploadValue, pFileName)
{
let filename;
let filename = DocumentUtil.getFilenameFromUpload(pUploadValue);
if(pFileName != null && pFileName != "")
{
filename = pFileName;
}
else
{
filename = DocumentUtil.getFilenameFromUpload(pUploadValue);
filename = pFileName + "." + DocumentUtil.getFileExtensionFromUpload(filename);
}
let bindata = DocumentUtil.getBindataFromUpload(pUploadValue);
fileIO.storeData(path + filename, bindata, util.DATA_BINARY, false);
......@@ -117,6 +148,20 @@ DocumentUtil.getFilenameFromUpload = function(pUploadValue) {
return '';
}
/**
* Utility function to retrieve the fileextension from an uploadcomponent value.
*
* @param {String} pFileName filename with extension, f.e.: myFile.today.txt
* @return {String} the filename extension
*/
DocumentUtil.getFileExtensionFromUpload = function(pFileName) {
var res = pFileName.split(".");
if(res.length > 0)
return res[res.length-1];
else
return '';
}
/**
* Utility function to retrieve the filedata from an uploadcomponent value.
* The value of an uploadcomponent contains filename + filedata separated by
......
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