Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/firefly/html/css/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ img, html {
-moz-background-clip: padding;
-webkit-background-clip: padding;
background-clip: padding-box;
border-radius: 4px;
}

.Resizer:hover {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* sort_info: ORDER_ASC_BY
* col-name: the name of the column.
* index: index of the column. index starts from 0.
* operator: can be one of '> < = ! >= <= IN'
* operator: can be one of '> < = ! >= <= IN LIKE'
*
* <p>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public DataGroupPart getData(ServerRequest sr) throws DataAccessException {
try {
postProcessData(dgFile, request);
page = IpacTableParser.getData(dgFile, request.getStartIndex(), request.getPageSize());
page.getTableDef().ensureStatus(); // make sure there's a status line so
} catch (Exception e) {
LOGGER.error(e, "Fail to parse ipac table file: " + dgFile);
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static JSONObject toJsonTableRequest(TableServerRequest req) {
treq.put(TableServerRequest.START_IDX, req.getStartIndex());
treq.put(TableServerRequest.PAGE_SIZE, req.getPageSize());
if (req.getFilters() != null) {
treq.put( TableServerRequest.FILTERS, StringUtils.toString(req.getFilters(), ",") );
treq.put( TableServerRequest.FILTERS, TableServerRequest.toFilterStr(req.getFilters()) );
}
if (req.getMeta() != null) {
for (String key : req.getMeta().keySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,19 @@ DataGroup.Attribute getAttribute(String key) {
return null;
}

public DataGroupPart.State getStatus() {
public void ensureStatus() {
DataGroup.Attribute a = getAttribute(DataGroupPart.LOADING_STATUS);
if (a != null && !StringUtils.isEmpty(a.getValue())) {
return DataGroupPart.State.valueOf(String.valueOf(a.getValue()));
} else {
return DataGroupPart.State.COMPLETED;
if (a == null || StringUtils.isEmpty(a.getValue())) {
setStatus(DataGroupPart.State.COMPLETED);
}
}

public DataGroupPart.State getStatus() {
ensureStatus();
DataGroup.Attribute a = getAttribute(DataGroupPart.LOADING_STATUS);
return DataGroupPart.State.valueOf(String.valueOf(a.getValue()));
}

public int getLineSepLength() {
return lineSepLength;
}
Expand Down
5 changes: 2 additions & 3 deletions src/firefly/js/core/ReduxFlux.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ actionCreators.set(ImagePlotCntlr.EXPANDED_AUTO_PLAY, ImagePlotCntlr.autoPlayAct
actionCreators.set(DrawLayerCntlr.DETACH_LAYER_FROM_PLOT, makeDetachLayerActionCreator(drawLayerFactory));

actionCreators.set(TablesCntlr.FETCH_TABLE, TablesCntlr.fetchTable);
actionCreators.set(TablesCntlr.REFETCH_TABLE, TablesCntlr.fetchTable);
actionCreators.set(TablesCntlr.LOAD_TABLE, TablesCntlr.loadTable);
actionCreators.set(TablesCntlr.TBL_HIGHLIGHT_ROW, TablesCntlr.highlightRow);

Expand Down Expand Up @@ -231,9 +232,7 @@ function getState() {
function createSmartComponent(connector, component) {
var Wrapper = connect(connector)(component);
return (
<Provider store={redux}>
{() => <Wrapper/>}
</Provider>
<Provider store={redux}><Wrapper/></Provider>
);
}

Expand Down
88 changes: 88 additions & 0 deletions src/firefly/js/tables/FilterInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* Created by loi on 1/15/16.
*/


/*
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
*/
import {isEmpty, merge} from 'lodash';


const op_regex = new RegExp('(<|>|>=|<=|=|!=|like|in)');
const cond_regex = new RegExp('^' + op_regex.source + '\\s+(.+)', 'i');
const filter_regex = new RegExp('(\\S+)\\s+' + op_regex.source + '\\s+(.+)', 'i');

export const FILTER_TTIPS = 'Valid values are one of (=, >, <, !=, >=, <=, LIKE) followed by a value separated by a space. \n' +
`Or 'IN', followed by a list of values separated by commas. \n` +
'Examples: > 12345; != 3000; IN a,b,c,d';

/**
* convenience class to handle the table's filter information.
* data is stored as a string of 'col op expression' separated by comma. ie. 'id > 1, id < 100,band <= 2'
* convert to filterInfo:
* {
* col: ['op expression']
* }
* use parse and serialize to object to string and vice-versa
*/
export class FilterInfo {
constructor() {
}

static parse(filterString) {
var filterInfo = new FilterInfo();
if (filterString) {
filterString && filterString.split(';').forEach( (v) => {
const parts = v.trim().match(filter_regex);
if (parts.length > 3) filterInfo.addFilter(parts[1], `${parts[2]} ${parts[3]}`);
});
}
return filterInfo;
}

static isValid(conditions) {
return isEmpty(conditions) || conditions.split(';').reduce( (rval, v) => {
return rval && cond_regex.test(v.trim());
}, true);
}

static validator(conditions) {
const valid = FilterInfo.isValid(conditions);
return {valid, message: FILTER_TTIPS};
}

serialize() {
return Object.keys(this).reduce( (rval, key) => {
this[key].split(';').forEach((v) => {
if (v.length) {
rval = (rval.length ? rval + ';': '') + `${key} ${v.trim()}`;
}
} );
return rval;
}, '');
}

addFilter(colName, conditions) {
this[colName] = isEmpty(this[colName]) ? conditions : `${this[colName]}; ${conditions}`;
}

setFilter(colName, conditions) {
Reflect.deleteProperty(this, colName);
if (!isEmpty(conditions)) {
conditions && conditions.split(';').forEach( (v) => {
const parts = v.trim().match(cond_regex);
if (parts.length > 2) this.addFilter(colName, `${parts[1]} ${parts[2]}`);
});
}
}

getFilter(colName) {
return this[colName] && this[colName].toString();
}

isEqual(colName, value) {
const oldVal = this.getFilter(colName);
return (isEmpty(oldVal) && isEmpty(value)) || oldVal === value;
}
}
7 changes: 7 additions & 0 deletions src/firefly/js/tables/TableStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export class TableStore {

}

onFilter(filterIntoString) {
const {request} = this.tableModel;
request.filters = filterIntoString;
this.handleAction(TblCntlr.REFETCH_TABLE, {request, highlightedRow: 0});
}

onPageSizeChange(nPageSize) {
nPageSize = Number.parseInt(nPageSize);
const {tbl_id, pageSize, highlightedRow} = TblUtil.gatherTableState(this.tableModel);
Expand Down Expand Up @@ -104,6 +110,7 @@ export class RemoteTableStore extends TableStore {
switch (type) {
case (TblCntlr.TBL_SELECT_ROW) :
case (TblCntlr.TBL_HIGHLIGHT_ROW) :
case (TblCntlr.REFETCH_TABLE) :
flux.process({type, payload});
break;

Expand Down
17 changes: 10 additions & 7 deletions src/firefly/js/tables/TablesCntlr.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const TABLE_SPACE_PATH = 'table_space';

/*---------------------------- ACTIONS -----------------------------*/
export const FETCH_TABLE = `${TABLE_SPACE_PATH}.fetchTable`;
export const REFETCH_TABLE = `${TABLE_SPACE_PATH}.refetchTable`;
export const REPLACE_TABLE = `${TABLE_SPACE_PATH}.replaceTable`;
export const LOAD_TABLE = `${TABLE_SPACE_PATH}.loadTable`;
export const LOAD_TABLE_STATUS = `${TABLE_SPACE_PATH}.loadTableStatus`;
export const LOAD_TABLE_COMPLETE = `${TABLE_SPACE_PATH}.loadTableComplete`;
Expand Down Expand Up @@ -54,7 +56,11 @@ export function fetchTable(action) {
if (!action.err) {
var {request, hlRowIdx} = action.payload;
TblUtil.doFetchTable(request, hlRowIdx).then ( (tableModel) => {
dispatch( loadTable({type:LOAD_TABLE, payload: tableModel}) );
if (action.type === REFETCH_TABLE) {
dispatch( {type:REPLACE_TABLE, payload: tableModel} );
} else {
dispatch( loadTable({type:LOAD_TABLE, payload: tableModel}) );
}
}).catch( (error) => {
logError(error);
// if fetch causes error, re-dispatch that same action with error msg.
Expand All @@ -68,7 +74,6 @@ export function fetchTable(action) {

/*---------------------------- REDUCERS -----------------------------*/
export function reducer(state={}, action={}) {
var inTable;
const {tbl_id, selectionInfo, highlightedRow} = action.payload || {};
switch (action.type) {
case (TBL_SELECT_ROW) :
Expand All @@ -80,12 +85,10 @@ export function reducer(state={}, action={}) {
case (LOAD_TABLE_STATUS) :
case (LOAD_TABLE_COMPLETE) :
case (LOAD_TABLE) :
inTable = action.payload;
return TblUtil.smartMerge(state, {[inTable.tbl_id] : inTable});
return TblUtil.smartMerge(state, {[tbl_id] : action.payload});

case (FETCH_TABLE) :
inTable = { tbl_id : action.payload.tbl_id, tableMeta : {'isLoading' : true}};
return TblUtil.smartMerge(state, {[inTable.tbl_id] : inTable});
case (REPLACE_TABLE) :
return Object.assign({}, state, {[tbl_id] : action.payload});

default:
return state;
Expand Down
Loading