From c20e5037854ee05cb3296af8326fba83267c56e8 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 25 Sep 2016 22:27:11 +0800 Subject: [PATCH] show/hide add a topic instructions more consistently --- frontend/src/Metamaps/Backbone/index.js | 1 - frontend/src/Metamaps/Control.js | 27 ++++++++++++++++--------- frontend/src/Metamaps/Create.js | 6 ++++++ frontend/src/Metamaps/JIT.js | 11 ++++++---- package.json | 1 + 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/frontend/src/Metamaps/Backbone/index.js b/frontend/src/Metamaps/Backbone/index.js index 2c7ae530..b1ba9e78 100644 --- a/frontend/src/Metamaps/Backbone/index.js +++ b/frontend/src/Metamaps/Backbone/index.js @@ -98,7 +98,6 @@ _Backbone.Map = Backbone.Model.extend({ $.ajax({ url: '/maps/' + this.id + '/contains.json', success: start, - error: errorFunc, async: false }) }, diff --git a/frontend/src/Metamaps/Control.js b/frontend/src/Metamaps/Control.js index 2c14cfca..c6c963ac 100644 --- a/frontend/src/Metamaps/Control.js +++ b/frontend/src/Metamaps/Control.js @@ -1,6 +1,7 @@ /* global Metamaps, $ */ import _ from 'lodash' +import outdent from 'outdent' import Active from './Active' import Filter from './Filter' @@ -52,9 +53,8 @@ const Control = { var n = Selected.Nodes.length var e = Selected.Edges.length - var ntext = n == 1 ? '1 topic' : n + ' topics' - var etext = e == 1 ? '1 synapse' : e + ' synapses' - var text = 'You have ' + ntext + ' and ' + etext + ' selected. ' + var ntext = n === 1 ? '1 topic' : n + ' topics' + var etext = e === 1 ? '1 synapse' : e + ' synapses' var authorized = Active.Map.authorizeToEdit(Active.Mapper) @@ -63,11 +63,18 @@ const Control = { return } - var r = confirm(text + 'Are you sure you want to permanently delete them all? This will remove them from all maps they appear on.') - if (r == true) { + var r = confirm(outdent` + You have ${ntext} and ${etext} selected. Are you sure you want + to permanently delete them all? This will remove them from all + maps they appear on.`) + if (r) { Control.deleteSelectedEdges() Control.deleteSelectedNodes() } + + if (Metamaps.Topics.length === 0) { + GlobalUI.showDiv('#instructions') + } }, deleteSelectedNodes: function () { // refers to deleting topics permanently if (!Active.Map) return @@ -191,7 +198,7 @@ const Control = { duration: 500 }) setTimeout(function () { - if (nodeid == Visualize.mGraph.root) { // && Visualize.type === "RGraph" + if (nodeid === Visualize.mGraph.root) { // && Visualize.type === "RGraph" var newroot = _.find(graph.graph.nodes, function (n) { return n.id !== nodeid; }) graph.root = newroot ? newroot.id : null } @@ -231,7 +238,7 @@ const Control = { color: Settings.colors.synapses.normal }) - if (Mouse.edgeHoveringOver == edge) { + if (Mouse.edgeHoveringOver === edge) { edge.setDataset('current', { showDesc: true, lineWidth: 4 @@ -414,8 +421,8 @@ const Control = { } } - var nString = nCount == 1 ? (nCount.toString() + ' topic and ') : (nCount.toString() + ' topics and ') - var sString = sCount == 1 ? (sCount.toString() + ' synapse') : (sCount.toString() + ' synapses') + var nString = nCount === 1 ? (nCount.toString() + ' topic and ') : (nCount.toString() + ' topics and ') + var sString = sCount === 1 ? (sCount.toString() + ' synapse') : (sCount.toString() + ' synapses') var message = nString + sString + ' you created updated to ' + permission GlobalUI.notifyUser(message) @@ -444,7 +451,7 @@ const Control = { } } - var nString = nCount == 1 ? (nCount.toString() + ' topic') : (nCount.toString() + ' topics') + var nString = nCount === 1 ? (nCount.toString() + ' topic') : (nCount.toString() + ' topics') var message = nString + ' you can edit updated to ' + metacode.get('name') GlobalUI.notifyUser(message) diff --git a/frontend/src/Metamaps/Create.js b/frontend/src/Metamaps/Create.js index c9252aba..1fc18b87 100644 --- a/frontend/src/Metamaps/Create.js +++ b/frontend/src/Metamaps/Create.js @@ -13,6 +13,7 @@ import GlobalUI from './GlobalUI' * Dependencies: * - Metamaps.Backbone * - Metamaps.Metacodes + * - Metamaps.Topics */ const Create = { @@ -223,8 +224,10 @@ const Create = { }) Create.newTopic.beingCreated = true Create.newTopic.name = '' + GlobalUI.hideDiv('#instructions') }, hide: function (force) { + if (Create.newTopic.beingCreated === false) return if (force || !Create.newTopic.pinned) { $('#new_topic').fadeOut('fast') Create.newTopic.beingCreated = false @@ -234,6 +237,9 @@ const Create = { Create.newTopic.pinned = false } $('#topic_name').typeahead('val', '') + if (Metamaps.Topics.length === 0) { + GlobalUI.showDiv('#instructions') + } } }, newSynapse: { diff --git a/frontend/src/Metamaps/JIT.js b/frontend/src/Metamaps/JIT.js index 2b14d18c..fa5c894f 100644 --- a/frontend/src/Metamaps/JIT.js +++ b/frontend/src/Metamaps/JIT.js @@ -148,11 +148,14 @@ const JIT = { if (Metamaps.Mappings) Metamaps.Mappings.remove(mapping) }) + // set up addTopic instructions in case they delete all the topics + // i.e. if there are 0 topics at any time, it should have instructions again + $('#instructions div').hide() + if (Metamaps.Active.Map.authorizeToEdit(Active.Mapper)) { + $('#instructions div.addTopic').show() + } + if (self.vizData.length == 0) { - $('#instructions div').hide() - if (Metamaps.Active.Map.authorizeToEdit(Active.Mapper)) { - $('#instructions div.addTopic').show() - } GlobalUI.showDiv('#instructions') Visualize.loadLater = true } else { diff --git a/package.json b/package.json index b71e34bf..37d953ee 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "csv-parse": "1.1.7", "lodash": "4.16.1", "node-uuid": "1.4.7", + "outdent": "0.2.1", "react": "15.3.2", "react-dom": "15.3.2", "socket.io": "0.9.12",