datainout
Version:
Import and reports data
82 lines (81 loc) • 2.36 kB
JavaScript
// src/reporters/SheetMeta.ts
var SheetMeta = class {
constructor(opts) {
this.byJobIndex = true;
this.sheetMetas = {};
this.mapSheetByJobIndex = {};
this.currentSheetName = 0;
this.rowCount = 0;
this.sheetNames = [];
this.isCompleted = false;
this.jobCount = 0;
var _a;
for (let i = 0; i < opts.length; i++)
if (opts[i].jobs || opts[i].maxRow) this.addSheetMeta(opts[i].name, (_a = opts[i].jobs) != null ? _a : opts[i].maxRow);
}
// private addSheetMeta(name: string, jobIndexes: number[]): this;
// private addSheetMeta(name: string, rowCount: number): this;
addSheetMeta(name, data) {
if (typeof data === "number") {
this.byJobIndex = false;
this.sheetMetas[name] = {
isCompleted: false,
rowCount: 0,
maxRow: data
};
} else if (Array.isArray(data)) {
this.byJobIndex = true;
this.sheetMetas[name] = {
isCompleted: false,
rowCount: 0,
jobCount: data.length,
maxRow: 0
};
this.jobCount += data.length;
data.forEach((e) => {
this.mapSheetByJobIndex[e] = name;
});
}
this.sheetNames.push(name);
return this;
}
completeJob(index) {
const name = this.mapSheetByJobIndex[index];
if (this.sheetMetas[name].jobCount) {
this.sheetMetas[name].jobCount -= 1;
this.sheetMetas[name].isCompleted = this.sheetMetas[name].jobCount <= 0;
this.jobCount--;
this.isCompleted = this.jobCount <= 0;
}
}
get IsCompleted() {
return this.isCompleted;
}
get RowCount() {
return this.rowCount;
}
updateRowCount(isCompleted, rowCount) {
var _a;
const name = this.sheetNames[this.currentSheetName];
const sheetMeta = this.sheetMetas[name];
if (isCompleted) sheetMeta.isCompleted = isCompleted;
else if (!this.byJobIndex) {
this.rowCount += rowCount;
if (((_a = sheetMeta.maxRow) != null ? _a : 0) < sheetMeta.rowCount) {
this.currentSheetName++;
sheetMeta.isCompleted = true;
}
sheetMeta.rowCount += rowCount;
}
}
getSheetName(index) {
if (this.byJobIndex && index) return this.mapSheetByJobIndex[index];
return this.sheetNames[this.currentSheetName];
}
getSheetStatus(name) {
return this.sheetMetas[name].isCompleted;
}
};
export {
SheetMeta
};