mirror of
https://github.com/sismics/docs.git
synced 2024-11-25 07:07:57 +01:00
#201: file processing indicator
This commit is contained in:
parent
b330d54ca2
commit
f44b4bb0e0
@ -1,11 +1,10 @@
|
|||||||
package com.sismics.docs.core.event;
|
package com.sismics.docs.core.event;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import com.sismics.docs.core.model.jpa.File;
|
import com.sismics.docs.core.model.jpa.File;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New file created event.
|
* New file created event.
|
||||||
*
|
*
|
||||||
|
@ -59,5 +59,7 @@ public class FileCreatedAsyncListener {
|
|||||||
// Update Lucene index
|
// Update Lucene index
|
||||||
LuceneDao luceneDao = new LuceneDao();
|
LuceneDao luceneDao = new LuceneDao();
|
||||||
luceneDao.createFile(fileCreatedAsyncEvent.getFile());
|
luceneDao.createFile(fileCreatedAsyncEvent.getFile());
|
||||||
|
|
||||||
|
FileUtil.endProcessingFile(file.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,9 @@ import java.io.InputStream;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File entity utilities.
|
* File entity utilities.
|
||||||
@ -40,6 +43,11 @@ public class FileUtil {
|
|||||||
* Logger.
|
* Logger.
|
||||||
*/
|
*/
|
||||||
private static final Logger log = LoggerFactory.getLogger(FileUtil.class);
|
private static final Logger log = LoggerFactory.getLogger(FileUtil.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File ID of files currently being processed.
|
||||||
|
*/
|
||||||
|
private static Set<String> processingFileSet = Collections.synchronizedSet(new HashSet<String>());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract content from a file.
|
* Extract content from a file.
|
||||||
@ -269,6 +277,7 @@ public class FileUtil {
|
|||||||
|
|
||||||
// Raise a new file created event and document updated event if we have a document
|
// Raise a new file created event and document updated event if we have a document
|
||||||
if (documentId != null) {
|
if (documentId != null) {
|
||||||
|
startProcessingFile(fileId);
|
||||||
FileCreatedAsyncEvent fileCreatedAsyncEvent = new FileCreatedAsyncEvent();
|
FileCreatedAsyncEvent fileCreatedAsyncEvent = new FileCreatedAsyncEvent();
|
||||||
fileCreatedAsyncEvent.setUserId(userId);
|
fileCreatedAsyncEvent.setUserId(userId);
|
||||||
fileCreatedAsyncEvent.setLanguage(language);
|
fileCreatedAsyncEvent.setLanguage(language);
|
||||||
@ -285,4 +294,32 @@ public class FileUtil {
|
|||||||
|
|
||||||
return fileId;
|
return fileId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start processing a file.
|
||||||
|
*
|
||||||
|
* @param fileId File ID
|
||||||
|
*/
|
||||||
|
public static void startProcessingFile(String fileId) {
|
||||||
|
processingFileSet.add(fileId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End processing a file.
|
||||||
|
*
|
||||||
|
* @param fileId File ID
|
||||||
|
*/
|
||||||
|
public static void endProcessingFile(String fileId) {
|
||||||
|
processingFileSet.remove(fileId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if a file is currently processing.
|
||||||
|
*
|
||||||
|
* @param fileId File ID
|
||||||
|
* @return True if the file is processing
|
||||||
|
*/
|
||||||
|
public static boolean isProcessingFile(String fileId) {
|
||||||
|
return processingFileSet.contains(fileId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,6 +196,7 @@ public class FileResource extends BaseResource {
|
|||||||
try {
|
try {
|
||||||
java.nio.file.Path storedFile = DirectoryUtil.getStorageDirectory().resolve(id);
|
java.nio.file.Path storedFile = DirectoryUtil.getStorageDirectory().resolve(id);
|
||||||
java.nio.file.Path unencryptedFile = EncryptionUtil.decryptFile(storedFile, user.getPrivateKey());
|
java.nio.file.Path unencryptedFile = EncryptionUtil.decryptFile(storedFile, user.getPrivateKey());
|
||||||
|
FileUtil.startProcessingFile(id);
|
||||||
FileCreatedAsyncEvent fileCreatedAsyncEvent = new FileCreatedAsyncEvent();
|
FileCreatedAsyncEvent fileCreatedAsyncEvent = new FileCreatedAsyncEvent();
|
||||||
fileCreatedAsyncEvent.setUserId(principal.getId());
|
fileCreatedAsyncEvent.setUserId(principal.getId());
|
||||||
fileCreatedAsyncEvent.setLanguage(documentDto.getLanguage());
|
fileCreatedAsyncEvent.setLanguage(documentDto.getLanguage());
|
||||||
@ -283,6 +284,7 @@ public class FileResource extends BaseResource {
|
|||||||
* @apiSuccess {String} files.id ID
|
* @apiSuccess {String} files.id ID
|
||||||
* @apiSuccess {String} files.mimetype MIME type
|
* @apiSuccess {String} files.mimetype MIME type
|
||||||
* @apiSuccess {String} files.name File name
|
* @apiSuccess {String} files.name File name
|
||||||
|
* @apiSuccess {String} files.processing True if the file is currently processing
|
||||||
* @apiSuccess {String} files.document_id Document ID
|
* @apiSuccess {String} files.document_id Document ID
|
||||||
* @apiSuccess {String} files.create_date Create date (timestamp)
|
* @apiSuccess {String} files.create_date Create date (timestamp)
|
||||||
* @apiSuccess {String} files.size File size (in bytes)
|
* @apiSuccess {String} files.size File size (in bytes)
|
||||||
@ -321,6 +323,7 @@ public class FileResource extends BaseResource {
|
|||||||
try {
|
try {
|
||||||
files.add(Json.createObjectBuilder()
|
files.add(Json.createObjectBuilder()
|
||||||
.add("id", fileDb.getId())
|
.add("id", fileDb.getId())
|
||||||
|
.add("processing", FileUtil.isProcessingFile(fileDb.getId()))
|
||||||
.add("name", JsonUtil.nullable(fileDb.getName()))
|
.add("name", JsonUtil.nullable(fileDb.getName()))
|
||||||
.add("mimetype", fileDb.getMimeType())
|
.add("mimetype", fileDb.getMimeType())
|
||||||
.add("document_id", JsonUtil.nullable(fileDb.getDocumentId()))
|
.add("document_id", JsonUtil.nullable(fileDb.getDocumentId()))
|
||||||
|
@ -114,7 +114,8 @@
|
|||||||
"upload_error": "Upload error",
|
"upload_error": "Upload error",
|
||||||
"upload_error_quota": "Quota reached",
|
"upload_error_quota": "Quota reached",
|
||||||
"drop_zone": "Drag & drop files here to upload",
|
"drop_zone": "Drag & drop files here to upload",
|
||||||
"add_files": "Add files"
|
"add_files": "Add files",
|
||||||
|
"file_processing_indicator": "This file is being processed. Searching will not be available before it is complete."
|
||||||
},
|
},
|
||||||
"workflow": {
|
"workflow": {
|
||||||
"workflow": "Workflow",
|
"workflow": "Workflow",
|
||||||
|
@ -45,6 +45,11 @@
|
|||||||
<div ui-sortable="fileSortableOptions" ng-model="files">
|
<div ui-sortable="fileSortableOptions" ng-model="files">
|
||||||
<div class="col-xs-6 col-sm-4 col-md-4 col-lg-3 text-center" ng-repeat="file in files">
|
<div class="col-xs-6 col-sm-4 col-md-4 col-lg-3 text-center" ng-repeat="file in files">
|
||||||
<div class="thumbnail handle" ng-if="file.id">
|
<div class="thumbnail handle" ng-if="file.id">
|
||||||
|
<div class="file-processing-indicator" ng-show="file.processing"
|
||||||
|
uib-tooltip="{{ 'document.view.content.file_processing_indicator' | translate }}">
|
||||||
|
<span class="fas fa-spin fa-circle-notch"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<a ng-click="openFile(file)">
|
<a ng-click="openFile(file)">
|
||||||
<img ng-src="../api/file/{{ file.id }}/data?size=thumb" uib-tooltip="{{ file.mimetype }} | {{ file.size | filesize }}" tooltip-placement="top" />
|
<img ng-src="../api/file/{{ file.id }}/data?size=thumb" uib-tooltip="{{ file.mimetype }} | {{ file.size | filesize }}" tooltip-placement="top" />
|
||||||
</a>
|
</a>
|
||||||
|
@ -214,6 +214,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// File processing indicator
|
||||||
|
.file-processing-indicator {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 2;
|
||||||
|
margin-left: 8px;
|
||||||
|
margin-top: 8px;
|
||||||
|
color: #2ab2dc;
|
||||||
|
}
|
||||||
|
|
||||||
// File name
|
// File name
|
||||||
.file-name {
|
.file-name {
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
|
Loading…
Reference in New Issue
Block a user