start storing data in ServerData

This commit is contained in:
Devin Howard 2016-10-02 21:41:05 +08:00
parent 4b500a4428
commit 8026969799
6 changed files with 64 additions and 60 deletions

View file

@ -3,9 +3,9 @@
<%= render :partial => 'shared/metacodeBgColors' %> <%= render :partial => 'shared/metacodeBgColors' %>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
<% if current_user %> <% if current_user %>
Metamaps.Active.Mapper = <%= current_user.to_json.html_safe %> Metamaps.ServerData.ActiveMapper = <%= current_user.to_json.html_safe %>
<% else %> <% else %>
Metamaps.Active.Mapper = null; Metamaps.ServerData.ActiveMapper = null
<% end %> <% end %>
Metamaps.Loading.setup() Metamaps.Loading.setup()

View file

@ -9,13 +9,14 @@
<script> <script>
Metamaps.currentSection = "map"; Metamaps.currentSection = "map";
Metamaps.currentPage = <%= @map.id.to_s %>; Metamaps.currentPage = <%= @map.id.to_s %>;
Metamaps.Active.Map = <%= @map.to_json.html_safe %>; Metamaps.ServerData = Metamaps.ServerData || {}
Metamaps.Mappers = <%= @allmappers.to_json.html_safe %>; Metamaps.ServerData.ActiveMap = <%= @map.to_json.html_safe %>;
Metamaps.Collaborators = <%= @allcollaborators.to_json.html_safe %>; Metamaps.ServerData.Mappers = <%= @allmappers.to_json.html_safe %>;
Metamaps.Topics = <%= @alltopics.to_json(user: current_user).html_safe %>; Metamaps.ServerData.Collaborators = <%= @allcollaborators.to_json.html_safe %>;
Metamaps.Synapses = <%= @allsynapses.to_json.html_safe %>; Metamaps.ServerData.Topics = <%= @alltopics.to_json(user: current_user).html_safe %>;
Metamaps.Mappings = <%= @allmappings.to_json.html_safe %>; Metamaps.ServerData.Synapses = <%= @allsynapses.to_json.html_safe %>;
Metamaps.Messages = <%= @allmessages.to_json.html_safe %>; Metamaps.ServerData.Mappings = <%= @allmappings.to_json.html_safe %>;
Metamaps.Stars = <%= @allstars.to_json.html_safe %>; Metamaps.Messages = <%= @allmessages.to_json.html_safe %>;
Metamaps.Visualize.type = "ForceDirected"; Metamaps.Stars = <%= @allstars.to_json.html_safe %>;
Metamaps.Visualize.type = "ForceDirected";
</script> </script>

View file

@ -1,27 +1,20 @@
<%# <%#
#
# @file # @file
# This shows a topic view. It is used. # This shows a topic and its siblings.
# The first commented out section used to be a card at the top showing all
# info. Now we're moving towards most screens looking the same. The
# consequence of accessing data from this view is that you can't remove
# the topic that corresponds to the page you're on. Originally, accessing this
# page showed the topic with its neighbours arrayed around. Now it shows the
# same, but there's no cues to say which topic's page you're on. So when the
# map recenters on a new topic, it's like you're on that topic's page.
# Nice, but the URL and being unable to remove the root node still hamper that
# experience.
# URL: /topics/<topicid> # URL: /topics/<topicid>
# #
#%> %>
<% content_for :title, @topic.name + " | Metamaps" %> <% content_for :title, @topic.name + " | Metamaps" %>
<% content_for :mobile_title, @topic.name %> <% content_for :mobile_title, @topic.name %>
<script> <script>
Metamaps.currentSection = "topic"; Metamaps.currentSection = "topic"
Metamaps.currentPage = <%= @topic.id.to_s %>; Metamaps.currentPage = <%= @topic.id.to_s %>
Metamaps.Active.Topic = <%= @topic.to_json(user: current_user).html_safe %>; Metamaps.ServerData = Metamaps.ServerData || {}
Metamaps.Creators = <%= @allcreators.to_json.html_safe %>; Metamaps.ServerData.ActiveTopic = <%= @topic.to_json(user: current_user).html_safe %>
Metamaps.Topics = <%= @alltopics.to_json(user: current_user).html_safe %>; Metamaps.ServerData.Creators = <%= @allcreators.to_json.html_safe %>
Metamaps.Synapses = <%= @allsynapses.to_json.html_safe %>; Metamaps.ServerData.Topics = <%= @alltopics.to_json(user: current_user).html_safe %>
Metamaps.Visualize.type = "RGraph"; Metamaps.ServerData.Synapses = <%= @allsynapses.to_json.html_safe %>
Metamaps.ServerData.VisualizeType = "RGraph"
</script> </script>

View file

@ -1,7 +1,16 @@
import DataModelMap from './DataModel/Map'
import DataModelMapper from './DataModel/Mapper'
import DataModelTopic from './DataModel/Topic'
const Active = { const Active = {
Map: null, Map: null,
Mapper: null,
Topic: null, Topic: null,
Mapper: null init: function(serverData) {
}; if (serverData.Map) Active.Map = new DataModelMap(severData.ActiveMap)
if (serverData.Mapper) Active.Mapper = new DataModelMapper(serverData.ActiveMapper)
if (serverData.Topic) Active.Topic = new DataModelTopic(serverData.ActiveTopic)
}
}
export default Active export default Active

View file

