Skip to content

Commit cd8e95c

Browse files
committed
DM-7055: fix miscellaneous table issues
- disable sorting when content is html - table options: auto-adjust all column width based on content - table refractoring.. - renamed a few actions to better reflect what it's doing. - added TABLE_FILTER - document sequence of actions where applicable. - update build script to skip buildClient when possible.
1 parent bb37b2f commit cd8e95c

22 files changed

+187
-93
lines changed

buildScript/depends.gincl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ jar.destinationDir = file ("$rootDir/jars/build")
104104

105105
task buildClient (dependsOn: loadConfig) {
106106

107-
outputs.upToDateWhen { false }
107+
outputs.dir "${buildDir}/gwt/${project['app-name']}"
108+
inputs.dir "${projectDir}/js"
109+
inputs.dir "${fireflyPath}/src/firefly/js"
108110

109111
doLast {
110112
def res = project.ext.NPM 'run', 'build'

src/firefly/java/edu/caltech/ipac/firefly/data/TableServerRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class TableServerRequest extends ServerRequest implements Serializable, D
1717
public static final String DECIMATE_INFO = "decimate";
1818
public static final String TBL_FILE_PATH = "tblFilePath";
1919
public static final String TBL_ID = "tbl_id";
20-
public static final String TITLE = "tbl_table";
20+
public static final String TITLE = "title";
2121
public static final String FILTERS = "filters";
2222
public static final String SORT_INFO = "sortInfo";
2323
public static final String PAGE_SIZE = "pageSize";

src/firefly/java/edu/caltech/ipac/firefly/server/query/IpacTablePartProcessor.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ public DataGroupPart getData(ServerRequest sr) throws DataAccessException {
199199
try {
200200
dgFile = postProcessData(dgFile, request);
201201
page = IpacTableParser.getData(dgFile, request.getStartIndex(), request.getPageSize());
202-
page.getTableDef().ensureStatus(); // make sure there's a status line so
203-
page.getTableDef().setAttribute(TableServerRequest.TBL_FILE_PATH, ServerContext.replaceWithPrefix(dgFile)); // set table's meta tblFilePath to the file it came from.
202+
ensureTableMeta(page, request, dgFile); // inspect/edit meta info needed by client.
204203
} catch (Exception e) {
205204
LOGGER.error(e, "Fail to parse ipac table file: " + dgFile);
206205
throw e;
@@ -216,15 +215,14 @@ public DataGroupPart getData(ServerRequest sr) throws DataAccessException {
216215
LOGGER.error(e, "Error while processing request:" + StringUtils.truncate(sr, 512));
217216
throw new DataAccessException("Unexpected error", e);
218217
}
219-
// finally {
220-
// if (!doCache()) {
221-
// do not delete file even if it's not to be cached. download still relies on it.
222-
// if (dgFile != null) {
223-
// dgFile.delete();
224-
// }
225-
// }
226-
// }
218+
}
227219

220+
private void ensureTableMeta(DataGroupPart page, TableServerRequest request, File dgFile) {
221+
page.getTableDef().ensureStatus(); // make sure there's a status line so
222+
page.getTableDef().setAttribute(TableServerRequest.TBL_FILE_PATH, ServerContext.replaceWithPrefix(dgFile)); // set table's meta tblFilePath to the file it came from.
223+
if (!StringUtils.isEmpty(request.getTblTitle())) {
224+
page.getData().setTitle(request.getTblTitle()); // set the datagroup's title to the request title.
225+
}
228226
}
229227

230228
protected File postProcessData(File dgFile, TableServerRequest request) throws Exception {
@@ -648,3 +646,4 @@ protected static File convertToIpacTable(File tblFile, TableServerRequest reques
648646

649647
}
650648

649+
// some random comments

src/firefly/java/edu/caltech/ipac/firefly/server/util/ipactable/IpacTableParser.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ public static DataGroupPart getData(File inf, int start, int rows) throws IOExce
8787
DataGroup dg = new DataGroup(null, tableDef.getCols());
8888
dg.setRowIdxOffset(start);
8989

90-
dg.setAttributes(tableDef.getAllAttributes());
91-
9290
RandomAccessFile reader = new RandomAccessFile(inf, "r");
9391
long skip = ((long)start * (long)tableDef.getLineWidth()) + (long)tableDef.getRowStartOffset();
9492
int count = 0;
@@ -108,6 +106,13 @@ public static DataGroupPart getData(File inf, int start, int rows) throws IOExce
108106
reader.close();
109107
}
110108

109+
// sync attributes in datagroup with tabledef.
110+
Map<String, DataGroup.Attribute> attribs = dg.getAttributes();
111+
if (attribs.size() > 0) {
112+
tableDef.addAttributes(attribs.values().toArray(new DataGroup.Attribute[attribs.size()]));
113+
}
114+
dg.setAttributes(tableDef.getAllAttributes());
115+
111116
long totalRow = tableDef.getLineWidth() == 0 ? 0 :
112117
(inf.length() - tableDef.getRowStartOffset())/tableDef.getLineWidth();
113118
return new DataGroupPart(tableDef, dg, start, (int) totalRow);

src/firefly/java/edu/caltech/ipac/firefly/server/util/ipactable/JsonTableUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private static List<JSONObject> toJsonTableColumn(DataGroup dataGroup, TableDef
182182
}
183183
String sortable = getColAttr(tableDef, SORTABLE_TAG, cname);
184184
if (!StringUtils.isEmpty(sortable)) {
185-
c.put("sortable", sortable);
185+
c.put("sortable", Boolean.parseBoolean(sortable));
186186
}
187187
String units = getColAttr(tableDef, UNIT_TAG, cname);
188188
if (!StringUtils.isEmpty(units)) {

src/firefly/java/edu/caltech/ipac/util/DataGroup.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public void remove(DataObject s) {
183183
*/
184184
public void addAttribute(String key, String value) {
185185
_attributes.add(new Attribute(key, value));
186+
_cachedAttributesMap = null;
186187
}
187188

188189
/**

src/firefly/js/charts/ui/ChartsTableViewPanel.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ class ChartsPanel extends React.Component {
335335
filterInfoCls.setFilter(yCol, '> '+yMin);
336336
filterInfoCls.addFilter(yCol, '< '+yMax);
337337
const newRequest = Object.assign({}, tableModel.request, {filters: filterInfoCls.serialize()});
338-
TablesCntlr.dispatchTableFetch(newRequest, 0);
338+
TablesCntlr.dispatchTableFilter(newRequest, 0);
339339
}
340340
}
341341
}
@@ -344,7 +344,7 @@ class ChartsPanel extends React.Component {
344344
const request = get(this.props, 'tableModel.request');
345345
if (request && request.filters) {
346346
const newRequest = Object.assign({}, request, {filters: ''});
347-
TablesCntlr.dispatchTableFetch(newRequest, 0);
347+
TablesCntlr.dispatchTableFilter(newRequest, 0);
348348
}
349349
}
350350

@@ -688,7 +688,7 @@ export class FilterEditorWrapper extends React.Component {
688688
onChange={(obj) => {
689689
if (!isUndefined(obj.filterInfo)) {
690690
const newRequest = Object.assign({}, tableModel.request, {filters: obj.filterInfo});
691-
TablesCntlr.dispatchTableFetch(newRequest, 0);
691+
TablesCntlr.dispatchTableFilter(newRequest, 0);
692692
} else if (!isUndefined(obj.sortInfo)) {
693693
this.setState({sortInfo: obj.sortInfo});
694694
}

src/firefly/js/core/ReduxFlux.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ actionCreators.set(DrawLayerCntlr.DETACH_LAYER_FROM_PLOT, makeDetachLayerActionC
133133
actionCreators.set(TablesCntlr.TABLE_SEARCH, TablesCntlr.tableSearch);
134134
actionCreators.set(TablesCntlr.TABLE_FETCH, TablesCntlr.tableFetch);
135135
actionCreators.set(TablesCntlr.TABLE_SORT, TablesCntlr.tableFetch);
136+
actionCreators.set(TablesCntlr.TABLE_FILTER, TablesCntlr.tableFetch);
136137
actionCreators.set(TablesCntlr.TABLE_HIGHLIGHT, TablesCntlr.highlightRow);
137138

138139
actionCreators.set(TableStatsCntlr.LOAD_TBL_STATS, TableStatsCntlr.loadTblStats);

src/firefly/js/core/layout/FireflyLayoutManager.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {get, filter, omitBy, isNil} from 'lodash';
77

88
import {LO_VIEW, LO_MODE, SHOW_DROPDOWN, SET_LAYOUT_MODE, getLayouInfo, dispatchUpdateLayoutInfo} from '../LayoutCntlr.js';
99
import {clone} from '../../util/WebUtil.js';
10-
import {TBL_RESULTS_ADDED, TABLE_NEW, TABLE_REMOVE} from '../../tables/TablesCntlr.js';
10+
import {TBL_RESULTS_ADDED, TABLE_LOADED, TABLE_REMOVE} from '../../tables/TablesCntlr.js';
1111
import ImagePlotCntlr from '../../visualize/ImagePlotCntlr.js';
1212
import {isMetaDataTable, isCatalogTable} from '../../metaConvert/converterUtils.js';
1313
import {META_VIEWER_ID} from '../../visualize/ui/TriViewImageSection.jsx';
@@ -29,7 +29,7 @@ export function* layoutManager({title, views='tables | images | xyPlots'}) {
2929
const action = yield take([
3030
ImagePlotCntlr.PLOT_IMAGE_START, ImagePlotCntlr.PLOT_IMAGE,
3131
ImagePlotCntlr.DELETE_PLOT_VIEW, REPLACE_IMAGES,
32-
TBL_RESULTS_ADDED, TABLE_REMOVE, TABLE_NEW,
32+
TBL_RESULTS_ADDED, TABLE_REMOVE, TABLE_LOADED,
3333
SHOW_DROPDOWN, SET_LAYOUT_MODE
3434
]);
3535

@@ -55,7 +55,7 @@ export function* layoutManager({title, views='tables | images | xyPlots'}) {
5555
ignore = handleLayoutChanges(action);
5656
break;
5757

58-
case TABLE_NEW :
58+
case TABLE_LOADED :
5959
[showImages, images] = handleNewTable(action, images, showImages);
6060
break;
6161

src/firefly/js/drawingLayers/Catalog.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import DrawLayerCntlr from '../visualize/DrawLayerCntlr.js';
1515
import {MouseState} from '../visualize/VisMouseSync.js';
1616
import DrawOp from '../visualize/draw/DrawOp.js';
1717
import {makeWorldPt} from '../visualize/Point.js';
18-
import {dispatchTableHighlight,dispatchTableFetch} from '../tables/TablesCntlr.js';
18+
import {dispatchTableHighlight,dispatchTableFilter} from '../tables/TablesCntlr.js';
1919
import {COLOR_HIGHLIGHTED_PT} from '../visualize/draw/DrawingDef.js';
2020
import {MetaConst} from '../data/MetaConst.js';
2121
import {SelectInfo} from '../tables/SelectInfo.js';
@@ -338,7 +338,7 @@ function doClearFilter(dl) {
338338
const tbl= getTblById(dl.drawLayerId);
339339
if (!tbl) return;
340340
const newRequest = Object.assign({}, tbl.request, {filters: ''});
341-
dispatchTableFetch(newRequest);
341+
dispatchTableFilter(newRequest);
342342
}
343343

344344

@@ -358,7 +358,7 @@ function doFilter(dl,p,sel) {
358358
filter= `IN (${idxs.toString()})`;
359359
filterInfoCls.addFilter(dl.tableMeta['decimate_key'], filter);
360360
newRequest = Object.assign({}, tbl.request, {filters: filterInfoCls.serialize()});
361-
dispatchTableFetch(newRequest);
361+
dispatchTableFilter(newRequest);
362362
console.log(newRequest);
363363
console.log(idxs);
364364
}
@@ -368,7 +368,7 @@ function doFilter(dl,p,sel) {
368368
// filterInfoCls.setFilter(filter);
369369
filterInfoCls.setFilter('ROWID', filter);
370370
newRequest = Object.assign({}, tbl.request, {filters: filterInfoCls.serialize()});
371-
dispatchTableFetch(newRequest);
371+
dispatchTableFilter(newRequest);
372372
}
373373

374374
}

src/firefly/js/tables/TableConnector.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class TableConnector {
3535
// not implemented yet
3636
} else {
3737
request = Object.assign({}, request, {filters: filterIntoString});
38-
TblCntlr.dispatchTableFetch(request);
38+
TblCntlr.dispatchTableFilter(request);
3939
}
4040
}
4141

@@ -59,7 +59,7 @@ export class TableConnector {
5959
}, 'IN (') + ')';
6060
filterInfoCls.addFilter('ROWID', value);
6161
request = Object.assign({}, request, {filters: filterInfoCls.serialize()});
62-
TblCntlr.dispatchTableFetch(request);
62+
TblCntlr.dispatchTableFilter(request);
6363
});
6464
}
6565
}

src/firefly/js/tables/TableUtil.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,8 @@ export function getTableSourceUrl(columns, request, filename) {
478478
}
479479

480480
/**
481-
* returns a map of cname -> width. The width is the number of characters needed to display
481+
* returns an array of width indexed corresponding to the given columns.
482+
* The width is the number of characters needed to display
482483
* the header and the data as a table given columns and dataAry.
483484
* @param columns array of column object
484485
* @param dataAry array of array.
@@ -491,7 +492,7 @@ export function calcColumnWidths(columns, dataAry) {
491492
width = dataAry.reduce( (maxWidth, row) => {
492493
return Math.max(maxWidth, get(row, [idx, 'length'], 0));
493494
}, width); // max width of data
494-
pv[cname] = width;
495+
pv[idx] = width;
495496
return pv;
496497
}, {ROWID: 8});
497498
}

0 commit comments

Comments
 (0)