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 status = JSON.parse(data);
let requestedUrl = `http://${req.headers.host}`;
let downloadLink = '';
let deleteLink = '';
let filename = '';
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({
timestamp: status.time,
user: status.user,
username: status.user,
datasourceRef: status.datasourceRef,
rowsCount: status.exportedRows,
progress: status.progress,
status: status.status,
downloadLink,
filename,
});
}

13
src/services/exporter.ts

@ -21,7 +21,7 @@ const TIMESTAMP_COLUMN = 'timestamp';
export class Exporter {
private exportedRows = 0;
private createdTimestamp: number;
private user: string;
private username: string;
private datasourceRef: DataSourceRef;
private initCsvStream() {
@ -44,9 +44,9 @@ export class Exporter {
let time = moment().valueOf();
let data = {
time,
user: this.user,
username: this.username,
exportedRows: this.exportedRows,
progress: progress.toLocaleString('en', { style: 'percent' }),
progress: progress,
status,
datasourceRef: this.datasourceRef,
};
@ -58,8 +58,8 @@ export class Exporter {
}
}
public async export(data: Target[], datasourceUrl: string, user: string, from: number, to: number) {
this.user = user;
public async export(data: Target[], datasourceUrl: string, username: string, from: number, to: number) {
this.username = username;
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);

7
src/types/index.ts

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

Loading…
Cancel
Save