Skip to content

Commit

Permalink
Track cleaning (#24)
Browse files Browse the repository at this point in the history
* Initial cleaning model and schema

* Added icon for reporting cleaning

* Base cleanings controller and routes

* Cleaning form outline

* Ability to create new cleaning record

* Link now sends to add cleaning page

* Added information tooltip

* Thank you page

* Made date field required
  • Loading branch information
roberth05 authored Sep 15, 2019
1 parent 3d0d1c1 commit d0f78e0
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 1 deletion.
23 changes: 23 additions & 0 deletions app/controllers/cleanings_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class CleaningsController < ApplicationController
respond_to :html, :json
def create
@cleaning = Cleaning.new(cleaning_params)
if @cleaning.save
respond_to do |format|
format.html { render :created }
format.json { render(json: @cleaning) }
end
else
respond_to do |format|
format.json { render(json: {errors: @thing.errors}, status: 500) }
end
end
end

private

def cleaning_params
params.require(:cleanings).permit(:date_cleaned, :diverted, :user_id, :thing_id)
end

end
5 changes: 5 additions & 0 deletions app/models/cleaning.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Cleaning < ActiveRecord::Base
belongs_to :user
belongs_to :thing
validates :date_cleaned, presence: true
end
1 change: 1 addition & 0 deletions app/models/thing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Thing < ActiveRecord::Base
:full_address, :state, :street_address, :street_name,
:street_number, :zip
has_many :reminders
has_many :cleanings
validates :city_id, uniqueness: true, allow_nil: true
validates :lat, presence: true
validates :lng, presence: true
Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class User < ActiveRecord::Base
has_many :reminders_from, class_name: 'Reminder', foreign_key: 'from_user_id'
has_many :reminders_to, class_name: 'Reminder', foreign_key: 'to_user_id'
has_many :things
has_many :cleanings
validates :first_name, presence: true
validates_formatting_of :email, using: :email
validates_formatting_of :sms_number, using: :us_phone, allow_blank: true
Expand Down
17 changes: 17 additions & 0 deletions app/views/cleanings/_cleaning_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
= form_for :cleanings, :url => {action: 'create'}, :html => {:id => "cleaning-form", :class => "form-vertical"} do |f|
:javascript
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip();
});
.form-group
%label.control-label{:for => "date_cleaned", :id => "date_cleaned_label"}
= t("labels.date_cleaned")
= f.date_field "date_cleaned", :class => "form-control", :required => true
%label.control-label{:for => "diverted", :id => "diverted_label"}
= t("labels.diverted")
%i.fa.fa-question-circle{:data_toggle=>"tooltip", :title=>"Please enter the type and weight of the materials you pulled out of the drain. Ex: 2lbs of hard plastic & 3lbs of pine straw. This information helps tremendously with research."}
= f.text_area "diverted", :class => "form-control"
= f.hidden_field "user_id", :value => params[:user]
= f.hidden_field "thing_id", :value => params[:thing]
.form-actions
= f.submit t("buttons.submit_cleaning"), :class => "btn btn-primary btn-block"
6 changes: 6 additions & 0 deletions app/views/cleanings/created.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%h1
Cleaning Reported
%p
Thank you for cleaning your drain! Keeping our waterways clean is critical to our neighborhoods.
%button.btn.btn-default{:type => "button", :"data-dismiss" => "modal", :onclick=>"window.close(); return false"}
Close
1 change: 1 addition & 0 deletions app/views/cleanings/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= render :partial => "cleaning_form"
4 changes: 4 additions & 0 deletions app/views/users/thank_you.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
%h2
= t("titles.thank_you", thing: t("defaults.thing"))
%br/
%a{ target: '_blank', href: "#{new_cleanings_path(:user => current_user, :thing => params[:thing_id])}" }
%i.fa.fa-check-square.fa-2x
%br/
%a{ target: '_blank', href: "mailto:?subject=#{URI.encode(t("titles.main", thing: t("defaults.thing")))}&body=#{URI.encode(t("titles.email_text", root_url: root_url, thing: t("defaults.thing")))}" }
%i.fa.fa-envelope-square.fa-2x
%a{ target: '_blank', href: "https://www.facebook.com/sharer/sharer.php?u=#{root_url}" }
Expand Down
3 changes: 3 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ de:
sign_in: "Einloggen"
sign_out: "Ausloggen"
sign_up: "Registrieren"
submit_cleaning: "Reinigung Abschicken"
update: "Aktualisierung"
captions:
optional: "(optional)"
Expand Down Expand Up @@ -44,6 +45,8 @@ de:
address_2: "Adresszeile 2"
city: "Stadt"
city_state: "Stadt"
date_cleaned: "Datum gereinigt"
diverted: "Material aus dem Abfluss Umgeleitet"
email: "E-Mail-Adresse"
name: "Name"
name_thing: "Geben Sie diesem %{thing} einen Namen"
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ en:
sign_out: "Sign out"
sign_up: "Sign up"
sign_up_or_in: "Register / Sign in"
submit_cleaning: "Report Cleaning"
update: "Update"
captions:
optional: "(optional)"
Expand Down Expand Up @@ -48,6 +49,8 @@ en:
address_2: "Address Line 2"
city: "City"
city_state: "City"
date_cleaned: "Date Cleaned"
diverted: "Materials Diverted from Drain"
email: "Email address"
first_name: "First name"
last_name: "Last name"
Expand Down
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

resource :reminders
resource :things
resource :cleanings do
collection do
get 'cleaning_form'
end
end

mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
root to: 'main#index'
end
16 changes: 16 additions & 0 deletions db/migrate/20190901004437_create_cleanings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CreateCleanings < ActiveRecord::Migration
def change
create_table :cleanings do |t|
t.timestamps
t.text :diverted
t.date :date_cleaned
t.integer :thing_id
t.integer :user_id

t.timestamps null: false
end

add_index :cleanings, :user_id
add_index :cleanings, :thing_id
end
end
14 changes: 13 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,23 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160326200455) do
ActiveRecord::Schema.define(version: 20190901004437) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "cleanings", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "diverted"
t.date "date_cleaned"
t.integer "thing_id"
t.integer "user_id"
end

add_index "cleanings", ["thing_id"], name: "index_cleanings_on_thing_id", using: :btree
add_index "cleanings", ["user_id"], name: "index_cleanings_on_user_id", using: :btree

create_table "rails_admin_histories", force: :cascade do |t|
t.string "message"
t.string "username"
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/cleanings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
diverted: MyText
date_cleaned: 2019-09-01
thing_id: thing_1

two:
diverted: MyText
date_cleaned: 2019-09-01
thing_id: thing_2
7 changes: 7 additions & 0 deletions test/models/cleaning_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class CleaningTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit d0f78e0

Please sign in to comment.