From 80269697994312aad39feb15ac849f2db6f06a78 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 2 Oct 2016 21:41:05 +0800 Subject: [PATCH] start storing data in ServerData --- app/views/layouts/_foot.html.erb | 4 +- app/views/maps/show.html.erb | 19 +++++---- app/views/topics/show.html.erb | 29 +++++-------- frontend/src/Metamaps/Active.js | 13 +++++- frontend/src/Metamaps/DataModel/index.js | 53 ++++++++++++------------ frontend/src/Metamaps/index.js | 6 +-- 6 files changed, 64 insertions(+), 60 deletions(-) diff --git a/app/views/layouts/_foot.html.erb b/app/views/layouts/_foot.html.erb index ebcc38c2..e309c65f 100644 --- a/app/views/layouts/_foot.html.erb +++ b/app/views/layouts/_foot.html.erb @@ -3,9 +3,9 @@ <%= render :partial => 'shared/metacodeBgColors' %> diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb index 02a147c4..119f2f40 100644 --- a/app/views/topics/show.html.erb +++ b/app/views/topics/show.html.erb @@ -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/ # -#%> +%> <% content_for :title, @topic.name + " | Metamaps" %> <% content_for :mobile_title, @topic.name %> diff --git a/frontend/src/Metamaps/Active.js b/frontend/src/Metamaps/Active.js index c61a8bb9..fe8bda6d 100644 --- a/frontend/src/Metamaps/Active.js +++ b/frontend/src/Metamaps/Active.js @@ -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 diff --git a/frontend/src/Metamaps/DataModel/index.js b/frontend/src/Metamaps/DataModel/index.js index fb80c268..bd9cc342 100644 --- a/frontend/src/Metamaps/DataModel/index.js +++ b/frontend/src/Metamaps/DataModel/index.js @@ -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 diff --git a/frontend/src/Metamaps/index.js b/frontend/src/Metamaps/index.js index 5611a478..012af50b 100644 --- a/frontend/src/Metamaps/index.js +++ b/frontend/src/Metamaps/index.js @@ -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