fetch metacodes
This commit is contained in:
parent
fe88cf27de
commit
0e530626ed
6 changed files with 42 additions and 20 deletions
|
@ -1,7 +1,7 @@
|
|||
const request = require('request')
|
||||
|
||||
function apiProxyMiddleware (req, res, next) {
|
||||
if (!req.xhr) {
|
||||
if (!(req.xhr || req.originalUrl.indexOf('.json') > -1)) {
|
||||
return next()
|
||||
}
|
||||
console.log('xhr request', req.originalUrl)
|
||||
|
|
|
@ -66,22 +66,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<div class="importDialogWrapper"></div>
|
||||
<div id="loading"></div>
|
||||
<script type="text/javascript">
|
||||
var Metamaps = {
|
||||
ServerData: {
|
||||
RAILS_ENV: 'development',
|
||||
ActiveMapper: {
|
||||
id: 10,
|
||||
name: 'Connor',
|
||||
email: 'co@co.com',
|
||||
admin: false,
|
||||
image: 'https://metamaps-live.s3.amazonaws.com/users/images/555/629/996/sixtyfour/11835c3.png?1417298429'
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script src="/lib/jquery-1.12.4.min.js"></script>
|
||||
<script src="/lib/jquery-ui.min.js"></script>
|
||||
<script src="/lib/ajaxq.js"></script>
|
||||
|
@ -100,7 +85,16 @@
|
|||
<script src="/lib/typeahead.bundle.js"></script>
|
||||
<script type="text/javascript" src="/metamaps.bundle.js"></script>
|
||||
<script type="text/javascript">
|
||||
Metamaps.Loading.setup()
|
||||
Metamaps.ServerData = Metamaps.ServerData || {}
|
||||
Metamaps.ServerData.RAILS_ENV = 'development'
|
||||
Metamaps.ServerData.ActiveMapper = {
|
||||
id: 10,
|
||||
name: 'Connor',
|
||||
email: 'co@co.com',
|
||||
admin: false,
|
||||
image: 'https://metamaps-live.s3.amazonaws.com/users/images/555/629/996/sixtyfour/11835c3.png?1417298429'
|
||||
}
|
||||
Metamaps.Loading.setup()
|
||||
</script>
|
||||
|
||||
<div class="templates">
|
||||
|
|
|
@ -5,6 +5,7 @@ import ActionCable from 'action-cable-node'
|
|||
|
||||
import Active from './Active'
|
||||
import Control from './Control'
|
||||
import config from '../config'
|
||||
import DataModel from './DataModel'
|
||||
import Map from './Map'
|
||||
import Mapper from './Mapper'
|
||||
|
@ -16,7 +17,7 @@ import Visualize from './Visualize'
|
|||
const Cable = {
|
||||
init: () => {
|
||||
let self = Cable
|
||||
self.cable = ActionCable.createConsumer()
|
||||
self.cable = ActionCable.createConsumer(config.ACTIONCABLE)
|
||||
},
|
||||
subscribeToMap: id => {
|
||||
let self = Cable
|
||||
|
|
10
src/Metamaps/DataFetcher.js
Normal file
10
src/Metamaps/DataFetcher.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
async function getMetacodes() {
|
||||
const res = await fetch('/metacodes.json')
|
||||
const data = await res.json()
|
||||
return data
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getMetacodes
|
||||
}
|
|
@ -5,6 +5,7 @@ import AutoLayout from './AutoLayout'
|
|||
import Cable from './Cable'
|
||||
import Control from './Control'
|
||||
import Create from './Create'
|
||||
import DataFetcher from './DataFetcher'
|
||||
import DataModel from './DataModel'
|
||||
import Debug from './Debug'
|
||||
import Filter from './Filter'
|
||||
|
@ -38,6 +39,7 @@ Metamaps.AutoLayout = AutoLayout
|
|||
Metamaps.Cable = Cable
|
||||
Metamaps.Control = Control
|
||||
Metamaps.Create = Create
|
||||
Metamaps.DataFetcher = DataFetcher
|
||||
Metamaps.DataModel = DataModel
|
||||
Metamaps.Debug = Debug
|
||||
Metamaps.Filter = Filter
|
||||
|
@ -69,7 +71,7 @@ Metamaps.Util = Util
|
|||
Metamaps.Views = Views
|
||||
Metamaps.Visualize = Visualize
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
function runInitFunctions(serverData) {
|
||||
// initialize all the modules
|
||||
for (const prop in Metamaps) {
|
||||
// this runs the init function within each sub-object on the Metamaps one
|
||||
|
@ -78,9 +80,21 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
Metamaps[prop].hasOwnProperty('init') &&
|
||||
typeof (Metamaps[prop].init) === 'function'
|
||||
) {
|
||||
Metamaps[prop].init(Metamaps.ServerData)
|
||||
Metamaps[prop].init(serverData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fetch data from API then pass into init functions
|
||||
document.addEventListener('DOMContentLoaded', async function() {
|
||||
Metamaps.ServerData = Metamaps.ServerData || {}
|
||||
try {
|
||||
const metacodes = await DataFetcher.getMetacodes()
|
||||
Metamaps.ServerData.Metacodes = metacodes
|
||||
runInitFunctions(Metamaps.ServerData)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
})
|
||||
|
||||
export default Metamaps
|
||||
|
|
3
src/config.js
Normal file
3
src/config.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
export default {
|
||||
ACTIONCABLE: 'ws://localhost:3001/cable'
|
||||
}
|
Loading…
Reference in a new issue