try to move all rails data into Metamaps.ServerData

Metamaps.Erb and currentPage and currentSection are still not in; should they be?
This commit is contained in:
Devin Howard 2016-10-02 22:28:00 +08:00
parent 8026969799
commit 7c9b6a2205
33 changed files with 417 additions and 515 deletions

View file

@ -5,11 +5,11 @@
# %> # %>
<script> <script>
Metamaps.Maps.Active = <%= @maps.to_json.html_safe %>;
Metamaps.currentPage = "active";
<% content_for :title, "Explore Active Maps | Metamaps" %> <% content_for :title, "Explore Active Maps | Metamaps" %>
<% content_for :mobile_title, "Recently Active" %> <% content_for :mobile_title, "Recently Active" %>
Metamaps.currentSection = "explore"; Metamaps.currentSection = "explore";
Metamaps.currentPage = "active";
Metamaps.Maps.Active = <%= @maps.to_json.html_safe %>;
Metamaps.GlobalUI.Search.focus(); Metamaps.GlobalUI.Search.focus();
</script> </script>

View file

@ -5,11 +5,11 @@
# %> # %>
<script> <script>
Metamaps.Maps.Featured = <%= @maps.to_json.html_safe %>;
Metamaps.currentPage = "featured";
<% content_for :title, "Explore Featured Maps | Metamaps" %> <% content_for :title, "Explore Featured Maps | Metamaps" %>
<% content_for :mobile_title, "Featured Maps" %> <% content_for :mobile_title, "Featured Maps" %>
Metamaps.currentSection = "explore"; Metamaps.currentSection = "explore";
Metamaps.currentPage = "featured";
Metamaps.Maps.Featured = <%= @maps.to_json.html_safe %>;
Metamaps.GlobalUI.Search.focus(); Metamaps.GlobalUI.Search.focus();
</script> </script>

View file

@ -5,14 +5,14 @@
# %> # %>
<script> <script>
Metamaps.Maps.Mapper = {
models: <%= @maps.to_json.html_safe %>,
id: <%= params[:id] %>
};
Metamaps.currentPage = "mapper";
<% content_for :title, @user.name + " | Metamaps" %> <% content_for :title, @user.name + " | Metamaps" %>
<% content_for :mobile_title, @user.name %> <% content_for :mobile_title, @user.name %>
Metamaps.currentSection = "explore"; Metamaps.currentSection = "explore";
Metamaps.currentPage = "mapper";
Metamaps.Maps.Mapper = {
models: <%= @maps.to_json.html_safe %>,
id: <%= params[:id] %>
};
Metamaps.GlobalUI.Search.focus(); Metamaps.GlobalUI.Search.focus();
</script> </script>

View file

@ -5,11 +5,11 @@
# %> # %>
<script> <script>
Metamaps.Maps.Mine = <%= @maps.to_json.html_safe %>;
Metamaps.currentPage = "mine";
<% content_for :title, "Explore My Maps | Metamaps" %> <% content_for :title, "Explore My Maps | Metamaps" %>
<% content_for :mobile_title, "My Maps" %> <% content_for :mobile_title, "My Maps" %>
Metamaps.currentPage = "mine";
Metamaps.currentSection = "explore"; Metamaps.currentSection = "explore";
Metamaps.Maps.Mine = <%= @maps.to_json.html_safe %>;
Metamaps.GlobalUI.Search.focus(); Metamaps.GlobalUI.Search.focus();
</script> </script>

View file

@ -5,11 +5,11 @@
# %> # %>
<script> <script>
Metamaps.Maps.Shared = <%= @maps.to_json.html_safe %>;
Metamaps.currentPage = "shared";
<% content_for :title, "Explore Shared Maps | Metamaps" %> <% content_for :title, "Explore Shared Maps | Metamaps" %>
<% content_for :mobile_title, "Shared With Me" %> <% content_for :mobile_title, "Shared With Me" %>
Metamaps.currentPage = "shared";
Metamaps.currentSection = "explore"; Metamaps.currentSection = "explore";
Metamaps.Maps.Shared = <%= @maps.to_json.html_safe %>;
Metamaps.GlobalUI.Search.focus(); Metamaps.GlobalUI.Search.focus();
</script> </script>

View file

@ -5,11 +5,11 @@
# %> # %>
<script> <script>
Metamaps.Maps.Starred = <%= @maps.to_json.html_safe %>;
Metamaps.currentPage = "starred";
<% content_for :title, "Starred Maps | Metamaps" %> <% content_for :title, "Starred Maps | Metamaps" %>
<% content_for :mobile_title, "Starred Maps" %> <% content_for :mobile_title, "Starred Maps" %>
Metamaps.currentPage = "starred";
Metamaps.currentSection = "explore"; Metamaps.currentSection = "explore";
Metamaps.Maps.Starred = <%= @maps.to_json.html_safe %>;
Metamaps.GlobalUI.Search.focus(); Metamaps.GlobalUI.Search.focus();
</script> </script>

View file

@ -4,50 +4,49 @@
#%> #%>
<div class="templates"> <div class="templates">
<script type="text/template" id="mapInfoBoxTemplate">
<script type="text/template" id="mapInfoBoxTemplate"> <div class="requestTitle">Click here to name this map!</div>
<div class="requestTitle">Click here to name this map!</div> <div class="mapInfoName" id="mapInfoName">{{{name}}}</div>
<div class="mapInfoName" id="mapInfoName">{{{name}}}</div>
<div class="mapInfoStat"> <div class="mapInfoStat">
<div class="infoStatIcon mapContributors hoverForTip"> <div class="infoStatIcon mapContributors hoverForTip">
<img id="mapContribs" class="{{contributors_class}}" <img id="mapContribs" class="{{contributors_class}}"
width="25" height="25" src="{{contributor_image}}" /> width="25" height="25" src="{{contributor_image}}" />
<span class="count">{{contributor_count}}</span> <span class="count">{{contributor_count}}</span>
<div class="tip">{{{contributor_list}}}</div> <div class="tip">{{{contributor_list}}}</div>
</div>
<div class="infoStatIcon mapTopics">
{{topic_count}}
</div>
<div class="infoStatIcon mapSynapses">
{{synapse_count}}
</div>
<div class="infoStatIcon mapPermission {{permission}} hoverForTip">
{{{map_creator_tip}}}
</div>
<div class="clearfloat"></div>
</div>
<div class="mapInfoDesc" id="mapInfoDesc">
{{{desc}}}
</div>
<div class="mapInfoMeta">
<p class="mapCreatedAt"><span>Created by:</span> {{user_name}} on {{created_at}}</p>
<p class="mapEditedAt"><span>Last edited:</span> {{updated_at}}</p>
<div class="mapInfoButtonsWrapper">
<div class="mapInfoDelete">
<div class="deleteMap"></div>
<span>Delete</span>
</div> </div>
<div class="mapInfoShare"> <div class="infoStatIcon mapTopics">
<div class="mapInfoShareIcon"></div> {{topic_count}}
<span>Share</span> </div>
<div class="infoStatIcon mapSynapses">
{{synapse_count}}
</div>
<div class="infoStatIcon mapPermission {{permission}} hoverForTip">
{{{map_creator_tip}}}
</div>
<div class="clearfloat"></div>
</div>
<div class="mapInfoDesc" id="mapInfoDesc">
{{{desc}}}
</div>
<div class="mapInfoMeta">
<p class="mapCreatedAt"><span>Created by:</span> {{user_name}} on {{created_at}}</p>
<p class="mapEditedAt"><span>Last edited:</span> {{updated_at}}</p>
<div class="mapInfoButtonsWrapper">
<div class="mapInfoDelete">
<div class="deleteMap"></div>
<span>Delete</span>
</div>
<div class="mapInfoShare">
<div class="mapInfoShareIcon"></div>
<span>Share</span>
</div>
</div> </div>
</div> </div>
</div> </script>
</script>
<script type="text/template" id="topicSearchTemplate"> <script type="text/template" id="topicSearchTemplate">
<div class="result{{rtype}}"> <div class="result{{rtype}}">
<div class="topicMetacode searchResIconWrapper"> <div class="topicMetacode searchResIconWrapper">
<img src="{{typeImageURL}}" class="topicIcon" /> <img src="{{typeImageURL}}" class="topicIcon" />
@ -68,17 +67,17 @@
{{synapseCount}} {{synapseCount}}
</div> </div>
<div class="topicOriginatorIcon hoverForTip"> <div class="topicOriginatorIcon hoverForTip">
<img width="18" height="18" src="{{originatorImage}}"> <img width="18" height="18" src="{{originatorImage}}">
<span class="tip topicOriginator">{{originator}}</span> <span class="tip topicOriginator">{{originator}}</span>
</div> </div>
<div class="topicPermission {{permission}}"> <div class="topicPermission {{permission}}">
</div> </div>
</div> </div>
<div class="clearfloat"></div> <div class="clearfloat"></div>
</div> </div>
</script> </script>
<script type="text/template" id="mapSearchTemplate"> <script type="text/template" id="mapSearchTemplate">
<div class="result{{rtype}}"> <div class="result{{rtype}}">
<div class="searchResIconWrapper"> <div class="searchResIconWrapper">
<img class="icon" src="<%= asset_path('metamap36c.png') %>"> <img class="icon" src="<%= asset_path('metamap36c.png') %>">
@ -95,7 +94,7 @@
{{synapseCount}} {{synapseCount}}
</div> </div>
<div class="mapContributorsIcon hoverForTip"> <div class="mapContributorsIcon hoverForTip">
<img id="mapContribs" width="25" height="25" src="{{mapContributorImage}}" /> <img id="mapContribs" width="25" height="25" src="{{mapContributorImage}}" />
<div class="tip"> <div class="tip">
<ul> <ul>
{{{contributorTip}}} {{{contributorTip}}}
@ -108,9 +107,9 @@
</div> </div>
<div class="clearfloat"></div> <div class="clearfloat"></div>
</div> </div>
</script> </script>
<script type="text/template" id="mapperSearchTemplate"> <script type="text/template" id="mapperSearchTemplate">
<div class="result{{rtype}}"> <div class="result{{rtype}}">
<div class="searchResIconWrapper"> <div class="searchResIconWrapper">
<img class="icon" width="32" height="32" src="{{profile}}"> <img class="icon" width="32" height="32" src="{{profile}}">
@ -131,9 +130,9 @@
</div> </div>
<div class="clearfloat"></div> <div class="clearfloat"></div>
</div> </div>
</script> </script>
<script type="text/template" id="collaboratorSearchTemplate"> <script type="text/template" id="collaboratorSearchTemplate">
<div class="collabResult"> <div class="collabResult">
<div class="collabIconWrapper"> <div class="collabIconWrapper">
<img class="icon" width="25" height="25" src="{{profile}}"> <img class="icon" width="25" height="25" src="{{profile}}">
@ -143,95 +142,106 @@
</div> </div>
<div class="clearfloat"></div> <div class="clearfloat"></div>
</div> </div>
</script> </script>
<script type="text/template" id="synapseAutocompleteTemplate"> <script type="text/template" id="synapseAutocompleteTemplate">
<div class="result{{rtype}}"> <div class="result{{rtype}}">
<p class="autocompleteSection synapseDesc">{{label}}</p> <p class="autocompleteSection synapseDesc">{{label}}</p>
<div class="synapseMetadata"> <div class="synapseMetadata">
<div class="synapseOriginatorIcon hoverForTip"> <div class="synapseOriginatorIcon hoverForTip">
<img width="24" height="24" src="{{originatorImage}}" /> <img width="24" height="24" src="{{originatorImage}}" />
<span class="tooltips synapseOriginator">{{originator}}</span> <span class="tooltips synapseOriginator">{{originator}}</span>
</div>
<div class="synapsePermission {{permission}}"></div>
</div> </div>
<div class="clearfloat"></div> <div class="synapsePermission {{permission}}"></div>
</div> </div>
</script> <div class="clearfloat"></div>
<script type="text/template" id="topicAutocompleteTemplate">
<div>
<img class="autocompleteSection topicType" width="24" height="24" src="{{typeImageURL}}" alt="{{type}}" title="{{type}}" />
<p class="autocompleteSection topicTitle">{{label}}</p>
<div class="expandTopicMetadata"></div>
<div class="topicMetadata">
<div class="topicNumMaps">{{mapCount}}</div>
<div class="topicNumSynapses">{{synapseCount}}</div>
<div class="topicOriginatorIcon hoverForTip">
<img width="24" height="24" src="{{originatorImage}}" />
<span class="tooltips topicOriginator">{{originator}}</span>
</div>
<div class="topicPermission {{permission}}"></div>
</div>
<div class="clearfloat"></div>
</div>
</script>
<script type="text/template" id="topicCardTemplate">
<div class="CardOnGraph {{hasAttachment}}" id="topic_{{id}}">
<span class="title">
<div class="titleWrapper" id="titleActivator">
<span class="best_in_place best_in_place_name"
data-bip-url="/topics/{{id}}"
data-bip-object="topic"
data-bip-attribute="name"
data-bip-activator="#titleActivator"
data-bip-value="{{name}}"
data-bip-type="textarea">{{name}}</span>
</div>
</span>
<div class="links">
<div class="linkItem icon">
<div class="metacodeTitle {{metacode_class}}">
{{metacode}}
<div class="expandMetacodeSelect"></div>
</div>
<div class="metacodeImage" style="background-image:url({{imgsrc}});" title="click and drag to move card"></div>
<div class="metacodeSelect">{{{metacode_select}}}</div>
</div>
<div class="linkItem contributor">
<a href="/explore/mapper/{{userid}}" target="_blank"><img src="<%= asset_path('user.png') %>" class="contributorIcon" width="32" height="32" /></a>
<div class="contributorName">{{username}}</div>
</div>
<div class="linkItem mapCount">
<div class="mapCountIcon"></div>
{{map_count}}
<div class ="hoverTip">Click to see which maps topic appears on</div>
<div class="tip"><ul>{{{inmaps}}}</ul></div>
</div>
<a href="/topics/{{id}}" target="_blank" class="linkItem synapseCount">
<div class="synapseCountIcon"></div>
{{synapse_count}}
<div class="tip">Click to see this topics synapses</div>
</a>
<div class="linkItem mapPerm {{mk_permission}}" title="{{permission}}"></div>
<div class="clearfloat"></div>
</div>
<div class="scroll">
<div class="desc">
<span class="best_in_place best_in_place_desc" data-bip-url="/topics/{{id}}" data-bip-object="topic" data-bip-nil="{{desc_nil}}" data-bip-attribute="desc" data-bip-type="textarea" data-bip-value="{{desc_markdown}}">{{{desc_html}}}</span>
<div class="clearfloat"></div>
</div>
</div>
<div class="embeds">
{{{embeds}}}
</div>
<div class="attachments {{attachmentsHidden}}">
{{{attachments}}}
</div>
<div class="clearfloat"></div>
</div> </div>
</script> </script>
<script type="text/template" id="topicAutocompleteTemplate">
<div>
<img class="autocompleteSection topicType" width="24" height="24"
src="{{typeImageURL}}" alt="{{type}}" title="{{type}}" />
<p class="autocompleteSection topicTitle">{{label}}</p>
<div class="expandTopicMetadata"></div>
<div class="topicMetadata">
<div class="topicNumMaps">{{mapCount}}</div>
<div class="topicNumSynapses">{{synapseCount}}</div>
<div class="topicOriginatorIcon hoverForTip">
<img width="24" height="24" src="{{originatorImage}}" />
<span class="tooltips topicOriginator">{{originator}}</span>
</div>
<div class="topicPermission {{permission}}"></div>
</div>
<div class="clearfloat"></div>
</div>
</script>
<script type="text/template" id="topicCardTemplate">
<div class="CardOnGraph {{hasAttachment}}" id="topic_{{id}}">
<span class="title">
<div class="titleWrapper" id="titleActivator">
<span class="best_in_place best_in_place_name"
data-bip-url="/topics/{{id}}"
data-bip-object="topic"
data-bip-attribute="name"
data-bip-activator="#titleActivator"
data-bip-value="{{name}}"
data-bip-type="textarea"
>
{{name}}
</span>
</div>
</span>
<div class="links">
<div class="linkItem icon">
<div class="metacodeTitle {{metacode_class}}">
{{metacode}}
<div class="expandMetacodeSelect"></div>
</div>
<div class="metacodeImage" style="background-image:url({{imgsrc}});" title="click and drag to move card"></div>
<div class="metacodeSelect">{{{metacode_select}}}</div>
</div>
<div class="linkItem contributor">
<a href="/explore/mapper/{{userid}}" target="_blank"><img src="<%= asset_path('user.png') %>" class="contributorIcon" width="32" height="32" /></a>
<div class="contributorName">{{username}}</div>
</div>
<div class="linkItem mapCount">
<div class="mapCountIcon"></div>
{{map_count}}
<div class ="hoverTip">Click to see which maps topic appears on</div>
<div class="tip"><ul>{{{inmaps}}}</ul></div>
</div>
<a href="/topics/{{id}}" target="_blank" class="linkItem synapseCount">
<div class="synapseCountIcon"></div>
{{synapse_count}}
<div class="tip">Click to see this topics synapses</div>
</a>
<div class="linkItem mapPerm {{mk_permission}}" title="{{permission}}"></div>
<div class="clearfloat"></div>
<div class="scroll">
<div class="desc">
<span class="best_in_place best_in_place_desc"
data-bip-url="/topics/{{id}}"
data-bip-object="topic"
data-bip-nil="{{desc_nil}}"
data-bip-attribute="desc"
data-bip-type="textarea"
data-bip-value="{{desc_markdown}}"
>
{{{desc_html}}}
</span>
<div class="clearfloat"></div>
</div>
</div>
<div class="embeds">
{{{embeds}}}
</div>
<div class="attachments {{attachmentsHidden}}">
{{{attachments}}}
</div>
<div class="clearfloat"></div>
</div>
</script>
</div> </div>

