Skip to content

Commit

Permalink
Merge pull request #59 from go-spatial/source-polish
Browse files Browse the repository at this point in the history
Source polish
  • Loading branch information
justenPalmer authored Apr 9, 2019
2 parents 0736590 + 2e91265 commit 632b03f
Show file tree
Hide file tree
Showing 21 changed files with 211 additions and 252 deletions.
10 changes: 10 additions & 0 deletions src/model/Msource.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ export default {

Mstyle.save();

const now = new Date().getTime() // set the reload stamp to now

Store.dispatch({
type:'SOURCE_RELOAD',
payload:{
sourceKey:key,
when:now
}
});

return resolve();
});
},
Expand Down
4 changes: 2 additions & 2 deletions src/model/Mstyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ const Mstyle = {

errorAdd:function(error){
return new Promise((resolve,reject)=>{

const key = MapboxError.getKey(error);
const message = MapboxError.getMessage(error);

const err = {
key:key,
message:message
message:message,
error:error,
};

Store.dispatch({
Expand Down
2 changes: 1 addition & 1 deletion src/page/Phome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Vnav from '../view/Vnav';
import VstyleAdd from '../view/Vstyles/VstyleAdd';
import Vstyles from '../view/Vstyles';

import {NavLink, Link, Route, Switch} from 'react-router-dom';
import {Link, Route, Switch} from 'react-router-dom';


const mapStoreToProps = (store)=>{
Expand Down
5 changes: 1 addition & 4 deletions src/page/Pstyle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ import Valert from '../view/Valert';
import Vmap from '../view/Vmap';
import Vstyle from '../view/Vstyle';

import Vpanel from '../view/Vpanel';
import Mpanel from '../model/Mpanel';

const mapStoreToProps = (store)=>{
return {
style:store.style,
error:store.styleError
} // props
}
};
const mapDispatchToProps = {};

Expand Down
2 changes: 1 addition & 1 deletion src/page/Pstyles.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Vnav from '../view/Vnav';
import VstyleAdd from '../view/Vstyles/VstyleAdd';
import Vstyles from '../view/Vstyles';

import {NavLink, Link, Route, Switch} from 'react-router-dom';
import {Link, Route, Switch} from 'react-router-dom';


const mapStoreToProps = (store)=>{
Expand Down
8 changes: 6 additions & 2 deletions src/reducer/Rstyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {Map, List, fromJS} from 'immutable';

const iState = Map({
loaded:false,
rec:undefined
rec:undefined,
rebuildMap:null,
});

export default function(state = iState, action){
Expand Down Expand Up @@ -98,7 +99,6 @@ export default function(state = iState, action){
return layer.get('id') === action.layerId;
});
if (ind === -1) throw new Error('layer matching layerId not found');
const val = fromJS(action.payload);
const style = state.removeIn(['rec','layers',ind, ...action.prop]);
return setUpdated(style);
}
Expand All @@ -107,6 +107,10 @@ export default function(state = iState, action){
const style = state.setIn(['rec','sources',action.key],source);
return setUpdated(style);
}
case 'SOURCE_RELOAD':{
const style = state.setIn(['rebuildMap'], new Date().getTime())
return style
}
default:
return state;
}
Expand Down
4 changes: 1 addition & 3 deletions src/reducer/RstyleError.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import {Map, List, fromJS} from 'immutable';
import {Map} from 'immutable';

const iState = Map({});

export default function(state = iState, action){
switch (action.type){
case 'STYLE_ERROR_DEFINE':{
let errors = Map();
//console.log('STYLE_ERROR_DEFINE',action.payload);
action.payload.forEach((error)=>{
errors = errors.setIn(error.key,error.message);
});
return errors;
}
case 'STYLE_ERROR_ADD':{
//console.log('STYLE_ERROR_DEFINE',action.payload);
return state.setIn(action.payload.key,action.payload.message);
}
default:
Expand Down
8 changes: 4 additions & 4 deletions src/utility/MapboxError.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default {
}
*/

if (!error || !error.message || error.message.indexOf(':') === -1) return ['general'];
const prefix = error.message.split(':')[0];
if (!error || !error.message || error.message.indexOf(': ') === -1) return ['general'];
const prefix = error.message.split(': ')[0];
const parts = prefix.split('.');
let key = [];
parts.forEach((part)=>{
Expand All @@ -30,7 +30,7 @@ export default {
if (!error) return;
if (!error.message && error.stack) return error.stack;
if (!error.message && !error.stack) return 'unidentified mapbox error';
if (error.message.indexOf(':') === -1) return error.message;
return error.message.split(':')[1];
if (error.message.indexOf(': ') === -1) return error.message;
return error.message.split(': ')[1];
}
};
4 changes: 1 addition & 3 deletions src/view/Vcode/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import Mstyle from '../../model/Mstyle';
import Vfield from '../Vfield';

export default class Vsources extends React.Component {
export default class Vcode extends React.Component {
constructor(props) {
super(props);
this.state = {};
Expand All @@ -25,8 +25,6 @@ export default class Vsources extends React.Component {

const maxContentH = window.innerHeight - 44;

console.log('code render errs:',errors);

const field = {
value:Mstyle.getMapStyle(),
error:errors,
Expand Down
7 changes: 0 additions & 7 deletions src/view/Vconfig/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ export default class Vconfig extends React.Component {
config: PropTypes.object
}

constructor(props) {
super(props);
const {} = props;


}

render (){
const {config, error, handle} = this.props;

Expand Down
24 changes: 4 additions & 20 deletions src/view/Vfeature/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ export default class Vfeature extends React.Component {
}

render (){
const {features, handle} = this.props;

// get property values
const {features} = this.props;

let cols = ['id'];
features.map((feature)=>{
if (!feature.properties) return;
if (!feature.properties) return null;
Object.keys(feature.properties).map((i)=>{
if (cols.indexOf(i) === -1) cols.push(i);
return null;
});
return null;
});

let ids = [];
Expand All @@ -36,7 +36,6 @@ export default class Vfeature extends React.Component {
return false;
});


return <table className="table font-sm table-sm">
<thead>
<tr>
Expand All @@ -58,20 +57,5 @@ export default class Vfeature extends React.Component {
</tbody>

</table>

/*
{features.map((feature)=>{
console.log('feature:',feature);
return <li key={feature.id} onClick={()=>{this.handle.featureClick(feature);}}><a href="javascript://">
{Object.keys(feature.properties).map((i)=>{
return i+': '+feature.properties[i];
})}
</a></li>
})}
*/
}
};
12 changes: 4 additions & 8 deletions src/view/Vfield/VfieldAC.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default class VfieldAC extends React.Component {
name: PropTypes.string.isRequired,
value: PropTypes.string,
placeholder: PropTypes.string,
helper: PropTypes.string,
error: PropTypes.string,
options: PropTypes.array,
autoFocus: PropTypes.boolean,
Expand All @@ -38,8 +37,6 @@ export default class VfieldAC extends React.Component {
this.state.value = field.value;
}

//console.log('AC handle:',handle);

this.handle = {
inputChange:(e)=>{
this.setState({inputValue: e.target.value});
Expand Down Expand Up @@ -102,7 +99,6 @@ export default class VfieldAC extends React.Component {
this.handle.change(value);
},
liClick:(value)=>{
console.log('li click:',value);
this.handle.select(value);
},
cancel:()=>{
Expand All @@ -124,7 +120,6 @@ export default class VfieldAC extends React.Component {
if (handle.selectedClick) handle.selectedClick();
},
selectedKeyUp:(e)=>{
console.log('selected keyUp',e);
/*
if (e.key === 'ArrowDown'){
this.props.handle.focusNext();
Expand Down Expand Up @@ -175,23 +170,24 @@ export default class VfieldAC extends React.Component {
}

render (){
const {field, handle} = this.props;
const {field} = this.props;
const value = field.controlled ? this.state.value : field.value;

//console.log('handle change:',value);
if (value !== null && value.length > 0 && (!this.state.mode || this.state.mode === 'view')){

//check if value is valid option, if not show error
/*
let found = false;
for (let i=0,len=field.options.length;i<len;i++){
let option = field.options[i];
if (option.value === value){
found = true;
}
}

*/
let error = null; //(!found)? 'expression not found': null;


return <div className="form-group mb-0 position-relative">
{field.label && <label className="mb-0">{field.label}</label>}
{field.icon && <i className="material-icons md-18">{field.icon}</i>}
Expand Down
5 changes: 1 addition & 4 deletions src/view/Vfield/VfieldColor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export default class VfieldColor extends React.Component {
name: PropTypes.string.isRequired,
value: PropTypes.string,
placeholder: PropTypes.string,
helper: PropTypes.string,
error: PropTypes.string,
options: PropTypes.array,
autoFocus: PropTypes.boolean
Expand Down Expand Up @@ -85,8 +84,6 @@ export default class VfieldColor extends React.Component {
}
},
colorSet:(color)=>{
console.log('color:',color);

let value;
switch(color.source){
case 'rgb':
Expand Down Expand Up @@ -123,7 +120,7 @@ export default class VfieldColor extends React.Component {
}

render (){
const {field, handle, error} = this.props;
const {field, error} = this.props;
const value = field.controlled ? this.state.value : field.value || '';

const colors = MaterialColor.getAll();
Expand Down
2 changes: 0 additions & 2 deletions src/view/Vfield/VfieldFile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default class VfieldFile extends React.Component {
name: PropTypes.string.isRequired,
value: PropTypes.object,
placeholder: PropTypes.string,
helper: PropTypes.string,
error: PropTypes.string
}),
handle: PropTypes.object
Expand All @@ -30,7 +29,6 @@ export default class VfieldFile extends React.Component {
this.handle = {
change:(e)=>{
const file = e.target.files[0];
const name = e.target.name;
if (controlled){
this.setState({value:file});
}
Expand Down
9 changes: 3 additions & 6 deletions src/view/Vlayer/VlayerEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import VlayerEditor from './VlayerEditor';
import VlayerDelete from './VlayerDelete';

import Mlayer from '../../model/Mlayer';
import Mstyle from '../../model/Mstyle';

export default class VlayerEdit extends React.Component {

Expand Down Expand Up @@ -83,10 +82,6 @@ export default class VlayerEdit extends React.Component {

const layerError = error.getIn(['layers',Mlayer.getInd(this.id)]);

//console.log('layer err:',error);

// change map mode to show_hidden source layers

if (layer === undefined){
return <Valert message="no layer found"/>;
}
Expand All @@ -99,7 +94,9 @@ export default class VlayerEdit extends React.Component {
case 'edit':
section = <VlayerEditor key={this.id} handle={handle} error={layerError} layer={layer}/>;
break;

default:
section = <VlayerEditor key={this.id} handle={handle} error={layerError} layer={layer}/>;
break;
}

switch (this.state.modal){
Expand Down
6 changes: 1 addition & 5 deletions src/view/Vlayer/VlayerGroup/VlayerGroupSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Vproperty from '../../Vproperty';
import VpropertyAdd from '../../Vproperty/VpropertyAdd';

import Mlayer from '../../../model/Mlayer';
import Msource from '../../../model/Msource';

export default class VlayerGroupSettings extends React.Component {
static propTypes = {
Expand All @@ -22,7 +21,6 @@ export default class VlayerGroupSettings extends React.Component {

this.handle = {
change:(field)=>{
console.log('change:',field);
Mlayer.setIn(layer.get('id'),[field.name],field.value);
},
focus:handle.focus
Expand All @@ -36,8 +34,6 @@ export default class VlayerGroupSettings extends React.Component {
render (){
const {layer, handle, focus, error} = this.props;

const layerId = layer.get('id');

const spec = styleSpec.latest.layer;

let addSpec = {
Expand All @@ -60,7 +56,7 @@ export default class VlayerGroupSettings extends React.Component {

return <div className="">
{layer.keySeq().map((key)=>{
if (!addSpec[key]) return;
if (!addSpec[key]) return <div/>;

return <Vproperty key={key} property={{
name:key,
Expand Down
Loading

0 comments on commit 632b03f

Please sign in to comment.