Skip to content

Commit

Permalink
Merge branch 'testing'
Browse files Browse the repository at this point in the history
  • Loading branch information
mapcentia committed May 3, 2021
2 parents d70a8b9 + 329e689 commit 2eca948
Show file tree
Hide file tree
Showing 20 changed files with 709 additions and 141 deletions.
13 changes: 9 additions & 4 deletions browser/PlotManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class PlotManager {
results.map((dataItem) => {
if (dataItem.key === item.id && typeof dataItem.value !== "undefined") {
plots[index] = JSON.parse(dataItem.value);
delete plots[index].measurementsCachedData;
}
});
});
Expand Down Expand Up @@ -90,6 +91,7 @@ class PlotManager {
let plots = [];
results.map((item, index) => {
plots[index] = JSON.parse(item.value);
delete plots[index].measurementsCachedData;
});

plots.map((item, index) => {
Expand Down Expand Up @@ -152,17 +154,19 @@ class PlotManager {
}

update(data) {
let clone = JSON.parse(JSON.stringify(data));
clone.measurementsCachedData = {};
return new Promise((resolve, reject) => {
if (!data || !data.id) {
console.error(`Invalid plot was provided`, data);
if (!clone || !clone.id) {
console.error(`Invalid plot was provided`, clone);
reject(`Invalid plot was provided`);
} else {
$.ajax({
url: `${this.apiUrlLocal}/${data.id}`,
url: `${this.apiUrlLocal}/${clone.id}`,
method: 'PUT',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(data),
data: JSON.stringify(clone),
success: (body) => {
if (body.success) {
resolve();
Expand Down Expand Up @@ -210,6 +214,7 @@ class PlotManager {
}
});
}

}

export default PlotManager;
57 changes: 29 additions & 28 deletions browser/components/DashboardComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import SortablePlotsGridComponent from './SortablePlotsGridComponent';
import {isNumber} from 'util';
import arrayMove from 'array-move';
import trustedIpAddresses from '../trustedIpAddresses';
import {getPlotData} from '../services/plot';

let syncInProg = false;

Expand Down Expand Up @@ -579,8 +580,10 @@ class DashboardComponent extends React.Component {
let count = 0;
plots.forEach((e, i) => {
if ('id' in e) {
let obj = e.measurementsCachedData;
if (Object.keys(obj).length === 0 && obj.constructor === Object) {
let obj = e.measurements;
if (obj && Object.keys(obj).length === 0 && obj.constructor === Object) {
preCount++;
} else if (!obj) {
preCount++;
} else {
for (let key in obj) {
Expand All @@ -596,32 +599,29 @@ class DashboardComponent extends React.Component {
let obj = e.measurementsCachedData;
let shadowI = i;
newPlots[shadowI] = e;
if (Object.keys(obj).length === 0 && obj.constructor === Object) {
count++;
} else {
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
let rel;
rel = key.split(":")[1].startsWith("_") ? "chemicals.boreholes_time_series_with_chemicals" : "sensor.sensordata_with_correction";
// Lazy load data and sync
// Only load active plots
if (activePlots.includes(e.id)) {
$.ajax({
url: "/api/sql/jupiter?srs=25832&q=SELECT * FROM " + rel + " WHERE boreholeno='" + key.split(":")[0] + "'",
scriptCharset: "utf-8",
success: (response) => {
newPlots[shadowI].measurementsCachedData[key].data = response.features[0];
count++;
if (count === preCount) {
console.log("All plots synced");
_self.setPlots(newPlots);
}
}
})
} else {
count++;
if (!e.measurementsCachedData) {
e.measurementsCachedData = {};
}
for (let index in e.measurements) {
let key = e.measurements[index];
// Lazy load data and sync
// Only load active plots
if (activePlots.includes(e.id)) {
getPlotData(key).then((response) => {
if (!newPlots[shadowI].measurementsCachedData[key]) {
newPlots[shadowI].measurementsCachedData[key] = {};
}
}
newPlots[shadowI].measurementsCachedData[key].data = response.data.features[0];
count++;
if (count === preCount) {
console.log("All plots synced");
_self.setPlots(newPlots);
}
}).catch((error) => {
console.log(error);
})
} else {
count++;
}
}
}
Expand Down Expand Up @@ -742,7 +742,8 @@ class DashboardComponent extends React.Component {
this.setState({activePlots}, () => {
this.props.onActivePlotsChange(this.state.activePlots, plots);
setTimeout(() => {
document.getElementById("syncWithDatabaseBtn").click();
// document.getElementById("syncWithDatabaseBtn").click();
this.syncPlotData();
}, 200);
});
}
Expand Down
97 changes: 97 additions & 0 deletions browser/components/DataSelectorFilterComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React from 'react';
import {connect} from 'react-redux';

const DEFAULT_FILTER_COUNT = 3;

class DataSelectorFilterComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
filters: {
filter1: {
label: 'Filter 1',
operators: ['<', '>', '<='],
type: 'number'
},
filter2: {
label: 'Filter 2',
operators: ['===', '!='],
type: 'text'
}
},
selectedFilters: [{filter: null, selectedOperator: null, type: 'text', value: null, operators: []}, {filter: null, selectedOperator: null, type: 'text', value: null, operators: []}, {filter: null, selectedOperator: null, type: 'text', value: null, operators: []}],

};
}

componentDidMount() {
}

handleFilterChange(event, index) {
var selectedFilters = this.state.selectedFilters;
var filterInfo = this.state.filters[event.target.value];
var operators = [];
var type = 'text'
if (filterInfo) {
operators = filterInfo.operators;
type = filterInfo.type;
}
selectedFilters[index].operators = operators;
selectedFilters[index].type = type;
this.setState(selectedFilters);
}

getFilters(filterCount) {
return this.state.selectedFilters.map((filter, index) => {
return <tr>
<td style={{padding: '0 20px'}}>
<select className="form-control" onChange={(event) => this.handleFilterChange(event, index)} value={filter.filter}>
<option value="">{__('Select Filter')}</option>
{Object.keys(this.state.filters).map((filterKey) => <option value={filterKey}>{this.state.filters[filterKey].label}</option>)}
</select>
</td>
<td style={{padding: '0 5px'}}>
<select className="filter-operators form-control" style={{width: '50px', textAlign: 'center'}} value={filter.selectedOperator}>
{filter.operators.map((operator) => {
return <option value={operator}>{operator}</option>
})}
</select>
</td>
<td style={{padding: '0 5px'}}>
<input type={filter.type} className='form-control' />
</td>
</tr>
});
}

render() {
return (
<div style={{paddingTop: '10px', paddingLeft: '20px' }}>
{__('Match')}
<select className="condition-type-filter">
<option value="all">{__('All')}</option>
<option value="any">{__('Any')}</option>
</select>
{__(' the conditions')}
<div className="filters">
<table>
<tbody>
{this.getFilters(DEFAULT_FILTER_COUNT)}
</tbody>
</table>
</div>
</div>)
}
}

DataSelectorFilterComponent.propTypes = {
};


const mapStateToProps = state => ({
});

const mapDispatchToProps = dispatch => ({
});

export default connect(mapStateToProps, mapDispatchToProps)(DataSelectorFilterComponent);
64 changes: 64 additions & 0 deletions browser/components/DataSelectorGlobalFilterComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';
import {connect} from 'react-redux';
import {selectStartDate, selectEndDate, selectMeasurementCount} from "../redux/actions";

class DataSelectorGlobalFilterComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
startDate: null,
endDate: null,
count: null
};
}

componentDidMount() {
}

render() {
return (
<div style={{paddingTop: '10px', paddingLeft: '20px'}}>
<div className="filters">
<h4>Periode</h4>
<div className="row">
<div className="col-md-6">Fra <input type="date" onChange={(e) => {
e.preventDefault();
this.props.selectStartDate(e.target.value)
}} className='form-control'
value={this.props.selectedStartDate}/></div>
<div className="col-md-6">Til <input type="date" onChange={(e) => {
e.preventDefault();
this.props.selectEndDate(e.target.value)
}} className='form-control'
value={this.props.selectedEndDate}/></div>
</div>
<div className="row">
<div className="col-md-6">
<h4>Antal målinger</h4>
<input type="number" onChange={(e) => {
e.preventDefault();
this.props.selectMeasurementCount(e.target.value)
}} className='form-control'
value={this.props.selectedMeasurementCount}/>
</div>
</div>
</div>
</div>)
}
}

DataSelectorGlobalFilterComponent.propTypes = {};

const mapStateToProps = state => ({
selectedStartDate: state.global.selectedStartDate,
selectedEndDate: state.global.selectedEndDate,
selectedMeasurementCount: state.global.selectedMeasurementCount
});

const mapDispatchToProps = dispatch => ({
selectStartDate: (date) => dispatch(selectStartDate(date)),
selectEndDate: (date) => dispatch(selectEndDate(date)),
selectMeasurementCount: (count) => dispatch(selectMeasurementCount(count))
});

export default connect(mapStateToProps, mapDispatchToProps)(DataSelectorGlobalFilterComponent);
8 changes: 7 additions & 1 deletion browser/components/DataSourceSelector.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import {connect} from 'react-redux'
import {connect} from 'react-redux';
import DataSelectorFilterComponent from './DataSelectorFilterComponent';

import {selectLayer, unselectLayer} from '../redux/actions'

Expand All @@ -10,6 +11,9 @@ import {selectLayer, unselectLayer} from '../redux/actions'
class DataSourceSelector extends React.Component {
constructor(props) {
super(props);
this.state = {
openFilter: null
}
}

componentDidMount() {
Expand Down Expand Up @@ -66,6 +70,8 @@ class DataSourceSelector extends React.Component {
}
}}/> {titles.join(' / ')}
</label>
{/*<button type="button" className="btn btn-xs btn-primary" title={__(`Filter`)} onClick={() => { this.state.openFilter === key ? this.setState({openFilter: null}) : this.setState({openFilter: key})}}><i className='material-icons'>filter_list</i></button>*/}
{/*{this.state.openFilter === key ? <DataSelectorFilterComponent /> : null}*/}
</div>
</div>);
};
Expand Down
Loading

0 comments on commit 2eca948

Please sign in to comment.