|
|
import { EStatus, ProgressBarUIBase } from './progressBarUIBase.js';
|
|
|
|
|
|
export class ProgressBarUI extends ProgressBarUIBase {
|
|
|
htmlProgressSliderRef: HTMLDivElement;
|
|
|
htmlProgressLabelRef: HTMLDivElement;
|
|
|
currentStatus: EStatus;
|
|
|
timeStart: number;
|
|
|
currentProgress: number;
|
|
|
showProgressBarFlag: boolean;
|
|
|
|
|
|
constructor(
|
|
|
public override rootElement: HTMLElement,
|
|
|
public showSectionFlag: boolean,
|
|
|
private centerNode: () => void,
|
|
|
) {
|
|
|
super('crystools-progressBar-root', rootElement);
|
|
|
this.createDOM();
|
|
|
}
|
|
|
|
|
|
createDOM = (): void => {
|
|
|
this.rootElement.setAttribute('title', 'click to see the current working node');
|
|
|
this.rootElement.addEventListener('click', this.centerNode);
|
|
|
|
|
|
const progressBar = document.createElement('div');
|
|
|
progressBar.classList.add('crystools-progress-bar');
|
|
|
this.rootElement.append(progressBar);
|
|
|
|
|
|
const progressSlider = document.createElement('div');
|
|
|
this.htmlProgressSliderRef = progressSlider;
|
|
|
progressSlider.classList.add('crystools-slider');
|
|
|
progressBar.append(this.htmlProgressSliderRef);
|
|
|
|
|
|
const progressLabel = document.createElement('div');
|
|
|
progressLabel.classList.add('crystools-label');
|
|
|
progressLabel.innerHTML = '0%';
|
|
|
this.htmlProgressLabelRef = progressLabel;
|
|
|
progressBar.append(this.htmlProgressLabelRef);
|
|
|
};
|
|
|
|
|
|
|
|
|
updateDisplay = (currentStatus: EStatus, timeStart: number, currentProgress: number): void => {
|
|
|
if (!(this.showSectionFlag && this.showProgressBarFlag)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (!(this.htmlProgressLabelRef && this.htmlProgressSliderRef)) {
|
|
|
console.error('htmlProgressLabelRef or htmlProgressSliderRef is undefined');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.currentStatus = currentStatus;
|
|
|
this.timeStart = timeStart;
|
|
|
this.currentProgress = currentProgress;
|
|
|
|
|
|
if (currentStatus === EStatus.executed) {
|
|
|
|
|
|
this.htmlProgressLabelRef.innerHTML = 'cached';
|
|
|
|
|
|
const timeElapsed = Date.now() - timeStart;
|
|
|
if (timeStart > 0 && timeElapsed > 0) {
|
|
|
this.htmlProgressLabelRef.innerHTML = new Date(timeElapsed).toISOString().substr(11, 8);
|
|
|
}
|
|
|
this.htmlProgressSliderRef.style.width = '0';
|
|
|
|
|
|
} else if (currentStatus === EStatus.execution_error) {
|
|
|
|
|
|
this.htmlProgressLabelRef.innerHTML = 'ERROR';
|
|
|
this.htmlProgressSliderRef.style.backgroundColor = 'var(--error-text)';
|
|
|
|
|
|
} else if (currentStatus === EStatus.executing) {
|
|
|
|
|
|
this.htmlProgressLabelRef.innerHTML = `${currentProgress}%`;
|
|
|
this.htmlProgressSliderRef.style.width = this.htmlProgressLabelRef.innerHTML;
|
|
|
this.htmlProgressSliderRef.style.backgroundColor = 'green';
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
public showSection = (value: boolean): void => {
|
|
|
this.showSectionFlag = value;
|
|
|
this.displaySection();
|
|
|
};
|
|
|
|
|
|
|
|
|
public showProgressBar = (value: boolean): void => {
|
|
|
this.showProgressBarFlag = value;
|
|
|
this.displaySection();
|
|
|
};
|
|
|
|
|
|
private displaySection = (): void => {
|
|
|
this.rootElement.style.display = (this.showSectionFlag && this.showProgressBarFlag) ? 'block' : 'none';
|
|
|
};
|
|
|
}
|
|
|
|