Browse Source

it works

pull/3/head
rozetko 2 years ago
parent
commit
cbd7e67161
  1. 10
      src/routes/tasks.ts
  2. 13
      src/services/exporter.ts
  3. 7
      src/types/index.ts

10
src/routes/tasks.ts

@ -35,20 +35,18 @@ async function getTasks(req, res) {
let data = fs.readFileSync(path.join(EXPORTED_PATH, item), 'utf8'); let data = fs.readFileSync(path.join(EXPORTED_PATH, item), 'utf8');
let status = JSON.parse(data); let status = JSON.parse(data);
let requestedUrl = `http://${req.headers.host}`; let filename = '';
let downloadLink = '';
let deleteLink = '';
if(status.status === 'finished') { if(status.status === 'finished') {
downloadLink = `<a class="download-csv" href="${requestedUrl}/static/${file.name}.csv" target="_blank"><i class="fa fa-download"></i></a>`; filename = file.name;
} }
resp.push({ resp.push({
timestamp: status.time, timestamp: status.time,
user: status.user, username: status.user,
datasourceRef: status.datasourceRef, datasourceRef: status.datasourceRef,
rowsCount: status.exportedRows, rowsCount: status.exportedRows,
progress: status.progress, progress: status.progress,
status: status.status, status: status.status,
downloadLink, filename,
}); });
} }

13
src/services/exporter.ts

@ -21,7 +21,7 @@ const TIMESTAMP_COLUMN = 'timestamp';
export class Exporter { export class Exporter {
private exportedRows = 0; private exportedRows = 0;
private createdTimestamp: number; private createdTimestamp: number;
private user: string; private username: string;
private datasourceRef: DataSourceRef; private datasourceRef: DataSourceRef;
private initCsvStream() { private initCsvStream() {
@ -44,9 +44,9 @@ export class Exporter {
let time = moment().valueOf(); let time = moment().valueOf();
let data = { let data = {
time, time,
user: this.user, username: this.username,
exportedRows: this.exportedRows, exportedRows: this.exportedRows,
progress: progress.toLocaleString('en', { style: 'percent' }), progress: progress,
status, status,
datasourceRef: this.datasourceRef, datasourceRef: this.datasourceRef,
}; };
@ -58,8 +58,8 @@ export class Exporter {
} }
} }
public async export(data: Target[], datasourceUrl: string, user: string, from: number, to: number) { public async export(data: Target[], datasourceUrl: string, username: string, from: number, to: number) {
this.user = user; this.username = username;
this.validateTargets(datasourceUrl, data); this.validateTargets(datasourceUrl, data);
@ -82,7 +82,8 @@ export class Exporter {
} }
}); });
this.datasourceRef = data.length === 1 ? data[0].datasource : { uid: 'all', type: 'all' }; const datasource = data[0].datasource;
this.datasourceRef = data.length === 1 ? { uid: datasource.uid, type: datasource.type } : { uid: 'all', type: 'all' };
await this.updateStatus(ExportStatus.EXPORTING, 0); await this.updateStatus(ExportStatus.EXPORTING, 0);

7
src/types/index.ts

@ -80,7 +80,8 @@ export interface PanelModel {
alert?: any; alert?: any;
} }
export type Task = DataQuery & { // TODO: rename to query
export type Task = Omit<DataQuery, 'datasource'> & {
selected: boolean; selected: boolean;
panel: PanelModel; panel: PanelModel;
datasource: DataSourceSettings; datasource: DataSourceSettings;
@ -88,10 +89,10 @@ export type Task = DataQuery & {
export type TaskTableRowConfig = { export type TaskTableRowConfig = {
timestamp: number; timestamp: number;
user: string; username: string;
datasourceRef: DataSourceRef; datasourceRef: DataSourceRef;
rowsCount: number; rowsCount: number;
progress: number; progress: number;
status: string; status: string;
downloadLink: string; filename?: string;
}; };

Loading…
Cancel
Save