From 131e27aefe202d11c2b5301bcb95afeac53c9b3f Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Tue, 1 Jan 2013 17:45:35 -0500 Subject: [PATCH] converted all references to items to topics --- .../images/ui-bg_flat_75_ffffff_40x100.png | Bin 0 -> 178 bytes app/assets/javascripts/Jit/filters.js | 28 +-- app/assets/javascripts/Jit/graphsettings.js | 90 ++++----- app/assets/javascripts/application.js | 6 +- .../carousel/cloud-carousel.1.0.5.js | 2 +- app/assets/javascripts/topics.js.coffee | 6 + app/assets/stylesheets/application.css | 8 +- app/assets/stylesheets/jquery-ui.css | 10 +- app/assets/stylesheets/maps.css.scss | 2 +- app/assets/stylesheets/topics.css.scss | 37 ++++ app/controllers/main_controller.rb | 10 +- app/controllers/maps_controller.rb | 34 ++-- app/controllers/synapses_controller.rb | 20 +- app/controllers/topics_controller.rb | 163 +++++++++++++++++ app/helpers/topics_helper.rb | 128 +++++++++++++ app/models/map.rb | 44 ++--- app/models/mapping.rb | 2 +- app/models/metacode.rb | 5 + app/models/synapse.rb | 36 ++-- app/models/topic.rb | 171 ++++++++++++++++++ app/models/user.rb | 2 +- app/views/layouts/application.html.erb | 4 +- app/views/main/console.html.erb | 6 +- app/views/main/metamap.html.erb | 6 +- app/views/main/search.js.erb | 12 +- app/views/maps/_map.html.erb | 2 +- app/views/maps/_newsynapse.html.erb | 4 +- app/views/maps/_newtopic.html.erb | 6 +- app/views/maps/edit.html.erb | 4 +- app/views/maps/show.html.erb | 2 +- app/views/synapses/_new.html.erb | 4 +- app/views/synapses/create.js.erb | 8 +- app/views/synapses/edit.html.erb | 12 +- app/views/synapses/index.html.erb | 2 +- app/views/synapses/new.html.erb | 12 +- app/views/synapses/show.html.erb | 2 +- app/views/topics/_new.html.erb | 15 ++ app/views/topics/_topic.html.erb | 10 + app/views/topics/create.js.erb | 83 +++++++++ app/views/topics/destroy.js.erb | 1 + app/views/topics/edit.html.erb | 14 ++ app/views/topics/index.html.erb | 11 ++ app/views/topics/new.html.erb | 16 ++ app/views/topics/show.html.erb | 38 ++++ app/views/topics/showcard.html.erb | 29 +++ app/views/users/show.html.erb | 4 +- config/routes.rb | 6 +- db/migrate/20120920013446_create_users.rb | 4 +- db/migrate/20121005160234_create_synapses.rb | 12 +- db/migrate/20121026000731_create_mappings.rb | 10 +- db/migrate/20130101193917_create_topics.rb | 13 ++ db/migrate/20130101194424_create_metacodes.rb | 10 + db/migrate/20130101215010_items_to_topics.rb | 9 + db/schema.rb | 22 ++- test/fixtures/mappings.yml | 4 +- test/fixtures/metacodes.yml | 117 ++++++++++++ test/fixtures/topics.yml | 11 ++ test/functional/topics_controller_test.rb | 7 + test/unit/helpers/topics_helper_test.rb | 4 + test/unit/metacode_test.rb | 7 + test/unit/topic_test.rb | 7 + 61 files changed, 1142 insertions(+), 212 deletions(-) create mode 100644 app/assets/images/ui-bg_flat_75_ffffff_40x100.png create mode 100644 app/assets/javascripts/topics.js.coffee create mode 100644 app/assets/stylesheets/topics.css.scss create mode 100644 app/controllers/topics_controller.rb create mode 100644 app/helpers/topics_helper.rb create mode 100644 app/models/metacode.rb create mode 100644 app/models/topic.rb create mode 100644 app/views/topics/_new.html.erb create mode 100644 app/views/topics/_topic.html.erb create mode 100644 app/views/topics/create.js.erb create mode 100644 app/views/topics/destroy.js.erb create mode 100644 app/views/topics/edit.html.erb create mode 100644 app/views/topics/index.html.erb create mode 100644 app/views/topics/new.html.erb create mode 100644 app/views/topics/show.html.erb create mode 100644 app/views/topics/showcard.html.erb create mode 100644 db/migrate/20130101193917_create_topics.rb create mode 100644 db/migrate/20130101194424_create_metacodes.rb create mode 100644 db/migrate/20130101215010_items_to_topics.rb create mode 100644 test/fixtures/metacodes.yml create mode 100644 test/fixtures/topics.yml create mode 100644 test/functional/topics_controller_test.rb create mode 100644 test/unit/helpers/topics_helper_test.rb create mode 100644 test/unit/metacode_test.rb create mode 100644 test/unit/topic_test.rb diff --git a/app/assets/images/ui-bg_flat_75_ffffff_40x100.png b/app/assets/images/ui-bg_flat_75_ffffff_40x100.png new file mode 100644 index 0000000000000000000000000000000000000000..ac8b229af950c29356abf64a6c4aa894575445f0 GIT binary patch literal 178 zcmeAS@N?(olHy`uVBq!ia0vp^8bF-F!3HG1q!d*FsY*{5$B>N1x91EQ4=4yQYz+E8 zPo9&<{J;c_6SHRil>2s{Zw^OT)6@jj2u|u!(plXsM>LJD`vD!n;OXk;vd$@?2>^GI BH@yG= literal 0 HcmV?d00001 diff --git a/app/assets/javascripts/Jit/filters.js b/app/assets/javascripts/Jit/filters.js index caa0f769..936657fc 100644 --- a/app/assets/javascripts/Jit/filters.js +++ b/app/assets/javascripts/Jit/filters.js @@ -1,6 +1,6 @@ // create filters for maps, and for card views -// keep an array of which item categories are currently visible. +// keep an array of which metacodes are currently visible. var categoryVisible = new Object(); categoryVisible['Group'] = true; @@ -44,7 +44,7 @@ function switchVisible(category, duration) { function hideCategory(category, duration) { if (duration == null) duration = 500; Mconsole.graph.eachNode( function (n) { - if (n.getData('itemcatname') == category) { + if (n.getData('metacode') == category) { n.setData('alpha', 0.4, 'end'); n.eachAdjacency(function(adj) { adj.setData('alpha', 0.4, 'end'); @@ -61,7 +61,7 @@ function hideCategory(category, duration) { function showCategory(category, duration) { if (duration == null) duration = 500; Mconsole.graph.eachNode( function (n) { - if (n.getData('itemcatname') == category) { + if (n.getData('metacode') == category) { n.setData('alpha', 1, 'end'); n.eachAdjacency(function(adj) { adj.setData('alpha', 1, 'end'); @@ -130,31 +130,31 @@ function onCanvasSearch(name,mapID,mapperID) { if (name != null) { if (n.name.indexOf(name) !== -1 && name != "") { n.setData('onCanvas', true); - //$('.name.item_' + n.id).css('display','block'); + //$('.name.topic_' + n.id).css('display','block'); } else { n.setData('onCanvas', false); - //$('.name.item_' + n.id).css('display','none'); + //$('.name.topic_' + n.id).css('display','none'); } } else if (mapID != null) { if (n.getData('inmaps').indexOf(parseInt(mapID)) !== -1) { n.setData('onCanvas', true); - //$('.name.item_' + n.id).css('display','block'); + //$('.name.topic_' + n.id).css('display','block'); } else { n.setData('onCanvas', false); - //$('.name.item_' + n.id).css('display','none'); + //$('.name.topic_' + n.id).css('display','none'); } } else if (mapperID != null) { if (n.getData('userid').toString() == mapperID) { n.setData('onCanvas', true); - //$('.name.item_' + n.id).css('display','block'); + //$('.name.topic_' + n.id).css('display','block'); } else { n.setData('onCanvas', false); - //$('.name.item_' + n.id).css('display','none'); + //$('.name.topic_' + n.id).css('display','none'); } } Mconsole.plot(); @@ -194,7 +194,7 @@ $(document).ready(function() { Mconsole.graph.eachNode( function (n) { n.setData('inCommons', false); n.setData('onCanvas', false); - //$('.name.item_' + n.id).css('display','block'); + //$('.name.topic_' + n.id).css('display','block'); }); Mconsole.plot(); $('#closeFind, #findWhere').css('display','none'); @@ -372,7 +372,7 @@ $(document).ready(function() { $('.find_topic_by_name #topic_by_name_input').bind('railsAutocomplete.select', function(event, data){ /* Do something here */ if (data.item.id != undefined) { - window.open("/items/" + data.item.id) + window.open("/topics/" + data.item.id) } $('.find_topic_by_name #topic_by_name_input').val(''); }); @@ -471,7 +471,7 @@ $(document).ready(function() { event.preventDefault(); }); - // toggle visibility of item categories based on status in the filters list + // toggle visibility of topics with metacodes based on status in the filters list $('.find_topic_by_metacode ul li').click(function(event) { obj = document.getElementById('container'); @@ -485,7 +485,7 @@ $(document).ready(function() { } // this means that we are on a card view else { - $('.item').fadeIn('slow'); + $('.topic').fadeIn('slow'); } $('.find_topic_by_metacode ul li').not('#hideAll, #showAll').removeClass('toggledOff'); for (var catVis in categoryVisible) { @@ -499,7 +499,7 @@ $(document).ready(function() { } // this means that we are on a card view else { - $('.item').fadeOut('slow'); + $('.topic').fadeOut('slow'); } $('.find_topic_by_metacode ul li').not('#hideAll, #showAll').addClass('toggledOff'); for (var catVis in categoryVisible) { diff --git a/app/assets/javascripts/Jit/graphsettings.js b/app/assets/javascripts/Jit/graphsettings.js index 8dddd433..ad3e679c 100644 --- a/app/assets/javascripts/Jit/graphsettings.js +++ b/app/assets/javascripts/Jit/graphsettings.js @@ -61,15 +61,15 @@ function graphSettings(type) { }, onDragEnd: function() { if (tempInit && tempNode2 == null) { - $('#item_addSynapse').val("true"); - $('#new_item').fadeIn('fast'); + $('#topic_addSynapse').val("true"); + $('#new_topic').fadeIn('fast'); addMetacode(); - $('#item_name').focus(); + $('#topic_name').focus(); } else if (tempInit && tempNode2 != null) { - $('#item_addSynapse').val("false"); - $('#synapse_item1id').val(tempNode.id); - $('#synapse_item2id').val(tempNode2.id); + $('#topic_addSynapse').val("false"); + $('#synapse_topic1id').val(tempNode.id); + $('#synapse_topic2id').val(tempNode2.id); $('#new_synapse').fadeIn('fast'); $('#synapse_desc').focus(); tempNode = null; @@ -81,9 +81,9 @@ function graphSettings(type) { tempNode = null; tempNode2 = null; tempInit = false; - $('#item_addSynapse').val("false"); - $('#item_item1id').val(0); - $('#item_item2id').val(0); + $('#topic_addSynapse').val("false"); + $('#topic_topic1id').val(0); + $('#topic_topic2id').val(0); Mconsole.plot(); }, //Implement the same handler for touchscreens @@ -112,14 +112,14 @@ function graphSettings(type) { // on label creation and only for DOM labels (not native canvas ones). onCreateLabel: function (domElement, node) { var html = - '

' + node.getData("itemcatname") + '

' + - '' + node.getData(' + - '
' + node.name + '' + + '

' + node.getData("metacode") + '

' + + '' + node.getData(' + + '
' + node.name + '' + '' + '

' + node.getData('desc') + '

' + '' + node.getData('link') + '
'; var showCard = document.createElement('div'); - showCard.className = 'showcard item_' + node.id; + showCard.className = 'showcard topic_' + node.id; showCard.innerHTML = html; showCard.style.display = "none"; domElement.appendChild(showCard); @@ -139,7 +139,7 @@ function graphSettings(type) { modes: ['edge-property:lineWidth:color'], duration: 500 }); - $('.showcard.item_' + node.id).fadeOut('fast', function(){ + $('.showcard.topic_' + node.id).fadeOut('fast', function(){ $('.name').css('display','block'); Mconsole.plot(); }); @@ -149,7 +149,7 @@ function graphSettings(type) { // to the main node label var nameContainer = document.createElement('span'), style = nameContainer.style; - nameContainer.className = 'name item_' + node.id; + nameContainer.className = 'name topic_' + node.id; nameContainer.innerHTML = '
' + node.name + '
'; domElement.appendChild(nameContainer); style.fontSize = "0.9em"; @@ -239,15 +239,15 @@ function graphSettings(type) { }, onDragEnd: function() { if (tempInit && tempNode2 == null) { - $('#item_addSynapse').val("true"); - $('#new_item').fadeIn('fast'); + $('#topic_addSynapse').val("true"); + $('#new_topic').fadeIn('fast'); addMetacode(); - $('#item_name').focus(); + $('#topic_name').focus(); } else if (tempInit && tempNode2 != null) { - $('#item_addSynapse').val("false"); - $('#synapse_item1id').val(tempNode.id); - $('#synapse_item2id').val(tempNode2.id); + $('#topic_addSynapse').val("false"); + $('#synapse_topic1id').val(tempNode.id); + $('#synapse_topic2id').val(tempNode2.id); $('#new_synapse').fadeIn('fast'); $('#synapse_desc').focus(); tempNode = null; @@ -294,14 +294,14 @@ function graphSettings(type) { // on label creation and only for DOM labels (not native canvas ones). onCreateLabel: function (domElement, node) { var html = - '

' + node.getData("itemcatname") + '

' + - '' + node.getData(' + - '
' + node.name + '' + + '

' + node.getData("metacode") + '

' + + '' + node.getData(' + + '
' + node.name + '' + '' + '

' + node.getData('desc') + '

' + '' + node.getData('link') + '
'; var showCard = document.createElement('div'); - showCard.className = 'showcard item_' + node.id; + showCard.className = 'showcard topic_' + node.id; showCard.innerHTML = html; showCard.style.display = "none"; domElement.appendChild(showCard); @@ -322,7 +322,7 @@ function graphSettings(type) { modes: ['edge-property:lineWidth:color'], duration: 500 }); - $('.showcard.item_' + node.id).fadeOut('fast', function(){ + $('.showcard.topic_' + node.id).fadeOut('fast', function(){ $('.name').css('display','block'); Mconsole.plot(); }); @@ -333,7 +333,7 @@ function graphSettings(type) { // to the main node label var nameContainer = document.createElement('span'), style = nameContainer.style; - nameContainer.className = 'name item_' + node.id; + nameContainer.className = 'name topic_' + node.id; nameContainer.innerHTML = '
' + node.name + '
'; domElement.appendChild(nameContainer); style.fontSize = "0.9em"; @@ -410,7 +410,7 @@ var nodeSettings = { 'render': function (node, canvas) { var pos = node.pos.getc(true), dim = node.getData('dim'), - cat = node.getData('itemcatname'), + cat = node.getData('metacode'), inCommons = node.getData('inCommons'), onCanvas = node.getData('onCanvas'), ctx = canvas.getCtx(); @@ -502,8 +502,8 @@ function selectNodeOnClickHandler(node) { $('.showcard').css('display','none'); $('.name').css('display','block'); - $('.name.item_' + node.id).css('display','none'); - $('.showcard.item_' + node.id).fadeIn('fast'); + $('.name.topic_' + node.id).css('display','none'); + $('.showcard.topic_' + node.id).fadeIn('fast'); //set final styles Mconsole.graph.eachNode(function (n) { @@ -552,18 +552,18 @@ function canvasDoubleClickHandler(canvasLoc,e) { if (now - storedTime < TOLERANCE) { //pop up node creation :) - $('#item_grabItem').val("null"); - $('#item_addSynapse').val("false"); - document.getElementById('new_item').style.left = e.x + "px"; - document.getElementById('new_item').style.top = e.y + "px"; - $('#item_x').val(canvasLoc.x); - $('#item_y').val(canvasLoc.y); - $('#new_item').fadeIn('fast'); + $('#topic_grabTopic').val("null"); + $('#topic_addSynapse').val("false"); + document.getElementById('new_topic').style.left = e.x + "px"; + document.getElementById('new_topic').style.top = e.y + "px"; + $('#topic_x').val(canvasLoc.x); + $('#topic_y').val(canvasLoc.y); + $('#new_topic').fadeIn('fast'); addMetacode(); - $('#item_name').focus(); + $('#topic_name').focus(); } else { canvasDoubleClickHandlerObject.storedTime = now; - $('#new_item').fadeOut('fast'); + $('#new_topic').fadeOut('fast'); $('#new_synapse').fadeOut('fast'); tempInit = false; tempNode = null; @@ -576,7 +576,7 @@ function canvasDoubleClickHandler(canvasLoc,e) { function clickDragOnTopic(node, eventInfo, e) { if (node && !node.nodeFrom) { $('#new_synapse').fadeOut('fast'); - $('#new_item').fadeOut('fast'); + $('#new_topic').fadeOut('fast'); var pos = eventInfo.getPos(); // if it's a left click, move the node if (e.button == 0 && !e.altKey ) { @@ -608,15 +608,15 @@ function clickDragOnTopic(node, eventInfo, e) { n.setData('dim', 25, 'current'); }); //pop up node creation :) - $('#item_grabItem').val("null"); + $('#topic_grabTopic').val("null"); var myX = e.x - 110; var myY = e.y - 30; - document.getElementById('new_item').style.left = myX + "px"; - document.getElementById('new_item').style.top = myY + "px"; + document.getElementById('new_topic').style.left = myX + "px"; + document.getElementById('new_topic').style.top = myY + "px"; document.getElementById('new_synapse').style.left = myX + "px"; document.getElementById('new_synapse').style.top = myY + "px"; - $('#item_x').val(eventInfo.getPos().x); - $('#item_y').val(eventInfo.getPos().y); + $('#topic_x').val(eventInfo.getPos().x); + $('#topic_y').val(eventInfo.getPos().y); Mconsole.plot(); renderMidArrow({ x: tempNode.pos.getc().x, y: tempNode.pos.getc().y }, { x: pos.x, y: pos.y }, 13, false, Mconsole.canvas); Mconsole.fx.plotNode(tempNode, Mconsole.canvas); diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 6069ec05..c38362e5 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -25,14 +25,14 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null, $(document).ready(function() { - $('#new_item, #new_synapse').bind('contextmenu', function(e){ + $('#new_topic, #new_synapse').bind('contextmenu', function(e){ return false; }); /// this is for the topic creation autocomplete field - $('#item_name').bind('railsAutocomplete.select', function(event, data){ + $('#topic_name').bind('railsAutocomplete.select', function(event, data){ if (data.item.id != undefined) { - $('#item_grabItem').val(data.item.id); + $('#topic_grabTopic').val(data.item.id); } }); diff --git a/app/assets/javascripts/carousel/cloud-carousel.1.0.5.js b/app/assets/javascripts/carousel/cloud-carousel.1.0.5.js index 1b33702e..0dd961af 100644 --- a/app/assets/javascripts/carousel/cloud-carousel.1.0.5.js +++ b/app/assets/javascripts/carousel/cloud-carousel.1.0.5.js @@ -187,7 +187,7 @@ if ( items[this.frontIndex] === undefined ) { return; } // Images might not have loaded yet. $(options.titleBox).html( $(items[this.frontIndex].image).attr('title')); // METAMAPS CODE - $('#item_metacode').val( $(items[this.frontIndex].image).attr('title')); + $('#topic_metacode').val( $(items[this.frontIndex].image).attr('title')); // NOT METAMAPS CODE $(options.altBox).html( $(items[this.frontIndex].image).attr('alt')); }; diff --git a/app/assets/javascripts/topics.js.coffee b/app/assets/javascripts/topics.js.coffee new file mode 100644 index 00000000..52b1d028 --- /dev/null +++ b/app/assets/javascripts/topics.js.coffee @@ -0,0 +1,6 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ + +jQuery -> + $('.best_in_place').best_in_place() \ No newline at end of file diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index fc1f50e7..3b7ef952 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -93,7 +93,7 @@ a { .new_user, .new_map, .edit_user, -.edit_item, +.edit_topic, .edit_synapse, .edit_map, .invite { @@ -135,18 +135,18 @@ a { right:3px; } -.anypage .new_item { +.anypage .new_topic { width:300px; margin:-40px 0 0 -50px; } -.anypage .new_item, +.anypage .new_topic, .anypage .new_synapse { display: block; position: absolute; } -.anypage #item_name { +.anypage #topic_name { width:200px; position:absolute; top:40px; diff --git a/app/assets/stylesheets/jquery-ui.css b/app/assets/stylesheets/jquery-ui.css index ac0b1b7c..4d2c8534 100644 --- a/app/assets/stylesheets/jquery-ui.css +++ b/app/assets/stylesheets/jquery-ui.css @@ -152,18 +152,18 @@ button.ui-button::-moz-focus-inner { border: 0; padding: 0; } /* reset extra pad .ui-menu { list-style:none; padding: 2px; margin: 0; display:block; outline: none; } .ui-menu .ui-menu { margin-top: -3px; position: absolute; } -.ui-menu .ui-menu-item { margin: 0; padding: 0; zoom: 1; width: 100%; } +.ui-menu .ui-menu-topic { margin: 0; padding: 0; zoom: 1; width: 100%; } .ui-menu .ui-menu-divider { margin: 5px -2px 5px -2px; height: 0; font-size: 0; line-height: 0; border-width: 1px 0 0 0; } -.ui-menu .ui-menu-item a { text-decoration: none; display: block; padding: 2px .4em; line-height: 1.5; zoom: 1; font-weight: normal; } -.ui-menu .ui-menu-item a.ui-state-focus, -.ui-menu .ui-menu-item a.ui-state-active { font-weight: normal; margin: -1px; } +.ui-menu .ui-menu-topic a { text-decoration: none; display: block; padding: 2px .4em; line-height: 1.5; zoom: 1; font-weight: normal; } +.ui-menu .ui-menu-topic a.ui-state-focus, +.ui-menu .ui-menu-topic a.ui-state-active { font-weight: normal; margin: -1px; } .ui-menu .ui-state-disabled { font-weight: normal; margin: .4em 0 .2em; line-height: 1.5; } .ui-menu .ui-state-disabled a { cursor: default; } /* icon support */ .ui-menu-icons { position: relative; } -.ui-menu-icons .ui-menu-item a { position: relative; padding-left: 2em; } +.ui-menu-icons .ui-menu-topic a { position: relative; padding-left: 2em; } /* left-aligned */ .ui-menu .ui-icon { position: absolute; top: .2em; left: .2em; } diff --git a/app/assets/stylesheets/maps.css.scss b/app/assets/stylesheets/maps.css.scss index 3fdbcb09..3b527c51 100644 --- a/app/assets/stylesheets/maps.css.scss +++ b/app/assets/stylesheets/maps.css.scss @@ -46,4 +46,4 @@ line-height: 24px;} // add topic on maps pages .selecttype { border:1px solid #000; margin-top: 20px; border-radius:15px; } -.mapspages .new_item h3 { padding: 10px 26px; display: block; cursor: pointer; color: #2d6a5d; float:left; } \ No newline at end of file +.mapspages .new_topic h3 { padding: 10px 26px; display: block; cursor: pointer; color: #2d6a5d; float:left; } \ No newline at end of file diff --git a/app/assets/stylesheets/topics.css.scss b/app/assets/stylesheets/topics.css.scss new file mode 100644 index 00000000..7fbc6738 --- /dev/null +++ b/app/assets/stylesheets/topics.css.scss @@ -0,0 +1,37 @@ +// Place all the styles related to the Topics controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +.topic { display:block; float:left; position:relative; width:175px; height:300px; padding:10px 5px 10px 35px; background: url('bg.png'); border-radius:15px; margin:30px 0 30px 50px; color:#000; } + +.topic .delete {position: absolute; +top: -14px; +left: 0px; +background: none; +border: 0; +color: white; +border: none; +font-size: 14px; +margin: 0; +padding: 0; +cursor:pointer; +} + +.topic .scroll { display:block; height:283px; } + +.topic .type {position: absolute; +color: white; +top: -22px; +right: 0; +font-weight: bold; +font-size: 20px; +line-height: 24px;} + +.topic .icon { position:absolute; top:135px; left:-25px; } + +.topic .title { font-size:22px; line-height:25px; display:block; border-bottom:2px solid #000; padding-bottom:5px; } + +.topic .desc { font-size:15px; font-family:Arial, Helvetica, sans-serif; } +.topic .desc h3 { font-style:normal; margin-top:5px; } + +.topic .link { position:absolute; width:170px; top:295px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } \ No newline at end of file diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index b7949c25..7b8e7e3a 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -1,5 +1,5 @@ class MainController < ApplicationController - include ItemsHelper + include TopicsHelper before_filter :require_user, only: [:invite] @@ -11,16 +11,16 @@ class MainController < ApplicationController def search @current = current_user - @items = Array.new() + @topics = Array.new() if params[:topics_by_user_id] != "" @user = User.find(params[:topics_by_user_id]) - @items = Item.visibleToUser(@current, @user) + @topics = Topic.visibleToUser(@current, @user) elsif params[:topics_by_map_id] != "" @map = Map.find(params[:topics_by_map_id]) - @items = @map.items.delete_if{|item| not item.authorize_to_view(@current)} + @topics = @map.topics.delete_if{|topic| not topic.authorize_to_view(@current)} end respond_to do |format| - format.js { respond_with(@items) } + format.js { respond_with(@topics) } end end diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 4487abba..1e93a7c3 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -63,15 +63,15 @@ class MapsController < ApplicationController if params[:map][:topicsToMap] @all = params[:map][:topicsToMap] @all = @all.split(',') - @all.each do |item| - item = item.split('/') + @all.each do |topic| + topic = topic.split('/') @mapping = Mapping.new() - @mapping.category = "Item" + @mapping.category = "Topic" @mapping.user = @user @mapping.map = @map - @mapping.item = Item.find(item[0]) - @mapping.xloc = item[1] - @mapping.yloc = item[2] + @mapping.topic = Topic.find(topic[0]) + @mapping.xloc = topic[1] + @mapping.yloc = topic[2] @mapping.save end @map.arranged = true @@ -95,9 +95,9 @@ class MapsController < ApplicationController redirect_to root_url and return end - @outitems = @map.items.order("name ASC").delete_if{|item| not item.authorize_to_view(@current)} + @outtopics = @map.topics.order("name ASC").delete_if{|topic| not topic.authorize_to_view(@current)} - respond_with(@user, @map, @outitems) + respond_with(@user, @map, @outtopics) end # PUT maps/:id @@ -107,10 +107,10 @@ class MapsController < ApplicationController @map.attributes = params[:map] @map.save - if params[:outitems] - @outitems = params[:outitems] - @outitems.each do |item| - @mapping = Mapping.where("map_id = ? AND item_id = ?", @map.id, item).first + if params[:outtopics] + @outtopics = params[:outtopics] + @outtopics.each do |topic| + @mapping = Mapping.where("map_id = ? AND topic_id = ?", @map.id, topic).first @mapping.delete end end @@ -126,11 +126,11 @@ class MapsController < ApplicationController if params[:map][:coordinates] @all = params[:map][:coordinates] @all = @all.split(',') - @all.each do |item| - item = item.split('/') - @mapping = Mapping.find(item[0]) - @mapping.xloc = item[1] - @mapping.yloc = item[2] + @all.each do |topic| + topic = topic.split('/') + @mapping = Mapping.find(topic[0]) + @mapping.xloc = topic[1] + @mapping.yloc = topic[2] @mapping.save end @map.arranged = true diff --git a/app/controllers/synapses_controller.rb b/app/controllers/synapses_controller.rb index 75a0a9ff..8e23c638 100644 --- a/app/controllers/synapses_controller.rb +++ b/app/controllers/synapses_controller.rb @@ -1,5 +1,5 @@ class SynapsesController < ApplicationController - include ItemsHelper + include TopicsHelper before_filter :require_user, only: [:new, :create, :edit, :update] @@ -39,10 +39,10 @@ class SynapsesController < ApplicationController def show @current = current_user @synapse = Synapse.find(params[:id]).authorize_to_show(@current) - @item1 = @synapse.item1.authorize_to_show(@current) - @item2 = @synapse.item2.authorize_to_show(@current) + @topic1 = @synapse.topic1.authorize_to_show(@current) + @topic2 = @synapse.topic2.authorize_to_show(@current) - if @synapse && @item1 && @item2 + if @synapse && @topic1 && @topic2 @synapsejson = @synapse.selfplusnodes_as_json.html_safe else redirect_to root_url and return @@ -60,8 +60,8 @@ class SynapsesController < ApplicationController @user = current_user @synapse = Synapse.new() @synapse.desc = params[:synapse][:desc] - @synapse.item1 = Item.find(params[:synapse][:item1id]) - @synapse.item2 = Item.find(params[:synapse][:item2id]) + @synapse.topic1 = Topic.find(params[:synapse][:topic1id]) + @synapse.topic2 = Topic.find(params[:synapse][:topic2id]) @synapse.permission = "commons" @synapse.category = "from-to" @synapse.weight = 5 @@ -90,12 +90,12 @@ class SynapsesController < ApplicationController @synapse = Synapse.find(params[:id]).authorize_to_edit(@current) if @synapse - @items = Item.visibleToUser(@current, nil) + @topics = Topic.visibleToUser(@current, nil) elsif not @synapse redirect_to root_url and return end - respond_with(@synapse, @items) + respond_with(@synapse, @topics) end # PUT synapses/:id @@ -106,8 +106,8 @@ class SynapsesController < ApplicationController if @synapse @synapse.desc = params[:synapse][:desc] @synapse.category = params[:synapse][:category] - @synapse.item1 = Item.find(params[:node1_id][:node1]) - @synapse.item2 = Item.find(params[:node2_id][:node2]) + @synapse.topic1 = Topic.find(params[:node1_id][:node1]) + @synapse.topic2 = Topic.find(params[:node2_id][:node2]) @synapse.permission = params[:synapse][:permission] @synapse.save end diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb new file mode 100644 index 00000000..eef727a7 --- /dev/null +++ b/app/controllers/topics_controller.rb @@ -0,0 +1,163 @@ +class TopicsController < ApplicationController + before_filter :require_user, only: [:new, :create, :edit, :update] + + respond_to :html, :js, :json + + autocomplete :topic, :name, :full => true, :extra_data => [:user_id] + + + # GET topics + # or GET /users/:user_id/topics + def index + @current = current_user + + if params[:user_id] + @user = User.find(params[:user_id]) + @topics = Topic.order("name ASC").visibleToUser(@current, @user) + elsif + @topics = Topic.order("name ASC").visibleToUser(@current, nil) + end + + respond_with(@user,@topics) + end + + # Get topics/new + def new + @topic = Topic.new + @user = current_user + + respond_with(@topic) + end + + # GET topics/:id + def show + @current = current_user + @topic = Topic.find(params[:id]).authorize_to_show(@current) + + if @topic + @relatives = @topic.network_as_json(@current).html_safe + else + redirect_to root_url and return + end + + respond_to do |format| + format.html { respond_with(@topic, @user) } + format.json { respond_with(@relatives) } + end + end + + # GET showcard/:id + def showcard + @user = current_user + @topic = Topic.find(params[:id]).authorize_to_show(@user) + + respond_to do |format| + format.html { respond_with(@topic, @user) } + end + end + + # POST topics + def create + + @user = current_user + + # if the topic exists grab it and return it + if params[:topic][:grabTopic] != "null" + @topic = Topic.find(params[:topic][:grabTopic]) + # if the topic doesn't exist yet, create it + else + @topic = Topic.new() + @topic.name = params[:topic][:name] + @topic.desc = "" + @topic.link = "" + @topic.permission = 'commons' + @topic.metacode = Metacode.find_by_name(params[:topic][:metacode]) + @topic.user = @user + + @topic.save + end + + # pass on to the topic create js whether it's being created with a synapse + @synapse = "false" + if params[:topic][:addSynapse] == "true" + @synapse = "true" + end + + # also create an object to return the position to the canvas + @position = Hash.new() + @position['x'] = params[:topic][:x] + @position['y'] = params[:topic][:y] + + # set this for the case where the topic is being created on a map. + @mapping = Mapping.new() + if params[:topic][:map] + @mapping.category = "Topic" + @mapping.user = @user + @mapping.map = Map.find(params[:topic][:map]) + @mapping.topic = @topic + @mapping.xloc = params[:topic][:x] + @mapping.yloc = params[:topic][:y] + @mapping.save + end + + respond_to do |format| + format.html { respond_with(@user, location: topic_url(@topic)) } + format.js { respond_with(@topic, @mapping, @synapse, @position) } + end + end + + # GET topics/:id/edit + def edit + @current = current_user + @topic = Topic.find(params[:id]).authorize_to_edit(@current) + + if not @topic + redirect_to root_url and return + end + + respond_with(@topic) + end + + # PUT topics/:id + def update + @current = current_user + @topic = Topic.find(params[:id]).authorize_to_edit(@current) + + if @topic + @topic.name = params[:topic][:name] + @topic.desc = params[:topic][:desc] + @topic.link = params[:topic][:link] + @topic.permission = params[:topic][:permission] + @topic.metacode = Metacode.find(params[:category][:metacode_id]) + @topic.save + end + + respond_with(@user, location: topic_url(@topic)) do |format| + end + end + + # DELETE topics/:id + def destroy + @current = current_user + @topic = Topic.find(params[:id]).authorize_to_edit(@current) + + if @topic + @synapses = @topic.synapses + @mappings = @topic.mappings + + @synapses.each do |synapse| + synapse.delete + end + + @mappings.each do |mapping| + mapping.delete + end + + @topic.delete + end + + respond_to do |format| + format.js + end + end +end diff --git a/app/helpers/topics_helper.rb b/app/helpers/topics_helper.rb new file mode 100644 index 00000000..d9c8358e --- /dev/null +++ b/app/helpers/topics_helper.rb @@ -0,0 +1,128 @@ +module TopicsHelper + +#find all nodes in any given nodes network + def network(node, array, count) + # recurse starting with a node to find all connected nodes and return an array of topics that constitutes the starting nodes network + + # if the array of nodes is empty initialize it + if array.nil? + array = Array.new + end + + # add the node to the array + array.push(node) + + if count == 0 + return array + end + + count = count - 1 + + # check if each relative is already in the array and if not, call the network function again + if not node.relatives.empty? + if (node.relatives-array).empty? + return array + else + (node.relatives-array).each do |relative| + array = (array | network(relative, array, count)) + end + return array + end + + elsif node.relatives.empty? + return array + end + end + + #return a json object containing all of a users added synapses + def synapses_as_json(current, synapses) + Jbuilder.encode do |json| + @topics = Array.new + + synapses.each do |synapse| + @topics.push(synapse.topic1) if (not @topics.include?(synapse.topic1)) && synapse.topic1.authorize_to_view(current) + @topics.push(synapse.topic2) if (not @topics.include?(synapse.topic2)) && synapse.topic2.authorize_to_view(current) + end + + json.array!(@topics) do |topic| + json.adjacencies topic.synapses2.delete_if{|synapse| not @topics.include?(Topic.find_by_id(synapse.node1_id))} do |json, synapse| + json.nodeTo synapse.node1_id + json.nodeFrom synapse.node2_id + + @synapsedata = Hash.new + @synapsedata['$desc'] = synapse.desc + @synapsedata['$showDesc'] = false + @synapsedata['$category'] = synapse.category + @synapsedata['$id'] = synapse.id + @synapsedata['$userid'] = synapse.user.id + @synapsedata['$username'] = synapse.user.name + @synapsedata['$direction'] = [synapse.node1_id.to_s(), synapse.node2_id.to_s()] + json.data @synapsedata + end + + @inmaps = Array.new + topic.maps.each do |map| + @inmaps.push(map.id) + end + + @topicdata = Hash.new + @topicdata['$desc'] = topic.desc + @topicdata['$link'] = topic.link + @topicdata['$metacode'] = topic.metacode.name + @topicdata['$inmaps'] = @inmaps + @topicdata['$userid'] = topic.user.id + @topicdata['$username'] = topic.user.name + json.data @topicdata + json.id topic.id + json.name topic.name + end + end + end + + def all_as_json(current, user) + + # current is current user + + Jbuilder.encode do |json| + if user.nil? + @topics = Topic.visibleToUser(current, nil) + @synapses = Synapse.visibleToUser(current, nil) + else + @topics = Topic.visibleToUser(current, user) + @synapses = Synapse.visibleToUser(current, user) + end + + json.array!(@topics) do |topic| + json.adjacencies topic.synapses2.delete_if{|synapse| (not @topics.include?(Topic.find_by_id(synapse.node1_id))) || (not @synapses.include?(synapse))} do |json, synapse| + json.nodeTo synapse.node1_id + json.nodeFrom synapse.node2_id + + @synapsedata = Hash.new + @synapsedata['$desc'] = synapse.desc + @synapsedata['$category'] = synapse.category + @synapsedata['$userid'] = synapse.user.id + @synapsedata['$username'] = synapse.user.name + json.data @synapsedata + end + + @inmaps = Array.new + topic.maps.each do |map| + @inmaps.push(map.id) + end + + @topicdata = Hash.new + @topicdata['$desc'] = topic.desc + @topicdata['$link'] = topic.link + @topicdata['$metacode'] = topic.metacode.name + @topicdata['$inmaps'] = @inmaps + @topicdata['$userid'] = topic.user.id + @topicdata['$username'] = topic.user.name + + json.data @topicdata + json.id topic.id + json.name topic.name + end + end + end + +end diff --git a/app/models/map.rb b/app/models/map.rb index 2c538a52..4793c40c 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -2,14 +2,14 @@ class Map < ActiveRecord::Base belongs_to :user -has_many :itemmappings, :class_name => 'Mapping', :conditions => {:category => 'Item'} +has_many :topicmappings, :class_name => 'Mapping', :conditions => {:category => 'Topic'} has_many :synapsemappings, :class_name => 'Mapping', :conditions => {:category => 'Synapse'} -has_many :items, :through => :itemmappings +has_many :topics, :through => :topicmappings has_many :synapses, :through => :synapsemappings def mappings - itemmappings + synapsemappings + topicmappings + synapsemappings end @@ -17,14 +17,14 @@ end #build a json object of a map def self_as_json(current) Jbuilder.encode do |json| - @items = self.items + @topics = self.topics @synapses = self.synapses - json.array!(@items.delete_if{|item| not item.authorize_to_view(current)}) do |item| + json.array!(@topics.delete_if{|topic| not topic.authorize_to_view(current)}) do |topic| - #json.adjacencies item.synapses2.delete_if{|synapse| (not @items.include?(synapse.item1)) || (not @synapses.include?(synapse)) || (not synapse.authorize_to_view(current)) || (not synapse.item1.authorize_to_view(current)) } do |json, synapse| + #json.adjacencies topic.synapses2.delete_if{|synapse| (not @topics.include?(synapse.topic1)) || (not @synapses.include?(synapse)) || (not synapse.authorize_to_view(current)) || (not synapse.topic1.authorize_to_view(current)) } do |json, synapse| - json.adjacencies item.synapses1.delete_if{|synapse| (not @items.include?(synapse.item2)) || (not synapse.authorize_to_view(current)) || (not synapse.item2.authorize_to_view(current)) } do |json, synapse| + json.adjacencies topic.synapses1.delete_if{|synapse| (not @topics.include?(synapse.topic2)) || (not synapse.authorize_to_view(current)) || (not synapse.topic2.authorize_to_view(current)) } do |json, synapse| json.nodeTo synapse.node2_id json.nodeFrom synapse.node1_id @@ -40,24 +40,24 @@ end end @inmaps = Array.new - item.maps.each do |map| + topic.maps.each do |map| @inmaps.push(map.id) end - @itemdata = Hash.new - @itemdata['$desc'] = item.desc - @itemdata['$link'] = item.link - @itemdata['$itemcatname'] = item.item_category.name - @itemdata['$inmaps'] = @inmaps - @itemdata['$userid'] = item.user.id - @itemdata['$username'] = item.user.name - @mapping = Mapping.find_by_item_id_and_map_id(item.id,self.id) - @itemdata['$xloc'] = @mapping.xloc - @itemdata['$yloc'] = @mapping.yloc - @itemdata['$mappingid'] = @mapping.id - json.data @itemdata - json.id item.id - json.name item.name + @topicdata = Hash.new + @topicdata['$desc'] = topic.desc + @topicdata['$link'] = topic.link + @topicdata['$metacode'] = topic.metacode.name + @topicdata['$inmaps'] = @inmaps + @topicdata['$userid'] = topic.user.id + @topicdata['$username'] = topic.user.name + @mapping = Mapping.find_by_topic_id_and_map_id(topic.id,self.id) + @topicdata['$xloc'] = @mapping.xloc + @topicdata['$yloc'] = @mapping.yloc + @topicdata['$mappingid'] = @mapping.id + json.data @topicdata + json.id topic.id + json.name topic.name end end end diff --git a/app/models/mapping.rb b/app/models/mapping.rb index b36fee81..434c19ff 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -1,6 +1,6 @@ class Mapping < ActiveRecord::Base -belongs_to :item, :class_name => "Item", :foreign_key => "item_id" +belongs_to :topic, :class_name => "Topic", :foreign_key => "topic_id" belongs_to :synapse, :class_name => "Synapse", :foreign_key => "synapse_id" belongs_to :map, :class_name => "Map", :foreign_key => "map_id" diff --git a/app/models/metacode.rb b/app/models/metacode.rb new file mode 100644 index 00000000..c181a19f --- /dev/null +++ b/app/models/metacode.rb @@ -0,0 +1,5 @@ +class Metacode < ActiveRecord::Base + +has_many :topics + +end diff --git a/app/models/synapse.rb b/app/models/synapse.rb index 6324f236..c7fe44e1 100644 --- a/app/models/synapse.rb +++ b/app/models/synapse.rb @@ -2,8 +2,8 @@ class Synapse < ActiveRecord::Base belongs_to :user -belongs_to :item1, :class_name => "Item", :foreign_key => "node1_id" -belongs_to :item2, :class_name => "Item", :foreign_key => "node2_id" +belongs_to :topic1, :class_name => "Topic", :foreign_key => "node1_id" +belongs_to :topic2, :class_name => "Topic", :foreign_key => "node2_id" has_many :mappings has_many :maps, :through => :mappings @@ -26,12 +26,12 @@ has_many :maps, :through => :mappings def selfplusnodes_as_json Jbuilder.encode do |json| - @items = Array.new - @items.push(self.item1) - @items.push(self.item2) + @topics = Array.new + @topics.push(self.topic1) + @topics.push(self.topic2) - json.array!(@items) do |item| - json.adjacencies item.synapses1.delete_if{|synapse| not @items.include?(Item.find_by_id(synapse.node2_id))} do |json, synapse| + json.array!(@topics) do |topic| + json.adjacencies topic.synapses1.delete_if{|synapse| not @topics.include?(Topic.find_by_id(synapse.node2_id))} do |json, synapse| json.nodeTo synapse.node2_id json.nodeFrom synapse.node1_id @@ -47,20 +47,20 @@ has_many :maps, :through => :mappings end @inmaps = Array.new - item.maps.each do |map| + topic.maps.each do |map| @inmaps.push(map.id) end - @itemdata = Hash.new - @itemdata['$desc'] = item.desc - @itemdata['$link'] = item.link - @itemdata['$itemcatname'] = item.item_category.name - @itemdata['$inmaps'] = @inmaps - @itemdata['$userid'] = item.user.id - @itemdata['$username'] = item.user.name - json.data @itemdata - json.id item.id - json.name item.name + @topicdata = Hash.new + @topicdata['$desc'] = topic.desc + @topicdata['$link'] = topic.link + @topicdata['$metacode'] = topic.metacode.name + @topicdata['$inmaps'] = @inmaps + @topicdata['$userid'] = topic.user.id + @topicdata['$username'] = topic.user.name + json.data @topicdata + json.id topic.id + json.name topic.name end end end diff --git a/app/models/topic.rb b/app/models/topic.rb new file mode 100644 index 00000000..bb4199a1 --- /dev/null +++ b/app/models/topic.rb @@ -0,0 +1,171 @@ +class Topic < ActiveRecord::Base + +include TopicsHelper + +belongs_to :user + +has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id' +has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id' +has_many :topics1, :through => :synapses2, :source => :topic1 +has_many :topics2, :through => :synapses1, :source => :topic2 + +has_many :mappings +has_many :maps, :through => :mappings + + def synapses + synapses1 + synapses2 + end + + def relatives + topics1 + topics2 + end + +belongs_to :metacode + + # has no viewable synapses helper function + def has_viewable_synapses(current) + result = false + self.synapses.each do |synapse| + if synapse.authorize_to_view(current) + result = true + end + end + return result + end + + ###### JSON ###### + + def self_as_json + Jbuilder.encode do |json| + @inmaps = Array.new + self.maps.each do |map| + @inmaps.push(map.id) + end + + @topicdata = Hash.new + @topicdata['$desc'] = self.desc + @topicdata['$link'] = self.link + @topicdata['$metacode'] = self.metacode.name + @topicdata['$inmaps'] = @inmaps + @topicdata['$userid'] = self.user.id + @topicdata['$username'] = self.user.name + json.data @topicdata + json.id self.id + json.name self.name + end + end + + #build a json object of everything connected to a specified node + def network_as_json(current) + Jbuilder.encode do |json| + @topics = network(self,nil,4) + + if @topics.count > 1 + json.array!(@topics.delete_if{|topic| (not topic.authorize_to_view(current)) || (not topic.has_viewable_synapses(current))}) do |topic| + + json.adjacencies topic.synapses1.delete_if{|synapse| (not @topics.include?(synapse.topic2)) || (not synapse.authorize_to_view(current)) || (not synapse.topic2.authorize_to_view(current)) } do |json, synapse| + json.nodeTo synapse.node2_id + json.nodeFrom synapse.node1_id + + @synapsedata = Hash.new + @synapsedata['$desc'] = synapse.desc + @synapsedata['$showDesc'] = false + @synapsedata['$category'] = synapse.category + @synapsedata['$id'] = synapse.id + @synapsedata['$userid'] = synapse.user.id + @synapsedata['$username'] = synapse.user.name + @synapsedata['$direction'] = [synapse.node1_id.to_s(), synapse.node2_id.to_s()] + json.data @synapsedata + end + + @inmaps = Array.new + topic.maps.each do |map| + @inmaps.push(map.id) + end + + @topicdata = Hash.new + @topicdata['$desc'] = topic.desc + @topicdata['$link'] = topic.link + @topicdata['$metacode'] = topic.metacode.name + @topicdata['$inmaps'] = @inmaps + @topicdata['$userid'] = topic.user.id + @topicdata['$username'] = topic.user.name + json.data @topicdata + json.id topic.id + json.name topic.name + end + elsif @topics.count == 1 + json.array!(@topics) do |topic| + @inmaps = Array.new + topic.maps.each do |map| + @inmaps.push(map.id) + end + + @topicdata = Hash.new + @topicdata['$desc'] = topic.desc + @topicdata['$link'] = topic.link + @topicdata['$metacode'] = topic.metacode.name + @topicdata['$inmaps'] = @inmaps + @topicdata['$userid'] = topic.user.id + @topicdata['$username'] = topic.user.name + json.data @topicdata + json.id topic.id + json.name topic.name + end + end + end + end + + ##### PERMISSIONS ###### + + scope :visibleToUser, lambda { |current, user| + if user != nil + if user != current + Topic.find_all_by_user_id_and_permission(user.id, "commons") | Topic.find_all_by_user_id_and_permission(user.id, "public") + elsif user == current + Topic.find_all_by_user_id_and_permission(user.id, "commons") | Topic.find_all_by_user_id_and_permission(user.id, "public") | current.topics.where(:permission => "private") + end + elsif (current != nil && user == nil) + Topic.find_all_by_permission("commons") | Topic.find_all_by_permission("public") | current.topics.where(:permission => "private") + elsif (current == nil) + Topic.find_all_by_permission("commons") | Topic.find_all_by_permission("public") + end + } + + # returns false if user not allowed to 'show' Topic, Synapse, or Map + def authorize_to_show(user) + if (self.permission == "private" && self.user != user) + return false + end + return self + end + + # returns false if user not allowed to 'edit' Topic, Synapse, or Map + def authorize_to_edit(user) + if (self.permission == "private" && self.user != user) + return false + elsif (self.permission == "public" && self.user != user) + return false + end + return self + end + + # returns Boolean if user allowed to view Topic, Synapse, or Map + def authorize_to_view(user) + if (self.permission == "private" && self.user != user) + return false + end + return true + end + + # returns Boolean based on whether user has permissions to edit or not + def authorize_linkto_edit(user) + if (self.user == user) + return true + elsif (self.permission == "commons") + return true + end + return false + end + +end diff --git a/app/models/user.rb b/app/models/user.rb index 1aaa3c3a..1e4f824c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,7 +2,7 @@ require 'open-uri' class User < ActiveRecord::Base -has_many :items +has_many :topics has_many :synapses has_many :maps has_many :mappings diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 2c28686a..f1703bd5 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -33,7 +33,7 @@ <% unless authenticated? %>
<% if authenticated? %> - <%= render :partial => 'items/new' %> + <%= render :partial => 'topics/new' %> <%= render :partial => 'synapses/new' %> <%= render :partial => 'maps/new' %> <% end %> @@ -43,8 +43,8 @@
- <%= form_for Item.new, :html => { :class => "find_topic_by_name find find_topic", :id => "find_topic_by_name" } do |f| %> - <%= f.autocomplete_field :name, autocomplete_item_name_items_path, :id => "topic_by_name_input", :placeholder => "Search for topics..." %> + <%= form_for Topic.new, :html => { :class => "find_topic_by_name find find_topic", :id => "find_topic_by_name" } do |f| %> + <%= f.autocomplete_field :name, autocomplete_topic_name_topics_path, :id => "topic_by_name_input", :placeholder => "Search for topics..." %> <% end %> <%= form_for Map.new, :html => { :class => "find_map_by_name find", :id => "find_map_by_name" } do |f| %> <%= f.autocomplete_field :name, autocomplete_map_name_maps_path, :id => "map_by_name_input", :placeholder => "Search for maps..." %> diff --git a/app/views/main/metamap.html.erb b/app/views/main/metamap.html.erb index f0977cac..23191a42 100644 --- a/app/views/main/metamap.html.erb +++ b/app/views/main/metamap.html.erb @@ -1,4 +1,4 @@ -<% unless @item.nil? %> +<% unless @topic.nil? %>
@@ -14,12 +14,12 @@ }); <% end %> -<% if @item.nil? %> +<% if @topic.nil? %>


