Skip to content

Commit

Permalink
complete repositories and shelf_locations
Browse files Browse the repository at this point in the history
  • Loading branch information
noel committed Apr 23, 2012
1 parent 394108c commit 5e0b719
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 73 deletions.
30 changes: 6 additions & 24 deletions app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,14 @@ class RepositoriesController < ApplicationController

def index
@repositories = Repository.all

respond_to do |format|
format.html
end
end

def show
@repository = Repository.find(params[:id])

respond_to do |format|
format.html
end
end

def new
@repository = Repository.new

respond_to do |format|
format.html
end
end

def edit
Expand All @@ -31,22 +19,18 @@ def edit
def create
@repository = Repository.new(params[:repository])

respond_to do |format|
if @repository.save
format.html { redirect_to repository_show_path(@repository.id)}
else
render :action => 'new'
end
if @repository.save
redirect_to url_for_repository(@repository.id)
else
render :action => 'new'
end
end

def update
@repository = Repository.find(params[:id])

if @repository.update_attributes(params[:repository])
render :action => 'index'
# redirect_to :controller => 'repositories', :action => 'edit', :id => @repository.id
#
redirect_to url_for_repository(@repository.id)
else
render :action => 'edit'
end
Expand All @@ -56,8 +40,6 @@ def destroy
@repository = Repository.find(params[:id])
@repository.destroy

respond_to do |format|
format.html { redirect_to repositories_url }
end
redirect_to repositories_url
end
end
18 changes: 1 addition & 17 deletions app/controllers/shelf_locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@ class ShelfLocationsController < ApplicationController

def index
@shelf_locations = ShelfLocation.all

respond_to do |format|
format.html
end
end

def show
@shelf_location = ShelfLocation.find(params[:id])

respond_to do |format|
format.html
end
end

def new
Expand All @@ -31,16 +23,13 @@ def create
@shelf_location = ShelfLocation.new(params[:shelf_location])

if @shelf_location.save

redirect_to url_for_repository( @shelf_location.repository_id)
else
render :action => 'new'
end
end

def update


@shelf_location = ShelfLocation.find(params[:id])

if @shelf_location.update_attributes(params[:shelf_location])
Expand All @@ -51,15 +40,10 @@ def update
end

def destroy

#Rails.logger.debug("what is ID: " + params[:id])

@shelf_location = ShelfLocation.find(params[:id])
repo = @shelf_location.repository_id
@shelf_location.destroy

respond_to do |format|
format.html { redirect_to url_for_repository repo }
end
redirect_to url_for_repository(repo)
end
end
18 changes: 8 additions & 10 deletions app/views/repositories/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<% form_for :repository, :url => {:action => @repository.new_record? ? 'create' : 'update', :urlified_name => @current_basket.urlified_name, :id => @repository} do |f| %>
<%= f.error_messages %>
<%= f.error_messages %>

<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.submit %>
</p>
5 changes: 4 additions & 1 deletion app/views/repositories/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<h1>Editing repository</h1>

<%= render 'form' %>
<% form_for @repository, :url => url_to_update_repository(@repository.id) do |f| %>
<%= render :partial => 'form',:locals=> {:f => f} %>
<% end %>
<%= link_to 'Back to Repository Listing', repositories_path %>
6 changes: 3 additions & 3 deletions app/views/repositories/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
<% @repositories.each do |repository| %>
<tr>
<td><%= repository.name %></td>
<td><%= link_to ('Show', :controller => :repositories, :action => :show, :id => repository.id, :urlified_name => @current_basket.urlified_name) %></td>
<td><%= link_to ('Edit', :controller => :repositories, :action => :edit, :id => repository.id, :urlified_name => @current_basket.urlified_name) %></td>
<td><%= link_to ('Show', url_for_repository(repository.id)) %></td>
<td><%= link_to ('Edit', url_to_edit_repository(repository.id)) %></td>

</tr>
<% end %>
</table>

<br />
<%= link_to "Create New Repository" , new_repository_path %>
<%= link_to "Create New Repository" , url_for_new_repository %>
6 changes: 4 additions & 2 deletions app/views/repositories/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<h1>New repository</h1>

