From 1633b61637c8b3c13b3551b22d8dbd817829d5ff Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Fri, 18 Jan 2013 17:08:06 -0500 Subject: [PATCH] permissions not fully fully functional yet, don't push to staging. editing of maps as cards in place. raw data available as json at maps/:id/json, or topics/:id/json, or synapses/:id/json --- app/assets/images/settings.png | Bin 0 -> 3071 bytes app/assets/javascripts/application.js | 35 +++++++++++++++++++- app/assets/javascripts/topics.js.coffee | 2 +- app/assets/stylesheets/base.css | 41 ++++++++++++++++++++++++ app/controllers/main_controller.rb | 9 ++++-- app/controllers/maps_controller.rb | 33 +++++++++++++++---- app/controllers/synapses_controller.rb | 26 +++++++++++++-- app/controllers/topics_controller.rb | 39 ++++++++++++++++------ app/controllers/users_controller.rb | 11 ++++--- app/models/map.rb | 10 ++++++ app/models/topic.rb | 10 ++++++ app/views/maps/_map.html.erb | 28 +++++++++++++--- app/views/maps/_new.html.erb | 3 +- app/views/maps/edit.html.erb | 3 +- app/views/maps/new.html.erb | 4 +-- config/routes.rb | 3 ++ 16 files changed, 219 insertions(+), 38 deletions(-) create mode 100644 app/assets/images/settings.png diff --git a/app/assets/images/settings.png b/app/assets/images/settings.png new file mode 100644 index 0000000000000000000000000000000000000000..d3348a381fc38a402edaa6ab537da40e1423f23c GIT binary patch literal 3071 zcmVKLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_C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v33gZ<8D~47E ztUS1iwkmDaPpj=$m#%)jCVEY4fnLGNg2A-`YwHVD3gv};>)hAvT~AmqS>Lr``i7kw zJ{5_It`yrBmlc25DBO7E8;5VoznR>Ww5hAaxn$2~(q`%A-YuS64wkBy=9dm`4cXeX z4c}I@?e+FW+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z0003hNklo1<7FP@`-O3wdy#2^kspa+eg0RUA2Kx3UM|BwIx N002ovPDHLkV1ir!xrYD% literal 0 HcmV?d00001 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) %> +
+ <% end %> + <% 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 %>

Map

<%= image_tag 'map.png', :class => 'icon', :size => '50x50' %> +
+ <% if map.user == user %> +
+
+ Permissions:  + <%= best_in_place map, :permission, :type => :select, :collection => [['commons', 'commons'], ['public','public'], ['private','private']] %> +
+
+
+ <% end %> +
<%= map.mk_permission %>
+
- <%=map.name %> + <%= best_in_place map, :name, :type => :input %>

<%= map.topics.count %> topics and <%= map.synapses.count %> synapses

-

<%= map.desc %>

+

<%= best_in_place map, :desc, :type => :textarea, :nil => "Click to add description." %>

+ + <% 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| %>

Edit Map

diff --git a/app/views/maps/new.html.erb b/app/views/maps/new.html.erb index b1378dc8..cb1cbdd2 100644 --- a/app/views/maps/new.html.erb +++ b/app/views/maps/new.html.erb @@ -1,8 +1,7 @@ <%# # @file # Form to create a new map. - # TODO: What URL is this accessible from? - # TODO: Is this code being used anymore? + # Accessible from /maps/new. Still in use. #%>
<%= form_for @map || Map.new, url: maps_url do |form|%> @@ -13,6 +12,7 @@ <%= 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.submit "Add Map", class: "add" %> <% end %>
diff --git a/config/routes.rb b/config/routes.rb index 173c127c..92afb1b9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,14 +18,17 @@ ISSAD::Application.routes.draw do resources :topics do get :autocomplete_topic_name, :on => :collection end + match 'topics/:id/:format', to: 'topics#json', via: :get, as: :json resources :synapses do get :autocomplete_synapse_desc, :on => :collection end + match 'synapses/:id/:format', to: 'synapses#json', via: :get, as: :json resources :maps do get :autocomplete_map_name, :on => :collection end + match 'maps/:id/:format', to: 'maps#json', via: :get, as: :json resources :users do get :autocomplete_user_name, :on => :collection