SUPPORT-8438 ready 2 roll
This commit is contained in:
parent
f5a589d265
commit
25ee603e7d
4 changed files with 116 additions and 32 deletions
|
|
@ -15,12 +15,19 @@ import org.springframework.beans.factory.annotation.Value;
|
|||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import ru.cg.webbpm.modules.standard_annotations.validation.NotNull;
|
||||
import ru.cg.webbpm.modules.webkit.beans.Behavior;
|
||||
|
||||
/**
|
||||
* @author Alexandr Shalaginov
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class EmployeeInfoFileUploadService {
|
||||
public class EmployeeInfoFileUploadService extends Behavior {
|
||||
|
||||
@NotNull
|
||||
public int maxFileSize;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(EmployeeInfoFileUploadService.class);
|
||||
|
||||
private final FileUploadWebDavClient fileWebDavUploadClient;
|
||||
|
|
@ -65,6 +72,10 @@ public class EmployeeInfoFileUploadService {
|
|||
}
|
||||
}
|
||||
|
||||
public int getMaxFileSize() {
|
||||
return this.maxFileSize;
|
||||
}
|
||||
|
||||
private boolean sendMessage(String message) {
|
||||
ProducerRecord<String, String> record = new ProducerRecord<>(this.kafkaTopicName, message);
|
||||
try {
|
||||
|
|
@ -103,4 +114,5 @@ public class EmployeeInfoFileUploadService {
|
|||
private String getDepartureDateTime() {
|
||||
return LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm"));
|
||||
}
|
||||
|
||||
}
|
||||
29
backend/src/main/java/rpc/ErvuFileUploadRpcService.java
Normal file
29
backend/src/main/java/rpc/ErvuFileUploadRpcService.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package rpc;
|
||||
|
||||
import ervu.service.fileupload.EmployeeInfoFileUploadService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import ru.cg.webbpm.modules.standard_annotations.validation.NotNull;
|
||||
import ru.cg.webbpm.modules.webkit.annotations.RpcCall;
|
||||
import ru.cg.webbpm.modules.webkit.annotations.RpcService;
|
||||
import ru.cg.webbpm.modules.webkit.beans.Behavior;
|
||||
|
||||
/**
|
||||
* @author Ivanov Denov
|
||||
*/
|
||||
|
||||
@RpcService
|
||||
public class ErvuFileUploadRpcService extends Behavior {
|
||||
|
||||
private final EmployeeInfoFileUploadService service;
|
||||
|
||||
@Autowired
|
||||
public ErvuFileUploadRpcService(EmployeeInfoFileUploadService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@RpcCall
|
||||
public int getMaxFileSize() {
|
||||
return this.service.getMaxFileSize();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ import {ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef} from
|
|||
import {FileItem, FileUploader} from "ng2-file-upload";
|
||||
import {FileLikeObject} from "ng2-file-upload/file-upload/file-like-object.class";
|
||||
import {EmployeeInfoFileFormType} from "./EmployeeInfoFileFormType";
|
||||
import {ErvuFileUploadRpcService} from "../../../generated/rpc/ErvuFileUploadRpcService";
|
||||
|
||||
@Component({
|
||||
moduleId: module.id,
|
||||
|
|
@ -18,13 +19,13 @@ import {EmployeeInfoFileFormType} from "./EmployeeInfoFileFormType";
|
|||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class ErvuFileUpload extends InputControl {
|
||||
|
||||
@NotNull("true")
|
||||
public selectFileFieldText: string;
|
||||
@NotNull("true")
|
||||
public selectFileButtonName: string;
|
||||
@NotNull("true")
|
||||
public removeFileButtonName: string;
|
||||
public maxFileSizeMb: number;
|
||||
public extensionFilter: string[] = [];
|
||||
public maxFilesToUpload: number;
|
||||
@NotNull("true")
|
||||
|
|
@ -51,6 +52,7 @@ export class ErvuFileUpload extends InputControl {
|
|||
protected isFilesListVisible: boolean = true;
|
||||
protected isProgressBarVisible: boolean = false;
|
||||
|
||||
private rpcService: ErvuFileUploadRpcService;
|
||||
private fileInputEl: any;
|
||||
private url: string = '/backend/employee/document';
|
||||
private messagesService: MessagesService;
|
||||
|
|
@ -63,34 +65,16 @@ export class ErvuFileUpload extends InputControl {
|
|||
initialize() {
|
||||
super.initialize();
|
||||
this.messagesService = this.injector.get(MessagesService);
|
||||
|
||||
this.uploader.setOptions({
|
||||
url: this.url,
|
||||
autoUpload: false,
|
||||
filters: [{
|
||||
name: 'extension',
|
||||
fn: (item: any): boolean => {
|
||||
if (!this.extensionFilter.length) {
|
||||
return true;
|
||||
}
|
||||
const fileExtension = item.name.substring(item.name.lastIndexOf('.') + 1, item.name.length);
|
||||
for (let ext of this.extensionFilter) {
|
||||
if (ext.toUpperCase() === fileExtension.toUpperCase()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}],
|
||||
maxFileSize: this.maxFileSizeMb ? this.maxFileSizeMb * 1024 * 1024 : undefined,
|
||||
queueLimit: this.maxFilesToUpload ? this.maxFilesToUpload : undefined,
|
||||
headers: [{
|
||||
name: "X-Employee-Info-File-Form-Type",
|
||||
value: EmployeeInfoFileFormType[this.formType]
|
||||
}]
|
||||
this.rpcService = this.getScript(ErvuFileUploadRpcService);
|
||||
if (!this.rpcService) {
|
||||
this.setUploaderOptions(undefined);
|
||||
this.setUploaderMethods(undefined);
|
||||
return;
|
||||
}
|
||||
this.rpcService.getMaxFileSize().then(fileSize => {
|
||||
this.setUploaderOptions(fileSize);
|
||||
this.setUploaderMethods(fileSize);
|
||||
});
|
||||
|
||||
this.setUploaderMethods();
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
|
|
@ -112,7 +96,35 @@ export class ErvuFileUpload extends InputControl {
|
|||
this.fileDeletedEvent.trigger();
|
||||
}
|
||||
|
||||
private setUploaderMethods() {
|
||||
private setUploaderOptions(maxFileSize: number) {
|
||||
this.uploader.setOptions({
|
||||
url: this.url,
|
||||
autoUpload: false,
|
||||
filters: [{
|
||||
name: 'extension',
|
||||
fn: (item: any): boolean => {
|
||||
if (!this.extensionFilter.length) {
|
||||
return true;
|
||||
}
|
||||
const fileExtension = item.name.substring(item.name.lastIndexOf('.') + 1, item.name.length);
|
||||
for (let ext of this.extensionFilter) {
|
||||
if (ext.toUpperCase() === fileExtension.toUpperCase()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}],
|
||||
maxFileSize: maxFileSize * 1024 * 1024,
|
||||
queueLimit: this.maxFilesToUpload ? this.maxFilesToUpload : undefined,
|
||||
headers: [{
|
||||
name: "X-Employee-Info-File-Form-Type",
|
||||
value: EmployeeInfoFileFormType[this.formType]
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
private setUploaderMethods(maxFileSize: number) {
|
||||
this.uploader.onBeforeUploadItem = (fileItem: FileItem) => {
|
||||
this.fileUploadStartEvent.trigger();
|
||||
this.isDropZoneVisible = false;
|
||||
|
|
@ -145,12 +157,13 @@ export class ErvuFileUpload extends InputControl {
|
|||
|
||||
this.uploader.onAfterAddingFile = (fileItem: FileItem) => {
|
||||
this.fileAddedEvent.trigger();
|
||||
}
|
||||
};
|
||||
|
||||
this.uploader.onWhenAddingFileFailed = (item: FileLikeObject, filter: any, options: any) => {
|
||||
switch (filter.name) {
|
||||
case "fileSize":
|
||||
this.messagesService.error(`Размер файла ${item.name} превышает предельно допустимый = ${this.maxFileSizeMb} MB`);
|
||||
// при maxFileSize = undefined будет бред, но тогда и нет повода показывать сообщения когда-либо
|
||||
this.messagesService.error(`Размер файла ${item.name} превышает предельно допустимый = ${maxFileSize} MB`);
|
||||
break;
|
||||
case "queueLimit":
|
||||
this.messagesService.error(`Не удалось добавить файл ${item.name}. `
|
||||
|
|
|
|||
|
|
@ -714,6 +714,12 @@
|
|||
<simple>false</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>formType</key>
|
||||
<value>
|
||||
<simple>"FORM_2"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>maxFilesToUpload</key>
|
||||
<value>
|
||||
|
|
@ -4990,6 +4996,30 @@
|
|||
</entry>
|
||||
</properties>
|
||||
</scripts>
|
||||
<scripts id="87ab8176-752d-4cd1-8afb-bf2cbfb020c9">
|
||||
<classRef type="JAVA">
|
||||
<className>ErvuFileUploadRpcService</className>
|
||||
<packageName>rpc</packageName>
|
||||
</classRef>
|
||||
<enabled>true</enabled>
|
||||
<expanded>true</expanded>
|
||||
</scripts>
|
||||
<scripts id="8e45a506-eb23-426e-85bd-87f02aee6f6f">
|
||||
<classRef type="JAVA">
|
||||
<className>EmployeeInfoFileUploadService</className>
|
||||
<packageName>ervu.service.fileupload</packageName>
|
||||
</classRef>
|
||||
<enabled>true</enabled>
|
||||
<expanded>true</expanded>
|
||||
<properties>
|
||||
<entry>
|
||||
<key>maxFileSize</key>
|
||||
<value>
|
||||
<simple>10</simple>
|
||||
</value>
|
||||
</entry>
|
||||
</properties>
|
||||
</scripts>
|
||||
</rootObjects>
|
||||
<rootObjects id="a0eb2a9a-94b5-4906-807b-eab28985625d">
|
||||
<prototypeId>fd7e47b9-dce1-4d14-9f3a-580c79f59579</prototypeId>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue