eslint commands and apply some style fixes ()

* auto eslint and add commands for eslint

* eslint the entire frontend folder
This commit is contained in:
Devin Howard 2017-01-11 12:52:34 -05:00 committed by GitHub
parent 8b738f3d28
commit 25b4d388de
18 changed files with 61 additions and 86 deletions

View file

@ -1,5 +1,7 @@
/* global $, ActionCable */ /* global $, ActionCable */
import { indexOf } from 'lodash'
import Active from './Active' import Active from './Active'
import Control from './Control' import Control from './Control'
import DataModel from './DataModel' import DataModel from './DataModel'
@ -42,14 +44,14 @@ const Cable = {
if (t1.authorizeToShow(m) && t2.authorizeToShow(m) && s.authorizeToShow(m) && !DataModel.Synapses.get(event.synapse.id)) { if (t1.authorizeToShow(m) && t2.authorizeToShow(m) && s.authorizeToShow(m) && !DataModel.Synapses.get(event.synapse.id)) {
// refactor the heck outta this, its adding wicked wait time // refactor the heck outta this, its adding wicked wait time
var topic1, topic2, node1, node2, synapse, mapping, cancel, mapper var topic1, topic2, node1, node2, synapse, mapping, cancel, mapper
function waitThenRenderSynapse() { const waitThenRenderSynapse = () => {
if (synapse && mapping && mapper) { if (synapse && mapping && mapper) {
topic1 = synapse.getTopic1() topic1 = synapse.getTopic1()
node1 = topic1.get('node') node1 = topic1.get('node')
topic2 = synapse.getTopic2() topic2 = synapse.getTopic2()
node2 = topic2.get('node') node2 = topic2.get('node')
Synapse.renderSynapse(mapping, synapse, node1, node2, false) Synapse.renderSynapse(mapping, synapse, node1, node2, false)
} else if (!cancel) { } else if (!cancel) {
setTimeout(waitThenRenderSynapse, 10) setTimeout(waitThenRenderSynapse, 10)
@ -108,7 +110,7 @@ const Cable = {
if (edge.getData('mappings').length - 1 === 0) { if (edge.getData('mappings').length - 1 === 0) {
Control.hideEdge(edge) Control.hideEdge(edge)
} }
var index = indexOf(edge.getData('synapses'), synapse) var index = indexOf(edge.getData('synapses'), synapse)
edge.getData('mappings').splice(index, 1) edge.getData('mappings').splice(index, 1)
edge.getData('synapses').splice(index, 1) edge.getData('synapses').splice(index, 1)
@ -129,15 +131,15 @@ const Cable = {
if (t.authorizeToShow(m) && !DataModel.Topics.get(event.topic.id)) { if (t.authorizeToShow(m) && !DataModel.Topics.get(event.topic.id)) {
// refactor the heck outta this, its adding wicked wait time // refactor the heck outta this, its adding wicked wait time
var topic, mapping, mapper, cancel var topic, mapping, mapper, cancel
function waitThenRenderTopic() { const waitThenRenderTopic = () => {
if (topic && mapping && mapper) { if (topic && mapping && mapper) {
Topic.renderTopic(mapping, topic, false, false) Topic.renderTopic(mapping, topic, false, false)
} else if (!cancel) { } else if (!cancel) {
setTimeout(waitThenRenderTopic, 10) setTimeout(waitThenRenderTopic, 10)
} }
} }
mapper = DataModel.Mappers.get(event.topic.user_id) mapper = DataModel.Mappers.get(event.topic.user_id)
if (mapper === undefined) { if (mapper === undefined) {
Mapper.get(event.topic.user_id, function(m) { Mapper.get(event.topic.user_id, function(m) {

View file

@ -1,5 +1,3 @@
/* global $ */
import _ from 'lodash' import _ from 'lodash'
import outdent from 'outdent' import outdent from 'outdent'
@ -7,7 +5,6 @@ import Active from './Active'
import DataModel from './DataModel' import DataModel from './DataModel'
import Filter from './Filter' import Filter from './Filter'
import GlobalUI from './GlobalUI' import GlobalUI from './GlobalUI'
import JIT from './JIT'
import Mouse from './Mouse' import Mouse from './Mouse'
import Selected from './Selected' import Selected from './Selected'
import Settings from './Settings' import Settings from './Settings'
@ -98,7 +95,6 @@ const Control = {
var permToDelete = Active.Mapper.id === topic.get('user_id') || Active.Mapper.get('admin') var permToDelete = Active.Mapper.id === topic.get('user_id') || Active.Mapper.get('admin')
if (permToDelete) { if (permToDelete) {
var mappableid = topic.id
var mapping = node.getData('mapping') var mapping = node.getData('mapping')
topic.destroy() topic.destroy()
DataModel.Mappings.remove(mapping) DataModel.Mappings.remove(mapping)
@ -148,7 +144,6 @@ const Control = {
} }
var topic = node.getData('topic') var topic = node.getData('topic')
var mappableid = topic.id
var mapping = node.getData('mapping') var mapping = node.getData('mapping')
mapping.destroy() mapping.destroy()
DataModel.Topics.remove(topic) DataModel.Topics.remove(topic)
@ -267,7 +262,6 @@ const Control = {
if (edge.getData('synapses').length - 1 === 0) { if (edge.getData('synapses').length - 1 === 0) {
Control.hideEdge(edge) Control.hideEdge(edge)
} }
var mappableid = synapse.id
synapse.destroy() synapse.destroy()
// the server will destroy the mapping, we just need to remove it here // the server will destroy the mapping, we just need to remove it here
@ -318,7 +312,6 @@ const Control = {
var synapse = edge.getData('synapses')[index] var synapse = edge.getData('synapses')[index]
var mapping = edge.getData('mappings')[index] var mapping = edge.getData('mappings')[index]
var mappableid = synapse.id
mapping.destroy() mapping.destroy()
DataModel.Synapses.remove(synapse) DataModel.Synapses.remove(synapse)

View file

@ -291,18 +291,18 @@ const Create = {
}, },
source: synapseBloodhound source: synapseBloodhound
}, },
{ {
name: 'existing_synapses', name: 'existing_synapses',
limit: 50, limit: 50,
display: function(s) { return s.label }, display: function(s) { return s.label },
templates: { templates: {
suggestion: function(s) { suggestion: function(s) {
return Hogan.compile($('#synapseAutocompleteTemplate').html()).render(s) return Hogan.compile($('#synapseAutocompleteTemplate').html()).render(s)
},
header: '<h3>Existing synapses</h3>'
}, },
source: existingSynapseBloodhound header: '<h3>Existing synapses</h3>'
}] },
source: existingSynapseBloodhound
}]
) )
$('#synapse_desc').keyup(function(e) { $('#synapse_desc').keyup(function(e) {

View file

@ -7,7 +7,6 @@ try { Backbone.$ = window.$ } catch (err) {}
import Active from '../Active' import Active from '../Active'
import InfoBox from '../Map/InfoBox' import InfoBox from '../Map/InfoBox'
import Mapper from '../Mapper' import Mapper from '../Mapper'
import Realtime from '../Realtime'
const Map = Backbone.Model.extend({ const Map = Backbone.Model.extend({
urlRoot: '/maps', urlRoot: '/maps',

View file

@ -1,5 +1,3 @@
/* global $ */
import _ from 'lodash' import _ from 'lodash'
import outdent from 'outdent' import outdent from 'outdent'
import Backbone from 'backbone' import Backbone from 'backbone'
@ -7,8 +5,6 @@ try { Backbone.$ = window.$ } catch (err) {}
import Active from '../Active' import Active from '../Active'
import Filter from '../Filter' import Filter from '../Filter'
import JIT from '../JIT'
import Realtime from '../Realtime'
import SynapseCard from '../SynapseCard' import SynapseCard from '../SynapseCard'
import Visualize from '../Visualize' import Visualize from '../Visualize'

View file

@ -1,13 +1,9 @@
/* global $ */
import _ from 'lodash' import _ from 'lodash'
import Backbone from 'backbone' import Backbone from 'backbone'
try { Backbone.$ = window.$ } catch (err) {} try { Backbone.$ = window.$ } catch (err) {}
import Active from '../Active' import Active from '../Active'
import Filter from '../Filter' import Filter from '../Filter'
import JIT from '../JIT'
import Realtime from '../Realtime'
import TopicCard from '../TopicCard' import TopicCard from '../TopicCard'
import Visualize from '../Visualize' import Visualize from '../Visualize'

View file

@ -6,6 +6,7 @@ import Visualize from './Visualize'
const PasteInput = { const PasteInput = {
// thanks to https://github.com/kevva/url-regex // thanks to https://github.com/kevva/url-regex
// eslint-disable-next-line no-useless-escape
URL_REGEX: new RegExp('^(?:(?:(?:[a-z]+:)?//)|www\.)(?:\S+(?::\S*)?@)?(?:localhost|(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#][^\s"]*)?$'), URL_REGEX: new RegExp('^(?:(?:(?:[a-z]+:)?//)|www\.)(?:\S+(?::\S*)?@)?(?:localhost|(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#][^\s"]*)?$'),
init: function() { init: function() {

View file

@ -14,7 +14,7 @@ module.exports = {
SEND_COORDS: 'SEND_COORDS', SEND_COORDS: 'SEND_COORDS',
DRAG_TOPIC: 'DRAG_TOPIC', DRAG_TOPIC: 'DRAG_TOPIC',
/* EVENTS RECEIVABLE FROM NODE SERVER*/ /* EVENTS RECEIVABLE FROM NODE SERVER */
JUNTO_UPDATED: 'JUNTO_UPDATED', JUNTO_UPDATED: 'JUNTO_UPDATED',
INVITED_TO_CALL: 'INVITED_TO_CALL', INVITED_TO_CALL: 'INVITED_TO_CALL',
INVITED_TO_JOIN: 'INVITED_TO_JOIN', INVITED_TO_JOIN: 'INVITED_TO_JOIN',
@ -29,5 +29,5 @@ module.exports = {
NEW_MAPPER: 'NEW_MAPPER', NEW_MAPPER: 'NEW_MAPPER',
LOST_MAPPER: 'LOST_MAPPER', LOST_MAPPER: 'LOST_MAPPER',
TOPIC_DRAGGED: 'TOPIC_DRAGGED', TOPIC_DRAGGED: 'TOPIC_DRAGGED',
PEER_COORDS_UPDATED: 'PEER_COORDS_UPDATED', PEER_COORDS_UPDATED: 'PEER_COORDS_UPDATED'
} }

View file

@ -8,8 +8,7 @@ import Cable from '../Cable'
import DataModel from '../DataModel' import DataModel from '../DataModel'
import JIT from '../JIT' import JIT from '../JIT'
import Util from '../Util' import Util from '../Util'
import Views from '../Views' import Views, { ChatView } from '../Views'
import { ChatView } from '../Views'
import Visualize from '../Visualize' import Visualize from '../Visualize'
import { import {
@ -152,7 +151,7 @@ let Realtime = {
config: { DOUBLE_CLICK_TOLERANCE: 200 } config: { DOUBLE_CLICK_TOLERANCE: 200 }
}) })
self.room.videoAdded(self.handleVideoAdded) self.room.videoAdded(self.handleVideoAdded)
self.startActiveMap() self.startActiveMap()
} // if Active.Mapper } // if Active.Mapper
}, },

View file

@ -4,18 +4,12 @@
everthing in this file happens as a result of websocket events everthing in this file happens as a result of websocket events
*/ */
import { indexOf } from 'lodash'
import { JUNTO_UPDATED } from './events' import { JUNTO_UPDATED } from './events'
import Active from '../Active' import Active from '../Active'
import { ChatView } from '../Views' import { ChatView } from '../Views'
import DataModel from '../DataModel' import DataModel from '../DataModel'
import GlobalUI from '../GlobalUI' import GlobalUI from '../GlobalUI'
import Control from '../Control'
import Mapper from '../Mapper'
import Topic from '../Topic'
import Synapse from '../Synapse'
import Util from '../Util' import Util from '../Util'
import Visualize from '../Visualize' import Visualize from '../Visualize'
@ -210,7 +204,7 @@ export const callInProgress = self => () => {
GlobalUI.notifyUser(notifyText, true) GlobalUI.notifyUser(notifyText, true)
$('#toast button.yes').click(e => self.joinCall()) $('#toast button.yes').click(e => self.joinCall())
$('#toast button.no').click(e => GlobalUI.clearNotify()) $('#toast button.no').click(e => GlobalUI.clearNotify())
ChatView.conversationInProgress() ChatView.conversationInProgress()
} }
export const callStarted = self => () => { export const callStarted = self => () => {

View file

@ -4,7 +4,6 @@ import Active from './Active'
import Control from './Control' import Control from './Control'
import Create from './Create' import Create from './Create'
import DataModel from './DataModel' import DataModel from './DataModel'
import JIT from './JIT'
import Map from './Map' import Map from './Map'
import Selected from './Selected' import Selected from './Selected'
import Settings from './Settings' import Settings from './Settings'

View file

@ -49,7 +49,7 @@ const ChatView = {
$('#' + ChatView.domId).hide() $('#' + ChatView.domId).hide()
}, },
render: () => { render: () => {
if (!Active.Map) return if (!Active.Map) return
const self = ChatView const self = ChatView
self.mapChat = ReactDOM.render(React.createElement(MapChat, { self.mapChat = ReactDOM.render(React.createElement(MapChat, {
conversationLive: self.conversationLive, conversationLive: self.conversationLive,
@ -111,7 +111,7 @@ const ChatView = {
conversationInProgress: participating => { conversationInProgress: participating => {
ChatView.conversationLive = true ChatView.conversationLive = true
ChatView.isParticipating = participating ChatView.isParticipating = participating
ChatView.render() ChatView.render()
}, },
conversationEnded: () => { conversationEnded: () => {
ChatView.conversationLive = false ChatView.conversationLive = false
@ -144,7 +144,7 @@ const ChatView = {
}, },
addMessage: (message, isInitial, wasMe) => { addMessage: (message, isInitial, wasMe) => {
const self = ChatView const self = ChatView
if (!isInitial) self.mapChat.newMessage() if (!isInitial) self.mapChat.newMessage()
if (!wasMe && !isInitial && self.alertSound) self.sound.play('receivechat') if (!wasMe && !isInitial && self.alertSound) self.sound.play('receivechat')
self.messages.add(message) self.messages.add(message)
self.render() self.render()

View file

@ -1,13 +1,7 @@
/* global $ */ /* global $ */
import Backbone from 'backbone'
import attachMediaStream from 'attachmediastream' import attachMediaStream from 'attachmediastream'
// TODO is this line good or bad
// Backbone.$ = window.$
import Active from '../Active'
import DataModel from '../DataModel'
import Realtime from '../Realtime' import Realtime from '../Realtime'
import VideoView from './VideoView' import VideoView from './VideoView'

View file

@ -9,7 +9,7 @@ import { JUNTO_UPDATED } from '../Realtime/events'
const Views = { const Views = {
init: (serverData) => { init: (serverData) => {
$(document).on(JUNTO_UPDATED, () => ExploreMaps.render()) $(document).on(JUNTO_UPDATED, () => ExploreMaps.render())
ChatView.init([serverData['sounds/MM_sounds.mp3'],serverData['sounds/MM_sounds.ogg']]) ChatView.init([serverData['sounds/MM_sounds.mp3'], serverData['sounds/MM_sounds.ogg']])
}, },
ExploreMaps, ExploreMaps,
ChatView, ChatView,

View file

@ -11,25 +11,25 @@ function addZero(i) {
return i return i
} }
function formatDate(created_at) { function formatDate(createdAt) {
let date = new Date(created_at) let date = new Date(createdAt)
let formatted = (date.getMonth() + 1) + '/' + date.getDate() let formatted = (date.getMonth() + 1) + '/' + date.getDate()
formatted += ' ' + addZero(date.getHours()) + ':' + addZero(date.getMinutes()) formatted += ' ' + addZero(date.getHours()) + ':' + addZero(date.getMinutes())
return formatted return formatted
} }
const Message = props => { const Message = props => {
const { user_image, user_name, message, created_at, heading } = props const { user_image: userImage, user_name: userName, message, created_at: createdAt, heading } = props
const messageHtml = {__html: linker.link(Util.addEmoji(message, { emoticons: false }))} const messageHtml = {__html: linker.link(Util.addEmoji(message, { emoticons: false }))}
return ( return (
<div className="chat-message"> <div className="chat-message">
<div className="chat-message-user"> <div className="chat-message-user">
{heading && <img src={user_image} />} {heading && <img src={userImage} />}
</div> </div>
{heading && <div className="chat-message-meta"> {heading && <div className="chat-message-meta">
<span className='chat-message-username'>{user_name}</span>&nbsp; <span className='chat-message-username'>{userName}</span>&nbsp;
<span className='chat-message-time'>{formatDate(created_at)}</span> <span className='chat-message-time'>{formatDate(createdAt)}</span>
</div>} </div>}
<div className="chat-message-text" dangerouslySetInnerHTML={messageHtml}></div> <div className="chat-message-text" dangerouslySetInnerHTML={messageHtml}></div>
<div className="clearfloat"></div> <div className="clearfloat"></div>

View file

@ -2,28 +2,28 @@ import React, { PropTypes, Component } from 'react'
class Participant extends Component { class Participant extends Component {
render() { render() {
const { conversationLive, mapperIsLive, isParticipating, isPending, id, self, image, username, selfName, color } = this.props const { conversationLive, mapperIsLive, isParticipating, isPending, id, self, image, username, color } = this.props
return ( return (
<div className={`participant participant-${id} ${self ? 'is-self' : ''}`}> <div className={`participant participant-${id} ${self ? 'is-self' : ''}`}>
<div className="chat-participant-image"> <div className="chat-participant-image">
<img src={image} style={{ border: `2px solid ${color}`}} /> <img src={image} style={{ border: `2px solid ${color}` }} />
</div> </div>
<div className="chat-participant-name"> <div className="chat-participant-name">
{username} {self ? '(me)' : ''} {username} {self ? '(me)' : ''}
</div> </div>
{!self && !conversationLive && <button {!self && !conversationLive && <button
className={`button chat-participant-invite-call ${isPending ? 'pending' : ''}`} className={`button chat-participant-invite-call ${isPending ? 'pending' : ''}`}
onClick={() => !isPending && this.props.inviteACall(id)} // Realtime.inviteACall(id) onClick={() => !isPending && this.props.inviteACall(id)} // Realtime.inviteACall(id)
/>} />}
{!self && mapperIsLive && !isParticipating && <button {!self && mapperIsLive && !isParticipating && <button
className={`button chat-participant-invite-join ${isPending ? 'pending' : ''}`} className={`button chat-participant-invite-join ${isPending ? 'pending' : ''}`}
onClick={() => !isPending && this.props.inviteToJoin(id)} // Realtime.inviteToJoin(id) onClick={() => !isPending && this.props.inviteToJoin(id)} // Realtime.inviteToJoin(id)
/>} />}
{isParticipating && <span className="chat-participant-participating"> {isParticipating && <span className="chat-participant-participating">
<div className="green-dot"></div> <div className="green-dot"></div>
</span>} </span>}
<div className="clearfloat"></div> <div className="clearfloat"></div>
</div> </div>
) )
} }
} }

View file

@ -41,7 +41,7 @@ class Header extends Component {
linkClass={activeClass('active')} linkClass={activeClass('active')}
data-router="true" data-router="true"
text="All Maps" text="All Maps"
/> />
<MapLink show={signedIn && explore} <MapLink show={signedIn && explore}
href="/explore/mine" href="/explore/mine"
linkClass={activeClass('my')} linkClass={activeClass('my')}

View file

@ -5,7 +5,9 @@
"scripts": { "scripts": {
"build": "webpack", "build": "webpack",
"build:watch": "webpack --watch", "build:watch": "webpack --watch",
"test": "mocha --compilers js:babel-core/register frontend/test" "test": "mocha --compilers js:babel-core/register frontend/test",
"eslint": "eslint frontend",
"eslint:fix": "eslint --fix frontend"
}, },
"repository": { "repository": {
"type": "git", "type": "git",