refactor of routes.rb done so far; further refactor needs design decisions

This commit is contained in:
MrZYX 2011-03-27 00:05:35 +01:00
parent 11b0a2c19d
commit b689d4695b
8 changed files with 31 additions and 37 deletions

View file

@ -10,7 +10,7 @@ class AspectMembershipsController < ApplicationController
#note :id is garbage #note :id is garbage
@person_id = params[:person_id] @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) @contact = current_user.contact_for(Person.where(:id => @person_id).first)
membership = @contact ? @contact.aspect_memberships.where(:aspect_id => @aspect_id).first : nil membership = @contact ? @contact.aspect_memberships.where(:aspect_id => @aspect_id).first : nil

View file

@ -149,15 +149,15 @@ class AspectsController < ApplicationController
def move_contact def move_contact
@person = Person.find(params[:person_id]) @person = Person.find(params[:person_id])
@from_aspect = current_user.aspects.where(:id => params[:from]).first @from_aspect = current_user.aspects.where(:id => params[:aspect_id]).first
@to_aspect = current_user.aspects.where(:id => params[:to][:to]).first @to_aspect = current_user.aspects.where(:id => params[:to]).first
response_hash = { } response_hash = { }
unless current_user.move_contact( @person, @to_aspect, @from_aspect) unless current_user.move_contact( @person, @to_aspect, @from_aspect)
flash[:error] = I18n.t 'aspects.move_contact.error',:inspect => params.inspect flash[:error] = I18n.t 'aspects.move_contact.error',:inspect => params.inspect
end 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[:notice] = I18n.t 'aspects.move_contact.success'
response_hash[:success] = true response_hash[:success] = true
else else

View file

@ -12,11 +12,11 @@
- if @aspect.contacts_visible - 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')), = 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 - else
= link_to image_tag('icons/padlock-closed.png', :height => 16, :width => 16, :id => "contact_visibility_padlock", :title => t('.aspect_list_is_not_visible')), = 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 %h3#aspect_name_title
%span.name= @aspect %span.name= @aspect

View file

@ -29,7 +29,7 @@
- if @ownership - if @ownership
.photo_options{:data=>{:actor=>"#{@photo.author.owner.id}", :actor_person => "#{@photo.author.id}", :image_url => "#{@photo.url(:thumb_large)}"}} .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" = link_to t('.edit'), '#', :id => "edit_photo_toggle"
%br %br

View file

@ -6,7 +6,7 @@
= t('aspects.manage.add_a_new_contact') = t('aspects.manage.add_a_new_contact')
= info_text(t('.enter_a_diaspora_username')) = 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') = 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 = hidden_field_tag :aspect_id, aspect_id
= submit_tag t('.create_request') = submit_tag t('.create_request')

View file

@ -7,20 +7,17 @@ Diaspora::Application.routes.draw do
# Posting and Reading # Posting and Reading
resources :aspects do resources :aspects do
collection do get 'manage' => :manage, :on => :collection
match 'move_contact' => :move_contact put 'move_contact' => :move_contact
match 'add_to_aspect' => :add_to_aspect put 'toggle_contact_visibility' => :toggle_contact_visibility
match 'remove_from_aspect' => :remove_from_aspect
match 'manage' => :manage
end
match 'toggle_contact_visibility' => :toggle_contact_visibility
end end
resources :status_messages, :only => [:new, :create, :destroy, :show] resources :status_messages, :only => [:new, :create, :destroy, :show]
get 'p/:id' => 'posts#show', :as => 'post' get 'p/:id' => 'posts#show', :as => 'post'
match 'photos/make_profile_photo' => 'photos#make_profile_photo' resources :photos, :except => [:index] do
resources :photos, :except => [:index] put 'make_profile_photo' => :make_profile_photo
end
resources :comments, :only => [:create, :destroy] resources :comments, :only => [:create, :destroy]
@ -63,9 +60,9 @@ Diaspora::Application.routes.draw do
end end
get 'login' => redirect('/users/sign_in') get 'login' => redirect('/users/sign_in')
scope 'admins' do scope 'admins', :controller => :admins do
match 'user_search' => 'admins#user_search' match 'user_search' => :user_search
match 'admin_inviter' => 'admins#admin_inviter' get 'admin_inviter' => :admin_inviter
end end
resource :profile resource :profile
@ -78,8 +75,8 @@ Diaspora::Application.routes.draw do
resources :people, :except => [:edit, :update] do resources :people, :except => [:edit, :update] do
resources :status_messages resources :status_messages
resources :photos resources :photos
post 'by_handle' => :retrieve_remote, :on => :collection, :as => 'person_by_handle'
end end
match 'people/by_handle' => 'people#retrieve_remote', :as => 'person_by_handle'
# Federation # Federation
@ -122,7 +119,7 @@ Diaspora::Application.routes.draw do
# Mobile site # Mobile site
match 'mobile/toggle', :to => 'home#toggle_mobile', :as => 'toggle_mobile' get 'mobile/toggle', :to => 'home#toggle_mobile', :as => 'toggle_mobile'
# Startpage # Startpage

View file

@ -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 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')) { dropzone.attr('data-aspect_id') != person.attr('data-aspect_id')) {
var aspect_id = person.attr('data-aspect_id')
$.ajax({ $.ajax({
url: "/aspects/move_contact/", type: "PUT",
url: "/aspects/" + aspect_id + "/move_contact",
data: { data: {
"person_id": person.attr('data-guid'), "person_id": person.attr('data-guid'),
"from": person.attr('data-aspect_id'), "to": dropzone.attr('data-aspect_id')
"to": {
"to": dropzone.attr('data-aspect_id')
}
}, },
success: function(data) { success: function(data) {
AspectEdit.onMovePersonSuccess(person, dropzone); 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"); Diaspora.widgets.alert.alert("Error removing contact", "You cannot remove the person from the last aspect");
} else { } else {
if (!person.hasClass('request')) { if (!person.hasClass('request')) {
var aspect_id = person.attr('data-aspect_id')
$.ajax({ $.ajax({
type: "POST", type: "DELETE",
url: "/aspects/remove_from_aspect", url: "/aspect_memberships/" + aspect_id,
data: { data: {
'person_id': person_id, 'person_id': person_id
'aspect_id': person.attr('data-aspect_id')
} }
}); });
} }
@ -115,7 +113,7 @@ var AspectEdit = {
changeName: function() { changeName: function() {
var $this = $(this), var $this = $(this),
id = $this.closest(".aspect").attr("data-guid"), id = $this.closest(".aspect").attr("data-guid"),
link = "/aspects/" + id; link = "/aspects/" + id;

View file

@ -258,15 +258,14 @@ describe AspectsController do
@person = Factory.create(:person) @person = Factory.create(:person)
@opts = { @opts = {
:person_id => @person.id, :person_id => @person.id,
:from => @alices_aspect_1.id, :aspect_id => @alices_aspect_1.id,
:to => :to => @alices_aspect_2.id
{:to => @alices_aspect_2.id}
} }
end end
it 'calls the move_contact_method' do it 'calls the move_contact_method' do
@controller.stub!(:current_user).and_return(@alice) @controller.stub!(:current_user).and_return(@alice)
@alice.should_receive(:move_contact) @alice.should_receive(:move_contact)
post "move_contact", @opts put :move_contact, @opts
end end
end end