metamaps--metamaps/src/Metamaps/index.js

106 lines
3.1 KiB
JavaScript
Raw Normal View History

import Active from './Active'
import AutoLayout from './AutoLayout'
import Cable from './Cable'
import Control from './Control'
import Create from './Create'
2018-03-05 09:53:45 -05:00
import DataFetcher from './DataFetcher'
import DataModel from './DataModel'
import Debug from './Debug'
import Filter from './Filter'
2016-09-30 00:20:16 +08:00
import GlobalUI, {
2017-09-22 18:38:38 -04:00
Notifications, ReactApp, Search, CreateMap, ImportDialog
2016-09-30 00:20:16 +08:00
} from './GlobalUI'
import Import from './Import'
import JIT from './JIT'
import Listeners from './Listeners'
import Loading from './Loading'
2018-03-08 10:22:11 -05:00
import Map, { InfoBox } from './Map'
import Mapper from './Mapper'
2016-09-22 17:14:34 +08:00
import Mouse from './Mouse'
import Organize from './Organize'
import PasteInput from './PasteInput'
import Realtime from './Realtime'
2016-09-22 17:14:34 +08:00
import Selected from './Selected'
import Settings from './Settings'
import Synapse from './Synapse'
import SynapseCard from './SynapseCard'
import Topic from './Topic'
import Util from './Util'
2016-09-22 20:16:18 -04:00
import Views from './Views'
import Visualize from './Visualize'
2016-10-03 08:32:37 +08:00
const Metamaps = window.Metamaps || {}
Metamaps.Active = Active
Metamaps.AutoLayout = AutoLayout
Metamaps.Cable = Cable
Metamaps.Control = Control
Metamaps.Create = Create
2018-03-05 09:53:45 -05:00
Metamaps.DataFetcher = DataFetcher
Metamaps.DataModel = DataModel
Metamaps.Debug = Debug
Metamaps.Filter = Filter
Metamaps.GlobalUI = GlobalUI
2017-09-22 18:38:38 -04:00
Metamaps.GlobalUI.Notifications = Notifications
react-router and rebuild app structure in react (#1091) * initial restructuring * stuff * lock version number * just keep using current mapinfobox * fix map upperRightUI layout * make mapsWidth work and add mobile * remove filterBoxOpen for now * redo the mobile menu in react * get account menu and invite lightbox working * fixed maps scrolling * make other routes work * fix signed out home page * fix accountbox toggling * add metacode edit routes * lots of fixes * fix map chat layout and tab bug * improve topic card readability and fix dragging bug * fixup mapchat stuff * fix up navigation to use react-router * jquery no longer handling access requests * handle case where user hasn't loaded yet * this shouldn't have been removed * add frame for topic view * rewrite map instructions * fix toast (and sign out bug) * fix apps pages and missing routes * made our request invite page look nice * filter box in react * forgot to add one proptype * remove extra comments * handle page title and mobile title updates * reenable google analytics * make filterbox use onclickoutside * reenable topic view in react * fix csrf auth token * fix little homepage styling issue * try putting preparevizdata in a timeout * installing render log to count * little fixes * fixup filters * make filter map function names more readable * eslint helps * renaming for clarity * use onclickoutside for account/sign in box * add some logging to see whether this is source of many renders * turns out chatview was heavily hogging memory * tiimeout not needed
2017-03-16 17:58:56 -04:00
Metamaps.GlobalUI.ReactApp = ReactApp
2016-09-30 00:20:16 +08:00
Metamaps.GlobalUI.Search = Search
Metamaps.GlobalUI.CreateMap = CreateMap
Metamaps.GlobalUI.ImportDialog = ImportDialog
Metamaps.Import = Import
Metamaps.JIT = JIT
Metamaps.Listeners = Listeners
Metamaps.Loading = Loading
Metamaps.Map = Map
2016-09-22 23:51:13 +08:00
Metamaps.Map.InfoBox = InfoBox
2016-09-22 17:14:34 +08:00
Metamaps.Maps = {}
Metamaps.Mapper = Mapper
2016-09-22 17:14:34 +08:00
Metamaps.Mouse = Mouse
Metamaps.Organize = Organize
Metamaps.PasteInput = PasteInput
Metamaps.Realtime = Realtime
2016-09-22 17:14:34 +08:00
Metamaps.Selected = Selected
Metamaps.Settings = Settings
Metamaps.Synapse = Synapse
Metamaps.SynapseCard = SynapseCard
Metamaps.Topic = Topic
Metamaps.Util = Util
Metamaps.Views = Views
Metamaps.Visualize = Visualize
2016-09-22 14:25:49 +08:00
2018-03-05 09:53:45 -05:00
function runInitFunctions(serverData) {
// initialize all the modules
for (const prop in Metamaps) {
2016-09-30 00:20:16 +08:00
// this runs the init function within each sub-object on the Metamaps one
if (Metamaps.hasOwnProperty(prop) &&
Metamaps[prop] != null &&
Metamaps[prop].hasOwnProperty('init') &&
typeof (Metamaps[prop].init) === 'function'
) {
2018-03-05 09:53:45 -05:00
Metamaps[prop].init(serverData)
2016-09-30 00:20:16 +08:00
}
}
2018-03-05 09:53:45 -05:00
}
// fetch data from API then pass into init functions
document.addEventListener('DOMContentLoaded', async function() {
Metamaps.ServerData = Metamaps.ServerData || {}
try {
2018-03-09 15:53:46 -05:00
// TODO: do these in parallel (Promise.all)
2018-03-05 09:53:45 -05:00
const metacodes = await DataFetcher.getMetacodes()
Metamaps.ServerData.Metacodes = metacodes
2018-03-05 23:27:38 -05:00
const metacodeSets = await DataFetcher.getMetacodeSets()
Metamaps.ServerData.metacodeSets = metacodeSets
2018-03-05 23:27:38 -05:00
const activeMapper = await DataFetcher.getCurrentUser()
if (activeMapper) {
Metamaps.ServerData.ActiveMapper = activeMapper
$('body').removeClass('unauthenticated').addClass('authenticated')
}
2018-03-05 09:53:45 -05:00
runInitFunctions(Metamaps.ServerData)
} catch (e) {
console.log(e)
}
2016-09-30 00:20:16 +08:00
})
export default Metamaps