<%= render 'form' %>
<% form_for @repository, :url => url_to_create_repository do |f| %>
<%= render :partial => 'form',:locals=> {:f => f} %>
<% end %>
<%= link_to 'Back', repositories_path %>
<%= link_to 'Back to Repository Listing', repositories_path %>
10 changes: 6 additions & 4 deletions app/views/repositories/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
new_shelf_location_path(:repo => @repository.id) %>
</p>
<p>
Edit
<%= link_to 'Edit', url_to_edit_repository(@repository.id) %>
|
Delete
|
<%= link_to 'Back', repositories_path %>
<%= link_to 'Delete', url_for_repository(@repository.id),
:confirm => 'Are you sure?',
:method => :delete %>
<br/>
<%= link_to 'Back to Repository Listing', repositories_path %>
</p>
6 changes: 3 additions & 3 deletions app/views/shelf_locations/_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
</td>
<td>
<%= link_to shelf_location.code ,
shelf_location_path( :id => shelf_location.id, :urlified_name => @current_basket.urlified_name ) %>
url_for_shelf_location(shelf_location.id) %>
</td>
<td>
<%= shelf_location.status %>
</td>
<td>
<%= link_to "Edit" , edit_shelf_location_path( :id => shelf_location.id, :urlified_name => @current_basket.urlified_name ) %>
<%= link_to "Edit" , url_to_edit_shelf_location(shelf_location.id) %>
|
<%= link_to "Delete" ,
shelf_location_path( :id => shelf_location.id, :urlified_name => @current_basket.urlified_name ),
url_for_shelf_location(shelf_location.id),
:confirm => 'Are you sure?',
:method => :delete %>
</td>
Expand Down
8 changes: 4 additions & 4 deletions app/views/shelf_locations/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<h1>Edit Shelf Location</h1>

<% form_for(@shelf_location,
:url =>
shelf_location_path( :id => @shelf_location.id,
:urlified_name => @current_basket.urlified_name ),
:url => url_for_shelf_location( @shelf_location.id),
:method => :put
) do |f| %>
<%= render :partial => "form", :locals => { :f => f, :repository => @shelf_location.repository } %>
<p>
<%= f.submit 'Update Shelf Location' %>
<%= link_to 'Back', shelf_locations_path %>
<br />
<br />
<%= link_to ('Back to Repository', url_for_repository(@repo.id)) %>
</p>
<% end %>

2 changes: 1 addition & 1 deletion app/views/shelf_locations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
</p>
<% end %>
<%= link_to ('Back to Repository', :controller => :repositories, :action => :show, :id => @repo.id, :urlified_name => @current_basket.urlified_name) %></td>
<%= link_to ('Back to Repository', url_for_repository(@repo.id)) %>
10 changes: 6 additions & 4 deletions app/views/shelf_locations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
Status: <%= @shelf_location.status %>
</p>
<p>
Edit
<%= link_to 'Edit', url_to_edit_shelf_location(@shelf_location.id) %>
|
Delete
|
<%= link_to 'Back', shelf_locations_path %>
<%= link_to 'Delete', url_for_shelf_location(@shelf_location.id),
:confirm => 'Are you sure?',
:method => :delete %>
<br/>
<%= link_to ('Back to Repository', url_for_repository(@shelf_location.repository_id)) %>
</p>
53 changes: 53 additions & 0 deletions lib/kete_trackable_items_controller_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,60 @@ def url_for_repository(repo_id)
:urlified_name => @current_basket.urlified_name,
:id => repo_id)
end

def url_to_create_repository
url_for(
:controller => "repositories",
:action => :create,
:urlified_name => @current_basket.urlified_name)
end

def url_to_edit_repository(repo_id)
url_for(
:controller => "repositories",
:action => :edit,
:urlified_name => @current_basket.urlified_name,
:id => repo_id)
end

def url_to_update_repository(repo_id)
url_for(
:controller => "repositories",
:action => :update,
:urlified_name => @current_basket.urlified_name,
:id => repo_id)
end

def url_for_new_repository
url_for(
:controller => "repositories",
:action => :new,
:urlified_name => @current_basket.urlified_name)
end

def url_for_shelf_location(shelf_id)
url_for(
:controller => "shelf_locations",
:action => :show,
:urlified_name => @current_basket.urlified_name,
:id => shelf_id)
end

def url_to_edit_shelf_location(shelf_id)
url_for(
:controller => "shelf_locations",
:action => :edit,
:urlified_name => @current_basket.urlified_name,
:id => shelf_id)
end

def url_to_edit_shelf_location(shelf_id)
url_for(
:controller => "shelf_locations",
:action => :edit,
:urlified_name => @current_basket.urlified_name,
:id => shelf_id)
end
end

end

0 comments on commit 5e0b719

Please sign in to comment.