@ -48,50 +48,51 @@ const DataModel = {
Mapping: Mapping, Mapping: Mapping,
MappingCollection: MappingCollection, MappingCollection: MappingCollection,
init: function () { Metacodes: new MetacodeCollection(),
Topics: new TopicCollection(),
Synapses: new SynapseCollection(),
Mappings: new MappingCollection(),
Mappers: new MapperCollection(),
Collaborators: new MapperCollection(),
Creators: new MapperCollection(),
init: function (serverData) {
var self = DataModel var self = DataModel
Metamaps.Metacodes = Metamaps.Metacodes ? new self.MetacodeCollection(Metamaps.Metacodes) : new self.MetacodeCollection() if (serverData.Metacodes) self.Metacodes = new MetacodeCollection(serverData.Metacodes)
// attach collection event listeners // attach collection event listeners
Metamaps.Topics = Metamaps.Topics ? new self.TopicCollection(Metamaps.Topics) : new self.TopicCollection() if (serverData.Topics) self.Topics = new TopicCollection(serverData.Topics)
Metamaps.Topics.on('add remove', function (topic) { self.Topics.on('add remove', function (topic) {
InfoBox.updateNumbers() InfoBox.updateNumbers()
Filter.checkMetacodes() Filter.checkMetacodes()
Filter.checkMappers() Filter.checkMappers()
}) })
Metamaps.Synapses = Metamaps.Synapses ? new self.SynapseCollection(Metamaps.Synapses) : new self.SynapseCollection() if (serverData.Synapses) self.Synapses = new SynapseCollection(serverData.Synapses)
Metamaps.Synapses.on('add remove', function (synapse) { self.Synapses.on('add remove', function (synapse) {
InfoBox.updateNumbers() InfoBox.updateNumbers()
Filter.checkSynapses() Filter.checkSynapses()
Filter.checkMappers() Filter.checkMappers()
}) })
if (Active.Map) { if (serverData.Mappings) self.Mappings = new MappingCollection(serverData.Mappings)
Metamaps.Mappings = Metamaps.Mappings ? new self.MappingCollection(Metamaps.Mappings) : new self.MappingCollection() self.Mappings.on('add remove', function (mapping) {
Metamaps.Mappings.on('add remove', function (mapping) { InfoBox.updateNumbers()
InfoBox.updateNumbers() Filter.checkSynapses()
Filter.checkSynapses() Filter.checkMetacodes()
Filter.checkMetacodes() Filter.checkMappers()
Filter.checkMappers() })
})
}
Metamaps.Mappers = Metamaps.Mappers ? new self.MapperCollection(Metamaps.Mappers) : new self.MapperCollection() if (serverData.Mappers) self.Mappers = new MapperCollection(serverData.Mappers)
Metamaps.Collaborators = Metamaps.Collaborators ? new self.MapperCollection(Metamaps.Collaborators) : new self.MapperCollection() if (serverData.Collaborators) self.Collaborators = new MapperCollection(serverData.Collaborators)
Metamaps.Creators = Metamaps.Creators ? new self.MapperCollection(Metamaps.Creators) : new self.MapperCollection() if (serverData.Creators) self.Creators = new MapperCollection(serverData.Creators)
if (Active.Map) {
Active.Map = new self.Map(Active.Map)
}
if (Active.Topic) {
Active.Topic = new self.Topic(Active.Topic)
}
} }
} }
// Note: Topics, Metacodes, Synapses, Mappers, Mappings, Collaborators, Creators are not exported
// You can access them by importing DataModel
export { Map, MapCollection, Mapper, MapperCollection, Mapping, MappingCollection, Message, MessageCollection, Metacode, MetacodeCollection, Synapse, SynapseCollection, Topic, TopicCollection } export { Map, MapCollection, Mapper, MapperCollection, Mapping, MappingCollection, Message, MessageCollection, Metacode, MetacodeCollection, Synapse, SynapseCollection, Topic, TopicCollection }
export default DataModel export default DataModel

View file

@ -10,7 +10,7 @@ import Create from './Create'
import Debug from './Debug' import Debug from './Debug'
import Filter from './Filter' import Filter from './Filter'
import GlobalUI, { import GlobalUI, {
Search, CreateMap, ImportDialog, Account as GlobalUI_Account Search, CreateMap, ImportDialog, Account as GlobalUIAccount
} from './GlobalUI' } from './GlobalUI'
import Import from './Import' import Import from './Import'
import JIT from './JIT' import JIT from './JIT'
@ -47,7 +47,7 @@ Metamaps.Filter = Filter
Metamaps.GlobalUI = GlobalUI Metamaps.GlobalUI = GlobalUI
Metamaps.GlobalUI.Search = Search Metamaps.GlobalUI.Search = Search
Metamaps.GlobalUI.CreateMap = CreateMap Metamaps.GlobalUI.CreateMap = CreateMap
Metamaps.GlobalUI.Account = GlobalUI_Account Metamaps.GlobalUI.Account = GlobalUIAccount
Metamaps.GlobalUI.ImportDialog = ImportDialog Metamaps.GlobalUI.ImportDialog = ImportDialog
Metamaps.Import = Import Metamaps.Import = Import
Metamaps.JIT = JIT Metamaps.JIT = JIT
@ -83,7 +83,7 @@ document.addEventListener('DOMContentLoaded', function () {
Metamaps[prop].hasOwnProperty('init') && Metamaps[prop].hasOwnProperty('init') &&
typeof (Metamaps[prop].init) === 'function' typeof (Metamaps[prop].init) === 'function'
) { ) {
Metamaps[prop].init() Metamaps[prop].init(Metamaps.ServerData)
} }
} }
// load whichever page you are on // load whichever page you are on