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' %>
<script type="text/javascript" charset="utf-8">
<% if current_user %>
Metamaps.Active.Mapper = <%= current_user.to_json.html_safe %>
Metamaps.ServerData.ActiveMapper = <%= current_user.to_json.html_safe %>
<% else %>
Metamaps.Active.Mapper = null;
Metamaps.ServerData.ActiveMapper = null
<% end %>
Metamaps.Loading.setup()

View file

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

View file

@ -1,27 +1,20 @@
<%#
#
# @file
# This shows a topic view. It is used.
# 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.
# This shows a topic and its siblings.
# URL: /topics/<topicid>
#
#%>
%>
<% content_for :title, @topic.name + " | Metamaps" %>
<% content_for :mobile_title, @topic.name %>
<script>
Metamaps.currentSection = "topic";
Metamaps.currentPage = <%= @topic.id.to_s %>;
Metamaps.Active.Topic = <%= @topic.to_json(user: current_user).html_safe %>;
Metamaps.Creators = <%= @allcreators.to_json.html_safe %>;
Metamaps.Topics = <%= @alltopics.to_json(user: current_user).html_safe %>;
Metamaps.Synapses = <%= @allsynapses.to_json.html_safe %>;
Metamaps.Visualize.type = "RGraph";
Metamaps.currentSection = "topic"
Metamaps.currentPage = <%= @topic.id.to_s %>
Metamaps.ServerData = Metamaps.ServerData || {}
Metamaps.ServerData.ActiveTopic = <%= @topic.to_json(user: current_user).html_safe %>
Metamaps.ServerData.Creators = <%= @allcreators.to_json.html_safe %>
Metamaps.ServerData.Topics = <%= @alltopics.to_json(user: current_user).html_safe %>
Metamaps.ServerData.Synapses = <%= @allsynapses.to_json.html_safe %>
Metamaps.ServerData.VisualizeType = "RGraph"
</script>

View file

@ -1,7 +1,16 @@
import DataModelMap from './DataModel/Map'
import DataModelMapper from './DataModel/Mapper'
import DataModelTopic from './DataModel/Topic'
const Active = {
Map: null,
Mapper: 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

View file

@ -48,50 +48,51 @@ const DataModel = {
Mapping: Mapping,
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
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
Metamaps.Topics = Metamaps.Topics ? new self.TopicCollection(Metamaps.Topics) : new self.TopicCollection()
Metamaps.Topics.on('add remove', function (topic) {
if (serverData.Topics) self.Topics = new TopicCollection(serverData.Topics)
self.Topics.on('add remove', function (topic) {
InfoBox.updateNumbers()
Filter.checkMetacodes()
Filter.checkMappers()
})
Metamaps.Synapses = Metamaps.Synapses ? new self.SynapseCollection(Metamaps.Synapses) : new self.SynapseCollection()
Metamaps.Synapses.on('add remove', function (synapse) {
if (serverData.Synapses) self.Synapses = new SynapseCollection(serverData.Synapses)
self.Synapses.on('add remove', function (synapse) {
InfoBox.updateNumbers()
Filter.checkSynapses()
Filter.checkMappers()
})
if (Active.Map) {
Metamaps.Mappings = Metamaps.Mappings ? new self.MappingCollection(Metamaps.Mappings) : new self.MappingCollection()
Metamaps.Mappings.on('add remove', function (mapping) {
InfoBox.updateNumbers()
Filter.checkSynapses()
Filter.checkMetacodes()
Filter.checkMappers()
})
}
if (serverData.Mappings) self.Mappings = new MappingCollection(serverData.Mappings)
self.Mappings.on('add remove', function (mapping) {
InfoBox.updateNumbers()
Filter.checkSynapses()
Filter.checkMetacodes()
Filter.checkMappers()
})
Metamaps.Mappers = Metamaps.Mappers ? new self.MapperCollection(Metamaps.Mappers) : new self.MapperCollection()
Metamaps.Collaborators = Metamaps.Collaborators ? new self.MapperCollection(Metamaps.Collaborators) : new self.MapperCollection()
Metamaps.Creators = Metamaps.Creators ? new self.MapperCollection(Metamaps.Creators) : new self.MapperCollection()
if (Active.Map) {
Active.Map = new self.Map(Active.Map)
}
if (Active.Topic) {
Active.Topic = new self.Topic(Active.Topic)
}
if (serverData.Mappers) self.Mappers = new MapperCollection(serverData.Mappers)
if (serverData.Collaborators) self.Collaborators = new MapperCollection(serverData.Collaborators)
if (serverData.Creators) self.Creators = new MapperCollection(serverData.Creators)
}
}
// 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 default DataModel

View file

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