diff --git a/app/assets/images/settings.png b/app/assets/images/settings.png new file mode 100644 index 00000000..d3348a38 Binary files /dev/null and b/app/assets/images/settings.png differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 53fa7a6a..5bf1dba0 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -83,7 +83,40 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null, },800); } ); - + + + // controls the sliding hover of the settings for cards + var sliding2 = false; + var lT2; + $(".permActivator").hover( + function () { + clearTimeout(lT2); + if (! sliding2) { + sliding2 = true; + $(this).animate({ + width: '203px', + height: '37px' + }, 300, function() { + sliding2 = false; + }); + } + }, + function () { + that = this; + lT2 = setTimeout(function() { + if (! sliding2) { + sliding2 = true; + $(that).animate({ + height: '16px', + width: '16px' + }, 300, function() { + sliding2 = false; + }); + } + },800); + } + ); + // this is to save the layout of maps when you're on a map page $("#saveLayout").click(function(event) { event.preventDefault(); diff --git a/app/assets/javascripts/topics.js.coffee b/app/assets/javascripts/topics.js.coffee index 6a1b3adb..1f13e754 100644 --- a/app/assets/javascripts/topics.js.coffee +++ b/app/assets/javascripts/topics.js.coffee @@ -3,4 +3,4 @@ # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ jQuery -> - $('.authenticated .best_in_place').best_in_place() \ No newline at end of file + $('.authenticated div.permission.canEdit .best_in_place').best_in_place() \ No newline at end of file diff --git a/app/assets/stylesheets/base.css b/app/assets/stylesheets/base.css index 82053042..416154e4 100644 --- a/app/assets/stylesheets/base.css +++ b/app/assets/stylesheets/base.css @@ -135,3 +135,44 @@ margin-right: -8px; .CardOnGraph .go-link { float:left; } + +.cardSettings { + position: absolute; + left: 12px; + top: 13px; +} + +.editSettings { + background: #ddd; + border-radius: 10px; + padding: 5px 0 5px 5px; + position: relative; + left: 16px; + width: 172px; + opacity: 0.98; + box-shadow: 4px 4px 5px #888888; + border: 1px solid #AAA; +} + +.editSettings span { + float:left; +} + +.permActivator { + width: 16px; + height: 16px; + background: url('settings.png') no-repeat 0 0; + overflow:hidden; +} + +.mapPerm { + background: #fff; + padding: 0 4px 4px 4px; + border-radius: 15px; + border: 1px solid #AAA; + position: absolute; + left: -7px; + top: 18px; + width:16px; + text-align:center; +} diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index d6fc3079..624fad22 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -6,9 +6,12 @@ class MainController < ApplicationController respond_to :html, :js, :json def home - @topics = Topic.order("created_at DESC").limit(3).visibleToUser(@current, nil) - @synapses = Synapse.order("created_at DESC").limit(3).visibleToUser(@current, nil) - @maps = Map.order("created_at DESC").limit(3).visibleToUser(@current, nil) + @topics = Topic.visibleToUser(@current, nil).sort! { |a,b| b.created_at <=> a.created_at } + @topics = @topics.slice(0,3) + @synapses = Synapse.visibleToUser(@current, nil).sort! { |a,b| b.created_at <=> a.created_at } + @synapses = @synapses.slice(0,3) + @maps = Map.visibleToUser(@current, nil).sort! { |a,b| b.created_at <=> a.created_at } + @maps = @maps.slice(0,3) respond_with(@topics, @synapses, @maps) end diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 9fe67c24..cdd9fba4 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -1,6 +1,6 @@ class MapsController < ApplicationController - before_filter :require_user, only: [:new, :create, :edit, :update, :savelayout] + before_filter :require_user, only: [:new, :create, :edit, :update, :savelayout, :destroy] respond_to :html, :js, :json @@ -48,6 +48,21 @@ class MapsController < ApplicationController end end + # GET maps/:id/json + def json + + @current = current_user + @map = Map.find(params[:id]).authorize_to_show(@current) + + if not @map + redirect_to root_url and return + end + + respond_to do |format| + format.json { render :json => @map.self_as_json(@current) } + end + end + # POST maps def create @@ -116,13 +131,19 @@ class MapsController < ApplicationController # PUT maps/:id def update - @map = Map.find(params[:id]) + @current = current_user + @map = Map.find(params[:id]).authorize_to_edit(@current) - @map.attributes = params[:map] - @map.save - - respond_with(@user, location: map_path(@map)) do |format| + if @map + if params[:map] + @map.name = params[:map][:name] if params[:map][:name] + @map.desc = params[:map][:desc] if params[:map][:desc] + @map.permission = params[:map][:permission] if params[:map][:permission] + end + @map.save end + + respond_with @map end # PUT maps/:id/savelayout diff --git a/app/controllers/synapses_controller.rb b/app/controllers/synapses_controller.rb index 37148792..c329bc25 100644 --- a/app/controllers/synapses_controller.rb +++ b/app/controllers/synapses_controller.rb @@ -1,7 +1,7 @@ class SynapsesController < ApplicationController include TopicsHelper - before_filter :require_user, only: [:new, :create, :edit, :update] + before_filter :require_user, only: [:new, :create, :edit, :update, :destroy] respond_to :html, :js, :json @@ -54,6 +54,20 @@ class SynapsesController < ApplicationController end end + # GET synapses/:id/json + def json + @current = current_user + @synapse = Synapse.find(params[:id]).authorize_to_show(@current) + + if not @synapse + redirect_to root_url and return + end + + respond_to do |format| + format.json { render :json => @synapse.selfplusnodes_as_json } + end + end + # POST synapses def create @@ -69,12 +83,18 @@ class SynapsesController < ApplicationController @synapse.save if params[:synapse][:map] - @mapping = Mapping.new() + @map = Map.find(params[:synapse][:map]) + + @mapping = Mapping.new() @mapping.category = "Synapse" @mapping.user = @user - @mapping.map = Map.find(params[:synapse][:map]) + @mapping.map = @map @mapping.synapse = @synapse @mapping.save + + # set the permission of the synapse to whatever the permission of the map is + @synapse.permission = @map.permission + @synapse.save end respond_to do |format| diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index ccbc0104..9ad6353a 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -1,5 +1,5 @@ class TopicsController < ApplicationController - before_filter :require_user, only: [:new, :create, :edit, :update] + before_filter :require_user, only: [:new, :create, :edit, :update, :destroy] respond_to :html, :js, :json @@ -45,6 +45,20 @@ class TopicsController < ApplicationController format.json { respond_with(@relatives) } end end + + # GET topics/:id/json + def json + @current = current_user + @topic = Topic.find(params[:id]).authorize_to_show(@current) + + if not @topic + redirect_to root_url and return + end + + respond_to do |format| + format.json { render :json => @topic.self_as_json } + end + end # POST topics def create @@ -63,6 +77,12 @@ class TopicsController < ApplicationController @topic.permission = 'commons' @topic.metacode = Metacode.find_by_name(params[:topic][:metacode]) @topic.user = @user + + #if being created on a map, set topic by default to whatever permissions the map is + if params[:topic][:map] + @map = Map.find(params[:topic][:map]) + @topic.permission = @map.permission + end @topic.save end @@ -81,9 +101,11 @@ class TopicsController < ApplicationController # set this for the case where the topic is being created on a map. @mapping = Mapping.new() if params[:topic][:map] + @map = Map.find(params[:topic][:map]) + @mapping.category = "Topic" @mapping.user = @user - @mapping.map = Map.find(params[:topic][:map]) + @mapping.map = @map @mapping.topic = @topic @mapping.xloc = params[:topic][:x] @mapping.yloc = params[:topic][:y] @@ -116,18 +138,15 @@ class TopicsController < ApplicationController if @topic if params[:topic] @topic.name = params[:topic][:name] if params[:topic][:name] - @topic.desc = params[:topic][:desc] if params[:topic][:desc] - @topic.link = params[:topic][:link] if params[:topic][:link] - @topic.permission = params[:topic][:permission] if params[:topic][:permission] + @topic.desc = params[:topic][:desc] if params[:topic][:desc] + @topic.link = params[:topic][:link] if params[:topic][:link] + @topic.permission = params[:topic][:permission] if params[:topic][:permission] @topic.metacode = Metacode.find_by_name(params[:topic][:metacode]) if params[:topic][:metacode] end @topic.save - end + end - respond_with @topic - -# respond_with(@user, location: topic_url(@topic)) do |format| -# end + respond_with @topic end # GET mappings/:map_id/:topic_id/removefrommap diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f603cb31..5ca2cf36 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -21,12 +21,15 @@ class UsersController < ApplicationController respond_with(@user) end - # GET /user + # GET /user/:id def show @user = User.find(params[:id]) - @topics = @user.topics.order("created_at DESC").limit(3) - @synapses = @user.synapses.order("created_at DESC").limit(3) - @maps = @user.maps.order("created_at DESC").limit(3) + @topics = Topic.visibleToUser(@current, @user).sort! { |a,b| b.created_at <=> a.created_at } + @topics = @topics.slice(0,3) + @synapses = Synapse.visibleToUser(@current, @user).sort! { |a,b| b.created_at <=> a.created_at } + @synapses = @synapses.slice(0,3) + @maps = Map.visibleToUser(@current, @user).sort! { |a,b| b.created_at <=> a.created_at } + @maps = @maps.slice(0,3) respond_with(@user, @topics, @synapses, @maps) end diff --git a/app/models/map.rb b/app/models/map.rb index 0877ba43..9f4df383 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -11,6 +11,16 @@ has_many :synapses, :through => :synapsemappings def mappings topicmappings + synapsemappings end + +def mk_permission + if self.permission == "commons" + "co" + elsif self.permission == "public" + "pu" + elsif self.permission == "private" + "pr" + end +end ###### JSON ###### diff --git a/app/models/topic.rb b/app/models/topic.rb index bf9076ab..cb6960a7 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -25,6 +25,16 @@ belongs_to :metacode def topic_autocomplete_method "Get: #{self.name}" end + + def mk_permission + if self.permission == "commons" + "cc" + elsif self.permission == "public" + "pu" + elsif self.permission == "private" + "pr" + end + end # has no viewable synapses helper function def has_viewable_synapses(current) diff --git a/app/views/maps/_map.html.erb b/app/views/maps/_map.html.erb index 9d3e5410..fdf5a566 100644 --- a/app/views/maps/_map.html.erb +++ b/app/views/maps/_map.html.erb @@ -1,16 +1,30 @@ <%# # @file # Shows a map as a card. - # I believe this is rendered on the profile pages. - # TODO: Am I correct? - # TODO: Is it rendered on any other pages? + # Any list of maps uses this rendering. #%> <%= div_for map do %> + <% if map.authorize_to_edit(user) %> +
+ + <% if map.authorize_to_edit(user) %> + + <% end %> <% end %> diff --git a/app/views/maps/_new.html.erb b/app/views/maps/_new.html.erb index a9526cb3..bcf4b8e2 100644 --- a/app/views/maps/_new.html.erb +++ b/app/views/maps/_new.html.erb @@ -9,8 +9,9 @@ <%= form.text_field :name %> <%= form.text_area :desc, class: "description", :rows => 5 %> - + <%= form.select(:permission, options_for_select(['commons', 'public', 'private'])) %> +Topics and synapses you create newly on this map will be set by default to the permissions of your map.
<%= form.hidden_field :topicsToMap, :value => 0 %> <%= form.hidden_field :synapsesToMap, :value => 0 %> <%= form.submit "Save", class: "add" %> diff --git a/app/views/maps/edit.html.erb b/app/views/maps/edit.html.erb index 9fe916a3..65bdc588 100644 --- a/app/views/maps/edit.html.erb +++ b/app/views/maps/edit.html.erb @@ -1,8 +1,7 @@ <%# # @file # Form for editing a map - # TODO: I think this code is no longer in use. Is it? - # TODO: What URL is this accessible at? + # Located at addresses /maps/:id/edit. In use. #%> <%= form_for @map, url: map_url(@map) do |form| %>Topics and synapses you create newly on this map will be set by default to the permissions of your map.
<%= form.submit "Add Map", class: "add" %> <% end %>