View file

@ -33,7 +33,8 @@
</div> </div>
</div> </div>
</div><!-- end yield --> </div><!-- end yield -->
<script> <script>
Metamaps.currentSection = ""; Metamaps.currentSection = ''
Metamaps.currentPage = ""; Metamaps.currentPage = ''
</script> </script>

View file

@ -18,5 +18,5 @@
Metamaps.ServerData.Mappings = <%= @allmappings.to_json.html_safe %>; Metamaps.ServerData.Mappings = <%= @allmappings.to_json.html_safe %>;
Metamaps.Messages = <%= @allmessages.to_json.html_safe %>; Metamaps.Messages = <%= @allmessages.to_json.html_safe %>;
Metamaps.Stars = <%= @allstars.to_json.html_safe %>; Metamaps.Stars = <%= @allstars.to_json.html_safe %>;
Metamaps.Visualize.type = "ForceDirected"; Metamaps.ServerData.VisualizeType = "ForceDirected";
</script> </script>

View file

@ -117,6 +117,6 @@
<div class="clearfloat"></div> <div class="clearfloat"></div>
<script> <script>
Metamaps.Create.selectedMetacodeSet = "metacodeset-<%= selectedSet %>"; Metamaps.Create.selectedMetacodeSet = "metacodeset-<%= selectedSet %>"
Metamaps.Create.selectedMetacodeSetIndex = <%= index %>; Metamaps.Create.selectedMetacodeSetIndex = <%= index %>
</script> </script>

View file

