Skip to content

Commit

Permalink
Add Quality Sorted Page (#134)
Browse files Browse the repository at this point in the history
* Added seeding of donations

* created quality filtering

* remind volunteer to contact donee

* added contact reminder for volunteers to contact donees

* added text

Co-authored-by: juliagrigni <[email protected]>
Co-authored-by: juliagrigni <[email protected]>
  • Loading branch information
3 people authored and tumbleshack committed Apr 24, 2021
1 parent 6212b28 commit 1e54024
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 41 deletions.
11 changes: 11 additions & 0 deletions app/assets/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ p, label {
background-color: white;

}
li.cute {
font-family: Cabin;
font-size: 24px;
color: #000;
margin: 10px;
}
ul.cute {
background: #e8f6fb;
border-radius: 5px;
width: 80%;
}

h1 {
font-family: Cabin;
Expand Down
47 changes: 26 additions & 21 deletions app/controllers/donations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,45 @@
class DonationsController < ApplicationController
before_action :set_donation, only: %i[ show edit update destroy ]
before_action :set_categories_and_items
before_action :set_donation, only: %i[ show edit update destroy quality_screen ]

before_action :authenticate_user!, only: %i[ index, my_donations ]

before_action -> { require_role(:root, :admin) }, only: :index
before_action -> { require_role(:root, :volunteer) }, only: :quality_screen

# GET /donations or /donations.json
def index
@donations = Donation.all
@allCategories = Category.all
@allItems = Item.all
end

# GET /donations/1 or /donations/1.json
def show
@allCategories = Category.all
@allItems = Item.all
end

# GET /donations/new
def new
@donation = Donation.new
@allCategories = Category.all
@allItems = Item.all
1.times { @donation.item_changes.build }
end

# GET /donations/1/edit
def edit
@allCategories = Category.all
@allItems = Item.all
end

def quality_check
end

def quality_screen

end

# GET /donations/my-donations
def my_donations
@allCategories = Category.all
@allItems = Item.all
@donations = current_user != nil ? Donation.where("email like ?", "%#{current_user.email}%") : nil
end

# POST /donations or /donations.json
def create
@allCategories = Category.all
@allItems = Item.all
@donation = Donation.new(donation_params)

respond_to do |format|
Expand All @@ -61,14 +58,16 @@ def create

# PATCH/PUT /donations/1 or /donations/1.json
def update
@allCategories = Category.all
@allItems = Item.all
respond_to do |format|
if @donation.update(donation_params)
if @donation.update(donation_params.except(:send_to_settle, :send_to_screen))
@donation.save

format.html { redirect_to @donation, notice: "Donation was successfully updated." }
format.json { render :show, status: :ok, location: @donation }
if donation_params[:send_to_screen] && current_user&.volunteer?
format.html { redirect_to quality_screen_path(@donation), notice: "Donation was successfully updated." }
else
format.html { redirect_to @donation, notice: "Donation was successfully updated." }
format.json { render :show, status: :ok, location: @donation }
end
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @donation.errors, status: :unprocessable_entity }
Expand All @@ -78,8 +77,6 @@ def update

# DELETE /donations/1 or /donations/1.json
def destroy
@allCategories = Category.all
@allItems = Item.all
@donation.destroy
respond_to do |format|
format.html { redirect_to donations_url, notice: "Donation was successfully destroyed." }
Expand All @@ -95,6 +92,14 @@ def set_donation

# Only allow a list of trusted parameters through.
def donation_params
params.require(:donation).permit(:full_name, :email, :phone, :county, :meet, :address, :availability, :comments, item_changes_attributes: [:id, :category_id, :quantity, :itemType, :size, :change_type, :_destroy])
params.require(:donation).permit(:full_name, :email, :phone, :county, :meet, :address, :availability, :comments,
:send_to_settle, :send_to_screen,
item_changes_attributes: [:id, :category_id, :quantity, :itemType, :size,
:change_type, :settle, :_destroy])
end

def set_categories_and_items
@allCategories = Category.all
@allItems = Item.all
end
end
6 changes: 6 additions & 0 deletions app/views/donations/quality_check.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<p id="notice"><%= notice %></p>

<h1>Donation Quality (<%= Donation.all.count %>)</h1>
<% Donation.all.each do |donation| %>
<%= render partial: 'requests/volunteer_request_block', locals: { request: donation } %>
<% end %>
61 changes: 61 additions & 0 deletions app/views/donations/quality_screen.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<div class="margins-needed">
<h1>Quality Donation Screening</h1>
<p>Remember to wear gloves and a mask while processing donations!</p>
<p>Please sort the items to make sure we only accept items that meet Carrie's Closet's quality standards, based on the CUTE acronym:</p>
<div class="centered-div">
<ul class="cute">
<li class="cute">Clean</li>
<li class="cute">Usable</li>
<li class="cute">Timely</li>
<li class="cute">Equipment</li>
</ul>
</div>
<p>If an item is equipment, such as a stroller, remember that it must be stored differently in inventory.</p>
<p>Adjust the quantities below to only show the items that Carrie's Closet will accept, <i>not</i> anything that will be thrown out.</p>

<% if current_user&.volunteer? %>
<%= render partial: "requests/item_change_form", locals: { request: @donation, send_to_screen: current_user&.volunteer? } %>
<% else %>
<% @donation.item_changes.each do |item| %>
<p><%= item.description %>
<% end %>
<% end %>

<h1>Contact the donor!</h1>
<i>Remember to contact the donor before you go to let them know when to meet and make sure they're still available.</i>
<p>
<strong>Full name:</strong>
<%= @donation.full_name %>
</p>

<p>
<strong>Email:</strong>
<%= @donation.email %>
</p>

<p>
<strong>Phone:</strong>
<%= @donation.phone %>
</p>

<% if @donation.meet %>
<p>
<strong>County:</strong>
<%= Request::COUNTIES.key(@donation.county) %>

</p>
<% else %>
<p>
<strong>Address:</strong>
<%= @donation.address %>
</p>
<% end %>

<p>
<strong>Availability:</strong>
<%= @donation.availability %>
</p>

<%= link_to 'Edit', edit_donation_path(@donation) %> |
<%= link_to 'Back', :back %>
</div>
21 changes: 13 additions & 8 deletions app/views/form_helpers/_item_selection.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,17 @@
</script>

<% send_to_settle ||= false %>
<% send_to_screen ||= false %>

<div class="field">
<%= form.label :items, 'What items would you like to request?' %>
<% unless send_to_screen %>
<%= form.label :items, 'What items would you like to request?' %>
<% end %>
<table id="items-table">
<thead>
<tr>
<% if current_user&.volunteer? && send_to_settle %>
<th>Settled</th>
<% if current_user&.volunteer? && (send_to_settle || send_to_screen) %>
<th><%= send_to_settle ? 'Settled' : 'Quality Items' %></th>
<th>Quantity</th>
<th>Description</th>
<% else %>
Expand All @@ -238,15 +241,15 @@
<% item_change = item_change_form.instance_variable_get(:@object) %>

<tr data-id=<%=item_change_form.index%>>
<% if current_user&.volunteer? && send_to_settle %>
<% @itemsToStock = @request.getItemStock() %>
<% if current_user&.volunteer? && (send_to_settle || send_to_screen) %>
<% @itemsToStock = @request.getItemStock() if send_to_settle %>
<td><%= item_change_form.number_field :settle %></td>
<td><%= item_change.quantity %></td>
<td>
<%= item_change.description %>
<% if @itemsToStock.keys.any?(item_change.id) %>
<% if send_to_settle && @itemsToStock.keys.any?(item_change.id) %>
<% if @itemsToStock[item_change.id] > 0 %>
- Limited Stock (<%= @itemsToStock[item_change.id] =%>)
- Limited Stock (<%= @itemsToStock[item_change.id] %>)
<% else %>
- Out of Stock
<% end %>
Expand All @@ -265,5 +268,7 @@
<%end%>
</tbody>
</table>
<button type="button" onclick="insertItemRow();">Add Item</button>
<% unless send_to_screen %>
<button type="button" onclick="insertItemRow();">Add Item</button>
<% end %>
</div>
6 changes: 5 additions & 1 deletion app/views/public/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
<br />
<% end %>

<% if current_user&.volunteer? %>
<div class="centered-div">
<%= link_to "Donation Quality Check", donations_quality_check_url, class: "home-link" %>
</div>
<br />

<div class="centered-div">
<%= link_to "Volunteer Requests", requests_volunteer_path, class: "home-link" %>
</div>
Expand Down
6 changes: 4 additions & 2 deletions app/views/requests/_item_change_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
<% end %>

<div class="margins-needed">
<%= render partial: 'form_helpers/item_selection', locals: { form: form, parent_f: :request, send_to_settle: send_to_settle } %>
<% send_to_settle ||= false %>
<% send_to_screen ||= false %>
<%= render partial: 'form_helpers/item_selection', locals: { form: form, parent_f: :request, send_to_settle: send_to_settle, send_to_screen: send_to_screen } %>

<div class="actions">
<% send_to_settle ||= false %>
<%= form.hidden_field :send_to_settle, value: send_to_settle %>
<%= form.hidden_field :send_to_screen, value: send_to_screen %>
<%= form.submit %>
</div>
</div>
Expand Down
14 changes: 10 additions & 4 deletions app/views/requests/_volunteer_request_block.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<div class="volunteer-request-list-block">
<% @itemsToStock = request.getItemStock() %>
<% isRequestElseDonation = request.respond_to?(:getItemStock) %>

<% @itemsToStock = request.getItemStock() if isRequestElseDonation %>
<ul>
<% request.item_changes.limit(5).each do |item| %>
<li>
<%= item.description %>
<% if @itemsToStock.keys.any?(item.id) %>
<% if !@itemsToStock.nil? && @itemsToStock.keys.any?(item.id) %>
<% if @itemsToStock[item.id] > 0 %>
- Limited Stock (<%= @itemsToStock[item.id] =%>)
<% else %>
Expand All @@ -21,7 +23,11 @@
<% end %>
</ul>

<b><i>Due in <%= time_ago_in_words(request.due_time) %></i></b>
<% if isRequestElseDonation %>
<b><i>Due in <%= time_ago_in_words(request.due_time) %></i></b>

<p><%= link_to 'View', settle_request_path(request) %></p>
<p><%= link_to 'View', settle_request_path(request) %></p>
<% else %>
<p><%= link_to 'View', quality_screen_path(request) %></p>
<% end %>
</div>
41 changes: 38 additions & 3 deletions app/views/requests/settle.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,51 @@
<% end %>
</p>

<% if current_user&.volunteer? && @request.status == "pending" %>
<%= link_to "Mark Ready for Delivery", requests_next_status_path(@request), class: "home-link" %>
<br>
<h1>Contact the donee!</h1>
<i>Remember to contact the donee before you go to let them know when to meet and make sure they're still available.</i>
<p>
<strong>Full name:</strong>
<%= @request.full_name %>
</p>

<p>
<strong>Email:</strong>
<%= @request.email %>
</p>

<p>
<strong>Phone:</strong>
<%= @request.phone %>
</p>

<% if @request.meet %>
<p>
<strong>County:</strong>
<%= Request::COUNTIES.key(@request.county) %>

</p>
<% else %>
<p>
<strong>Address:</strong>
<%= @request.address %>
</p>
<% end %>

<p>
<strong>Availability:</strong>
<%= @request.availability %>
</p>

<% if current_user&.volunteer? && @request.status == "delivery_ready" %>
<%= link_to "Mark Order Complete", requests_next_status_path(@request), class: "home-link" %>
<br>
<% end %>

<% if current_user&.volunteer? && @request.status == "pending" %>
<%= link_to "Mark Ready for Delivery", requests_next_status_path(@request), class: "home-link" %>
<br>
<% end %>

<%= link_to 'Edit', edit_request_path(@request) %> |
<%= link_to 'Back', :back %>
</div>
Loading

0 comments on commit 1e54024

Please sign in to comment.