From 4b500a4428518acbe5ac9bfef5e95bb54205ca1d Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 2 Oct 2016 21:10:41 +0800 Subject: [PATCH] move Metamaps.Loading into node modules --- app/views/layouts/_foot.html.erb | 27 +++++-------------- .../src/Metamaps/DataModel/MapCollection.js | 9 +++---- frontend/src/Metamaps/DataModel/index.js | 1 - frontend/src/Metamaps/GlobalUI/Search.js | 3 +-- frontend/src/Metamaps/Loading.js | 20 ++++++++++++++ frontend/src/Metamaps/Map/index.js | 4 +-- frontend/src/Metamaps/Router.js | 6 ++--- frontend/src/Metamaps/Views/ExploreMaps.js | 6 ++--- frontend/src/Metamaps/Visualize.js | 4 +-- frontend/src/Metamaps/index.js | 2 ++ 10 files changed, 41 insertions(+), 41 deletions(-) create mode 100644 frontend/src/Metamaps/Loading.js diff --git a/app/views/layouts/_foot.html.erb b/app/views/layouts/_foot.html.erb index 1f5ad1c8..ebcc38c2 100644 --- a/app/views/layouts/_foot.html.erb +++ b/app/views/layouts/_foot.html.erb @@ -2,28 +2,13 @@ <%= render :partial => 'layouts/templates' %> <%= render :partial => 'shared/metacodeBgColors' %> <%= render :partial => 'layouts/googleanalytics' if Rails.env.production? %> diff --git a/frontend/src/Metamaps/DataModel/MapCollection.js b/frontend/src/Metamaps/DataModel/MapCollection.js index f72e1e0e..a08309df 100644 --- a/frontend/src/Metamaps/DataModel/MapCollection.js +++ b/frontend/src/Metamaps/DataModel/MapCollection.js @@ -3,12 +3,9 @@ import Backbone from 'backbone' Backbone.$ = window.$ -import Map from './Map' +import Loading from '../Loading' -/* - * Dependencies: - * - Metamaps.Loading - */ +import Map from './Map' const MapCollection = Backbone.Collection.extend({ model: Map, @@ -50,7 +47,7 @@ const MapCollection = Backbone.Collection.extend({ getMaps: function (cb) { var self = this - Metamaps.Loading.show() + Loading.show() if (this.page !== 'loadedAll') { var numBefore = this.length diff --git a/frontend/src/Metamaps/DataModel/index.js b/frontend/src/Metamaps/DataModel/index.js index 45da7156..fb80c268 100644 --- a/frontend/src/Metamaps/DataModel/index.js +++ b/frontend/src/Metamaps/DataModel/index.js @@ -25,7 +25,6 @@ import MappingCollection from './MappingCollection' * Dependencies: * - Metamaps.Collaborators * - Metamaps.Creators - * - Metamaps.Loading * - Metamaps.Mappers * - Metamaps.Mappings * - Metamaps.Metacodes diff --git a/frontend/src/Metamaps/GlobalUI/Search.js b/frontend/src/Metamaps/GlobalUI/Search.js index 7ad1fbc1..82293ac3 100644 --- a/frontend/src/Metamaps/GlobalUI/Search.js +++ b/frontend/src/Metamaps/GlobalUI/Search.js @@ -18,8 +18,7 @@ const Search = { init: function () { var self = Search - // TODO does this overlap with Metamaps.Loading? - // devin sez: I'd like to remove Metamaps.Loading from the rails code + // this is similar to Metamaps.Loading, but it's for the search element var loader = new CanvasLoader('searchLoading') loader.setColor('#4fb5c0') // default is '#000000' loader.setDiameter(24) // default is 40 diff --git a/frontend/src/Metamaps/Loading.js b/frontend/src/Metamaps/Loading.js new file mode 100644 index 00000000..97275547 --- /dev/null +++ b/frontend/src/Metamaps/Loading.js @@ -0,0 +1,20 @@ +/* global CanvasLoader, $ */ + +const Loading = { + loader: new CanvasLoader('loading'), + hide: function () { + $('#loading').hide(); + }, + show: function () { + $('#loading').show(); + }, + setup: function () { + Loading.loader.setColor('#4fb5c0'); // default is '#000000' + Loading.loader.setDiameter(28); // default is 40 + Loading.loader.setDensity(41); // default is 40 + Loading.loader.setRange(0.9); // default is 1.3 + Loading.loader.show(); // Hidden by default + } +} + +export default Loading diff --git a/frontend/src/Metamaps/Map/index.js b/frontend/src/Metamaps/Map/index.js index bcf4397b..6bd4f00a 100644 --- a/frontend/src/Metamaps/Map/index.js +++ b/frontend/src/Metamaps/Map/index.js @@ -8,6 +8,7 @@ import Create from '../Create' import Filter from '../Filter' import GlobalUI from '../GlobalUI' import JIT from '../JIT' +import Loading from '../Loading' import Realtime from '../Realtime' import Router from '../Router' import Selected from '../Selected' @@ -24,7 +25,6 @@ import InfoBox from './InfoBox' * Dependencies: * - Metamaps.DataModel * - Metamaps.Erb - * - Metamaps.Loading * - Metamaps.Mappers * - Metamaps.Mappings * - Metamaps.Maps @@ -136,7 +136,7 @@ const Map = { Filter.checkMappers() Realtime.startActiveMap() - Metamaps.Loading.hide() + Loading.hide() // for mobile $('#header_content').html(map.get('name')) diff --git a/frontend/src/Metamaps/Router.js b/frontend/src/Metamaps/Router.js index 8bbd6949..f55fab48 100644 --- a/frontend/src/Metamaps/Router.js +++ b/frontend/src/Metamaps/Router.js @@ -6,6 +6,7 @@ import Backbone from 'backbone' import Active from './Active' import GlobalUI from './GlobalUI' +import Loading from './Loading' import Map from './Map' import Topic from './Topic' import Views from './Views' @@ -15,7 +16,6 @@ import Visualize from './Visualize' * Metamaps.Router.js.erb * * Dependencies: - * - Metamaps.Loading * - Metamaps.Maps */ @@ -134,7 +134,7 @@ const _Router = Backbone.Router.extend({ self.timeoutId = setTimeout(navigate, 300) } if (Metamaps.Maps[capitalize].length === 0) { - Metamaps.Loading.show() + Loading.show() Views.ExploreMaps.pending = true setTimeout(function () { Metamaps.Maps[capitalize].getMaps(navigate) // this will trigger an explore maps render @@ -178,7 +178,7 @@ const _Router = Backbone.Router.extend({ Topic.end() Active.Topic = null - Metamaps.Loading.show() + Loading.show() Map.end() Map.launch(id) }, diff --git a/frontend/src/Metamaps/Views/ExploreMaps.js b/frontend/src/Metamaps/Views/ExploreMaps.js index aa74626c..52d47ff3 100644 --- a/frontend/src/Metamaps/Views/ExploreMaps.js +++ b/frontend/src/Metamaps/Views/ExploreMaps.js @@ -6,12 +6,9 @@ import ReactDOM from 'react-dom' // TODO ensure this isn't a double import import Active from '../Active' import GlobalUI from '../GlobalUI' import Realtime from '../Realtime' +import Loading from '../Loading' import Maps from '../../components/Maps' -/* - * - Metamaps.Loading - */ - const ExploreMaps = { pending: false, mapper: null, @@ -63,6 +60,7 @@ const ExploreMaps = { ).resize() if (cb) cb() + Loading.hide() }, loadMore: function () { var self = ExploreMaps diff --git a/frontend/src/Metamaps/Visualize.js b/frontend/src/Metamaps/Visualize.js index a70ae21c..c5323972 100644 --- a/frontend/src/Metamaps/Visualize.js +++ b/frontend/src/Metamaps/Visualize.js @@ -6,6 +6,7 @@ import $jit from '../patched/JIT' import Active from './Active' import JIT from './JIT' +import Loading from './Loading' import Router from './Router' import TopicCard from './TopicCard' @@ -13,7 +14,6 @@ import TopicCard from './TopicCard' * Metamaps.Visualize * * Dependencies: - * - Metamaps.Loading * - Metamaps.Metacodes * - Metamaps.Synapses * - Metamaps.Topics @@ -161,7 +161,7 @@ const Visualize = { if (self.type == 'ForceDirected' && Active.Mapper) $.post('/maps/' + Active.Map.id + '/events/user_presence') function runAnimation () { - Metamaps.Loading.hide() + Loading.hide() // load JSON data, if it's not empty if (!self.loadLater) { // load JSON data. diff --git a/frontend/src/Metamaps/index.js b/frontend/src/Metamaps/index.js index 5dc99aa5..5611a478 100644 --- a/frontend/src/Metamaps/index.js +++ b/frontend/src/Metamaps/index.js @@ -15,6 +15,7 @@ import GlobalUI, { import Import from './Import' import JIT from './JIT' import Listeners from './Listeners' +import Loading from './Loading' import Map, { CheatSheet, InfoBox } from './Map' import Mapper from './Mapper' import Mobile from './Mobile' @@ -51,6 +52,7 @@ Metamaps.GlobalUI.ImportDialog = ImportDialog Metamaps.Import = Import Metamaps.JIT = JIT Metamaps.Listeners = Listeners +Metamaps.Loading = Loading Metamaps.Map = Map Metamaps.Map.CheatSheet = CheatSheet Metamaps.Map.InfoBox = InfoBox