Skip to content

Commit

Permalink
files downloads + img listing edits work
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniferwills committed Jun 2, 2020
1 parent 2c25343 commit 857cb07
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 55 deletions.
20 changes: 6 additions & 14 deletions app/controllers/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@ def create
errors = []
parameters[:files].each do |f|
tmp = {:title => parameters[:title], :private => parameters[:private], :tags => parameters[:tags], :file => f}
# byebug

@image = Image.create(tmp)
# byebug

if !(@image.save)
# byebug
render action: :upload
end

Expand All @@ -51,8 +48,10 @@ def create
# PATCH/PUT /images/1
# PATCH/PUT /images/1.json
def update

respond_to do |format|
if @image.update(update_params)

if @image.update(update_params[:image])
format.html { redirect_to @image, notice: 'Image was successfully updated.' }
format.json { render :show, status: :ok, location: @image }
else
Expand Down Expand Up @@ -81,18 +80,12 @@ def destroy_all
end
end


def download
send_data @resume, type: "application/pdf", disposition: "attachment"
end

def download_all
files = []
imgs = Image.all
imgs.each do |img|
files << img.file
end
# byebug

send_zip files
# send_data @resume, type: "application/pdf", disposition: "attachment"
Expand All @@ -109,14 +102,13 @@ def set_image
# Only allow a list of trusted parameters through.
def create_params
params.require(:files)
# byebug
params.require(:private)
params.permit(:title, :tags, :private, files: [])
params.permit(:title, :tags, files: [])
end

# Only allow a list of trusted parameters through.
def update_params
params.permit(:title, :tags, :private)
params.require(:image)
params.permit(:image => [:title, :tags])
end

end
15 changes: 5 additions & 10 deletions app/views/images/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1>Editing Image</h1>
<h1>Edit Image</h1>

<%= form_with(url: image_path(@image), method: "put", :html => {:class => "form-horizontal center"}) do |form| %>
<%= form_with(model: @image, :class => "form-horizontal center") do |form| %>
<div class="form-group">
<%= form.label(:title, "Image Title:") %>
<%= form.text_field :title, :value => @image.title %>
Expand All @@ -9,14 +9,9 @@
<%= form.label(:tags, "Choose Tags:") %>
<%= form.text_field :tags, :value => @image.tags%>
</div>
<div class="form-group">
<%= form.label(:private, "Make Picture Public:") %>
<%= form.check_box :private %>
</div>

<%= submit_tag("Save", :class => "btn btn-light") %>
<%= link_to 'Back', @image , :class => "btn btn-light"%>
<%= button_to "Delete", { controller: :images, action: :destroy, id: @image.id }, method: :delete, data: { confirm: 'Are you sure?' }, :class => "btn btn-light" %>


<% end %>

<%= link_to 'Back', @image , :class => "btn btn-light"%>
<%= button_to "Delete", { controller: :images, action: :destroy, id: @image.id }, method: :delete, data: { confirm: 'Are you sure?' }, :class => "btn btn-light" %>
41 changes: 21 additions & 20 deletions app/views/images/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
<div class="container-fluid">
<% if params[:uploaded_success] %>
<div class="alert alert-success" role="alert">
Files Uploaded Successfully!
</div>
<% end %>

<% if params[:uploaded_success] %>
<div class="alert alert-success" role="alert">
Files Uploaded Successfully!
</div>
<% end %>
<%= paginate @images %>
<%= paginate @images %>

<div class="card-columns">
<% @images.each do |img| %>
<div class="card">
<div class="card-block" >
<%= image_tag img.file , :width => "100%" %>
<div class="card-body">
<p class="card-title"><%= img.title %></p>

<div class="card-columns">
<% @images.each do |img| %>
<div class="card">
<div class="card-block" >
<%= image_tag img.file , :width => "100%" %>
<div class="card-body">
<p class="card-title"><%= img.title %></p>
<% unless img.tags.empty? %>
<p class="card-subtitle mb-2 text-muted">Tags: <%= img.tags %></p>
<% end %>

