Skip to content

Commit

Permalink
lots of linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mirandaflu committed Mar 24, 2017
1 parent 3246bfe commit b905d9e
Show file tree
Hide file tree
Showing 56 changed files with 1,057 additions and 1,064 deletions.
16 changes: 9 additions & 7 deletions app/components/attributes/checkboxinput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import React from 'react';

export default class TextInput extends React.Component {
state = { value: this.props.value }
handleChange = (event) => {
let newValue = !this.state.value;
handleChange = () => {
const newValue = !this.state.value;
this.props.onCommitChange({ target: {value: newValue }});
this.setState({ value: newValue });
}
componentWillReceiveProps(nextProps) {
this.setState({ value: nextProps.value });
}
render() { return (
<input type="checkbox"
checked={this.state.value}
onChange={this.handleChange} />
);}
render() {
return (
<input type="checkbox"
checked={this.state.value}
onChange={this.handleChange} />
);
}
}
19 changes: 9 additions & 10 deletions app/components/attributes/dateinput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,42 @@ import moment from 'moment';

export default class DateInput extends React.Component {
state = {
value: (this.props.value && this.props.value != '')? moment(this.props.value): null,
value: (this.props.value && this.props.value !== '') ? moment(this.props.value) : null,
tempValue: null
}
setTemp = () => this.setState({ tempValue: this.state.value });
handleChange = (value) => {
if (value._isAMomentObject) {
this.setState({ value: value });
value = new Date(value._d);
this.props.onCommitChange({ target: {value: value} });
const v = new Date(value._d);
this.props.onCommitChange({ target: {value: v} });
}
}
clearIfNotValid = (value) => {
if (!value._isAMomentObject) {
if (value == '') {
if (value === '') {
this.setState({ value: null });
this.props.onCommitChange({target: {value: null} });
}
else {
} else {
this.setState({ value: this.state.tempValue });
this.props.onCommitChange({target: {value: new Date(this.state.tempValue)} });
}
}
}
componentWillReceiveProps(nextProps) {
this.setState({
value: (nextProps.value && nextProps.value != '')? moment(nextProps.value): null
value: (nextProps.value && nextProps.value !== '') ? moment(nextProps.value) : null
});
}
render() {
return (
<Datetime
value={this.state.value}
dateFormat={(this.props.fieldType.indexOf('Date') != -1)? 'YYYY-MM-DD': false}
timeFormat={(this.props.fieldType.indexOf('Time') != -1)? 'hh:mm:ss a': false}
dateFormat={(this.props.fieldType.indexOf('Date') !== -1) ? 'YYYY-MM-DD' : false}
timeFormat={(this.props.fieldType.indexOf('Time') !== -1) ? 'hh:mm:ss a' : false}
onFocus={this.setTemp}
onBlur={this.clearIfNotValid}
onChange={this.handleChange} />
);
}
}
}
28 changes: 14 additions & 14 deletions app/components/attributes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,46 @@ import DateInput from './dateinput.jsx';
import LinkInput from './linkinput.jsx';

module.exports = {
"Static": {
'Static': {
component: StaticText
},
"Text": {
'Text': {
component: TextInput
},
"Number": {
'Number': {
component: NumberInput
},
"Checkbox": {
'Checkbox': {
component: CheckboxInput
},
"Single Select": {
'Single Select': {
component: SelectInput
},
"Multiple Select": {
'Multiple Select': {
component: SelectInput
},
"Date": {
'Date': {
component: DateInput
},
"Time": {
'Time': {
component: DateInput
},
"Date and Time": {
'Date and Time': {
component: DateInput
},
"Email Address": {
'Email Address': {
component: LinkInput
},
"URL": {
'URL': {
component: LinkInput
},
"Attribute Reference": {
'Attribute Reference': {
component: StaticText
},
"Single Field Reference": {
'Single Field Reference': {
component: SelectInput
},
"Multiple Field Reference": {
'Multiple Field Reference': {
component: SelectInput
}
};
Expand Down
16 changes: 8 additions & 8 deletions app/components/attributes/linkinput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class LinkInput extends React.Component {
editVisible: false
}
toggleEditMode = () => this.setState({ editVisible: !this.state.editVisible });
handleEditStart = (event) => this.setState({ editVisible: true });
handleEditStart = () => this.setState({ editVisible: true });
handleKeyDown = (event) => {
if (event.key === 'Enter') {
this.handleCommitChange(event);
Expand All @@ -22,17 +22,17 @@ export default class LinkInput extends React.Component {
}
render() {
let actualLink = this.state.value;
if (actualLink != '' && actualLink != null) {
if (this.props.fieldType == 'URL' && actualLink.slice(0,4) != 'http') {
actualLink = 'http://'+actualLink;
if (actualLink !== '' && actualLink !== null) {
if (this.props.fieldType === 'URL' && actualLink.slice(0, 4) !== 'http') {
actualLink = 'http://' + actualLink;
}
if (this.props.fieldType == 'Email Address' && actualLink.slice(0,6) != 'mailto') {
actualLink = 'mailto:'+actualLink;
if (this.props.fieldType === 'Email Address' && actualLink.slice(0, 6) !== 'mailto') {
actualLink = 'mailto:' + actualLink;
}
}
return (
<div>
{(!this.state.editVisible && this.state.value != '') &&
{(!this.state.editVisible && this.state.value !== '') &&
<div>
<a target="_blank" href={actualLink}>{this.state.value}</a>
<button className="pure-button button-xsmall"
Expand All @@ -41,7 +41,7 @@ export default class LinkInput extends React.Component {
</button>
</div>
}
{(this.state.editVisible || this.state.value == '') &&
{(this.state.editVisible || this.state.value === '') &&
<input type="text"
value={this.state.value}
onFocus={this.handleEditStart}
Expand Down
38 changes: 17 additions & 21 deletions app/components/attributes/selectinput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export default class SelectInput extends React.Component {
options: []
}
loadOptions = () => {
feathers_app.service('fields').get(this.props.field).then(field => {
feathers_app.service('fields').get(field.fieldReference).then(field => {
feathers_app.service('attributes').find({query:{
feathersApp.service('fields').get(this.props.field).then(field1 => {
feathersApp.service('fields').get(field1.fieldReference).then(field => {
feathersApp.service('attributes').find({query: {
coll: field.coll,
field: field.fieldReference
}}).then(attributes => {
Expand All @@ -24,21 +24,19 @@ export default class SelectInput extends React.Component {
}).catch(console.error);
}
handleChange = (value) => {
if (this.props.clearable && value == null) {
if (this.props.clearable && value === null) {
this.props.onCommitChange({ target: {value: null} });
this.setState({ value: null });
}
else if (this.props.fieldType.indexOf('Single') != -1) {
if (this.props.options.indexOf(value.value) == -1) {
} else if (this.props.fieldType.indexOf('Single') !== -1) {
if (this.props.options.indexOf(value.value) === -1) {
this.props.onCreateOption(value.value);
}
this.props.onCommitChange({ target: {value: value.value} });
this.setState({ value: value.value });
}
else if (this.props.fieldType.indexOf('Multiple') != -1) {
let valueArray = [];
for (let v of value) {
if (this.props.options.indexOf(v.value) == -1) {
} else if (this.props.fieldType.indexOf('Multiple') !== -1) {
const valueArray = [];
for (const v of value) {
if (this.props.options.indexOf(v.value) === -1) {
this.props.onCreateOption(v.value);
}
valueArray.push(v.value);
Expand All @@ -51,28 +49,26 @@ export default class SelectInput extends React.Component {
this.setState({ value: nextProps.value });
}
componentDidMount() {
if (this.props.fieldType.indexOf('Reference') != -1) {
if (this.props.fieldType.indexOf('Reference') !== -1) {
this.loadOptions();
}
}
render() {
let i = 0, that = this;
let options = [];
if (this.props.fieldType.indexOf('Reference') != -1) {
if (this.props.fieldType.indexOf('Reference') !== -1) {
options = this.state.options;
}
else {
for (let o of this.props.options) {
options = options.concat({'value':o, 'label':o});
} else {
for (const o of this.props.options) {
options = options.concat({'value': o, 'label': o});
}
}
let Component = (this.props.fieldType.indexOf('Reference') != -1)? Select: Select.Creatable;
const Component = (this.props.fieldType.indexOf('Reference') !== -1) ? Select : Select.Creatable;
return (
<Component
placeholder=""
value={this.state.value}
options={options}
multi={this.props.fieldType.indexOf('Multiple') != -1}
multi={this.props.fieldType.indexOf('Multiple') !== -1}
clearable={this.props.clearable || false}
onChange={this.handleChange} />
);
Expand Down
32 changes: 15 additions & 17 deletions app/components/attributes/statictext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,24 @@ import { Link } from 'react-router';
export default class StaticInput extends React.Component {
state = { value: this.props.value }
setValue = (props) => {
if (props.value == null || props.value == '') {
if (props.value === null || props.value === '') {
this.setState({ value: null });
}
else if (this.props.fieldType == 'Attribute Reference') {
feathers_app.service('attributes').find({query:{
} else if (this.props.fieldType === 'Attribute Reference') {
feathersApp.service('attributes').find({query: {
_id: props.value
}}).then(attributes => {
if (attributes.length == 0) {
if (attributes.length === 0) {
this.setState({ value: null });
}
else {
} else {
this.setState({ value: attributes[0].value });
}
}).catch();
}
else {
} else {
this.setState({ value: props.value });
}
}
handlePatchedAttribute = (attribute) => {
if (this.props.value == attribute._id) {
if (this.props.value === attribute._id) {
this.setValue(this.props);
}
}
Expand All @@ -33,21 +30,22 @@ export default class StaticInput extends React.Component {
}
componentDidMount() {
this.setValue(this.props);
if (this.props.fieldType == 'Attribute Reference') {
if (this.props.fieldType === 'Attribute Reference') {
this.attributePatchedListener = this.handlePatchedAttribute.bind(this);
feathers_app.service('attributes').on('patched', this.attributePatchedListener);
feathersApp.service('attributes').on('patched', this.attributePatchedListener);
}
}
componentWillUnmount() {
if (this.props.fieldType == 'Attribute Reference') {
feathers_app.service('attributes').removeListener('patched', this.attributePatchedListener);
if (this.props.fieldType === 'Attribute Reference') {
feathersApp.service('attributes').removeListener('patched', this.attributePatchedListener);
}
}
render() {
return (
<span className="staticInput" style={{padding:'4px'}}>
{this.props.fieldType == 'Attribute Reference' &&
<Link style={{float:'right'}} to={'/workspace/'+this.props.workspace+'/collection/'+this.props.collection+'/reference/'+this.props.thing+'/'+this.props.field}>
<span className="staticInput" style={{padding: '4px'}}>
{this.props.fieldType === 'Attribute Reference' &&
<Link style={{float: 'right'}}
to={'/workspace/' + this.props.workspace + '/collection/' + this.props.collection + '/reference/' + this.props.thing + '/' + this.props.field}>
<i className="fa fa-edit" />
</Link>
}
Expand Down
Loading

0 comments on commit b905d9e

Please sign in to comment.