Skip to content

Commit

Permalink
multi upload working
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniferwills committed May 31, 2020
1 parent 4ca48e7 commit 04afbfa
Show file tree
Hide file tree
Showing 23 changed files with 85 additions and 341 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ gem 'jbuilder', '~> 2.7'
gem 'bootstrap', '~> 4.3.1'
gem 'jquery-rails'
gem 'image_processing'
gem 'active_storage-send_zip'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
active_storage-send_zip (0.3.3)
rails (> 5.2)
rubyzip (< 3.0)
activejob (6.0.3.1)
activesupport (= 6.0.3.1)
globalid (>= 0.3.6)
Expand Down Expand Up @@ -210,6 +213,7 @@ PLATFORMS
ruby

DEPENDENCIES
active_storage-send_zip
bootsnap (>= 1.4.2)
bootstrap (~> 4.3.1)
byebug
Expand Down
44 changes: 32 additions & 12 deletions app/controllers/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ def edit
# POST /images
# POST /images.json
def create
@image = Image.new(create_params)
parameters =create_params
parameters[:files].each do |f|
tmp = {:title => parameters[:title], :private => parameters[:private], :tags => parameters[:tags], :file => f}

respond_to do |format|
if @image.save
format.html { redirect_to root_path, notice: 'Image was successfully created.' }
format.json { render :show, status: :created, location: @image }
else
@image = Image.create!(tmp)
if !(@image.save)
format.html { render :new }
format.json { render json: @image.errors, status: :unprocessable_entity }
end


end
redirect_to root_path, notice: 'Image was successfully created.'
end

# PATCH/PUT /images/1
Expand All @@ -50,13 +52,33 @@ def update
# DELETE /images/1
# DELETE /images/1.json
def destroy
@image.file.purge
@image.destroy
respond_to do |format|
format.html { redirect_to images_url, notice: 'Image was successfully destroyed.' }
format.html { redirect_to root_path, notice: 'Image was successfully destroyed.' }
format.json { head :no_content }
end
end

def destroy_all
@image.file.purge
@image.destroy
respond_to do |format|
format.html { redirect_to root_path, notice: 'Image was successfully destroyed.' }
format.json { head :no_content }
end
end


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

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


private
# Use callbacks to share common setup or constraints between actions.
def set_image
Expand All @@ -65,16 +87,14 @@ def set_image

# Only allow a list of trusted parameters through.
def create_params
params.require(:title)
params.require(:file)
params.require(:files)
# byebug
params.require(:private)
params.permit(:title, :tags, :file, :private)
params.permit(:title, :tags, :private, files: [])
end

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

Expand Down
74 changes: 0 additions & 74 deletions app/controllers/users_controller.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/users_helper.rb

This file was deleted.

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

<%= form_with(url: image_path, method: "post", :html => {:class => "form-horizontal center"}) do |form| %>
<%= form_with(url: image_path(@image), method: "put", :html => {:class => "form-horizontal center"}) do |form| %>
<div class="form-group">
<%= form.label(:title, "Image Title:") %>
<%= form.text_field :title, :required => true %>
<%= form.text_field :title, :value => @image.title %>
</div>
<div class="form-group">
<%= form.label(:tags, "Choose Tags:") %>
<%= form.text_field :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("Upload") %>

<%= 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 'Show', @image %> |
<%= link_to 'Back', images_path %>
53 changes: 28 additions & 25 deletions app/views/images/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
<p id="notice"><%= notice %></p>

<h1>Images</h1>

<table>
<thead>
<tr>
<th colspan="3"></th>
</tr>
</thead>

<tbody>
<% @images.each do |image| %>
<tr>
<td><%= link_to 'Show', image %></td>
<td><%= link_to 'Edit', edit_image_path(image) %></td>
<td><%= link_to 'Destroy', image, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Image', new_image_path %>
<h1>Public Images</h1>

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

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

</div>

</div>

</div>


<% end %>

</div>

</div>
6 changes: 4 additions & 2 deletions app/views/images/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
<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 'Back', images_path , :class => "btn btn-light"%>
<%= 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 'Back', root_path , :class => "btn btn-light"%>


</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<%= form_with(url: images_create_path, method: "post", :html => {:class => "form-horizontal center"}) do |form| %>
<div class="form-group">
<%= form.label(:file, "Choose File:") %>
<%= form.file_field :file, :required => true%>
<%= form.label(:files, "Choose Files:") %>
<%= form.file_field :files, multiple: true, :required => true%>
</div>
<div class="form-group">
<%= form.label(:title, "Image Title:") %>
<%= form.text_field :title, :required => true %>
<%= form.text_field :title %>
</div>
<div class="form-group">
<%= form.label(:tags, "Choose Tags:") %>
Expand Down
7 changes: 2 additions & 5 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_tag 'application', 'data-turbolinks-track': 'reload' %>

</head>

<body>
Expand All @@ -24,11 +25,7 @@
</li>

<li class="nav-item">
<%= link_to "Upload", site_upload_path, :class => "nav-link" %>
</li>

<li class="nav-item">
<%= link_to "Private", site_private_path, :class => "nav-link" %>
<%= link_to "Upload", images_upload_path, :class => "nav-link" %>
</li>

</ul>
Expand Down
26 changes: 0 additions & 26 deletions app/views/site/home.html.erb

This file was deleted.

26 changes: 0 additions & 26 deletions app/views/site/private.html.erb

This file was deleted.

17 changes: 0 additions & 17 deletions app/views/users/_form.html.erb

This file was deleted.

2 changes: 0 additions & 2 deletions app/views/users/_user.json.jbuilder

This file was deleted.

Loading

0 comments on commit 04afbfa

Please sign in to comment.