<% if img.tags %>
<p class="card-subtitle mb-2 text-muted">Tags: <%= img.tags %></p>
<% end %>
<%= link_to "View", image_path(img), :class => "btn btn-light" %>

<%= link_to "View", image_path(img), :class => "btn btn-light" %>
</div>

</div>

</div>

</div>


<% end %>
<% end %>

</div>

Expand Down
6 changes: 2 additions & 4 deletions app/views/images/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
<div class="card-body">
<p class="card-title"><%= @image.title %></p>

<% if @image.tags %>
<% unless @image.tags.empty? %>
<p class="card-subtitle mb-2 text-muted">Tags: <%= @image.tags %></p>
<% end %>

<%= link_to 'Edit', edit_image_path(@image), :class => "btn btn-light"%>
<%= link_to "Download", download_image_path(@image), "data-turbolinks" => false, :class => "btn btn-light" %>

<%= link_to "Download", rails_blob_path(@image.file, disposition: 'attachment'), :class => "btn btn-light" %>
<%= link_to 'Back', root_path , :class => "btn btn-light"%>


</div>

</div>
Expand Down
5 changes: 1 addition & 4 deletions app/views/images/upload.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
<%= form.label(:tags, "Choose Tags:") %>
<%= form.text_field :tags%>
</div>
<div class="form-group">
<%= form.label(:private, "Make Picture Public:") %>
<%= form.check_box :private %>
</div>


<%= submit_tag("Upload", :class => "btn btn-primary") %>

Expand Down
3 changes: 3 additions & 0 deletions app/views/kaminari/_first_page.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<li class="page-item">
<%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, remote: remote, class: 'page-link' %>
</li>
3 changes: 3 additions & 0 deletions app/views/kaminari/_gap.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<li class='page-item disabled'>
<%= link_to raw(t 'views.pagination.truncate'), '#', class: 'page-link' %>
</li>
3 changes: 3 additions & 0 deletions app/views/kaminari/_last_page.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<li class="page-item">
<%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, remote: remote, class: 'page-link' %>
</li>
3 changes: 3 additions & 0 deletions app/views/kaminari/_next_page.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<li class="page-item">
<%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, rel: 'next', remote: remote, class: 'page-link' %>
</li>
9 changes: 9 additions & 0 deletions app/views/kaminari/_page.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% if page.current? %>
<li class="page-item active">
<%= content_tag :a, page, data: { remote: remote }, rel: page.rel, class: 'page-link' %>
</li>
<% else %>
<li class="page-item">
<%= link_to page, url, remote: remote, rel: page.rel, class: 'page-link' %>
</li>
<% end %>
17 changes: 17 additions & 0 deletions app/views/kaminari/_paginator.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= paginator.render do %>
<nav>
<ul class="pagination">
<%= first_page_tag unless current_page.first? %>
<%= prev_page_tag unless current_page.first? %>
<% each_page do |page| %>
<% if page.left_outer? || page.right_outer? || page.inside_window? %>
<%= page_tag page %>
<% elsif !page.was_truncated? -%>
<%= gap_tag %>
<% end %>
<% end %>
<%= next_page_tag unless current_page.last? %>
<%= last_page_tag unless current_page.last? %>
</ul>
</nav>
<% end %>
3 changes: 3 additions & 0 deletions app/views/kaminari/_prev_page.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<li class="page-item">
<%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, rel: 'prev', remote: remote, class: 'page-link' %>
</li>
4 changes: 2 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
<body>

<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample04" aria-controls="navbarsExample04" aria-expanded="false" aria-label="Toggle navigation">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarsExample04">
<div class="collapse navbar-collapse" id="navbar">
<ul class="navbar-nav mr-auto">

<li class="nav-item active">
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
post 'images/download_all'
root to: 'images#index'
resources :images do
get :download, on: :member
post :update, on: :member
end

# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
Expand Down

0 comments on commit 857cb07

Please sign in to comment.