From b689d4695b2bdec5a250138565d17fc280b50e60 Mon Sep 17 00:00:00 2001 From: MrZYX Date: Sun, 27 Mar 2011 00:05:35 +0100 Subject: [PATCH] refactor of routes.rb done so far; further refactor needs design decisions --- .../aspect_memberships_controller.rb | 2 +- app/controllers/aspects_controller.rb | 6 ++--- app/views/aspects/edit.html.haml | 4 +-- app/views/photos/show.html.haml | 2 +- app/views/shared/_add_contact.html.haml | 2 +- config/routes.rb | 25 ++++++++----------- public/javascripts/aspect-edit.js | 20 +++++++-------- spec/controllers/aspects_controller_spec.rb | 7 +++--- 8 files changed, 31 insertions(+), 37 deletions(-) diff --git a/app/controllers/aspect_memberships_controller.rb b/app/controllers/aspect_memberships_controller.rb index 9d5c26a1c..6c8c410ec 100644 --- a/app/controllers/aspect_memberships_controller.rb +++ b/app/controllers/aspect_memberships_controller.rb @@ -10,7 +10,7 @@ class AspectMembershipsController < ApplicationController #note :id is garbage @person_id = params[:person_id] - @aspect_id = params[:aspect_id] + @aspect_id = params[:id] @contact = current_user.contact_for(Person.where(:id => @person_id).first) membership = @contact ? @contact.aspect_memberships.where(:aspect_id => @aspect_id).first : nil diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 3a4e78286..74791e6aa 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -149,15 +149,15 @@ class AspectsController < ApplicationController def move_contact @person = Person.find(params[:person_id]) - @from_aspect = current_user.aspects.where(:id => params[:from]).first - @to_aspect = current_user.aspects.where(:id => params[:to][:to]).first + @from_aspect = current_user.aspects.where(:id => params[:aspect_id]).first + @to_aspect = current_user.aspects.where(:id => params[:to]).first response_hash = { } unless current_user.move_contact( @person, @to_aspect, @from_aspect) flash[:error] = I18n.t 'aspects.move_contact.error',:inspect => params.inspect end - if aspect = current_user.aspects.where(:id => params[:to][:to]).first + if aspect = current_user.aspects.where(:id => params[:to]).first response_hash[:notice] = I18n.t 'aspects.move_contact.success' response_hash[:success] = true else diff --git a/app/views/aspects/edit.html.haml b/app/views/aspects/edit.html.haml index e62362f76..441e0951b 100644 --- a/app/views/aspects/edit.html.haml +++ b/app/views/aspects/edit.html.haml @@ -12,11 +12,11 @@ - if @aspect.contacts_visible = link_to image_tag('icons/padlock-open.png', :height => 16, :width => 16, :id => "contact_visibility_padlock", :class => 'open', :title => t('.aspect_list_is_visible')), - "aspects/#{@aspect.id}/toggle_contact_visibility", :remote => true + aspect_toggle_contact_visibility_path(@aspect), :method => :put, :remote => true - else = link_to image_tag('icons/padlock-closed.png', :height => 16, :width => 16, :id => "contact_visibility_padlock", :title => t('.aspect_list_is_not_visible')), - "aspects/#{@aspect.id}/toggle_contact_visibility", :remote => true + aspect_toggle_contact_visibility_path(@aspect), :method => :put, :remote => true %h3#aspect_name_title %span.name= @aspect diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 559fc0d3f..0d82dbcf4 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -29,7 +29,7 @@ - if @ownership .photo_options{:data=>{:actor=>"#{@photo.author.owner.id}", :actor_person => "#{@photo.author.id}", :image_url => "#{@photo.url(:thumb_large)}"}} - = link_to t('.make_profile_photo'), {:controller => "photos", :action => "make_profile_photo", :photo_id => @photo.id}, :remote => true, :class => 'make_profile_photo' + = link_to t('.make_profile_photo'), photo_make_profile_photo_path(@photo), :method => :put, :remote => true, :class => 'make_profile_photo' | = link_to t('.edit'), '#', :id => "edit_photo_toggle" %br diff --git a/app/views/shared/_add_contact.html.haml b/app/views/shared/_add_contact.html.haml index 063f40d63..c1c27781f 100644 --- a/app/views/shared/_add_contact.html.haml +++ b/app/views/shared/_add_contact.html.haml @@ -6,7 +6,7 @@ = t('aspects.manage.add_a_new_contact') = info_text(t('.enter_a_diaspora_username')) -= form_tag(person_by_handle_path, :id => "new_request_to_#{aspect_id}", :class => "webfinger_form", :remote => true) do += form_tag(person_by_handle_people_path, :id => "new_request_to_#{aspect_id}", :class => "webfinger_form", :remote => true) do = search_field_tag :diaspora_handle,'', :id => "request_d_handle_to_#{aspect_id}", :results => 5, :placeholder => t('.diaspora_handle') = hidden_field_tag :aspect_id, aspect_id = submit_tag t('.create_request') diff --git a/config/routes.rb b/config/routes.rb index 2390049e7..73b068de7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,20 +7,17 @@ Diaspora::Application.routes.draw do # Posting and Reading resources :aspects do - collection do - match 'move_contact' => :move_contact - match 'add_to_aspect' => :add_to_aspect - match 'remove_from_aspect' => :remove_from_aspect - match 'manage' => :manage - end - match 'toggle_contact_visibility' => :toggle_contact_visibility + get 'manage' => :manage, :on => :collection + put 'move_contact' => :move_contact + put 'toggle_contact_visibility' => :toggle_contact_visibility end resources :status_messages, :only => [:new, :create, :destroy, :show] get 'p/:id' => 'posts#show', :as => 'post' - match 'photos/make_profile_photo' => 'photos#make_profile_photo' - resources :photos, :except => [:index] + resources :photos, :except => [:index] do + put 'make_profile_photo' => :make_profile_photo + end resources :comments, :only => [:create, :destroy] @@ -63,9 +60,9 @@ Diaspora::Application.routes.draw do end get 'login' => redirect('/users/sign_in') - scope 'admins' do - match 'user_search' => 'admins#user_search' - match 'admin_inviter' => 'admins#admin_inviter' + scope 'admins', :controller => :admins do + match 'user_search' => :user_search + get 'admin_inviter' => :admin_inviter end resource :profile @@ -78,8 +75,8 @@ Diaspora::Application.routes.draw do resources :people, :except => [:edit, :update] do resources :status_messages resources :photos + post 'by_handle' => :retrieve_remote, :on => :collection, :as => 'person_by_handle' end - match 'people/by_handle' => 'people#retrieve_remote', :as => 'person_by_handle' # Federation @@ -122,7 +119,7 @@ Diaspora::Application.routes.draw do # Mobile site - match 'mobile/toggle', :to => 'home#toggle_mobile', :as => 'toggle_mobile' + get 'mobile/toggle', :to => 'home#toggle_mobile', :as => 'toggle_mobile' # Startpage diff --git a/public/javascripts/aspect-edit.js b/public/javascripts/aspect-edit.js index 7b18c9b1f..1c32bce05 100644 --- a/public/javascripts/aspect-edit.js +++ b/public/javascripts/aspect-edit.js @@ -61,14 +61,13 @@ var AspectEdit = { if (person.attr('data-aspect_id') != undefined && // a request doesn't have a data-aspect_id, but an existing contact does dropzone.attr('data-aspect_id') != person.attr('data-aspect_id')) { + var aspect_id = person.attr('data-aspect_id') $.ajax({ - url: "/aspects/move_contact/", + type: "PUT", + url: "/aspects/" + aspect_id + "/move_contact", data: { "person_id": person.attr('data-guid'), - "from": person.attr('data-aspect_id'), - "to": { - "to": dropzone.attr('data-aspect_id') - } + "to": dropzone.attr('data-aspect_id') }, success: function(data) { AspectEdit.onMovePersonSuccess(person, dropzone); @@ -97,13 +96,12 @@ var AspectEdit = { Diaspora.widgets.alert.alert("Error removing contact", "You cannot remove the person from the last aspect"); } else { if (!person.hasClass('request')) { - + var aspect_id = person.attr('data-aspect_id') $.ajax({ - type: "POST", - url: "/aspects/remove_from_aspect", + type: "DELETE", + url: "/aspect_memberships/" + aspect_id, data: { - 'person_id': person_id, - 'aspect_id': person.attr('data-aspect_id') + 'person_id': person_id } }); } @@ -115,7 +113,7 @@ var AspectEdit = { changeName: function() { var $this = $(this), - id = $this.closest(".aspect").attr("data-guid"), + id = $this.closest(".aspect").attr("data-guid"), link = "/aspects/" + id; diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index a2045961f..41b0481f3 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -258,15 +258,14 @@ describe AspectsController do @person = Factory.create(:person) @opts = { :person_id => @person.id, - :from => @alices_aspect_1.id, - :to => - {:to => @alices_aspect_2.id} + :aspect_id => @alices_aspect_1.id, + :to => @alices_aspect_2.id } end it 'calls the move_contact_method' do @controller.stub!(:current_user).and_return(@alice) @alice.should_receive(:move_contact) - post "move_contact", @opts + put :move_contact, @opts end end