SUPPORT-9561: change file download to deferred one
This commit is contained in:
parent
4b6fe9a2db
commit
0173c1740f
19 changed files with 7298 additions and 3063 deletions
8830
frontend/package-lock.json
generated
8830
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -119,10 +119,24 @@
|
|||
.webbpm.ervu_lkrp_ul ervu-download-file-button {
|
||||
display: block;
|
||||
}
|
||||
.webbpm.ervu_lkrp_ul .fieldset text + ervu-download-file-button {
|
||||
.webbpm.ervu_lkrp_ul .fieldset ervu-download-file-button,
|
||||
.webbpm.ervu_lkrp_ul year-combo-box .selectize-input {
|
||||
margin-top: var(--indent-mini);
|
||||
}
|
||||
|
||||
.webbpm.ervu_lkrp_ul year-combo-box .selectize-dropdown-content {
|
||||
padding: 5px 0;
|
||||
}
|
||||
|
||||
.webbpm.ervu_lkrp_ul .message-clock {
|
||||
background: url(../img/svg/clock-32x32.svg) no-repeat 0 0;
|
||||
display: block;
|
||||
font-size: var(--l-size-text-primary);
|
||||
height: 32px;
|
||||
margin: var(--indent-mini) 0;
|
||||
padding-left: var(--indent-big);
|
||||
}
|
||||
|
||||
.webbpm.ervu_lkrp_ul .btn,
|
||||
.webbpm.ervu_lkrp_ul .fieldset .btn-main:not(.info):not(.link) .btn,
|
||||
.webbpm.ervu_lkrp_ul .modal.show button-component.btn-main:not(.info):not(.link) .btn,
|
||||
|
|
@ -1422,4 +1436,4 @@
|
|||
}
|
||||
.webbpm.ervu_lkrp_ul .plain-text {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef} from "@angular/core";
|
||||
import {AbstractButton, MessagesService, NotNull, ObjectRef} from "@webbpm/base-package";
|
||||
import {HttpClient, HttpHeaders} from "@angular/common/http";
|
||||
import {InMemoryStaticGrid} from "../grid/InMemoryStaticGrid";
|
||||
import {Subscription} from "rxjs";
|
||||
|
||||
/**
|
||||
* @author: Eduard Tihomirov
|
||||
|
|
@ -14,13 +12,9 @@ import {Subscription} from "rxjs";
|
|||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class ErvuDownloadFileButton extends AbstractButton {
|
||||
|
||||
private httpClient: HttpClient;
|
||||
private messageService: MessagesService;
|
||||
private gridLoadedSubscription: Subscription;
|
||||
|
||||
@ObjectRef()
|
||||
@NotNull()
|
||||
public grid: InMemoryStaticGrid;
|
||||
|
||||
@NotNull()
|
||||
public fileName: string;
|
||||
|
|
@ -36,29 +30,10 @@ export class ErvuDownloadFileButton extends AbstractButton {
|
|||
super.initialize();
|
||||
this.httpClient = this.injector.get(HttpClient);
|
||||
this.messageService = this.injector.get(MessagesService);
|
||||
if (this.grid.isInitialized() && this.grid.getRowDataSize() > 0) {
|
||||
this.setEnabled(true);
|
||||
this.setVisible(true);
|
||||
}
|
||||
this.gridLoadedSubscription = this.grid.gridLoaded.subscribe(() => {
|
||||
if (this.grid.getRowDataSize() > 0) {
|
||||
this.setEnabled(true);
|
||||
this.setVisible(true);
|
||||
}
|
||||
else {
|
||||
this.setEnabled(false);
|
||||
this.setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
super.ngOnDestroy();
|
||||
this.gridLoadedSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
public doClickActions(): Promise<any> {
|
||||
return this.httpClient.get('kafka/excerpt', {
|
||||
return this.httpClient.get('excerpt/download', {
|
||||
responseType: 'blob',
|
||||
headers: new HttpHeaders({'Client-Time-Zone' : Intl.DateTimeFormat().resolvedOptions().timeZone}),
|
||||
observe: 'response'
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
import {
|
||||
AbstractButton, AnalyticalScope,
|
||||
Behavior,
|
||||
ComboBox, Dialog,
|
||||
MessagesService,
|
||||
NotNull,
|
||||
ObjectRef
|
||||
} from "@webbpm/base-package";
|
||||
import {HttpClient, HttpHeaders} from "@angular/common/http";
|
||||
|
||||
@AnalyticalScope(AbstractButton)
|
||||
export class ErvuFileRequestButton extends Behavior {
|
||||
|
||||
@NotNull()
|
||||
@ObjectRef()
|
||||
public year: ComboBox;
|
||||
|
||||
@NotNull()
|
||||
@ObjectRef()
|
||||
public beforeRequestDialog: Dialog;
|
||||
|
||||
@NotNull()
|
||||
@ObjectRef()
|
||||
public afterRequestDialog: Dialog;
|
||||
|
||||
private button: AbstractButton;
|
||||
private httpClient: HttpClient;
|
||||
private messageService: MessagesService;
|
||||
private onClickFunction: Function;
|
||||
private onYearValueChange: Function;
|
||||
|
||||
initialize() {
|
||||
super.initialize();
|
||||
this.button = this.getScript(AbstractButton);
|
||||
this.httpClient = this.injector.get(HttpClient);
|
||||
this.messageService = this.injector.get(MessagesService);
|
||||
this.onClickFunction = () => {
|
||||
if (!this.year.getValue()) {
|
||||
this.messageService.error("Не выбран период");
|
||||
return;
|
||||
}
|
||||
|
||||
this.httpClient.post("excerpt", this.year.getValue(), {
|
||||
headers: new HttpHeaders(
|
||||
{'Client-Time-Zone': Intl.DateTimeFormat().resolvedOptions().timeZone})
|
||||
}).toPromise()
|
||||
.then(() => {
|
||||
this.beforeRequestDialog.hide();
|
||||
this.afterRequestDialog.show();
|
||||
})
|
||||
.catch(e => this.messageService.error(e));
|
||||
};
|
||||
this.onYearValueChange = () => this.button.setEnabled(this.year.getValue());
|
||||
}
|
||||
|
||||
bindEvents() {
|
||||
super.bindEvents();
|
||||
this.button.addClickListener(this.onClickFunction);
|
||||
this.year.addUserChangeValueListener(this.onYearValueChange);
|
||||
}
|
||||
|
||||
unbindEvents() {
|
||||
super.unbindEvents();
|
||||
this.button.removeClickListener(this.onClickFunction);
|
||||
this.year.removeUserChangeValueListener(this.onYearValueChange);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
import {AbstractButton, AnalyticalScope, Behavior, NotNull, ObjectRef, Text} from "@webbpm/base-package";
|
||||
import {Subscription} from "rxjs";
|
||||
import {InMemoryStaticGrid} from "../grid/InMemoryStaticGrid";
|
||||
import {OnDestroy} from "@angular/core";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {ExcerptStatus} from "../enum/ExcerptStatus";
|
||||
|
||||
@AnalyticalScope(AbstractButton)
|
||||
export class ErvuFileRequestDialogButton extends Behavior implements OnDestroy {
|
||||
|
||||
@ObjectRef()
|
||||
@NotNull()
|
||||
public grid: InMemoryStaticGrid;
|
||||
|
||||
@ObjectRef()
|
||||
@NotNull()
|
||||
public text: Text;
|
||||
|
||||
@ObjectRef()
|
||||
@NotNull()
|
||||
public downloadButton: AbstractButton;
|
||||
|
||||
@NotNull()
|
||||
public requestSentMsg: string;
|
||||
|
||||
private button: AbstractButton;
|
||||
private httpClient: HttpClient;
|
||||
private gridLoadedSubscription: Subscription;
|
||||
private fileStatus: string = ExcerptStatus.NONE;
|
||||
|
||||
initialize() {
|
||||
super.initialize();
|
||||
this.button = this.getScript(AbstractButton);
|
||||
this.httpClient = this.injector.get(HttpClient);
|
||||
this.gridLoadedSubscription = this.grid.gridLoaded.subscribe(() => {
|
||||
this.button.setEnabled(this.grid.getRowDataSize() > 0
|
||||
&& this.fileStatus !== ExcerptStatus.IN_PROGRESS);
|
||||
this.button.setVisible(this.grid.getRowDataSize() > 0);
|
||||
});
|
||||
}
|
||||
|
||||
start() {
|
||||
super.start();
|
||||
this.getFileStatus()
|
||||
.then(status => {
|
||||
this.fileStatus = status;
|
||||
|
||||
if (this.grid.isInitialized() && this.grid.getRowDataSize() > 0) {
|
||||
this.button.setEnabled(status !== ExcerptStatus.IN_PROGRESS);
|
||||
this.button.setVisible(true);
|
||||
}
|
||||
|
||||
if (status === ExcerptStatus.IN_PROGRESS) {
|
||||
this.button.setTooltip(this.requestSentMsg);
|
||||
this.text.setValue(this.requestSentMsg);
|
||||
|
||||
}
|
||||
this.downloadButton.setEnabled(status === ExcerptStatus.READY);
|
||||
this.downloadButton.setVisible(status === ExcerptStatus.READY);
|
||||
});
|
||||
}
|
||||
|
||||
private getFileStatus(): Promise<string> {
|
||||
return this.httpClient.get('excerpt/status', {observe: 'response'}).toPromise()
|
||||
.then(res => res.body.toString());
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.gridLoadedSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
5
frontend/src/ts/ervu/component/enum/ExcerptStatus.ts
Normal file
5
frontend/src/ts/ervu/component/enum/ExcerptStatus.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export enum ExcerptStatus {
|
||||
NONE = 'none',
|
||||
IN_PROGRESS = 'in-progress',
|
||||
READY = 'ready'
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue