Skip to content

Commit

Permalink
Update data source
Browse files Browse the repository at this point in the history
  • Loading branch information
grassick committed May 27, 2021
1 parent 1a9e28a commit bf2ffba
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
14 changes: 13 additions & 1 deletion lib/widgets/blocks/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,25 @@ class TrackingDataSource extends mwater_expressions_1.DataSource {
this.onStartQuery = onStartQuery;
this.onEndQuery = onEndQuery;
}
/** Performs a single query. Calls cb with (error, rows) */
performQuery(query, cb) {
if (!cb) {
return new Promise((resolve, reject) => {
this.performQuery(query, (error, rows) => {
if (error) {
reject(error);
}
else {
resolve(error);
}
});
});
}
this.onStartQuery();
this.dataSource.performQuery(query, (error, rows) => {
this.onEndQuery();
cb(error, rows);
});
return;
}
/** Get the url to download an image (by id from an image or imagelist column)
Height, if specified, is minimum height needed. May return larger image
Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion src/widgets/blocks/print.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useState, useRef, useMemo, useEffect } from 'react';
import { createPortal } from 'react-dom';
import { LabeledProperty, PropertyEditor } from '../propertyEditors';
import { Select } from 'react-library/lib/bootstrap';
import { JsonQLQuery } from 'jsonql';

/** Block that can be printed by a print button at top right */
export interface PrintBlockDef extends BlockDef {
Expand Down Expand Up @@ -305,12 +306,27 @@ class TrackingDataSource extends DataSource {
}

/** Performs a single query. Calls cb with (error, rows) */
performQuery(query: any, cb: (error: any, rows: Row[]) => void) {
performQuery(query: JsonQLQuery): Promise<Row[]>;
performQuery(query: JsonQLQuery, cb: (error: any, rows: Row[]) => void): void;
performQuery(query: any, cb?: (error: any, rows: Row[]) => void): Promise<Row[]> | void {
if (!cb) {
return new Promise<Row[]>((resolve, reject) => {
this.performQuery(query, (error, rows) => {
if (error) {
reject(error)
}
else {
resolve(error)
}
})
})
}
this.onStartQuery()
this.dataSource.performQuery(query, (error, rows) => {
this.onEndQuery()
cb(error, rows)
})
return
}

/** Get the url to download an image (by id from an image or imagelist column)
Expand Down

0 comments on commit bf2ffba

Please sign in to comment.