@ -1,9 +1,10 @@
/* global Metamaps, $ */ /* global $ */
import _ from 'lodash' import _ from 'lodash'
import outdent from 'outdent' import outdent from 'outdent'
import Active from './Active' import Active from './Active'
import DataModel from './DataModel'
import Filter from './Filter' import Filter from './Filter'
import GlobalUI from './GlobalUI' import GlobalUI from './GlobalUI'
import JIT from './JIT' import JIT from './JIT'
@ -12,16 +13,6 @@ import Selected from './Selected'
import Settings from './Settings' import Settings from './Settings'
import Visualize from './Visualize' import Visualize from './Visualize'
/*
* Metamaps.Control.js
*
* Dependencies:
* - Metamaps.Mappings
* - Metamaps.Metacodes
* - Metamaps.Synapses
* - Metamaps.Topics
*/
const Control = { const Control = {
init: function () {}, init: function () {},
selectNode: function (node, e) { selectNode: function (node, e) {
@ -72,7 +63,7 @@ const Control = {
Control.deleteSelectedNodes() Control.deleteSelectedNodes()
} }
if (Metamaps.Topics.length === 0) { if (DataModel.Topics.length === 0) {
GlobalUI.showDiv('#instructions') GlobalUI.showDiv('#instructions')
} }
}, },
@ -110,7 +101,7 @@ const Control = {
var mappableid = topic.id var mappableid = topic.id
var mapping = node.getData('mapping') var mapping = node.getData('mapping')
topic.destroy() topic.destroy()
Metamaps.Mappings.remove(mapping) DataModel.Mappings.remove(mapping)
$(document).trigger(JIT.events.deleteTopic, [{ $(document).trigger(JIT.events.deleteTopic, [{
mappableid: mappableid mappableid: mappableid
}]) }])
@ -127,7 +118,7 @@ const Control = {
}) })
_.each(nodeids, function(nodeid) { _.each(nodeids, function(nodeid) {
if (Active.Topic.id !== nodeid) { if (Active.Topic.id !== nodeid) {
Metamaps.Topics.remove(nodeid) DataModel.Topics.remove(nodeid)
Control.hideNode(nodeid) Control.hideNode(nodeid)
} }
}) })
@ -165,7 +156,7 @@ const Control = {
var mappableid = topic.id var mappableid = topic.id
var mapping = node.getData('mapping') var mapping = node.getData('mapping')
mapping.destroy() mapping.destroy()
Metamaps.Topics.remove(topic) DataModel.Topics.remove(topic)
$(document).trigger(JIT.events.removeTopic, [{ $(document).trigger(JIT.events.removeTopic, [{
mappableid: mappableid mappableid: mappableid
}]) }])
@ -293,7 +284,7 @@ const Control = {
synapse.destroy() synapse.destroy()
// the server will destroy the mapping, we just need to remove it here // the server will destroy the mapping, we just need to remove it here
Metamaps.Mappings.remove(mapping) DataModel.Mappings.remove(mapping)
edge.getData('mappings').splice(index, 1) edge.getData('mappings').splice(index, 1)
edge.getData('synapses').splice(index, 1) edge.getData('synapses').splice(index, 1)
if (edge.getData('displayIndex')) { if (edge.getData('displayIndex')) {
@ -348,7 +339,7 @@ const Control = {
var mappableid = synapse.id var mappableid = synapse.id
mapping.destroy() mapping.destroy()
Metamaps.Synapses.remove(synapse) DataModel.Synapses.remove(synapse)
edge.getData('mappings').splice(index, 1) edge.getData('mappings').splice(index, 1)
edge.getData('synapses').splice(index, 1) edge.getData('synapses').splice(index, 1)
@ -432,7 +423,7 @@ const Control = {
GlobalUI.notifyUser('Working...') GlobalUI.notifyUser('Working...')
var metacode = Metamaps.Metacodes.get(metacode_id) var metacode = DataModel.Metacodes.get(metacode_id)
// variables to keep track of how many nodes and synapses you had the ability to change the permission of // variables to keep track of how many nodes and synapses you had the ability to change the permission of
var nCount = 0 var nCount = 0

View file

@ -1,5 +1,6 @@
/* global Metamaps, $, Hogan, Bloodhound */ /* global $, Hogan, Bloodhound */
import DataModel from './DataModel'
import Mouse from './Mouse' import Mouse from './Mouse'
import Selected from './Selected' import Selected from './Selected'
import Synapse from './Synapse' import Synapse from './Synapse'
@ -7,15 +8,6 @@ import Topic from './Topic'
import Visualize from './Visualize' import Visualize from './Visualize'
import GlobalUI from './GlobalUI' import GlobalUI from './GlobalUI'
/*
* Metamaps.Create.js
*
* Dependencies:
* - Metamaps.DataModel
* - Metamaps.Metacodes
* - Metamaps.Topics
*/
const Create = { const Create = {
isSwitchingSet: false, // indicates whether the metacode set switch lightbox is open isSwitchingSet: false, // indicates whether the metacode set switch lightbox is open
selectedMetacodeSet: null, selectedMetacodeSet: null,
@ -59,7 +51,7 @@ const Create = {
} }
var codesToSwitchToIds var codesToSwitchToIds
var metacodeModels = new Metamaps.DataModel.MetacodeCollection() var metacodeModels = new DataModel.MetacodeCollection()
Create.selectedMetacodeSetIndex = index Create.selectedMetacodeSetIndex = index
Create.selectedMetacodeSet = 'metacodeset-' + set Create.selectedMetacodeSet = 'metacodeset-' + set
@ -80,7 +72,7 @@ const Create = {
// sort by name // sort by name
for (var i = 0; i < codesToSwitchToIds.length; i++) { for (var i = 0; i < codesToSwitchToIds.length; i++) {
metacodeModels.add(Metamaps.Metacodes.get(codesToSwitchToIds[i])) metacodeModels.add(DataModel.Metacodes.get(codesToSwitchToIds[i]))
} }
metacodeModels.sort() metacodeModels.sort()
@ -243,7 +235,7 @@ const Create = {
$('.pinCarousel').removeClass('isPinned') $('.pinCarousel').removeClass('isPinned')
Create.newTopic.pinned = false Create.newTopic.pinned = false
} }
if (Metamaps.Topics.length === 0) { if (DataModel.Topics.length === 0) {
GlobalUI.showDiv('#instructions') GlobalUI.showDiv('#instructions')
} }
Create.newTopic.beingCreated = false Create.newTopic.beingCreated = false

View file

@ -1,5 +1,3 @@
/* global Metamaps */
import Backbone from 'backbone' import Backbone from 'backbone'
Backbone.$ = window.$ Backbone.$ = window.$

View file

@ -11,10 +11,10 @@ import Realtime from '../Realtime'
import SynapseCard from '../SynapseCard' import SynapseCard from '../SynapseCard'
import Visualize from '../Visualize' import Visualize from '../Visualize'
import DataModel from './index'
/* /*
* Dependencies: * Metamaps.Erb
* - Metamaps.Mappings
* - Metamaps.Topics
*/ */
const Synapse = Backbone.Model.extend({ const Synapse = Backbone.Model.extend({
@ -96,10 +96,10 @@ const Synapse = Backbone.Model.extend({
else return false else return false
}, },
getTopic1: function () { getTopic1: function () {
return Metamaps.Topics.get(this.get('topic1_id')) return DataModel.Topics.get(this.get('topic1_id'))
}, },
getTopic2: function () { getTopic2: function () {
return Metamaps.Topics.get(this.get('topic2_id')) return DataModel.Topics.get(this.get('topic2_id'))
}, },
getDirection: function () { getDirection: function () {
var t1 = this.getTopic1() var t1 = this.getTopic1()
@ -113,7 +113,7 @@ const Synapse = Backbone.Model.extend({
getMapping: function () { getMapping: function () {
if (!Active.Map) return false if (!Active.Map) return false
return Metamaps.Mappings.findWhere({ return DataModel.Mappings.findWhere({
map_id: Active.Map.id, map_id: Active.Map.id,
mappable_type: 'Synapse', mappable_type: 'Synapse',
mappable_id: this.isNew() ? this.cid : this.id mappable_id: this.isNew() ? this.cid : this.id

View file

@ -1,4 +1,4 @@
/* global Metamaps, $ */ /* global $ */
import _ from 'lodash' import _ from 'lodash'
import Backbone from 'backbone' import Backbone from 'backbone'
@ -11,11 +11,7 @@ import Realtime from '../Realtime'
import TopicCard from '../TopicCard' import TopicCard from '../TopicCard'
import Visualize from '../Visualize' import Visualize from '../Visualize'
/* import DataModel from './index'
* Dependencies:
* - Metamaps.Mappings
* - Metamaps.Metacodes
*/
const Topic = Backbone.Model.extend({ const Topic = Backbone.Model.extend({
urlRoot: '/topics', urlRoot: '/topics',
@ -99,12 +95,12 @@ const Topic = Backbone.Model.extend({
}, },
getDate: function () {}, getDate: function () {},
getMetacode: function () { getMetacode: function () {
return Metamaps.Metacodes.get(this.get('metacode_id')) return DataModel.Metacodes.get(this.get('metacode_id'))
}, },
getMapping: function () { getMapping: function () {
if (!Active.Map) return false if (!Active.Map) return false
return Metamaps.Mappings.findWhere({ return DataModel.Mappings.findWhere({
map_id: Active.Map.id, map_id: Active.Map.id,
mappable_type: 'Topic', mappable_type: 'Topic',
mappable_id: this.isNew() ? this.cid : this.id mappable_id: this.isNew() ? this.cid : this.id

View file

@ -1,5 +1,3 @@
/* global Metamaps */
import Active from '../Active' import Active from '../Active'
import Filter from '../Filter' import Filter from '../Filter'
import { InfoBox } from '../Map' import { InfoBox } from '../Map'
@ -19,19 +17,6 @@ import SynapseCollection from './SynapseCollection'
import Mapping from './Mapping' import Mapping from './Mapping'
import MappingCollection from './MappingCollection' import MappingCollection from './MappingCollection'
/*
* DataModel.js
*
* Dependencies:
* - Metamaps.Collaborators
* - Metamaps.Creators
* - Metamaps.Mappers
* - Metamaps.Mappings
* - Metamaps.Metacodes
* - Metamaps.Synapses
* - Metamaps.Topics
*/
const DataModel = { const DataModel = {
Map: Map, Map: Map,
MapCollection: MapCollection, MapCollection: MapCollection,
@ -48,45 +33,50 @@ const DataModel = {
Mapping: Mapping, Mapping: Mapping,
MappingCollection: MappingCollection, MappingCollection: MappingCollection,
Metacodes: new MetacodeCollection(),
Topics: new TopicCollection(),
Synapses: new SynapseCollection(),
Mappings: new MappingCollection(),
Mappers: new MapperCollection(),
Collaborators: new MapperCollection(), Collaborators: new MapperCollection(),
Creators: new MapperCollection(), Creators: new MapperCollection(),
Mappers: new MapperCollection(),
Mappings: new MappingCollection(),
Messages: [],
Metacodes: new MetacodeCollection(),
Stars: [],
Synapses: new SynapseCollection(),
Topics: new TopicCollection(),
init: function (serverData) { init: function (serverData) {
var self = DataModel var self = DataModel
if (serverData.Collaborators) self.Collaborators = new MapperCollection(serverData.Collaborators)
if (serverData.Creators) self.Creators = new MapperCollection(serverData.Creators)
if (serverData.Mappers) self.Mappers = new MapperCollection(serverData.Mappers)
if (serverData.Mappings) self.Mappings = new MappingCollection(serverData.Mappings)
if (serverData.Messages) self.Messages = serverData.Messages
if (serverData.Metacodes) self.Metacodes = new MetacodeCollection(serverData.Metacodes) if (serverData.Metacodes) self.Metacodes = new MetacodeCollection(serverData.Metacodes)
if (serverData.Stars) self.Stars = serverData.Stars
// attach collection event listeners if (serverData.Synapses) self.Synapses = new SynapseCollection(serverData.Synapses)
if (serverData.Topics) self.Topics = new TopicCollection(serverData.Topics) if (serverData.Topics) self.Topics = new TopicCollection(serverData.Topics)
self.attachCollectionEvents()
},
attachCollectionEvents: function () {
var self = DataModel
self.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()
}) })
if (serverData.Synapses) self.Synapses = new SynapseCollection(serverData.Synapses)
self.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 (serverData.Mappings) self.Mappings = new MappingCollection(serverData.Mappings)
self.Mappings.on('add remove', function (mapping) { self.Mappings.on('add remove', function (mapping) {
InfoBox.updateNumbers() InfoBox.updateNumbers()
Filter.checkSynapses() Filter.checkSynapses()
Filter.checkMetacodes() Filter.checkMetacodes()
Filter.checkMappers() Filter.checkMappers()
}) })
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)
} }
} }

View file

@ -1,23 +1,14 @@
/* global Metamaps, $ */ /* global $ */
import _ from 'lodash' import _ from 'lodash'
import Active from './Active' import Active from './Active'
import Control from './Control' import Control from './Control'
import DataModel from './DataModel'
import GlobalUI from './GlobalUI' import GlobalUI from './GlobalUI'
import Settings from './Settings' import Settings from './Settings'
import Visualize from './Visualize' import Visualize from './Visualize'
/*
* Metamaps.Filter.js.erb
*
* Dependencies:
* - Metamaps.Creators
* - Metamaps.Mappers
* - Metamaps.Metacodes
* - Metamaps.Synapses
* - Metamaps.Topics
*/
const Filter = { const Filter = {
filters: { filters: {
name: '', name: '',
@ -148,7 +139,7 @@ const Filter = {
// the first option enables us to accept // the first option enables us to accept
// ['Topics', 'Synapses'] as 'collection' // ['Topics', 'Synapses'] as 'collection'
if (typeof collection === 'object') { if (typeof collection === 'object') {
Metamaps[collection[0]].each(function (model) { DataModel[collection[0]].each(function (model) {
var prop = model.get(propertyToCheck) var prop = model.get(propertyToCheck)
if (prop !== null) { if (prop !== null) {
prop = prop.toString() prop = prop.toString()
@ -157,7 +148,7 @@ const Filter = {
} }
} }
}) })
Metamaps[collection[1]].each(function (model) { DataModel[collection[1]].each(function (model) {
var prop = model.get(propertyToCheck) var prop = model.get(propertyToCheck)
if (prop !== null) { if (prop !== null) {
prop = prop.toString() prop = prop.toString()
@ -167,7 +158,7 @@ const Filter = {
} }
}) })
} else if (typeof collection === 'string') { } else if (typeof collection === 'string') {
Metamaps[collection].each(function (model) { DataModel[collection].each(function (model) {
var prop = model.get(propertyToCheck) var prop = model.get(propertyToCheck)
if (prop !== null) { if (prop !== null) {
prop = prop.toString() prop = prop.toString()
@ -196,8 +187,8 @@ const Filter = {
} }
// for each new filter to be added, create a list item for it and fade it in // for each new filter to be added, create a list item for it and fade it in
_.each(added, function (identifier) { _.each(added, function (identifier) {
model = Metamaps[correlatedModel].get(identifier) || model = DataModel[correlatedModel].get(identifier) ||
Metamaps[correlatedModel].find(function (model) { DataModel[correlatedModel].find(function (model) {
return model.get(propertyToCheck) === identifier return model.get(propertyToCheck) === identifier
}) })
li = model.prepareLiForFilter() li = model.prepareLiForFilter()
@ -359,7 +350,7 @@ const Filter = {
var opacityForFilter = onMap ? 0 : 0.4 var opacityForFilter = onMap ? 0 : 0.4
Metamaps.Topics.each(function (topic) { DataModel.Topics.each(function (topic) {
var n = topic.get('node') var n = topic.get('node')
var metacode_id = topic.get('metacode_id').toString() var metacode_id = topic.get('metacode_id').toString()
@ -400,11 +391,11 @@ const Filter = {
}) })
// flag all the edges back to 'untouched' // flag all the edges back to 'untouched'
Metamaps.Synapses.each(function (synapse) { DataModel.Synapses.each(function (synapse) {
var e = synapse.get('edge') var e = synapse.get('edge')
e.setData('touched', false) e.setData('touched', false)
}) })
Metamaps.Synapses.each(function (synapse) { DataModel.Synapses.each(function (synapse) {
var e = synapse.get('edge') var e = synapse.get('edge')
var desc var desc
var user_id = synapse.get('user_id').toString() var user_id = synapse.get('user_id').toString()

View file

@ -1,13 +1,9 @@
/* global Metamaps, $ */ /* global $ */
import Active from '../Active' import Active from '../Active'
import DataModel from '../DataModel'
import GlobalUI from './index' import GlobalUI from './index'
/*
* Metamaps.DataModel
* Metamaps.Maps
*/
const CreateMap = { const CreateMap = {
newMap: null, newMap: null,
emptyMapForm: '', emptyMapForm: '',
@ -17,7 +13,7 @@ const CreateMap = {
init: function () { init: function () {
var self = CreateMap var self = CreateMap
self.newMap = new Metamaps.DataModel.Map({ permission: 'commons' }) self.newMap = new DataModel.Map({ permission: 'commons' })
self.bindFormEvents() self.bindFormEvents()
@ -109,7 +105,7 @@ const CreateMap = {
success: function (model) { success: function (model) {
var self = CreateMap var self = CreateMap
// push the new map onto the collection of 'my maps' // push the new map onto the collection of 'my maps'
Metamaps.Maps.Mine.add(model) DataModel.Maps.Mine.add(model)
GlobalUI.clearNotify() GlobalUI.clearNotify()
$('#wrapper').append(self.generateSuccessMessage(model.id)) $('#wrapper').append(self.generateSuccessMessage(model.id))
@ -128,7 +124,7 @@ const CreateMap = {
} }
self.bindFormEvents() self.bindFormEvents()
self.newMap = new Metamaps.DataModel.Map({ permission: 'commons' }) self.newMap = new DataModel.Map({ permission: 'commons' })
return false return false
} }

View file

@ -5,7 +5,6 @@ import Router from '../Router'
/* /*
* Metamaps.Erb * Metamaps.Erb
* Metamaps.Maps
*/ */
const Search = { const Search = {

View file

@ -1,20 +1,16 @@
/* global Metamaps, $ */ /* global $ */
import clipboard from 'clipboard-js' import clipboard from 'clipboard-js'
import Active from '../Active' import Active from '../Active'
import Create from '../Create' import Create from '../Create'
import DataModel from '../DataModel'
import Search from './Search' import Search from './Search'
import CreateMap from './CreateMap' import CreateMap from './CreateMap'
import Account from './Account' import Account from './Account'
import ImportDialog from './ImportDialog' import ImportDialog from './ImportDialog'
/*
* Metamaps.DataModel
* Metamaps.Maps
*/
const GlobalUI = { const GlobalUI = {
notifyTimeout: null, notifyTimeout: null,
lightbox: null, lightbox: null,
@ -38,26 +34,26 @@ const GlobalUI = {
$('#lightbox_screen, #lightbox_close').click(self.closeLightbox) $('#lightbox_screen, #lightbox_close').click(self.closeLightbox)
// initialize global backbone models and collections // initialize global backbone models and collections
if (Active.Mapper) Active.Mapper = new Metamaps.DataModel.Mapper(Active.Mapper) if (Active.Mapper) Active.Mapper = new DataModel.Mapper(Active.Mapper)
var myCollection = Metamaps.Maps.Mine ? Metamaps.Maps.Mine : [] var myCollection = DataModel.Maps.Mine ? DataModel.Maps.Mine : []
var sharedCollection = Metamaps.Maps.Shared ? Metamaps.Maps.Shared : [] var sharedCollection = DataModel.Maps.Shared ? DataModel.Maps.Shared : []
var starredCollection = Metamaps.Maps.Starred ? Metamaps.Maps.Starred : [] var starredCollection = DataModel.Maps.Starred ? DataModel.Maps.Starred : []
var mapperCollection = [] var mapperCollection = []
var mapperOptionsObj = { id: 'mapper', sortBy: 'updated_at' } var mapperOptionsObj = { id: 'mapper', sortBy: 'updated_at' }
if (Metamaps.Maps.Mapper) { if (DataModel.Maps.Mapper) {
mapperCollection = Metamaps.Maps.Mapper.models mapperCollection = DataModel.Maps.Mapper.models
mapperOptionsObj.mapperId = Metamaps.Maps.Mapper.id mapperOptionsObj.mapperId = DataModel.Maps.Mapper.id
} }
var featuredCollection = Metamaps.Maps.Featured ? Metamaps.Maps.Featured : [] var featuredCollection = DataModel.Maps.Featured ? DataModel.Maps.Featured : []
var activeCollection = Metamaps.Maps.Active ? Metamaps.Maps.Active : [] var activeCollection = DataModel.Maps.Active ? DataModel.Maps.Active : []
Metamaps.Maps.Mine = new Metamaps.DataModel.MapCollection(myCollection, { id: 'mine', sortBy: 'updated_at' }) DataModel.Maps.Mine = new DataModel.MapCollection(myCollection, { id: 'mine', sortBy: 'updated_at' })
Metamaps.Maps.Shared = new Metamaps.DataModel.MapCollection(sharedCollection, { id: 'shared', sortBy: 'updated_at' }) DataModel.Maps.Shared = new DataModel.MapCollection(sharedCollection, { id: 'shared', sortBy: 'updated_at' })
Metamaps.Maps.Starred = new Metamaps.DataModel.MapCollection(starredCollection, { id: 'starred', sortBy: 'updated_at' }) DataModel.Maps.Starred = new DataModel.MapCollection(starredCollection, { id: 'starred', sortBy: 'updated_at' })
// 'Mapper' refers to another mapper // 'Mapper' refers to another mapper
Metamaps.Maps.Mapper = new Metamaps.DataModel.MapCollection(mapperCollection, mapperOptionsObj) DataModel.Maps.Mapper = new DataModel.MapCollection(mapperCollection, mapperOptionsObj)
Metamaps.Maps.Featured = new Metamaps.DataModel.MapCollection(featuredCollection, { id: 'featured', sortBy: 'updated_at' }) DataModel.Maps.Featured = new DataModel.MapCollection(featuredCollection, { id: 'featured', sortBy: 'updated_at' })
Metamaps.Maps.Active = new Metamaps.DataModel.MapCollection(activeCollection, { id: 'active', sortBy: 'updated_at' }) DataModel.Maps.Active = new DataModel.MapCollection(activeCollection, { id: 'active', sortBy: 'updated_at' })
}, },
showDiv: function (selector) { showDiv: function (selector) {
$(selector).show() $(selector).show()

View file

@ -1,26 +1,16 @@
/* global Metamaps, $ */ /* global $ */
import parse from 'csv-parse' import parse from 'csv-parse'
import _ from 'lodash' import _ from 'lodash'
import Active from './Active' import Active from './Active'
import AutoLayout from './AutoLayout' import AutoLayout from './AutoLayout'
import DataModel from './DataModel'
import GlobalUI from './GlobalUI' import GlobalUI from './GlobalUI'
import Map from './Map' import Map from './Map'
import Synapse from './Synapse' import Synapse from './Synapse'
import Topic from './Topic' import Topic from './Topic'
/*
* Metamaps.Import.js.erb
*
* Dependencies:
* - Metamaps.DataModel
* - Metamaps.Mappings
* - Metamaps.Metacodes
* - Metamaps.Synapses
* - Metamaps.Topics
*/
const Import = { const Import = {
// note that user is not imported // note that user is not imported
topicWhitelist: [ topicWhitelist: [
@ -255,10 +245,10 @@ const Import = {
parsedSynapses.forEach(function (synapse) { parsedSynapses.forEach(function (synapse) {
// only createSynapseWithParameters once both topics are persisted // only createSynapseWithParameters once both topics are persisted
// if there isn't a cidMapping, check by topic name instead // if there isn't a cidMapping, check by topic name instead
var topic1 = Metamaps.Topics.get(self.cidMappings[synapse.topic1]) var topic1 = DataModel.Topics.get(self.cidMappings[synapse.topic1])
if (!topic1) topic1 = Metamaps.Topics.findWhere({ name: synapse.topic1 }) if (!topic1) topic1 = DataModel.Topics.findWhere({ name: synapse.topic1 })
var topic2 = Metamaps.Topics.get(self.cidMappings[synapse.topic2]) var topic2 = DataModel.Topics.get(self.cidMappings[synapse.topic2])
if (!topic2) topic2 = Metamaps.Topics.findWhere({ name: synapse.topic2 }) if (!topic2) topic2 = DataModel.Topics.findWhere({ name: synapse.topic2 })
if (!topic1 || !topic2) { if (!topic1 || !topic2) {
console.error("One of the two topics doesn't exist!") console.error("One of the two topics doesn't exist!")
@ -291,15 +281,15 @@ const Import = {
link, xloc, yloc, import_id, opts = {}) { link, xloc, yloc, import_id, opts = {}) {
var self = Import var self = Import
$(document).trigger(Map.events.editedByActiveMapper) $(document).trigger(Map.events.editedByActiveMapper)
var metacode = Metamaps.Metacodes.where({name: metacode_name})[0] || null var metacode = DataModel.Metacodes.where({name: metacode_name})[0] || null
if (metacode === null) { if (metacode === null) {
metacode = Metamaps.Metacodes.where({ name: 'Wildcard' })[0] metacode = DataModel.Metacodes.where({ name: 'Wildcard' })[0]
console.warn("Couldn't find metacode " + metacode_name + ' so used Wildcard instead.') console.warn("Couldn't find metacode " + metacode_name + ' so used Wildcard instead.')
} }
var topic_permission = permission || Active.Map.get('permission') var topic_permission = permission || Active.Map.get('permission')
var defer_to_map_id = permission === topic_permission ? Active.Map.get('id') : null var defer_to_map_id = permission === topic_permission ? Active.Map.get('id') : null
var topic = new Metamaps.DataModel.Topic({ var topic = new DataModel.Topic({
name: name, name: name,
metacode_id: metacode.id, metacode_id: metacode.id,
permission: topic_permission, permission: topic_permission,
@ -308,19 +298,19 @@ const Import = {
link: link || '', link: link || '',
calculated_permission: Active.Map.get('permission') calculated_permission: Active.Map.get('permission')
}) })
Metamaps.Topics.add(topic) DataModel.Topics.add(topic)
if (import_id !== null && import_id !== undefined) { if (import_id !== null && import_id !== undefined) {
self.cidMappings[import_id] = topic.cid self.cidMappings[import_id] = topic.cid
} }
var mapping = new Metamaps.DataModel.Mapping({ var mapping = new DataModel.Mapping({
xloc: xloc, xloc: xloc,
yloc: yloc, yloc: yloc,
mappable_id: topic.cid, mappable_id: topic.cid,
mappable_type: 'Topic' mappable_type: 'Topic'
}) })
Metamaps.Mappings.add(mapping) DataModel.Mappings.add(mapping)
// this function also includes the creation of the topic in the database // this function also includes the creation of the topic in the database
Topic.renderTopic(mapping, topic, true, true, { Topic.renderTopic(mapping, topic, true, true, {
@ -340,20 +330,20 @@ const Import = {
return return
} // if } // if
var synapse = new Metamaps.DataModel.Synapse({ var synapse = new DataModel.Synapse({
desc: desc || '', desc: desc || '',
category: category || 'from-to', category: category || 'from-to',
permission: permission, permission: permission,
topic1_id: topic1.id, topic1_id: topic1.id,
topic2_id: topic2.id topic2_id: topic2.id
}) })
Metamaps.Synapses.add(synapse) DataModel.Synapses.add(synapse)
var mapping = new Metamaps.DataModel.Mapping({ var mapping = new DataModel.Mapping({
mappable_type: 'Synapse', mappable_type: 'Synapse',
mappable_id: synapse.cid mappable_id: synapse.cid
}) })
Metamaps.Mappings.add(mapping) DataModel.Mappings.add(mapping)
Synapse.renderSynapse(mapping, synapse, node1, node2, true) Synapse.renderSynapse(mapping, synapse, node1, node2, true)
}, },

View file

@ -8,6 +8,7 @@ import $jit from '../patched/JIT'
import Active from './Active' import Active from './Active'
import Control from './Control' import Control from './Control'
import Create from './Create' import Create from './Create'
import DataModel from './DataModel'
import Filter from './Filter' import Filter from './Filter'
import GlobalUI from './GlobalUI' import GlobalUI from './GlobalUI'
import Map from './Map' import Map from './Map'
@ -25,10 +26,6 @@ import clipboard from 'clipboard-js'
/* /*
* Metamaps.Erb * Metamaps.Erb
* Metamaps.Mappings
* Metamaps.Metacodes
* Metamaps.Synapses
* Metamaps.Topics
*/ */
let panningInt let panningInt
@ -140,15 +137,15 @@ const JIT = {
self.vizData = [] self.vizData = []
Visualize.loadLater = false Visualize.loadLater = false
const results = self.convertModelsToJIT(Metamaps.Topics, Metamaps.Synapses) const results = self.convertModelsToJIT(DataModel.Topics, DataModel.Synapses)
self.vizData = results[0] self.vizData = results[0]
// clean up the synapses array in case of any faulty data // clean up the synapses array in case of any faulty data
_.each(results[1], function (synapse) { _.each(results[1], function (synapse) {
mapping = synapse.getMapping() mapping = synapse.getMapping()
Metamaps.Synapses.remove(synapse) DataModel.Synapses.remove(synapse)
if (Metamaps.Mappings) Metamaps.Mappings.remove(mapping) if (DataModel.Mappings) DataModel.Mappings.remove(mapping)
}) })
// set up addTopic instructions in case they delete all the topics // set up addTopic instructions in case they delete all the topics
@ -1191,7 +1188,7 @@ const JIT = {
eY = -1 * eY eY = -1 * eY
const edgesToToggle = [] const edgesToToggle = []
Metamaps.Synapses.each(function (synapse) { DataModel.Synapses.each(function (synapse) {
const e = synapse.get('edge') const e = synapse.get('edge')
if (edgesToToggle.indexOf(e) === -1) { if (edgesToToggle.indexOf(e) === -1) {
edgesToToggle.push(e) edgesToToggle.push(e)
@ -1579,15 +1576,15 @@ const JIT = {
loader.setRange(0.9) // default is 1.3 loader.setRange(0.9) // default is 1.3
loader.show() // Hidden by default loader.show() // Hidden by default
const topics = Metamaps.Topics.map(function (t) { return t.id }) const topics = DataModel.Topics.map(function (t) { return t.id })
const topicsString = topics.join() const topics_string = topics.join()
const successCallback = function (data) { const successCallback = function (data) {
$('#loadingSiblings').remove() $('#loadingSiblings').remove()
for (var key in data) { for (var key in data) {
const string = Metamaps.Metacodes.get(key).get('name') + ' (' + data[key] + ')' const string = `${DataModel.Metacodes.get(key).get('name')} (${data[key]})`
$('#fetchSiblingList').append('<li class="getSiblings" data-id="' + key + '">' + string + '</li>') $('#fetchSiblingList').append(`<li class="getSiblings" data-id="${key}">${string}</li>`)
} }
$('.rc-siblings .getSiblings').click(function () { $('.rc-siblings .getSiblings').click(function () {

View file

@ -3,17 +3,13 @@
import outdent from 'outdent' import outdent from 'outdent'
import Active from '../Active' import Active from '../Active'
import DataModel from '../DataModel'
import GlobalUI from '../GlobalUI' import GlobalUI from '../GlobalUI'
import Router from '../Router' import Router from '../Router'
import Util from '../Util' import Util from '../Util'
/* /*
* Metamaps.Collaborators
* Metamaps.Erb * Metamaps.Erb
* Metamaps.Mappers
* Metamaps.Maps
* Metamaps.Synapses
* Metamaps.Topics
*/ */
const InfoBox = { const InfoBox = {
@ -106,7 +102,7 @@ const InfoBox = {
var isCreator = map.authorizePermissionChange(Active.Mapper) var isCreator = map.authorizePermissionChange(Active.Mapper)
var canEdit = map.authorizeToEdit(Active.Mapper) var canEdit = map.authorizeToEdit(Active.Mapper)
var relevantPeople = map.get('permission') === 'commons' ? Metamaps.Mappers : Metamaps.Collaborators var relevantPeople = map.get('permission') === 'commons' ? DataModel.Mappers : DataModel.Collaborators
var shareable = map.get('permission') !== 'private' var shareable = map.get('permission') !== 'private'
obj['name'] = canEdit ? Hogan.compile(self.nameHTML).render({id: map.id, name: map.get('name')}) : map.get('name') obj['name'] = canEdit ? Hogan.compile(self.nameHTML).render({id: map.id, name: map.get('name')}) : map.get('name')
@ -251,24 +247,24 @@ const InfoBox = {
}, },
removeCollaborator: function (collaboratorId) { removeCollaborator: function (collaboratorId) {
var self = InfoBox var self = InfoBox
Metamaps.Collaborators.remove(Metamaps.Collaborators.get(collaboratorId)) DataModel.Collaborators.remove(DataModel.Collaborators.get(collaboratorId))
var mapperIds = Metamaps.Collaborators.models.map(function (mapper) { return mapper.id }) var mapperIds = DataModel.Collaborators.models.map(function (mapper) { return mapper.id })
$.post('/maps/' + Active.Map.id + '/access', { access: mapperIds }) $.post('/maps/' + Active.Map.id + '/access', { access: mapperIds })
self.updateNumbers() self.updateNumbers()
}, },
addCollaborator: function (newCollaboratorId) { addCollaborator: function (newCollaboratorId) {
var self = InfoBox var self = InfoBox
if (Metamaps.Collaborators.get(newCollaboratorId)) { if (DataModel.Collaborators.get(newCollaboratorId)) {
GlobalUI.notifyUser('That user already has access') GlobalUI.notifyUser('That user already has access')
return return
} }
function callback(mapper) { function callback(mapper) {
Metamaps.Collaborators.add(mapper) DataModel.Collaborators.add(mapper)
var mapperIds = Metamaps.Collaborators.models.map(function (mapper) { return mapper.id }) var mapperIds = DataModel.Collaborators.models.map(function (mapper) { return mapper.id })
$.post('/maps/' + Active.Map.id + '/access', { access: mapperIds }) $.post('/maps/' + Active.Map.id + '/access', { access: mapperIds })
var name = Metamaps.Collaborators.get(newCollaboratorId).get('name') var name = DataModel.Collaborators.get(newCollaboratorId).get('name')
GlobalUI.notifyUser(name + ' will be notified by email') GlobalUI.notifyUser(name + ' will be notified by email')
self.updateNumbers() self.updateNumbers()
} }
@ -289,7 +285,7 @@ const InfoBox = {
}, },
createContributorList: function () { createContributorList: function () {
var self = InfoBox var self = InfoBox
var relevantPeople = Active.Map.get('permission') === 'commons' ? Metamaps.Mappers : Metamaps.Collaborators var relevantPeople = Active.Map.get('permission') === 'commons' ? DataModel.Mappers : DataModel.Collaborators
var activeMapperIsCreator = Active.Mapper && Active.Mapper.id === Active.Map.get('user_id') var activeMapperIsCreator = Active.Mapper && Active.Mapper.id === Active.Map.get('user_id')
var string = '' var string = ''
string += '<ul>' string += '<ul>'
@ -315,7 +311,7 @@ const InfoBox = {
var self = InfoBox var self = InfoBox
var mapper = Active.Mapper var mapper = Active.Mapper
var relevantPeople = Active.Map.get('permission') === 'commons' ? Metamaps.Mappers : Metamaps.Collaborators var relevantPeople = Active.Map.get('permission') === 'commons' ? DataModel.Mappers : DataModel.Collaborators
var contributors_class = '' var contributors_class = ''
if (relevantPeople.length === 2) contributors_class = 'multiple mTwo' if (relevantPeople.length === 2) contributors_class = 'multiple mTwo'
@ -333,8 +329,8 @@ const InfoBox = {
$('.mapContributors .tip').unbind().click(function (event) { $('.mapContributors .tip').unbind().click(function (event) {
event.stopPropagation() event.stopPropagation()
}) })
$('.mapTopics').text(Metamaps.Topics.length) $('.mapTopics').text(DataModel.Topics.length)
$('.mapSynapses').text(Metamaps.Synapses.length) $('.mapSynapses').text(DataModel.Synapses.length)
$('.mapEditedAt').html('<span>Last edited: </span>' + Util.nowDateFormatted()) $('.mapEditedAt').html('<span>Last edited: </span>' + Util.nowDateFormatted())
}, },
@ -388,10 +384,10 @@ const InfoBox = {
if (doIt && authorized) { if (doIt && authorized) {
InfoBox.close() InfoBox.close()
Metamaps.Maps.Active.remove(map) DataModel.Maps.Active.remove(map)
Metamaps.Maps.Featured.remove(map) DataModel.Maps.Featured.remove(map)
Metamaps.Maps.Mine.remove(map) DataModel.Maps.Mine.remove(map)
Metamaps.Maps.Shared.remove(map) DataModel.Maps.Shared.remove(map)
map.destroy() map.destroy()
Router.home() Router.home()
GlobalUI.notifyUser('Map eliminated!') GlobalUI.notifyUser('Map eliminated!')

View file

@ -1,10 +1,12 @@
/* global Metamaps, $ */ /* global $ */
import outdent from 'outdent' import outdent from 'outdent'
import Active from '../Active' import Active from '../Active'
import AutoLayout from '../AutoLayout' import AutoLayout from '../AutoLayout'
import Create from '../Create' import Create from '../Create'
import DataModel from '../DataModel'
import DataModelMap from '../DataModel/Map'
import Filter from '../Filter' import Filter from '../Filter'
import GlobalUI from '../GlobalUI' import GlobalUI from '../GlobalUI'
import JIT from '../JIT' import JIT from '../JIT'
@ -23,14 +25,7 @@ import InfoBox from './InfoBox'
* Metamaps.Map.js.erb * Metamaps.Map.js.erb
* *
* Dependencies: * Dependencies:
* - Metamaps.DataModel
* - Metamaps.Erb * - Metamaps.Erb
* - Metamaps.Mappers
* - Metamaps.Mappings
* - Metamaps.Maps
* - Metamaps.Messages
* - Metamaps.Synapses
* - Metamaps.Topics
*/ */
const Map = { const Map = {
@ -83,15 +78,15 @@ const Map = {
}, },
launch: function (id) { launch: function (id) {
var start = function (data) { var start = function (data) {
Active.Map = new Metamaps.DataModel.Map(data.map) Active.Map = new DataModelMap(data.map)
Metamaps.Mappers = new Metamaps.DataModel.MapperCollection(data.mappers) DataModel.Mappers = new DataModel.MapperCollection(data.mappers)
Metamaps.Collaborators = new Metamaps.DataModel.MapperCollection(data.collaborators) DataModel.Collaborators = new DataModel.MapperCollection(data.collaborators)
Metamaps.Topics = new Metamaps.DataModel.TopicCollection(data.topics) DataModel.Topics = new DataModel.TopicCollection(data.topics)
Metamaps.Synapses = new Metamaps.DataModel.SynapseCollection(data.synapses) DataModel.Synapses = new DataModel.SynapseCollection(data.synapses)
Metamaps.Mappings = new Metamaps.DataModel.MappingCollection(data.mappings) DataModel.Mappings = new DataModel.MappingCollection(data.mappings)
Metamaps.Messages = data.messages DataModel.Messages = data.messages
Metamaps.Stars = data.stars DataModel.Stars = data.stars
Metamaps.DataModel.attachCollectionEvents() DataModel.attachCollectionEvents()
var map = Active.Map var map = Active.Map
var mapper = Active.Mapper var mapper = Active.Mapper
@ -164,9 +159,9 @@ const Map = {
} }
}, },
updateStar: function () { updateStar: function () {
if (!Active.Mapper || !Metamaps.Stars) return if (!Active.Mapper || !DataModel.Stars) return
// update the star/unstar icon // update the star/unstar icon
if (Metamaps.Stars.find(function (s) { return s.user_id === Active.Mapper.id })) { if (DataModel.Stars.find(function (s) { return s.user_id === Active.Mapper.id })) {
$('.starMap').addClass('starred') $('.starMap').addClass('starred')
$('.starMap .tooltipsAbove').html('Unstar') $('.starMap .tooltipsAbove').html('Unstar')
} else { } else {
@ -179,8 +174,8 @@ const Map = {
if (!Active.Map) return if (!Active.Map) return
$.post('/maps/' + Active.Map.id + '/star') $.post('/maps/' + Active.Map.id + '/star')
Metamaps.Stars.push({ user_id: Active.Mapper.id, map_id: Active.Map.id }) DataModel.Stars.push({ user_id: Active.Mapper.id, map_id: Active.Map.id })
Metamaps.Maps.Starred.add(Active.Map) DataModel.Maps.Starred.add(Active.Map)
GlobalUI.notifyUser('Map is now starred') GlobalUI.notifyUser('Map is now starred')
self.updateStar() self.updateStar()
}, },
@ -189,8 +184,8 @@ const Map = {
if (!Active.Map) return if (!Active.Map) return
$.post('/maps/' + Active.Map.id + '/unstar') $.post('/maps/' + Active.Map.id + '/unstar')
Metamaps.Stars = Metamaps.Stars.filter(function (s) { return s.user_id != Active.Mapper.id }) DataModel.Stars = DataModel.Stars.filter(function (s) { return s.user_id != Active.Mapper.id })
Metamaps.Maps.Starred.remove(Active.Map) DataModel.Maps.Starred.remove(Active.Map)
self.updateStar() self.updateStar()
}, },
fork: function () { fork: function () {
@ -218,7 +213,7 @@ const Map = {
} }
}) })
// collect the unfiltered synapses // collect the unfiltered synapses
Metamaps.Synapses.each(function (synapse) { DataModel.Synapses.each(function (synapse) {
var desc = synapse.get('desc') var desc = synapse.get('desc')
var descNotFiltered = Filter.visible.synapses.indexOf(desc) > -1 var descNotFiltered = Filter.visible.synapses.indexOf(desc) > -1
@ -239,8 +234,8 @@ const Map = {
}, },
leavePrivateMap: function () { leavePrivateMap: function () {
var map = Active.Map var map = Active.Map
Metamaps.Maps.Active.remove(map) DataModel.Maps.Active.remove(map)
Metamaps.Maps.Featured.remove(map) DataModel.Maps.Featured.remove(map)
Router.home() Router.home()
GlobalUI.notifyUser('Sorry! That map has been changed to Private.') GlobalUI.notifyUser('Sorry! That map has been changed to Private.')
}, },
@ -259,7 +254,7 @@ const Map = {
}, },
editedByActiveMapper: function () { editedByActiveMapper: function () {
if (Active.Mapper) { if (Active.Mapper) {
Metamaps.Mappers.add(Active.Mapper) DataModel.Mappers.add(Active.Mapper)
} }
}, },
exportImage: function () { exportImage: function () {

View file

@ -1,9 +1,6 @@
/* global $ */ /* global $ */
/* import DataModel from './DataModel'
* Dependencies:
* Metamaps.DataModel
*/
const Mapper = { const Mapper = {
// this function is to retrieve a mapper JSON object from the database // this function is to retrieve a mapper JSON object from the database
@ -12,7 +9,7 @@ const Mapper = {
$.ajax({ $.ajax({
url: `/users/${id}.json`, url: `/users/${id}.json`,
success: data => { success: data => {
callback(new Metamaps.DataModel.Mapper(data)) callback(new DataModel.Mapper(data))
} }
}) })
} }

View file

@ -302,9 +302,10 @@ export const newMapper = self => data => {
var notifyMessage = data.username + ' just joined the map' var notifyMessage = data.username + ' just joined the map'
if (firstOtherPerson) { if (firstOtherPerson) {
notifyMessage += ' <button type="button" class="toast-button button" onclick="Metamaps.Realtime.inviteACall(' + data.userid + ')">Suggest A Video Call</button>' notifyMessage += ' <button type="button" class="toast-button button">Suggest A Video Call</button>'
} }
GlobalUI.notifyUser(notifyMessage) GlobalUI.notifyUser(notifyMessage)
$('#toast button').click(e => self.inviteACall(data.userid))
self.sendMapperInfo(data.userid) self.sendMapperInfo(data.userid)
} }
} }
@ -335,9 +336,11 @@ export const invitedToCall = self => inviter => {
var username = self.mappersOnMap[inviter].name var username = self.mappersOnMap[inviter].name
var notifyText = '<img src="' + self['junto_spinner_darkgrey.gif'] + '" style="display: inline-block; margin-top: -12px; margin-bottom: -6px; vertical-align: top;" />' var notifyText = '<img src="' + self['junto_spinner_darkgrey.gif'] + '" style="display: inline-block; margin-top: -12px; margin-bottom: -6px; vertical-align: top;" />'
notifyText += username + ' is inviting you to a conversation. Join live?' notifyText += username + ' is inviting you to a conversation. Join live?'
notifyText += ' <button type="button" class="toast-button button" onclick="Metamaps.Realtime.acceptCall(' + inviter + ')">Yes</button>' notifyText += ' <button type="button" class="toast-button button yes">Yes</button>'
notifyText += ' <button type="button" class="toast-button button btn-no" onclick="Metamaps.Realtime.denyCall(' + inviter + ')">No</button>' notifyText += ' <button type="button" class="toast-button button btn-no no">No</button>'
GlobalUI.notifyUser(notifyText, true) GlobalUI.notifyUser(notifyText, true)
$('#toast button.yes').click(e => self.acceptCall(inviter))
$('#toast button.no').click(e => self.denyCall(inviter))
} }
export const invitedToJoin = self => inviter => { export const invitedToJoin = self => inviter => {
@ -346,9 +349,11 @@ export const invitedToJoin = self => inviter => {
var username = self.mappersOnMap[inviter].name var username = self.mappersOnMap[inviter].name
var notifyText = username + ' is inviting you to the conversation. Join?' var notifyText = username + ' is inviting you to the conversation. Join?'
notifyText += ' <button type="button" class="toast-button button" onclick="Metamaps.Realtime.joinCall()">Yes</button>' notifyText += ' <button type="button" class="toast-button button yes">Yes</button>'
notifyText += ' <button type="button" class="toast-button button btn-no" onclick="Metamaps.Realtime.denyInvite(' + inviter + ')">No</button>' notifyText += ' <button type="button" class="toast-button button btn-no no">No</button>'
GlobalUI.notifyUser(notifyText, true) GlobalUI.notifyUser(notifyText, true)
$('#toast button.yes').click(e => self.joinCall())
$('#toast button.no').click(e => self.denyInvite(inviter))
} }
export const mapperJoinedCall = self => id => { export const mapperJoinedCall = self => id => {
@ -385,18 +390,24 @@ export const mapperLeftCall = self => id => {
export const callInProgress = self => () => { export const callInProgress = self => () => {
var notifyText = "There's a conversation happening, want to join?" var notifyText = "There's a conversation happening, want to join?"
notifyText += ' <button type="button" class="toast-button button" onclick="Metamaps.Realtime.joinCall()">Yes</button>' notifyText += ' <button type="button" class="toast-button button yes">Yes</button>'
notifyText += ' <button type="button" class="toast-button button btn-no" onclick="Metamaps.GlobalUI.clearNotify()">No</button>' notifyText += ' <button type="button" class="toast-button button btn-no no">No</button>'
GlobalUI.notifyUser(notifyText, true) GlobalUI.notifyUser(notifyText, true)
$('#toast button.yes').click(e => self.joinCall())
$('#toast button.no').click(e => GlobalUI.clearNotify())
self.room.conversationInProgress() self.room.conversationInProgress()
} }
export const callStarted = self => () => { export const callStarted = self => () => {
if (self.inConversation) return if (self.inConversation) return
var notifyText = "There's a conversation starting, want to join?" var notifyText = "There's a conversation starting, want to join?"
notifyText += ' <button type="button" class="toast-button button" onclick="Metamaps.Realtime.joinCall()">Yes</button>' notifyText += ' <button type="button" class="toast-button button">Yes</button>'
notifyText += ' <button type="button" class="toast-button button btn-no" onclick="Metamaps.GlobalUI.clearNotify()">No</button>' notifyText += ' <button type="button" class="toast-button button btn-no">No</button>'
GlobalUI.notifyUser(notifyText, true) GlobalUI.notifyUser(notifyText, true)
$('#toast button.yes').click(e => self.joinCall())
$('#toast button.no').click(e => GlobalUI.clearNotify())
self.room.conversationInProgress() self.room.conversationInProgress()
} }

View file

@ -1,8 +1,7 @@
/* global Metamaps, $ */ /* global $ */
import Backbone from 'backbone' import Backbone from 'backbone'
//TODO is this line good or bad? Backbone.$ = window.$
//Backbone.$ = window.$
import Active from './Active' import Active from './Active'
import GlobalUI from './GlobalUI' import GlobalUI from './GlobalUI'
@ -12,13 +11,6 @@ import Topic from './Topic'
import Views from './Views' import Views from './Views'
import Visualize from './Visualize' import Visualize from './Visualize'
/*
* Metamaps.Router.js.erb
*
* Dependencies:
* - Metamaps.Maps
*/
const _Router = Backbone.Router.extend({ const _Router = Backbone.Router.extend({
currentPage: '', currentPage: '',
currentSection: '', currentSection: '',
@ -57,10 +49,10 @@ const _Router = Backbone.Router.extend({
GlobalUI.showDiv('#explore') GlobalUI.showDiv('#explore')
Views.ExploreMaps.setCollection(Metamaps.Maps.Active) Views.ExploreMaps.setCollection(DataModel.Maps.Active)
if (Metamaps.Maps.Active.length === 0) { if (DataModel.Maps.Active.length === 0) {
Views.ExploreMaps.pending = true Views.ExploreMaps.pending = true
Metamaps.Maps.Active.getMaps(navigate) // this will trigger an explore maps render DataModel.Maps.Active.getMaps(navigate) // this will trigger an explore maps render
} else { } else {
Views.ExploreMaps.render(navigate) Views.ExploreMaps.render(navigate)
} }
@ -109,23 +101,23 @@ const _Router = Backbone.Router.extend({
// this will mean it's a mapper page being loaded // this will mean it's a mapper page being loaded
if (id) { if (id) {
if (Metamaps.Maps.Mapper.mapperId !== id) { if (DataModel.Maps.Mapper.mapperId !== id) {
// empty the collection if we are trying to load the maps // empty the collection if we are trying to load the maps
// collection of a different mapper than we had previously // collection of a different mapper than we had previously
Metamaps.Maps.Mapper.reset() DataModel.Maps.Mapper.reset()
Metamaps.Maps.Mapper.page = 1 DataModel.Maps.Mapper.page = 1
} }
Metamaps.Maps.Mapper.mapperId = id DataModel.Maps.Mapper.mapperId = id
} }
Views.ExploreMaps.setCollection(Metamaps.Maps[capitalize]) Views.ExploreMaps.setCollection(DataModel.Maps[capitalize])
var navigate = function () { var navigate = function () {
var path = '/explore/' + self.currentPage var path = '/explore/' + self.currentPage
// alter url if for mapper profile page // alter url if for mapper profile page
if (self.currentPage === 'mapper') { if (self.currentPage === 'mapper') {
path += '/' + Metamaps.Maps.Mapper.mapperId path += '/' + DataModel.Maps.Mapper.mapperId
} }
self.navigate(path) self.navigate(path)
@ -133,11 +125,11 @@ const _Router = Backbone.Router.extend({
var navigateTimeout = function () { var navigateTimeout = function () {
self.timeoutId = setTimeout(navigate, 300) self.timeoutId = setTimeout(navigate, 300)
} }
if (Metamaps.Maps[capitalize].length === 0) { if (DataModel.Maps[capitalize].length === 0) {
Loading.show() Loading.show()
Views.ExploreMaps.pending = true Views.ExploreMaps.pending = true
setTimeout(function () { setTimeout(function () {
Metamaps.Maps[capitalize].getMaps(navigate) // this will trigger an explore maps render DataModel.Maps[capitalize].getMaps(navigate) // this will trigger an explore maps render
}, 300) // wait 300 milliseconds till the other animations are done to do the fetch }, 300) // wait 300 milliseconds till the other animations are done to do the fetch
} else { } else {
if (id) { if (id) {

View file

@ -1,4 +1,4 @@
/* global Metamaps, $ */ /* global $ */
import Active from './Active' import Active from './Active'
import Control from './Control' import Control from './Control'
@ -9,36 +9,24 @@ import Selected from './Selected'
import Settings from './Settings' import Settings from './Settings'
import Visualize from './Visualize' import Visualize from './Visualize'
/*
* Metamaps.Synapse.js.erb
*
* Dependencies:
* - Metamaps.DataModel
* - Metamaps.Mappings
* - Metamaps.Synapses
* - Metamaps.Topics
*/
const noOp = () => {} const noOp = () => {}
const Synapse = { const Synapse = {
// this function is to retrieve a synapse JSON object from the database // this function is to retrieve a synapse JSON object from the database
// @param id = the id of the synapse to retrieve // @param id = the id of the synapse to retrieve
get: function (id, callback = noOp) { get: function (id, callback = noOp) {
// if the desired topic is not yet in the local topic repository, fetch it // if the desired topic is not yet in the local topic repository, fetch it
if (Metamaps.Synapses.get(id) == undefined) { if (DataModel.Synapses.get(id) == undefined) {
$.ajax({ $.ajax({
url: '/synapses/' + id + '.json', url: '/synapses/' + id + '.json',
success: function (data) { success: function (data) {
Metamaps.Synapses.add(data) DataModel.Synapses.add(data)
callback(Metamaps.Synapses.get(id)) callback(DataModel.Synapses.get(id))
} }
}) })
} else callback(Metamaps.Synapses.get(id)) } else callback(DataModel.Synapses.get(id))
}, },
/*
*
*
*/
renderSynapse: function (mapping, synapse, node1, node2, createNewInDB) { renderSynapse: function (mapping, synapse, node1, node2, createNewInDB) {
var self = Synapse var self = Synapse
@ -98,12 +86,12 @@ const Synapse = {
// for each node in this array we will create a synapse going to the position2 node. // for each node in this array we will create a synapse going to the position2 node.
var synapsesToCreate = [] var synapsesToCreate = []
topic2 = Metamaps.Topics.get(Create.newSynapse.topic2id) topic2 = DataModel.Topics.get(Create.newSynapse.topic2id)
node2 = topic2.get('node') node2 = topic2.get('node')
var len = Selected.Nodes.length var len = Selected.Nodes.length
if (len == 0) { if (len == 0) {
topic1 = Metamaps.Topics.get(Create.newSynapse.topic1id) topic1 = DataModel.Topics.get(Create.newSynapse.topic1id)
synapsesToCreate[0] = topic1.get('node') synapsesToCreate[0] = topic1.get('node')
} else if (len > 0) { } else if (len > 0) {
synapsesToCreate = Selected.Nodes synapsesToCreate = Selected.Nodes
@ -112,18 +100,18 @@ const Synapse = {
for (var i = 0; i < synapsesToCreate.length; i++) { for (var i = 0; i < synapsesToCreate.length; i++) {
node1 = synapsesToCreate[i] node1 = synapsesToCreate[i]
topic1 = node1.getData('topic') topic1 = node1.getData('topic')
synapse = new Metamaps.DataModel.Synapse({ synapse = new DataModel.Synapse({
desc: Create.newSynapse.description, desc: Create.newSynapse.description,
topic1_id: topic1.isNew() ? topic1.cid : topic1.id, topic1_id: topic1.isNew() ? topic1.cid : topic1.id,
topic2_id: topic2.isNew() ? topic2.cid : topic2.id, topic2_id: topic2.isNew() ? topic2.cid : topic2.id,
}) })
Metamaps.Synapses.add(synapse) DataModel.Synapses.add(synapse)
mapping = new Metamaps.DataModel.Mapping({ mapping = new DataModel.Mapping({
mappable_type: 'Synapse', mappable_type: 'Synapse',
mappable_id: synapse.cid, mappable_id: synapse.cid,
}) })
Metamaps.Mappings.add(mapping) DataModel.Mappings.add(mapping)
// this function also includes the creation of the synapse in the database // this function also includes the creation of the synapse in the database
self.renderSynapse(mapping, synapse, node1, node2, true) self.renderSynapse(mapping, synapse, node1, node2, true)
@ -139,14 +127,14 @@ const Synapse = {
node2 node2
self.get(id, synapse => { self.get(id, synapse => {
var mapping = new Metamaps.DataModel.Mapping({ var mapping = new DataModel.Mapping({
mappable_type: 'Synapse', mappable_type: 'Synapse',
mappable_id: synapse.id, mappable_id: synapse.id,
}) })
Metamaps.Mappings.add(mapping) DataModel.Mappings.add(mapping)
topic1 = Metamaps.Topics.get(Create.newSynapse.topic1id) topic1 = DataModel.Topics.get(Create.newSynapse.topic1id)
node1 = topic1.get('node') node1 = topic1.get('node')
topic2 = Metamaps.Topics.get(Create.newSynapse.topic2id) topic2 = DataModel.Topics.get(Create.newSynapse.topic2id)
node2 = topic2.get('node') node2 = topic2.get('node')
Create.newSynapse.hide() Create.newSynapse.hide()
self.renderSynapse(mapping, synapse, node1, node2, true) self.renderSynapse(mapping, synapse, node1, node2, true)

View file

@ -1,10 +1,11 @@
/* global Metamaps, $ */ /* global $ */
import $jit from '../patched/JIT' import $jit from '../patched/JIT'
import Active from './Active' import Active from './Active'
import AutoLayout from './AutoLayout' import AutoLayout from './AutoLayout'
import Create from './Create' import Create from './Create'
import DataModel from './DataModel'
import Filter from './Filter' import Filter from './Filter'
import GlobalUI from './GlobalUI' import GlobalUI from './GlobalUI'
import JIT from './JIT' import JIT from './JIT'
@ -17,41 +18,30 @@ import TopicCard from './TopicCard'
import Util from './Util' import Util from './Util'
import Visualize from './Visualize' import Visualize from './Visualize'
/*
* Metamaps.Topic.js.erb
*
* Dependencies:
* - Metamaps.DataModel
* - Metamaps.Creators
* - Metamaps.Mappings
* - Metamaps.Synapses
* - Metamaps.Topics
*/
const noOp = () => {} const noOp = () => {}
const Topic = { const Topic = {
// this function is to retrieve a topic JSON object from the database // this function is to retrieve a topic JSON object from the database
// @param id = the id of the topic to retrieve // @param id = the id of the topic to retrieve
get: function (id, callback = noOp) { get: function (id, callback = noOp) {
// if the desired topic is not yet in the local topic repository, fetch it // if the desired topic is not yet in the local topic repository, fetch it
if (Metamaps.Topics.get(id) == undefined) { if (DataModel.Topics.get(id) == undefined) {
$.ajax({ $.ajax({
url: '/topics/' + id + '.json', url: '/topics/' + id + '.json',
success: function (data) { success: function (data) {
Metamaps.Topics.add(data) DataModel.Topics.add(data)
callback(Metamaps.Topics.get(id)) callback(DataModel.Topics.get(id))
} }
}) })
} else callback(Metamaps.Topics.get(id)) } else callback(DataModel.Topics.get(id))
}, },
launch: function (id) { launch: function (id) {
var bb = Metamaps.DataModel
var start = function (data) { var start = function (data) {
Active.Topic = new bb.Topic(data.topic) Active.Topic = new DataModel.Topic(data.topic)
Metamaps.Creators = new bb.MapperCollection(data.creators) DataModel.Creators = new DataModel.MapperCollection(data.creators)
Metamaps.Topics = new bb.TopicCollection([data.topic].concat(data.relatives)) DataModel.Topics = new DataModel.TopicCollection([data.topic].concat(data.relatives))
Metamaps.Synapses = new bb.SynapseCollection(data.synapses) DataModel.Synapses = new DataModel.SynapseCollection(data.synapses)
Metamaps.DataModel.attachCollectionEvents() DataModel.attachCollectionEvents()
document.title = Active.Topic.get('name') + ' | Metamaps' document.title = Active.Topic.get('name') + ' | Metamaps'
@ -101,7 +91,7 @@ const Topic = {
} }
}) })
Router.navigate('/topics/' + nodeid) Router.navigate('/topics/' + nodeid)
Active.Topic = Metamaps.Topics.get(nodeid) Active.Topic = DataModel.Topics.get(nodeid)
} }
}, },
fetchRelatives: function (nodes, metacode_id) { fetchRelatives: function (nodes, metacode_id) {
@ -109,10 +99,10 @@ const Topic = {
var node = $.isArray(nodes) ? nodes[0] : nodes var node = $.isArray(nodes) ? nodes[0] : nodes
var topics = Metamaps.Topics.map(function (t) { return t.id }) var topics = DataModel.Topics.map(function (t) { return t.id })
var topics_string = topics.join() var topics_string = topics.join()
var creators = Metamaps.Creators.map(function (t) { return t.id }) var creators = DataModel.Creators.map(function (t) { return t.id })
var creators_string = creators.join() var creators_string = creators.join()
var topic = node.getData('topic') var topic = node.getData('topic')
@ -124,13 +114,13 @@ const Topic = {
window.setTimeout(function() { successCallback(data) }, 100) window.setTimeout(function() { successCallback(data) }, 100)
return return
} }
if (data.creators.length > 0) Metamaps.Creators.add(data.creators) if (data.creators.length > 0) DataModel.Creators.add(data.creators)
if (data.topics.length > 0) Metamaps.Topics.add(data.topics) if (data.topics.length > 0) DataModel.Topics.add(data.topics)
if (data.synapses.length > 0) Metamaps.Synapses.add(data.synapses) if (data.synapses.length > 0) DataModel.Synapses.add(data.synapses)
var topicColl = new Metamaps.DataModel.TopicCollection(data.topics) var topicColl = new DataModel.TopicCollection(data.topics)
topicColl.add(topic) topicColl.add(topic)
var synapseColl = new Metamaps.DataModel.SynapseCollection(data.synapses) var synapseColl = new DataModel.SynapseCollection(data.synapses)
var graph = JIT.convertModelsToJIT(topicColl, synapseColl)[0] var graph = JIT.convertModelsToJIT(topicColl, synapseColl)[0]
Visualize.mGraph.op.sum(graph, { Visualize.mGraph.op.sum(graph, {
@ -142,7 +132,7 @@ const Topic = {
var i, l, t, s var i, l, t, s
Visualize.mGraph.graph.eachNode(function (n) { Visualize.mGraph.graph.eachNode(function (n) {
t = Metamaps.Topics.get(n.id) t = DataModel.Topics.get(n.id)
t.set({ node: n }, { silent: true }) t.set({ node: n }, { silent: true })
t.updateNode() t.updateNode()
@ -152,7 +142,7 @@ const Topic = {
l = edge.getData('synapseIDs').length l = edge.getData('synapseIDs').length
for (i = 0; i < l; i++) { for (i = 0; i < l; i++) {
s = Metamaps.Synapses.get(edge.getData('synapseIDs')[i]) s = DataModel.Synapses.get(edge.getData('synapseIDs')[i])
s.set({ edge: edge }, { silent: true }) s.set({ edge: edge }, { silent: true })
s.updateEdge() s.updateEdge()
} }
@ -309,25 +299,25 @@ const Topic = {
$(document).trigger(Map.events.editedByActiveMapper) $(document).trigger(Map.events.editedByActiveMapper)
var metacode = Metamaps.Metacodes.get(Create.newTopic.metacode) var metacode = DataModel.Metacodes.get(Create.newTopic.metacode)
var topic = new Metamaps.DataModel.Topic({ var topic = new DataModel.Topic({
name: Create.newTopic.name, name: Create.newTopic.name,
metacode_id: metacode.id, metacode_id: metacode.id,
defer_to_map_id: Active.Map.id defer_to_map_id: Active.Map.id
}) })
Metamaps.Topics.add(topic) DataModel.Topics.add(topic)
if (Create.newTopic.pinned) { if (Create.newTopic.pinned) {
var nextCoords = AutoLayout.getNextCoord({ mappings: Metamaps.Mappings }) var nextCoords = AutoLayout.getNextCoord({ mappings: DataModel.Mappings })
} }
var mapping = new Metamaps.DataModel.Mapping({ var mapping = new DataModel.Mapping({
xloc: nextCoords ? nextCoords.x : Create.newTopic.x, xloc: nextCoords ? nextCoords.x : Create.newTopic.x,
yloc: nextCoords ? nextCoords.y : Create.newTopic.y, yloc: nextCoords ? nextCoords.y : Create.newTopic.y,
mappable_id: topic.cid, mappable_id: topic.cid,
mappable_type: 'Topic', mappable_type: 'Topic',
}) })
Metamaps.Mappings.add(mapping) DataModel.Mappings.add(mapping)
// these can't happen until the value is retrieved, which happens in the line above // these can't happen until the value is retrieved, which happens in the line above
if (!Create.newTopic.pinned) Create.newTopic.hide() if (!Create.newTopic.pinned) Create.newTopic.hide()
@ -348,15 +338,15 @@ const Topic = {
self.get(id, (topic) => { self.get(id, (topic) => {
if (Create.newTopic.pinned) { if (Create.newTopic.pinned) {
var nextCoords = AutoLayout.getNextCoord({ mappings: Metamaps.Mappings }) var nextCoords = AutoLayout.getNextCoord({ mappings: DataModel.Mappings })
} }
var mapping = new Metamaps.Backbone.Mapping({ var mapping = new DataModel.Mapping({
xloc: nextCoords ? nextCoords.x : Create.newTopic.x, xloc: nextCoords ? nextCoords.x : Create.newTopic.x,
yloc: nextCoords ? nextCoords.y : Create.newTopic.y, yloc: nextCoords ? nextCoords.y : Create.newTopic.y,
mappable_type: 'Topic', mappable_type: 'Topic',
mappable_id: topic.id, mappable_id: topic.id,
}) })
Metamaps.Mappings.add(mapping) DataModel.Mappings.add(mapping)
self.renderTopic(mapping, topic, true, true) self.renderTopic(mapping, topic, true, true)
// this blocked the enterKeyHandler from creating a new topic as well // this blocked the enterKeyHandler from creating a new topic as well
@ -364,11 +354,11 @@ const Topic = {
}) })
}, },
getMapFromAutocomplete: function (data) { getMapFromAutocomplete: function (data) {
var self = Metamaps.Topic var self = Topic
$(document).trigger(Metamaps.Map.events.editedByActiveMapper) $(document).trigger(Map.events.editedByActiveMapper)
var metacode = Metamaps.Metacodes.findWhere({ name: 'Metamap' }) var metacode = DataModel.Metacodes.findWhere({ name: 'Metamap' })
var topic = new Metamaps.Backbone.Topic({ var topic = new Metamaps.Backbone.Topic({
name: data.name, name: data.name,
metacode_id: metacode.id, metacode_id: metacode.id,
@ -377,13 +367,13 @@ const Topic = {
}) })
Metamaps.Topics.add(topic) Metamaps.Topics.add(topic)
var mapping = new Metamaps.DataModel.Mapping({ var mapping = new DataModel.Mapping({
xloc: Metamaps.Create.newTopic.x, xloc: Create.newTopic.x,
yloc: Metamaps.Create.newTopic.y, yloc: Create.newTopic.y,
mappable_id: topic.cid, mappable_id: topic.cid,
mappable_type: 'Topic', mappable_type: 'Topic',
}) })
Metamaps.Mappings.add(mapping) DataModel.Mappings.add(mapping)
// these can't happen until the value is retrieved, which happens in the line above // these can't happen until the value is retrieved, which happens in the line above
if (!Create.newTopic.pinned) Create.newTopic.hide() if (!Create.newTopic.pinned) Create.newTopic.hide()
@ -399,14 +389,14 @@ const Topic = {
$(document).trigger(Map.events.editedByActiveMapper) $(document).trigger(Map.events.editedByActiveMapper)
self.get(id, (topic) => { self.get(id, (topic) => {
var nextCoords = AutoLayout.getNextCoord({ mappings: Metamaps.Mappings }) var nextCoords = AutoLayout.getNextCoord({ mappings: DataModel.Mappings })
var mapping = new Metamaps.DataModel.Mapping({ var mapping = new DataModel.Mapping({
xloc: nextCoords.x, xloc: nextCoords.x,
yloc: nextCoords.y, yloc: nextCoords.y,
mappable_type: 'Topic', mappable_type: 'Topic',
mappable_id: topic.id, mappable_id: topic.id,
}) })
Metamaps.Mappings.add(mapping) DataModel.Mappings.add(mapping)
self.renderTopic(mapping, topic, true, true) self.renderTopic(mapping, topic, true, true)
GlobalUI.notifyUser('Topic was added to your map!') GlobalUI.notifyUser('Topic was added to your map!')
}) })

View file

@ -1,18 +1,13 @@
/* global Metamaps, $, CanvasLoader, Countable, Hogan, embedly */ /* global $, CanvasLoader, Countable, Hogan, embedly */
import Active from './Active' import Active from './Active'
import DataModel from './DataModel'
import GlobalUI from './GlobalUI' import GlobalUI from './GlobalUI'
import Mapper from './Mapper' import Mapper from './Mapper'
import Router from './Router' import Router from './Router'
import Util from './Util' import Util from './Util'
import Visualize from './Visualize' import Visualize from './Visualize'
/*
* Metamaps.TopicCard.js
*
* Dependencies:
* - Metamaps.Metacodes
*/
const TopicCard = { const TopicCard = {
openTopicCard: null, // stores the topic that's currently open openTopicCard: null, // stores the topic that's currently open
authorizedToEdit: false, // stores boolean for edit permission for open topic card authorizedToEdit: false, // stores boolean for edit permission for open topic card
@ -182,7 +177,7 @@ const TopicCard = {
var metacodeLiClick = function () { var metacodeLiClick = function () {
selectingMetacode = false selectingMetacode = false
var metacodeId = parseInt($(this).attr('data-id')) var metacodeId = parseInt($(this).attr('data-id'))
var metacode = Metamaps.Metacodes.get(metacodeId) var metacode = DataModel.Metacodes.get(metacodeId)
$('.CardOnGraph').find('.metacodeTitle').html(metacode.get('name')) $('.CardOnGraph').find('.metacodeTitle').html(metacode.get('name'))
.append('<div class="expandMetacodeSelect"></div>') .append('<div class="expandMetacodeSelect"></div>')
.attr('class', 'metacodeTitle mbg' + metacode.id) .attr('class', 'metacodeTitle mbg' + metacode.id)

View file

@ -1,4 +1,4 @@
/* global Metamaps, $ */ /* global $ */
import React from 'react' import React from 'react'
import ReactDOM from 'react-dom' // TODO ensure this isn't a double import import ReactDOM from 'react-dom' // TODO ensure this isn't a double import

View file

@ -1,4 +1,4 @@
/* global Metamaps, $ */ /* global $ */
import Backbone from 'backbone' import Backbone from 'backbone'
import attachMediaStream from 'attachmediastream' import attachMediaStream from 'attachmediastream'
@ -7,16 +7,12 @@ import attachMediaStream from 'attachmediastream'
// Backbone.$ = window.$ // Backbone.$ = window.$
import Active from '../Active' import Active from '../Active'
import DataModel from '../DataModel'
import Realtime from '../Realtime' import Realtime from '../Realtime'
import ChatView from './ChatView' import ChatView from './ChatView'
import VideoView from './VideoView' import VideoView from './VideoView'
/*
* Dependencies:
* Metamaps.DataModel
*/
const Room = function(opts) { const Room = function(opts) {
var self = this var self = this
@ -170,14 +166,14 @@ Room.prototype.init = function () {
var self = this var self = this
//this.roomRef.child('messages').push(data) //this.roomRef.child('messages').push(data)
if (self.chat.alertSound) self.chat.sound.play('sendchat') if (self.chat.alertSound) self.chat.sound.play('sendchat')
var m = new Metamaps.DataModel.Message({ var m = new DataModel.Message({
message: data.message, message: data.message,
resource_id: Active.Map.id, resource_id: Active.Map.id,
resource_type: "Map" resource_type: "Map"
}) })
m.save(null, { m.save(null, {
success: function (model, response) { success: function (model, response) {
self.addMessages(new Metamaps.DataModel.MessageCollection(model), false, true) self.addMessages(new DataModel.MessageCollection(model), false, true)
$(document).trigger(Room.events.newMessage, [model]) $(document).trigger(Room.events.newMessage, [model])
}, },
error: function (model, response) { error: function (model, response) {

View file

@ -1,24 +1,16 @@
/* global Metamaps, $ */ /* global $ */
import _ from 'lodash' import _ from 'lodash'
import $jit from '../patched/JIT' import $jit from '../patched/JIT'
import Active from './Active' import Active from './Active'
import DataModel from './DataModel'
import JIT from './JIT' import JIT from './JIT'
import Loading from './Loading' import Loading from './Loading'
import Router from './Router' import Router from './Router'
import TopicCard from './TopicCard' import TopicCard from './TopicCard'
/*
* Metamaps.Visualize
*
* Dependencies:
* - Metamaps.Metacodes
* - Metamaps.Synapses
* - Metamaps.Topics
*/
const Visualize = { const Visualize = {
mGraph: null, // a reference to the graph object. mGraph: null, // a reference to the graph object.
cameraPosition: null, // stores the camera position when using a 3D visualization cameraPosition: null, // stores the camera position when using a 3D visualization
@ -27,6 +19,9 @@ const Visualize = {
touchDragNode: null, touchDragNode: null,
init: function () { init: function () {
var self = Visualize var self = Visualize
if (serverData.VisualizeType) self.type = serverData.VisualizeType
// disable awkward dragging of the canvas element that would sometimes happen // disable awkward dragging of the canvas element that would sometimes happen
$('#infovis-canvas').on('dragstart', function (event) { $('#infovis-canvas').on('dragstart', function (event) {
event.preventDefault() event.preventDefault()
@ -59,7 +54,7 @@ const Visualize = {
var i, l, startPos, endPos, topic, synapse var i, l, startPos, endPos, topic, synapse
self.mGraph.graph.eachNode(function (n) { self.mGraph.graph.eachNode(function (n) {
topic = Metamaps.Topics.get(n.id) topic = DataModel.Topics.get(n.id)
topic.set({ node: n }, { silent: true }) topic.set({ node: n }, { silent: true })
topic.updateNode() topic.updateNode()
@ -69,7 +64,7 @@ const Visualize = {
l = edge.getData('synapseIDs').length l = edge.getData('synapseIDs').length
for (i = 0; i < l; i++) { for (i = 0; i < l; i++) {
synapse = Metamaps.Synapses.get(edge.getData('synapseIDs')[i]) synapse = DataModel.Synapses.get(edge.getData('synapseIDs')[i])
synapse.set({ edge: edge }, { silent: true }) synapse.set({ edge: edge }, { silent: true })
synapse.updateEdge() synapse.updateEdge()
} }
@ -84,7 +79,7 @@ const Visualize = {
var i, l, startPos, endPos, topic, synapse var i, l, startPos, endPos, topic, synapse
self.mGraph.graph.eachNode(function (n) { self.mGraph.graph.eachNode(function (n) {
topic = Metamaps.Topics.get(n.id) topic = DataModel.Topics.get(n.id)
topic.set({ node: n }, { silent: true }) topic.set({ node: n }, { silent: true })
topic.updateNode() topic.updateNode()
mapping = topic.getMapping() mapping = topic.getMapping()
@ -95,7 +90,7 @@ const Visualize = {
l = edge.getData('synapseIDs').length l = edge.getData('synapseIDs').length
for (i = 0; i < l; i++) { for (i = 0; i < l; i++) {
synapse = Metamaps.Synapses.get(edge.getData('synapseIDs')[i]) synapse = DataModel.Synapses.get(edge.getData('synapseIDs')[i])
synapse.set({ edge: edge }, { silent: true }) synapse.set({ edge: edge }, { silent: true })
synapse.updateEdge() synapse.updateEdge()
} }
@ -189,12 +184,12 @@ const Visualize = {
// hold for a maximum of 80 passes, or 4 seconds of waiting time // hold for a maximum of 80 passes, or 4 seconds of waiting time
var tries = 0 var tries = 0
function hold () { function hold () {
var unique = _.uniq(Metamaps.Topics.models, function (metacode) { return metacode.get('metacode_id'); }), var unique = _.uniq(DataModel.Topics.models, function (metacode) { return metacode.get('metacode_id'); }),
requiredMetacodes = _.map(unique, function (metacode) { return metacode.get('metacode_id'); }), requiredMetacodes = _.map(unique, function (metacode) { return metacode.get('metacode_id'); }),
loadedCount = 0 loadedCount = 0
_.each(requiredMetacodes, function (metacode_id) { _.each(requiredMetacodes, function (metacode_id) {
var metacode = Metamaps.Metacodes.get(metacode_id), var metacode = DataModel.Metacodes.get(metacode_id),
img = metacode ? metacode.get('image') : false img = metacode ? metacode.get('image') : false
if (img && (img.complete || (typeof img.naturalWidth !== 'undefined' && img.naturalWidth !== 0))) { if (img && (img.complete || (typeof img.naturalWidth !== 'undefined' && img.naturalWidth !== 0))) {