Shucks, there is nothing in metamaps.

<% end %> <% if authenticated? %> - <%= render :partial => 'items/new' %> + <%= render :partial => 'topics/new' %> <%= render :partial => 'synapses/new' %> <% end %> diff --git a/app/views/main/search.js.erb b/app/views/main/search.js.erb index 6d3ab04c..04c5b436 100644 --- a/app/views/main/search.js.erb +++ b/app/views/main/search.js.erb @@ -7,11 +7,11 @@ var myX = -w + 400; var myY = -h + 100; var even = true; -<% @items.each do |item| %> +<% @topics.each do |topic| %> if ($.isEmptyObject(Mconsole.graph.nodes)) { - json = <%= item.self_as_json.html_safe %>; + json = <%= topic.self_as_json.html_safe %>; Mconsole.loadJSON(json); - var temp = Mconsole.graph.getNode('<%= item.id %>'); + var temp = Mconsole.graph.getNode('<%= topic.id %>'); temp.setData('dim', 1, 'start'); temp.setData('dim', 25, 'end'); temp.setData('inCommons',true); @@ -23,11 +23,11 @@ var even = true; even = !even; } else { - var temp = Mconsole.graph.getNode('<%= item.id %>'); + var temp = Mconsole.graph.getNode('<%= topic.id %>'); if (temp == null) { - var newnode = <%= item.self_as_json.html_safe %>; + var newnode = <%= topic.self_as_json.html_safe %>; Mconsole.graph.addNode(newnode); - var temp = Mconsole.graph.getNode('<%= item.id %>'); + var temp = Mconsole.graph.getNode('<%= topic.id %>'); temp.setData('dim', 1, 'start'); temp.setData('dim', 25, 'end'); temp.setData('inCommons',true); diff --git a/app/views/maps/_map.html.erb b/app/views/maps/_map.html.erb index ef735856..73b56a1b 100644 --- a/app/views/maps/_map.html.erb +++ b/app/views/maps/_map.html.erb @@ -2,7 +2,7 @@ <% if map.user == user %><%= link_to 'Delete', map_path(map), :class => 'delete', :confirm => 'Delete this map (nodes and synapses will remain)?', :method => :delete, :remote => true %><% end %>

<%= link_to map.name, map_path(map), :class => 'title' %> -

<%= map.desc %>

# of Topics: <%= map.items.count %>

# of Synapses: <%= map.synapses.count %>

+

<%= map.desc %>

# of Topics: <%= map.topics.count %>

# of Synapses: <%= map.synapses.count %>

<% end %> \ No newline at end of file diff --git a/app/views/maps/_newsynapse.html.erb b/app/views/maps/_newsynapse.html.erb index b707f622..06691e5e 100644 --- a/app/views/maps/_newsynapse.html.erb +++ b/app/views/maps/_newsynapse.html.erb @@ -1,8 +1,8 @@
<%= form_for Synapse.new, url: synapses_url, remote: true do |form| %> <%= form.autocomplete_field :desc, autocomplete_synapse_desc_synapses_path, :placeholder => "Describe the connection..." %> - <%= form.hidden_field :item1id, :value => 0 %> - <%= form.hidden_field :item2id, :value => 0 %> + <%= form.hidden_field :topic1id, :value => 0 %> + <%= form.hidden_field :topic2id, :value => 0 %> <%= form.hidden_field :map, :value => @map.id %> <% end %>
\ No newline at end of file diff --git a/app/views/maps/_newtopic.html.erb b/app/views/maps/_newtopic.html.erb index 145c84b2..5fd6eb61 100644 --- a/app/views/maps/_newtopic.html.erb +++ b/app/views/maps/_newtopic.html.erb @@ -1,12 +1,12 @@
-<%= form_for Item.new, url: items_url, remote: true do |form| %> +<%= form_for Topic.new, url: topics_url, remote: true do |form| %>
ActionActivityBizarreCatalystClosedExperienceFuture DevGroupIdeaImplicationInsightIntentionKnowledgeLocationOpen IssueOpinionOpportunityPersonPlatformProblemQuestionReferenceRequirementResourceRoleTaskToolTrajectory
- <%= form.autocomplete_field :name, autocomplete_item_name_items_path, :placeholder => "What is the name of your topic?" %> + <%= form.autocomplete_field :name, autocomplete_topic_name_topics_path, :placeholder => "What is the name of your topic?" %> <%= form.hidden_field :metacode, :value => "Action" %> <%= form.hidden_field :x, :value => 0 %> <%= form.hidden_field :y, :value => 0 %> <%= form.hidden_field :map, :value => @map.id %> - <%= form.hidden_field :grabItem, :value => "null" %> + <%= form.hidden_field :grabTopic, :value => "null" %> <%= form.hidden_field :addSynapse, :value => false %>
diff --git a/app/views/maps/edit.html.erb b/app/views/maps/edit.html.erb index 55818179..131617be 100644 --- a/app/views/maps/edit.html.erb +++ b/app/views/maps/edit.html.erb @@ -4,8 +4,8 @@ <%= form.text_field :name %> <%= form.text_area :desc, class: "description", :rows => 5 %> - - <%= select_tag "outitems", options_from_collection_for_select(@outitems, "id", "name"), { :multiple => true } %> + + <%= select_tag "outtopics", options_from_collection_for_select(@outtopics, "id", "name"), { :multiple => true } %> <%= form.select :permission, options_for_select(['commons', 'public', 'private'], @map.permission) %> <%= form.submit "Update", class: "update" %> diff --git a/app/views/maps/show.html.erb b/app/views/maps/show.html.erb index 9ca0a908..0d075348 100644 --- a/app/views/maps/show.html.erb +++ b/app/views/maps/show.html.erb @@ -1,6 +1,6 @@
-

# of Topics: <%= @map.items.count %>

+

# of Topics: <%= @map.topics.count %>

# of Synapses: <%= @map.synapses.count %>

<% if (@map.permission == "commons" && authenticated?) || @map.user == user %> <%= form_for @map, :url => savelayout_path(@map), :html => { :class => "saveMapLayout", :id => "saveMapLayout"}, remote: true do |form| %> diff --git a/app/views/synapses/_new.html.erb b/app/views/synapses/_new.html.erb index f9b2f8a6..3d7140a3 100644 --- a/app/views/synapses/_new.html.erb +++ b/app/views/synapses/_new.html.erb @@ -1,7 +1,7 @@
<%= form_for Synapse.new, url: synapses_url, remote: true do |form| %> <%= form.autocomplete_field :desc, autocomplete_synapse_desc_synapses_path, :placeholder => "Describe the connection..." %> - <%= form.hidden_field :item1id, :value => 0 %> - <%= form.hidden_field :item2id, :value => 0 %> + <%= form.hidden_field :topic1id, :value => 0 %> + <%= form.hidden_field :topic2id, :value => 0 %> <% end %>
\ No newline at end of file diff --git a/app/views/synapses/create.js.erb b/app/views/synapses/create.js.erb index 89c180fe..1823b646 100644 --- a/app/views/synapses/create.js.erb +++ b/app/views/synapses/create.js.erb @@ -1,13 +1,13 @@ $('#new_synapse').fadeOut('fast'); $('#synapse_desc').attr('value',''); -$('#synapse_item1id').attr('value','0'); -$('#synapse_item2id').attr('value','0'); +$('#synapse_topic1id').attr('value','0'); +$('#synapse_topic2id').attr('value','0'); var temp1, temp2, temp; if ( Mconsole != null) { - temp1 = Mconsole.graph.getNode(<%= @synapse.item1.id %>); - temp2 = Mconsole.graph.getNode(<%= @synapse.item2.id %>); + temp1 = Mconsole.graph.getNode(<%= @synapse.topic1.id %>); + temp2 = Mconsole.graph.getNode(<%= @synapse.topic2.id %>); Mconsole.graph.addAdjacence(temp1, temp2, {}); temp = Mconsole.graph.getAdjacence(temp1.id, temp2.id); console.log(temp); diff --git a/app/views/synapses/edit.html.erb b/app/views/synapses/edit.html.erb index fb6d8c92..ecb2bd49 100644 --- a/app/views/synapses/edit.html.erb +++ b/app/views/synapses/edit.html.erb @@ -1,16 +1,16 @@ <%= form_for @synapse, url: synapse_url do |form| %>

Edit Synapse

- <% if Item.visibleToUser(user, nil).count > 0 %> + <% if Topic.visibleToUser(user, nil).count > 0 %> - <%= select "node1_id", "node1", Item.order("name ASC").visibleToUser(user, nil).map {|p| [ p.name, p.id ] }, { :selected => @synapse.node1_id } %> + <%= select "node1_id", "node1", Topic.order("name ASC").visibleToUser(user, nil).map {|p| [ p.name, p.id ] }, { :selected => @synapse.node1_id } %> <% end %> - + <%= form.select :category, options_for_select(['none', 'both', 'from-to'], @synapse.category) %> - + <%= form.text_field :desc, class: "description" %> - <% if Item.visibleToUser(user, nil).count > 0 %> + <% if Topic.visibleToUser(user, nil).count > 0 %> - <%= select "node2_id", "node2", Item.order("name ASC").visibleToUser(user, nil).map {|p| [ p.name, p.id ] }, { :selected => @synapse.node2_id } %> + <%= select "node2_id", "node2", Topic.order("name ASC").visibleToUser(user, nil).map {|p| [ p.name, p.id ] }, { :selected => @synapse.node2_id } %> <% end %> <%= form.select :permission, options_for_select(['commons', 'public', 'private'], @synapse.permission) %> diff --git a/app/views/synapses/index.html.erb b/app/views/synapses/index.html.erb index 1f5fa883..0f7daa11 100644 --- a/app/views/synapses/index.html.erb +++ b/app/views/synapses/index.html.erb @@ -17,6 +17,6 @@ <% if authenticated? %> - <%= render :partial => 'items/new' %> + <%= render :partial => 'topics/new' %> <%= render :partial => 'synapses/new' %> <% end %> diff --git a/app/views/synapses/new.html.erb b/app/views/synapses/new.html.erb index df15d932..25253d08 100644 --- a/app/views/synapses/new.html.erb +++ b/app/views/synapses/new.html.erb @@ -1,17 +1,17 @@
<%= form_for @synapse, url: synapses_url do |form| %>

Add Synapse Between Topics

- <% if Item.visibleToUser(user, nil).count > 0 %> + <% if Topic.visibleToUser(user, nil).count > 0 %> - <%= select_tag :node1_id, options_from_collection_for_select(Item.order("name ASC").visibleToUser(user, nil), "id", "name") %> + <%= select_tag :node1_id, options_from_collection_for_select(Topic.order("name ASC").visibleToUser(user, nil), "id", "name") %> <% end %> - + <%= form.select :category, options_for_select(['none', 'both', 'from-to']) %> - + <%= form.text_field :desc, class: "description" %> - <% if Item.visibleToUser(user, nil).count > 0 %> + <% if Topic.visibleToUser(user, nil).count > 0 %> - <%= select_tag :node2_id, options_from_collection_for_select(Item.order("name ASC").visibleToUser(user, nil), "id", "name") %> + <%= select_tag :node2_id, options_from_collection_for_select(Topic.order("name ASC").visibleToUser(user, nil), "id", "name") %> <% end %> <%= form.select(:permission, options_for_select(['commons', 'public', 'private'])) %> diff --git a/app/views/synapses/show.html.erb b/app/views/synapses/show.html.erb index fba2e70a..876ea7c6 100644 --- a/app/views/synapses/show.html.erb +++ b/app/views/synapses/show.html.erb @@ -16,6 +16,6 @@ <% if authenticated? %> - <%= render :partial => 'items/new' %> + <%= render :partial => 'topics/new' %> <%= render :partial => 'synapses/new' %> <% end %> \ No newline at end of file diff --git a/app/views/topics/_new.html.erb b/app/views/topics/_new.html.erb new file mode 100644 index 00000000..0c9cd856 --- /dev/null +++ b/app/views/topics/_new.html.erb @@ -0,0 +1,15 @@ +
+<%= form_for Topic.new, url: topics_url, remote: true do |form| %> +
ActionActivityBizarreCatalystClosedExperienceFuture DevGroupIdeaImplicationInsightIntentionKnowledgeLocationOpen IssueOpinionOpportunityPersonPlatformProblemQuestionReferenceRequirementResourceRoleTaskToolTrajectory
+ <%= form.autocomplete_field :name, autocomplete_topic_name_topics_path, :placeholder => "What is the name of your topic?" %> + <%= form.hidden_field :metacode, :value => "Action" %> + <%= form.hidden_field :x, :value => 0 %> + <%= form.hidden_field :y, :value => 0 %> + <%= form.hidden_field :grabTopic, :value => "null" %> + <%= form.hidden_field :addSynapse, :value => false %> + +
+ +
+<% end %> +
diff --git a/app/views/topics/_topic.html.erb b/app/views/topics/_topic.html.erb new file mode 100644 index 00000000..346d8aeb --- /dev/null +++ b/app/views/topics/_topic.html.erb @@ -0,0 +1,10 @@ +<%= div_for topic, class: topic.metacode.name do %> + <% if topic.user == user %><%= link_to 'Delete', topic_path(topic), :class => 'delete', :confirm => 'Delete this topic and all synapses linking to it?', :method => :delete, :remote => true%><% end %> +

<%= topic.metacode.name %>

+ <%= image_tag topic.metacode.icon, :class => 'icon', :size => '50x50' %> +
+ <%= link_to topic.name, topic_path(topic), :class => 'title' %> +

<%=topic.desc %>

+
+ <%= link_to topic.link, topic.link, :class => 'link', :target => '_blank' %> +<% end %> \ No newline at end of file diff --git a/app/views/topics/create.js.erb b/app/views/topics/create.js.erb new file mode 100644 index 00000000..debc125c --- /dev/null +++ b/app/views/topics/create.js.erb @@ -0,0 +1,83 @@ +$('#new_topic').fadeOut('fast'); +$('#topic_name').data().autocomplete.term = null; +$('.ui-autocomplete').children().remove(); +$('.ui-autocomplete').css('display','none'); +$('#topic_name').attr('value',''); +$('#topic_grabTopic').attr('value','null'); +$('#topic_addSynapse').attr('value','false'); + + + +var newnode = <%= @topic.self_as_json.html_safe %>; +var x = <%= @position['x'] %>; +var y = <%= @position['y'] %>; + + +if (!$.isEmptyObject(Mconsole.graph.nodes)) { + Mconsole.graph.addNode(newnode); + + // set the animation for everything back to normal + Mconsole.graph.eachNode( function (n) { + n.setData('dim', 25, 'start'); + n.setData('dim', 25, 'end'); + }); + var temp = Mconsole.graph.getNode('<%= @topic.id %>'); + temp.setData('dim', 1, 'start'); + temp.setData('dim', 40, 'end'); + + if (gType == "centered") { + var tempPos = new $jit.Complex(x, y); + tempPos = tempPos.toPolar(); + temp.setPos(tempPos, 'current'); + temp.setPos(tempPos, 'start'); + temp.setPos(tempPos, 'end'); + } + else if (gType == "arranged" || gType == "chaotic") { + temp.setData('xloc',0); + temp.setData('yloc',0); + temp.setData('mappingid', '<%= @mapping.id %>'); + temp.setPos(new $jit.Complex(x, y), 'current'); + temp.setPos(new $jit.Complex(x, y), 'start'); + temp.setPos(new $jit.Complex(x, y), 'end'); + } + + if ( '<%= @synapse %>' == "true" ) { + $('#synapse_topic1id').val(tempNode.id); + $('#synapse_topic2id').val(temp.id); + $('#new_synapse').fadeIn('fast'); + $('#synapse_desc').focus(); + Mconsole.fx.animate({ + modes: ['node-property:dim'], + duration: 500, + onComplete: function() { + renderMidArrow({ x: tempNode.pos.getc().x, y: tempNode.pos.getc().y }, { x: temp.pos.getc().x, y: temp.pos.getc().y }, 13, false, Mconsole.canvas); + Mconsole.fx.plotNode(tempNode, Mconsole.canvas); + Mconsole.fx.plotNode(temp, Mconsole.canvas); + tempNode = null; + tempNode2 = null; + tempInit = false; + } + }); + } else { + Mconsole.fx.plotNode(temp, Mconsole.canvas); + Mconsole.fx.animate({ + modes: ['node-property:dim'], + duration: 500 + }); + } + +} else { + json = newnode; + Mconsole.loadJSON(json); + var temp = Mconsole.graph.getNode('<%= @topic.id %>'); + temp.setData('dim', 1, 'start'); + temp.setData('dim', 25, 'end'); + temp.setPos(new $jit.Complex(x, y), 'current'); + temp.setPos(new $jit.Complex(x, y), 'start'); + temp.setPos(new $jit.Complex(x, y), 'end'); + Mconsole.fx.plotNode(temp, Mconsole.canvas); + Mconsole.fx.animate({ + modes: ['node-property:dim'], + duration: 500 + }); +} diff --git a/app/views/topics/destroy.js.erb b/app/views/topics/destroy.js.erb new file mode 100644 index 00000000..da2a26ae --- /dev/null +++ b/app/views/topics/destroy.js.erb @@ -0,0 +1 @@ +$('#<%= dom_id(@topic) %>').fadeOut('slow'); \ No newline at end of file diff --git a/app/views/topics/edit.html.erb b/app/views/topics/edit.html.erb new file mode 100644 index 00000000..88b7a6af --- /dev/null +++ b/app/views/topics/edit.html.erb @@ -0,0 +1,14 @@ +<%= form_for @topic, url: topic_url do |form| %> +

Edit Topic

+ + <%= select "category", "metacode_id", Metacode.order("name ASC").all.collect {|p| [ p.name, p.id ] }, { :selected => @topic.metacode.id } %> + + <%= form.text_field :name %> + + <%= form.text_area :desc, class: "description", :rows => 5 %> + + <%= form.text_field :link, class: "link" %> + + <%= form.select :permission, options_for_select(['commons', 'public', 'private'], @topic.permission) %> + <%= form.submit "Update", class: "update" %> +<% end %> \ No newline at end of file diff --git a/app/views/topics/index.html.erb b/app/views/topics/index.html.erb new file mode 100644 index 00000000..f3b801d0 --- /dev/null +++ b/app/views/topics/index.html.erb @@ -0,0 +1,11 @@ +

<% if @user %><%= @user.name %>'s<% end %> Topics

+ +
+ <% @topics.each do |topic| %> + <%= render topic %> + <% end %> + <% if @topics.empty? %> +


Shucks, there are no topics. <% if authenticated? %><%= link_to "Create some if you want.", console_url %><% end %>

+ <% end %> +
+
\ No newline at end of file diff --git a/app/views/topics/new.html.erb b/app/views/topics/new.html.erb new file mode 100644 index 00000000..bcf9d9cc --- /dev/null +++ b/app/views/topics/new.html.erb @@ -0,0 +1,16 @@ +
+<%= form_for @topic || Topic.new, url: topics_path do |form| %> +

Add Topic

+ + <%= select_tag "category", options_from_collection_for_select(Metacode.order("name ASC").all, "id", "name") %> + + <%= form.text_field :name %> + + <%= form.text_area :desc, class: "description", :rows => 5 %> + + <%= form.text_field :link, class: "link" %> + + <%= form.select(:permission, options_for_select(['commons', 'public', 'private'])) %> + <%= form.submit "Add Topic", class: "addTopic", id: "addTopic" %> +<% end %> +
\ No newline at end of file diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb new file mode 100644 index 00000000..c80ea25b --- /dev/null +++ b/app/views/topics/show.html.erb @@ -0,0 +1,38 @@ +
+
+

<%= @topic.metacode.name %>

+ <%= image_tag @topic.metacode.icon, :class => 'icon', :size => '50x50' %> +
+
+

<%= @topic.name %> <% if (@topic.permission == "commons" && authenticated?) || @topic.user == user %><%= link_to "[edit]", edit_topic_path(@topic) %><% end %>

+
+

<%= @topic.desc %>

+
+
+
+

Link

+ <%= link_to @topic.link, @topic.link, :class => 'link', :target => '_blank' %> +
+
+
+ +
+
+
+
+
+
+ + + +<% if authenticated? %> + <%= render :partial => 'topics/new' %> + <%= render :partial => 'synapses/new' %> +<% end %> + diff --git a/app/views/topics/showcard.html.erb b/app/views/topics/showcard.html.erb new file mode 100644 index 00000000..ccceea1d --- /dev/null +++ b/app/views/topics/showcard.html.erb @@ -0,0 +1,29 @@ +
+
+

+ <%= @topic.metacode.name %> +

+ <%= @topic.metacode.name %> +
+ + <%= @topic.name %> + +
+ Added by: + + <%= @user.name %> + +
+
+

+ <%= @topic.desc %> +

+
+
+ + <%= @topic.link %> + +
+
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index cd1902f1..c7240ceb 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,13 +1,13 @@
-

# of Topics: <%= @user.items.count %>

+

# of Topics: <%= @user.topics.count %>

# of Synapses: <%= @user.synapses.count %>

# of Maps: <%= @user.maps.count %>

<%= @user.name %>

-

<%= link_to "View their topics", user_items_path(@user)%>

+

<%= link_to "View their topics", user_topics_path(@user)%>

<%= link_to "View their synapses", user_synapses_path(@user)%>

<%= link_to "View their maps", user_maps_path(@user) %>

diff --git a/config/routes.rb b/config/routes.rb index cd1dafda..fe7301d5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,8 +14,8 @@ ISSAD::Application.routes.draw do resource :session - resources :items do - get :autocomplete_item_name, :on => :collection + resources :topics do + get :autocomplete_topic_name, :on => :collection end resources :synapses do @@ -28,7 +28,7 @@ ISSAD::Application.routes.draw do resources :users do get :autocomplete_user_name, :on => :collection - resources :items, :only => [:index] + resources :topics, :only => [:index] resources :synapses, :only => [:index] resources :maps, :only => [:index] end diff --git a/db/migrate/20120920013446_create_users.rb b/db/migrate/20120920013446_create_users.rb index aa0cea24..6c603cd0 100644 --- a/db/migrate/20120920013446_create_users.rb +++ b/db/migrate/20120920013446_create_users.rb @@ -3,8 +3,8 @@ class CreateUsers < ActiveRecord::Migration create_table :users do |t| t.string :name t.string :email - t.string :code, :limit => 8 - t.string :joinedwithcode, :limit => 8 + t.string :code, :limit => 8 + t.string :joinedwithcode, :limit => 8 t.string :crypted_password t.string :password_salt t.string :persistence_token diff --git a/db/migrate/20121005160234_create_synapses.rb b/db/migrate/20121005160234_create_synapses.rb index 17b1f5a3..4ff17811 100644 --- a/db/migrate/20121005160234_create_synapses.rb +++ b/db/migrate/20121005160234_create_synapses.rb @@ -2,12 +2,12 @@ class CreateSynapses < ActiveRecord::Migration def change create_table :synapses do |t| t.text :desc - t.text :category - t.text :weight - t.text :permission - t.integer :node1_id - t.integer :node2_id - t.integer :user_id + t.text :category + t.text :weight + t.text :permission + t.integer :node1_id + t.integer :node2_id + t.integer :user_id t.timestamps end diff --git a/db/migrate/20121026000731_create_mappings.rb b/db/migrate/20121026000731_create_mappings.rb index b03ee426..01598d5c 100644 --- a/db/migrate/20121026000731_create_mappings.rb +++ b/db/migrate/20121026000731_create_mappings.rb @@ -2,12 +2,12 @@ class CreateMappings < ActiveRecord::Migration def change create_table :mappings do |t| t.text :category - t.integer :xloc + t.integer :xloc t.integer :yloc - t.integer :item_id - t.integer :synapse_id - t.integer :map_id - t.integer :user_id + t.integer :topic_id + t.integer :synapse_id + t.integer :map_id + t.integer :user_id t.timestamps end end diff --git a/db/migrate/20130101193917_create_topics.rb b/db/migrate/20130101193917_create_topics.rb new file mode 100644 index 00000000..34f9a538 --- /dev/null +++ b/db/migrate/20130101193917_create_topics.rb @@ -0,0 +1,13 @@ +class CreateTopics < ActiveRecord::Migration + def change + create_table :topics do |t| + t.text :name + t.text :desc + t.text :link + t.text :permission + t.integer :user_id + t.integer :metacode_id + t.timestamps + end + end +end diff --git a/db/migrate/20130101194424_create_metacodes.rb b/db/migrate/20130101194424_create_metacodes.rb new file mode 100644 index 00000000..154c8afe --- /dev/null +++ b/db/migrate/20130101194424_create_metacodes.rb @@ -0,0 +1,10 @@ +class CreateMetacodes < ActiveRecord::Migration + def change + create_table :metacodes do |t| + t.text :name + t.string :icon + + t.timestamps + end + end +end diff --git a/db/migrate/20130101215010_items_to_topics.rb b/db/migrate/20130101215010_items_to_topics.rb new file mode 100644 index 00000000..114c6fcf --- /dev/null +++ b/db/migrate/20130101215010_items_to_topics.rb @@ -0,0 +1,9 @@ +class ItemsToTopics < ActiveRecord::Migration + def change + rename_column :items, :item_category_id, :metacode_id + rename_column :mappings, :item_id, :topic_id + + rename_table :items, :topics + rename_table :item_categories, :metacodes + end +end diff --git a/db/schema.rb b/db/schema.rb index c4f01152..7ff926ce 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20121203225613) do +ActiveRecord::Schema.define(:version => 20130101215010) do create_table "item_categories", :force => true do |t| t.text "name" @@ -35,7 +35,7 @@ ActiveRecord::Schema.define(:version => 20121203225613) do t.text "category" t.integer "xloc" t.integer "yloc" - t.integer "item_id" + t.integer "topic_id" t.integer "synapse_id" t.integer "map_id" t.integer "user_id" @@ -53,6 +53,13 @@ ActiveRecord::Schema.define(:version => 20121203225613) do t.boolean "arranged" end + create_table "metacodes", :force => true do |t| + t.text "name" + t.string "icon" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "synapses", :force => true do |t| t.text "desc" t.text "category" @@ -65,6 +72,17 @@ ActiveRecord::Schema.define(:version => 20121203225613) do t.datetime "updated_at", :null => false end + create_table "topics", :force => true do |t| + t.text "name" + t.text "desc" + t.text "link" + t.text "permission" + t.integer "user_id" + t.integer "metacode_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "users", :force => true do |t| t.string "name" t.string "email" diff --git a/test/fixtures/mappings.yml b/test/fixtures/mappings.yml index c63aac0b..9cfe87b6 100644 --- a/test/fixtures/mappings.yml +++ b/test/fixtures/mappings.yml @@ -4,8 +4,8 @@ # model remove the '{}' from the fixture names and add the columns immediately # below each fixture, per the syntax in the comments below # -one: {} +#one: {} # column: value # -two: {} +#two: {} # column: value diff --git a/test/fixtures/metacodes.yml b/test/fixtures/metacodes.yml new file mode 100644 index 00000000..4af9d7ea --- /dev/null +++ b/test/fixtures/metacodes.yml @@ -0,0 +1,117 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: + name: Action + icon: action.png + +two: + name: Activity + icon: activity.png + +three: + name: Bizarre + icon: bizarre.png + +four: + name: Catalyst + icon: catalyst.png + +five: + name: Closed + icon: closed.png + +six: + name: Experience + icon: experience.png + +seven: + name: Future Dev + icon: futuredev.png + +eight: + name: Group + icon: group.png + +nine: + name: Idea + icon: idea.png + +ten: + name: Implication + icon: implication.png + +eleven: + name: Insight + icon: insight.png + +twelve: + name: Intention + icon: intention.png + +thirteen: + name: Knowledge + icon: knowledge.png + +fourteen: + name: Location + icon: location.png + +fifteen: + name: Open Issue + icon: openissue.png + +sixteen: + name: Opinion + icon: opinion.png + +seventeen: + name: Opportunity + icon: opportunity.png + +eighteen: + name: Person + icon: person.png + +nineteen: + name: Platform + icon: platform.png + +twenty: + name: Problem + icon: problem.png + +twenty-one: + name: Question + icon: question.png + +twenty-two: + name: Reference + icon: reference.png + +twenty-three: + name: Requirement + icon: requirement.png + +twenty-four: + name: Resource + icon: resource.png + +twenty-five: + name: Role + icon: role.png + +twenty-six: + name: Task + icon: task.png + +twenty-seven: + name: Tool + icon: tool.png + +twenty-eight: + name: Trajectory + icon: trajectory.png diff --git a/test/fixtures/topics.yml b/test/fixtures/topics.yml new file mode 100644 index 00000000..9cfe87b6 --- /dev/null +++ b/test/fixtures/topics.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +#one: {} +# column: value +# +#two: {} +# column: value diff --git a/test/functional/topics_controller_test.rb b/test/functional/topics_controller_test.rb new file mode 100644 index 00000000..dd41edd9 --- /dev/null +++ b/test/functional/topics_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class TopicsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/helpers/topics_helper_test.rb b/test/unit/helpers/topics_helper_test.rb new file mode 100644 index 00000000..12cc0b4f --- /dev/null +++ b/test/unit/helpers/topics_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class TopicsHelperTest < ActionView::TestCase +end diff --git a/test/unit/metacode_test.rb b/test/unit/metacode_test.rb new file mode 100644 index 00000000..7bfd318d --- /dev/null +++ b/test/unit/metacode_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class MetacodeTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/topic_test.rb b/test/unit/topic_test.rb new file mode 100644 index 00000000..90522ee5 --- /dev/null +++ b/test/unit/topic_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class TopicTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end