diff --git a/app/views/explore/active.html.erb b/app/views/explore/active.html.erb index 0ca442e5..fd9ebe68 100644 --- a/app/views/explore/active.html.erb +++ b/app/views/explore/active.html.erb @@ -5,11 +5,11 @@ # %> diff --git a/app/views/explore/featured.html.erb b/app/views/explore/featured.html.erb index 806b2fac..15ab97fc 100644 --- a/app/views/explore/featured.html.erb +++ b/app/views/explore/featured.html.erb @@ -5,11 +5,11 @@ # %> diff --git a/app/views/explore/mapper.html.erb b/app/views/explore/mapper.html.erb index 68792f47..7669b808 100644 --- a/app/views/explore/mapper.html.erb +++ b/app/views/explore/mapper.html.erb @@ -5,14 +5,14 @@ # %> diff --git a/app/views/explore/mine.html.erb b/app/views/explore/mine.html.erb index 8e39c296..8bf2da6f 100644 --- a/app/views/explore/mine.html.erb +++ b/app/views/explore/mine.html.erb @@ -5,11 +5,11 @@ # %> diff --git a/app/views/explore/shared.html.erb b/app/views/explore/shared.html.erb index 246498a0..a47757ec 100644 --- a/app/views/explore/shared.html.erb +++ b/app/views/explore/shared.html.erb @@ -5,11 +5,11 @@ # %> diff --git a/app/views/explore/starred.html.erb b/app/views/explore/starred.html.erb index 825dbf5d..83c8de13 100644 --- a/app/views/explore/starred.html.erb +++ b/app/views/explore/starred.html.erb @@ -5,11 +5,11 @@ # %> diff --git a/app/views/layouts/_templates.html.erb b/app/views/layouts/_templates.html.erb index 921a7d88..9e298b3c 100644 --- a/app/views/layouts/_templates.html.erb +++ b/app/views/layouts/_templates.html.erb @@ -4,50 +4,49 @@ #%>
- - + - + - + - + - + - - - - - - + + + + +
diff --git a/app/views/main/home.html.erb b/app/views/main/home.html.erb index d6e99b48..16870f13 100644 --- a/app/views/main/home.html.erb +++ b/app/views/main/home.html.erb @@ -33,7 +33,8 @@ + diff --git a/app/views/maps/show.html.erb b/app/views/maps/show.html.erb index ae391d6d..b25c7610 100644 --- a/app/views/maps/show.html.erb +++ b/app/views/maps/show.html.erb @@ -18,5 +18,5 @@ Metamaps.ServerData.Mappings = <%= @allmappings.to_json.html_safe %>; Metamaps.Messages = <%= @allmessages.to_json.html_safe %>; Metamaps.Stars = <%= @allstars.to_json.html_safe %>; - Metamaps.Visualize.type = "ForceDirected"; + Metamaps.ServerData.VisualizeType = "ForceDirected"; diff --git a/app/views/shared/_switchmetacodes.html.erb b/app/views/shared/_switchmetacodes.html.erb index 24739716..4c56dd41 100644 --- a/app/views/shared/_switchmetacodes.html.erb +++ b/app/views/shared/_switchmetacodes.html.erb @@ -117,6 +117,6 @@
diff --git a/frontend/src/Metamaps/Control.js b/frontend/src/Metamaps/Control.js index 7662f47d..8305e097 100644 --- a/frontend/src/Metamaps/Control.js +++ b/frontend/src/Metamaps/Control.js @@ -1,9 +1,10 @@ -/* global Metamaps, $ */ +/* global $ */ import _ from 'lodash' import outdent from 'outdent' import Active from './Active' +import DataModel from './DataModel' import Filter from './Filter' import GlobalUI from './GlobalUI' import JIT from './JIT' @@ -12,16 +13,6 @@ import Selected from './Selected' import Settings from './Settings' import Visualize from './Visualize' -/* - * Metamaps.Control.js - * - * Dependencies: - * - Metamaps.Mappings - * - Metamaps.Metacodes - * - Metamaps.Synapses - * - Metamaps.Topics - */ - const Control = { init: function () {}, selectNode: function (node, e) { @@ -72,7 +63,7 @@ const Control = { Control.deleteSelectedNodes() } - if (Metamaps.Topics.length === 0) { + if (DataModel.Topics.length === 0) { GlobalUI.showDiv('#instructions') } }, @@ -110,7 +101,7 @@ const Control = { var mappableid = topic.id var mapping = node.getData('mapping') topic.destroy() - Metamaps.Mappings.remove(mapping) + DataModel.Mappings.remove(mapping) $(document).trigger(JIT.events.deleteTopic, [{ mappableid: mappableid }]) @@ -127,7 +118,7 @@ const Control = { }) _.each(nodeids, function(nodeid) { if (Active.Topic.id !== nodeid) { - Metamaps.Topics.remove(nodeid) + DataModel.Topics.remove(nodeid) Control.hideNode(nodeid) } }) @@ -165,7 +156,7 @@ const Control = { var mappableid = topic.id var mapping = node.getData('mapping') mapping.destroy() - Metamaps.Topics.remove(topic) + DataModel.Topics.remove(topic) $(document).trigger(JIT.events.removeTopic, [{ mappableid: mappableid }]) @@ -293,7 +284,7 @@ const Control = { synapse.destroy() // 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('synapses').splice(index, 1) if (edge.getData('displayIndex')) { @@ -348,7 +339,7 @@ const Control = { var mappableid = synapse.id mapping.destroy() - Metamaps.Synapses.remove(synapse) + DataModel.Synapses.remove(synapse) edge.getData('mappings').splice(index, 1) edge.getData('synapses').splice(index, 1) @@ -432,7 +423,7 @@ const Control = { 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 var nCount = 0 diff --git a/frontend/src/Metamaps/Create.js b/frontend/src/Metamaps/Create.js index 1327821f..d12a5de5 100644 --- a/frontend/src/Metamaps/Create.js +++ b/frontend/src/Metamaps/Create.js @@ -1,5 +1,6 @@ -/* global Metamaps, $, Hogan, Bloodhound */ +/* global $, Hogan, Bloodhound */ +import DataModel from './DataModel' import Mouse from './Mouse' import Selected from './Selected' import Synapse from './Synapse' @@ -7,15 +8,6 @@ import Topic from './Topic' import Visualize from './Visualize' import GlobalUI from './GlobalUI' -/* - * Metamaps.Create.js - * - * Dependencies: - * - Metamaps.DataModel - * - Metamaps.Metacodes - * - Metamaps.Topics - */ - const Create = { isSwitchingSet: false, // indicates whether the metacode set switch lightbox is open selectedMetacodeSet: null, @@ -59,7 +51,7 @@ const Create = { } var codesToSwitchToIds - var metacodeModels = new Metamaps.DataModel.MetacodeCollection() + var metacodeModels = new DataModel.MetacodeCollection() Create.selectedMetacodeSetIndex = index Create.selectedMetacodeSet = 'metacodeset-' + set @@ -80,7 +72,7 @@ const Create = { // sort by name for (var i = 0; i < codesToSwitchToIds.length; i++) { - metacodeModels.add(Metamaps.Metacodes.get(codesToSwitchToIds[i])) + metacodeModels.add(DataModel.Metacodes.get(codesToSwitchToIds[i])) } metacodeModels.sort() @@ -243,7 +235,7 @@ const Create = { $('.pinCarousel').removeClass('isPinned') Create.newTopic.pinned = false } - if (Metamaps.Topics.length === 0) { + if (DataModel.Topics.length === 0) { GlobalUI.showDiv('#instructions') } Create.newTopic.beingCreated = false diff --git a/frontend/src/Metamaps/DataModel/MapCollection.js b/frontend/src/Metamaps/DataModel/MapCollection.js index a08309df..69b2f5a8 100644 --- a/frontend/src/Metamaps/DataModel/MapCollection.js +++ b/frontend/src/Metamaps/DataModel/MapCollection.js @@ -1,5 +1,3 @@ -/* global Metamaps */ - import Backbone from 'backbone' Backbone.$ = window.$ diff --git a/frontend/src/Metamaps/DataModel/Synapse.js b/frontend/src/Metamaps/DataModel/Synapse.js index b9a3153b..0be1cfda 100644 --- a/frontend/src/Metamaps/DataModel/Synapse.js +++ b/frontend/src/Metamaps/DataModel/Synapse.js @@ -11,10 +11,10 @@ import Realtime from '../Realtime' import SynapseCard from '../SynapseCard' import Visualize from '../Visualize' +import DataModel from './index' + /* - * Dependencies: - * - Metamaps.Mappings - * - Metamaps.Topics + * Metamaps.Erb */ const Synapse = Backbone.Model.extend({ @@ -96,10 +96,10 @@ const Synapse = Backbone.Model.extend({ else return false }, getTopic1: function () { - return Metamaps.Topics.get(this.get('topic1_id')) + return DataModel.Topics.get(this.get('topic1_id')) }, getTopic2: function () { - return Metamaps.Topics.get(this.get('topic2_id')) + return DataModel.Topics.get(this.get('topic2_id')) }, getDirection: function () { var t1 = this.getTopic1() @@ -113,7 +113,7 @@ const Synapse = Backbone.Model.extend({ getMapping: function () { if (!Active.Map) return false - return Metamaps.Mappings.findWhere({ + return DataModel.Mappings.findWhere({ map_id: Active.Map.id, mappable_type: 'Synapse', mappable_id: this.isNew() ? this.cid : this.id diff --git a/frontend/src/Metamaps/DataModel/Topic.js b/frontend/src/Metamaps/DataModel/Topic.js index 3d27814e..cd709a24 100644 --- a/frontend/src/Metamaps/DataModel/Topic.js +++ b/frontend/src/Metamaps/DataModel/Topic.js @@ -1,4 +1,4 @@ -/* global Metamaps, $ */ +/* global $ */ import _ from 'lodash' import Backbone from 'backbone' @@ -11,11 +11,7 @@ import Realtime from '../Realtime' import TopicCard from '../TopicCard' import Visualize from '../Visualize' -/* - * Dependencies: - * - Metamaps.Mappings - * - Metamaps.Metacodes - */ +import DataModel from './index' const Topic = Backbone.Model.extend({ urlRoot: '/topics', @@ -99,12 +95,12 @@ const Topic = Backbone.Model.extend({ }, getDate: function () {}, getMetacode: function () { - return Metamaps.Metacodes.get(this.get('metacode_id')) + return DataModel.Metacodes.get(this.get('metacode_id')) }, getMapping: function () { if (!Active.Map) return false - return Metamaps.Mappings.findWhere({ + return DataModel.Mappings.findWhere({ map_id: Active.Map.id, mappable_type: 'Topic', mappable_id: this.isNew() ? this.cid : this.id diff --git a/frontend/src/Metamaps/DataModel/index.js b/frontend/src/Metamaps/DataModel/index.js index bd9cc342..c973cb3b 100644 --- a/frontend/src/Metamaps/DataModel/index.js +++ b/frontend/src/Metamaps/DataModel/index.js @@ -1,5 +1,3 @@ -/* global Metamaps */ - import Active from '../Active' import Filter from '../Filter' import { InfoBox } from '../Map' @@ -19,19 +17,6 @@ import SynapseCollection from './SynapseCollection' import Mapping from './Mapping' import MappingCollection from './MappingCollection' -/* - * DataModel.js - * - * Dependencies: - * - Metamaps.Collaborators - * - Metamaps.Creators - * - Metamaps.Mappers - * - Metamaps.Mappings - * - Metamaps.Metacodes - * - Metamaps.Synapses - * - Metamaps.Topics - */ - const DataModel = { Map: Map, MapCollection: MapCollection, @@ -48,45 +33,50 @@ const DataModel = { Mapping: Mapping, MappingCollection: MappingCollection, - Metacodes: new MetacodeCollection(), - Topics: new TopicCollection(), - Synapses: new SynapseCollection(), - Mappings: new MappingCollection(), - Mappers: new MapperCollection(), Collaborators: 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) { 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) - - // attach collection event listeners + if (serverData.Stars) self.Stars = serverData.Stars + if (serverData.Synapses) self.Synapses = new SynapseCollection(serverData.Synapses) if (serverData.Topics) self.Topics = new TopicCollection(serverData.Topics) + + self.attachCollectionEvents() + }, + + attachCollectionEvents: function () { + var self = DataModel self.Topics.on('add remove', function (topic) { InfoBox.updateNumbers() Filter.checkMetacodes() Filter.checkMappers() }) - - if (serverData.Synapses) self.Synapses = new SynapseCollection(serverData.Synapses) self.Synapses.on('add remove', function (synapse) { InfoBox.updateNumbers() Filter.checkSynapses() 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() }) - - 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) } } diff --git a/frontend/src/Metamaps/Filter.js b/frontend/src/Metamaps/Filter.js index 59aa1bae..271e5758 100644 --- a/frontend/src/Metamaps/Filter.js +++ b/frontend/src/Metamaps/Filter.js @@ -1,23 +1,14 @@ -/* global Metamaps, $ */ +/* global $ */ import _ from 'lodash' import Active from './Active' import Control from './Control' +import DataModel from './DataModel' import GlobalUI from './GlobalUI' import Settings from './Settings' import Visualize from './Visualize' -/* - * Metamaps.Filter.js.erb - * - * Dependencies: - * - Metamaps.Creators - * - Metamaps.Mappers - * - Metamaps.Metacodes - * - Metamaps.Synapses - * - Metamaps.Topics - */ const Filter = { filters: { name: '', @@ -148,7 +139,7 @@ const Filter = { // the first option enables us to accept // ['Topics', 'Synapses'] as 'collection' if (typeof collection === 'object') { - Metamaps[collection[0]].each(function (model) { + DataModel[collection[0]].each(function (model) { var prop = model.get(propertyToCheck) if (prop !== null) { 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) if (prop !== null) { prop = prop.toString() @@ -167,7 +158,7 @@ const Filter = { } }) } else if (typeof collection === 'string') { - Metamaps[collection].each(function (model) { + DataModel[collection].each(function (model) { var prop = model.get(propertyToCheck) if (prop !== null) { 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 _.each(added, function (identifier) { - model = Metamaps[correlatedModel].get(identifier) || - Metamaps[correlatedModel].find(function (model) { + model = DataModel[correlatedModel].get(identifier) || + DataModel[correlatedModel].find(function (model) { return model.get(propertyToCheck) === identifier }) li = model.prepareLiForFilter() @@ -359,7 +350,7 @@ const Filter = { var opacityForFilter = onMap ? 0 : 0.4 - Metamaps.Topics.each(function (topic) { + DataModel.Topics.each(function (topic) { var n = topic.get('node') var metacode_id = topic.get('metacode_id').toString() @@ -400,11 +391,11 @@ const Filter = { }) // flag all the edges back to 'untouched' - Metamaps.Synapses.each(function (synapse) { + DataModel.Synapses.each(function (synapse) { var e = synapse.get('edge') e.setData('touched', false) }) - Metamaps.Synapses.each(function (synapse) { + DataModel.Synapses.each(function (synapse) { var e = synapse.get('edge') var desc var user_id = synapse.get('user_id').toString() diff --git a/frontend/src/Metamaps/GlobalUI/CreateMap.js b/frontend/src/Metamaps/GlobalUI/CreateMap.js index d53b4106..97110c91 100644 --- a/frontend/src/Metamaps/GlobalUI/CreateMap.js +++ b/frontend/src/Metamaps/GlobalUI/CreateMap.js @@ -1,13 +1,9 @@ -/* global Metamaps, $ */ +/* global $ */ import Active from '../Active' +import DataModel from '../DataModel' import GlobalUI from './index' -/* - * Metamaps.DataModel - * Metamaps.Maps - */ - const CreateMap = { newMap: null, emptyMapForm: '', @@ -17,7 +13,7 @@ const CreateMap = { init: function () { var self = CreateMap - self.newMap = new Metamaps.DataModel.Map({ permission: 'commons' }) + self.newMap = new DataModel.Map({ permission: 'commons' }) self.bindFormEvents() @@ -109,7 +105,7 @@ const CreateMap = { success: function (model) { var self = CreateMap // push the new map onto the collection of 'my maps' - Metamaps.Maps.Mine.add(model) + DataModel.Maps.Mine.add(model) GlobalUI.clearNotify() $('#wrapper').append(self.generateSuccessMessage(model.id)) @@ -128,7 +124,7 @@ const CreateMap = { } self.bindFormEvents() - self.newMap = new Metamaps.DataModel.Map({ permission: 'commons' }) + self.newMap = new DataModel.Map({ permission: 'commons' }) return false } diff --git a/frontend/src/Metamaps/GlobalUI/Search.js b/frontend/src/Metamaps/GlobalUI/Search.js index 82293ac3..eb5fe0a7 100644 --- a/frontend/src/Metamaps/GlobalUI/Search.js +++ b/frontend/src/Metamaps/GlobalUI/Search.js @@ -5,7 +5,6 @@ import Router from '../Router' /* * Metamaps.Erb - * Metamaps.Maps */ const Search = { diff --git a/frontend/src/Metamaps/GlobalUI/index.js b/frontend/src/Metamaps/GlobalUI/index.js index e82516c2..2444925a 100644 --- a/frontend/src/Metamaps/GlobalUI/index.js +++ b/frontend/src/Metamaps/GlobalUI/index.js @@ -1,20 +1,16 @@ -/* global Metamaps, $ */ +/* global $ */ import clipboard from 'clipboard-js' import Active from '../Active' import Create from '../Create' +import DataModel from '../DataModel' import Search from './Search' import CreateMap from './CreateMap' import Account from './Account' import ImportDialog from './ImportDialog' -/* - * Metamaps.DataModel - * Metamaps.Maps - */ - const GlobalUI = { notifyTimeout: null, lightbox: null, @@ -38,26 +34,26 @@ const GlobalUI = { $('#lightbox_screen, #lightbox_close').click(self.closeLightbox) // 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 sharedCollection = Metamaps.Maps.Shared ? Metamaps.Maps.Shared : [] - var starredCollection = Metamaps.Maps.Starred ? Metamaps.Maps.Starred : [] + var myCollection = DataModel.Maps.Mine ? DataModel.Maps.Mine : [] + var sharedCollection = DataModel.Maps.Shared ? DataModel.Maps.Shared : [] + var starredCollection = DataModel.Maps.Starred ? DataModel.Maps.Starred : [] var mapperCollection = [] var mapperOptionsObj = { id: 'mapper', sortBy: 'updated_at' } - if (Metamaps.Maps.Mapper) { - mapperCollection = Metamaps.Maps.Mapper.models - mapperOptionsObj.mapperId = Metamaps.Maps.Mapper.id + if (DataModel.Maps.Mapper) { + mapperCollection = DataModel.Maps.Mapper.models + mapperOptionsObj.mapperId = DataModel.Maps.Mapper.id } - var featuredCollection = Metamaps.Maps.Featured ? Metamaps.Maps.Featured : [] - var activeCollection = Metamaps.Maps.Active ? Metamaps.Maps.Active : [] - Metamaps.Maps.Mine = new Metamaps.DataModel.MapCollection(myCollection, { id: 'mine', sortBy: 'updated_at' }) - Metamaps.Maps.Shared = new Metamaps.DataModel.MapCollection(sharedCollection, { id: 'shared', sortBy: 'updated_at' }) - Metamaps.Maps.Starred = new Metamaps.DataModel.MapCollection(starredCollection, { id: 'starred', sortBy: 'updated_at' }) + var featuredCollection = DataModel.Maps.Featured ? DataModel.Maps.Featured : [] + var activeCollection = DataModel.Maps.Active ? DataModel.Maps.Active : [] + DataModel.Maps.Mine = new DataModel.MapCollection(myCollection, { id: 'mine', sortBy: 'updated_at' }) + DataModel.Maps.Shared = new DataModel.MapCollection(sharedCollection, { id: 'shared', sortBy: 'updated_at' }) + DataModel.Maps.Starred = new DataModel.MapCollection(starredCollection, { id: 'starred', sortBy: 'updated_at' }) // 'Mapper' refers to another mapper - Metamaps.Maps.Mapper = new Metamaps.DataModel.MapCollection(mapperCollection, mapperOptionsObj) - Metamaps.Maps.Featured = new Metamaps.DataModel.MapCollection(featuredCollection, { id: 'featured', sortBy: 'updated_at' }) - Metamaps.Maps.Active = new Metamaps.DataModel.MapCollection(activeCollection, { id: 'active', sortBy: 'updated_at' }) + DataModel.Maps.Mapper = new DataModel.MapCollection(mapperCollection, mapperOptionsObj) + DataModel.Maps.Featured = new DataModel.MapCollection(featuredCollection, { id: 'featured', sortBy: 'updated_at' }) + DataModel.Maps.Active = new DataModel.MapCollection(activeCollection, { id: 'active', sortBy: 'updated_at' }) }, showDiv: function (selector) { $(selector).show() diff --git a/frontend/src/Metamaps/Import.js b/frontend/src/Metamaps/Import.js index b829c0b1..d273edbb 100644 --- a/frontend/src/Metamaps/Import.js +++ b/frontend/src/Metamaps/Import.js @@ -1,26 +1,16 @@ -/* global Metamaps, $ */ +/* global $ */ import parse from 'csv-parse' import _ from 'lodash' import Active from './Active' import AutoLayout from './AutoLayout' +import DataModel from './DataModel' import GlobalUI from './GlobalUI' import Map from './Map' import Synapse from './Synapse' import Topic from './Topic' -/* - * Metamaps.Import.js.erb - * - * Dependencies: - * - Metamaps.DataModel - * - Metamaps.Mappings - * - Metamaps.Metacodes - * - Metamaps.Synapses - * - Metamaps.Topics - */ - const Import = { // note that user is not imported topicWhitelist: [ @@ -255,10 +245,10 @@ const Import = { parsedSynapses.forEach(function (synapse) { // only createSynapseWithParameters once both topics are persisted // if there isn't a cidMapping, check by topic name instead - var topic1 = Metamaps.Topics.get(self.cidMappings[synapse.topic1]) - if (!topic1) topic1 = Metamaps.Topics.findWhere({ name: synapse.topic1 }) - var topic2 = Metamaps.Topics.get(self.cidMappings[synapse.topic2]) - if (!topic2) topic2 = Metamaps.Topics.findWhere({ name: synapse.topic2 }) + var topic1 = DataModel.Topics.get(self.cidMappings[synapse.topic1]) + if (!topic1) topic1 = DataModel.Topics.findWhere({ name: synapse.topic1 }) + var topic2 = DataModel.Topics.get(self.cidMappings[synapse.topic2]) + if (!topic2) topic2 = DataModel.Topics.findWhere({ name: synapse.topic2 }) if (!topic1 || !topic2) { console.error("One of the two topics doesn't exist!") @@ -291,15 +281,15 @@ const Import = { link, xloc, yloc, import_id, opts = {}) { var self = Import $(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) { - 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.') } var topic_permission = permission || Active.Map.get('permission') 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, metacode_id: metacode.id, permission: topic_permission, @@ -308,19 +298,19 @@ const Import = { link: link || '', calculated_permission: Active.Map.get('permission') }) - Metamaps.Topics.add(topic) + DataModel.Topics.add(topic) if (import_id !== null && import_id !== undefined) { self.cidMappings[import_id] = topic.cid } - var mapping = new Metamaps.DataModel.Mapping({ + var mapping = new DataModel.Mapping({ xloc: xloc, yloc: yloc, mappable_id: topic.cid, mappable_type: 'Topic' }) - Metamaps.Mappings.add(mapping) + DataModel.Mappings.add(mapping) // this function also includes the creation of the topic in the database Topic.renderTopic(mapping, topic, true, true, { @@ -340,20 +330,20 @@ const Import = { return } // if - var synapse = new Metamaps.DataModel.Synapse({ + var synapse = new DataModel.Synapse({ desc: desc || '', category: category || 'from-to', permission: permission, topic1_id: topic1.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_id: synapse.cid }) - Metamaps.Mappings.add(mapping) + DataModel.Mappings.add(mapping) Synapse.renderSynapse(mapping, synapse, node1, node2, true) }, diff --git a/frontend/src/Metamaps/JIT.js b/frontend/src/Metamaps/JIT.js index f8bc51e8..e57244c0 100644 --- a/frontend/src/Metamaps/JIT.js +++ b/frontend/src/Metamaps/JIT.js @@ -8,6 +8,7 @@ import $jit from '../patched/JIT' import Active from './Active' import Control from './Control' import Create from './Create' +import DataModel from './DataModel' import Filter from './Filter' import GlobalUI from './GlobalUI' import Map from './Map' @@ -25,10 +26,6 @@ import clipboard from 'clipboard-js' /* * Metamaps.Erb - * Metamaps.Mappings - * Metamaps.Metacodes - * Metamaps.Synapses - * Metamaps.Topics */ let panningInt @@ -140,15 +137,15 @@ const JIT = { self.vizData = [] Visualize.loadLater = false - const results = self.convertModelsToJIT(Metamaps.Topics, Metamaps.Synapses) + const results = self.convertModelsToJIT(DataModel.Topics, DataModel.Synapses) self.vizData = results[0] // clean up the synapses array in case of any faulty data _.each(results[1], function (synapse) { mapping = synapse.getMapping() - Metamaps.Synapses.remove(synapse) - if (Metamaps.Mappings) Metamaps.Mappings.remove(mapping) + DataModel.Synapses.remove(synapse) + if (DataModel.Mappings) DataModel.Mappings.remove(mapping) }) // set up addTopic instructions in case they delete all the topics @@ -1191,7 +1188,7 @@ const JIT = { eY = -1 * eY const edgesToToggle = [] - Metamaps.Synapses.each(function (synapse) { + DataModel.Synapses.each(function (synapse) { const e = synapse.get('edge') if (edgesToToggle.indexOf(e) === -1) { edgesToToggle.push(e) @@ -1579,15 +1576,15 @@ const JIT = { loader.setRange(0.9) // default is 1.3 loader.show() // Hidden by default - const topics = Metamaps.Topics.map(function (t) { return t.id }) - const topicsString = topics.join() + const topics = DataModel.Topics.map(function (t) { return t.id }) + const topics_string = topics.join() const successCallback = function (data) { $('#loadingSiblings').remove() for (var key in data) { - const string = Metamaps.Metacodes.get(key).get('name') + ' (' + data[key] + ')' - $('#fetchSiblingList').append('
  • ' + string + '
  • ') + const string = `${DataModel.Metacodes.get(key).get('name')} (${data[key]})` + $('#fetchSiblingList').append(`
  • ${string}
  • `) } $('.rc-siblings .getSiblings').click(function () { diff --git a/frontend/src/Metamaps/Map/InfoBox.js b/frontend/src/Metamaps/Map/InfoBox.js index 79fa6c4d..95455fd4 100644 --- a/frontend/src/Metamaps/Map/InfoBox.js +++ b/frontend/src/Metamaps/Map/InfoBox.js @@ -3,17 +3,13 @@ import outdent from 'outdent' import Active from '../Active' +import DataModel from '../DataModel' import GlobalUI from '../GlobalUI' import Router from '../Router' import Util from '../Util' /* - * Metamaps.Collaborators * Metamaps.Erb - * Metamaps.Mappers - * Metamaps.Maps - * Metamaps.Synapses - * Metamaps.Topics */ const InfoBox = { @@ -106,7 +102,7 @@ const InfoBox = { var isCreator = map.authorizePermissionChange(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' 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) { var self = InfoBox - Metamaps.Collaborators.remove(Metamaps.Collaborators.get(collaboratorId)) - var mapperIds = Metamaps.Collaborators.models.map(function (mapper) { return mapper.id }) + DataModel.Collaborators.remove(DataModel.Collaborators.get(collaboratorId)) + var mapperIds = DataModel.Collaborators.models.map(function (mapper) { return mapper.id }) $.post('/maps/' + Active.Map.id + '/access', { access: mapperIds }) self.updateNumbers() }, addCollaborator: function (newCollaboratorId) { var self = InfoBox - if (Metamaps.Collaborators.get(newCollaboratorId)) { + if (DataModel.Collaborators.get(newCollaboratorId)) { GlobalUI.notifyUser('That user already has access') return } function callback(mapper) { - Metamaps.Collaborators.add(mapper) - var mapperIds = Metamaps.Collaborators.models.map(function (mapper) { return mapper.id }) + DataModel.Collaborators.add(mapper) + var mapperIds = DataModel.Collaborators.models.map(function (mapper) { return mapper.id }) $.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') self.updateNumbers() } @@ -289,7 +285,7 @@ const InfoBox = { }, createContributorList: function () { 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 string = '' string += '