From c425f63ee94d71b927a854e7be51069d915c0406 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Sun, 20 Sep 2015 22:30:44 -0500 Subject: [PATCH] send page start --- .rubocop.yml | 4 +++ README.md | 11 ++----- app/assets/javascripts/main.js | 10 ++++++ app/assets/stylesheets/main.scss | 37 +++++++++++++++++++++++ app/controllers/application_controller.rb | 6 ++++ app/controllers/pages_controller.rb | 10 +++++- app/models/person.rb | 2 ++ app/views/pages/page.html.haml | 24 +++++++++++++-- app/views/parents/index.html.haml | 2 +- db/migrate/20150904033833_init.rb | 11 ++++++- db/migrate/20150913220116_create_pages.rb | 12 -------- db/schema.rb | 3 +- test/fixtures/pages.yml | 26 ++++++++-------- 13 files changed, 117 insertions(+), 41 deletions(-) create mode 100644 app/assets/javascripts/main.js delete mode 100644 db/migrate/20150913220116_create_pages.rb diff --git a/.rubocop.yml b/.rubocop.yml index 3e622a0..d41f566 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -30,6 +30,10 @@ Metrics/LineLength: - lib/tasks/**/* - test/test_helper.rb +Metrics/AbcSize: + Exclude: + - db/migrate/**/* + Style/ClassAndModuleChildren: Exclude: - test/test_helper.rb diff --git a/README.md b/README.md index 73a2154..62720b9 100644 --- a/README.md +++ b/README.md @@ -14,15 +14,8 @@ A simple api to send sms messages with [twillio](https://www.twilio.com/). ## TODO -* lookup child -* lookup parent -* lookup child by parent -* lookup parent by child -* add parent -* add child -* edit parent -* edit child -* page parent +* page person +* active class on main navs * sorcery or a lower oauth solution * application log * app version file - milestone 0.9.0 diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js new file mode 100644 index 0000000..9d21052 --- /dev/null +++ b/app/assets/javascripts/main.js @@ -0,0 +1,10 @@ +function getPersonPhone(id, collection){ + for(var i = 0; i < collection.length; i++){ + if(collection[i].id == id){ + return collection[i].phone; + } + } +} + +$( document ).ready(function() { +}); diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss index 2a4a025..1b83046 100644 --- a/app/assets/stylesheets/main.scss +++ b/app/assets/stylesheets/main.scss @@ -64,3 +64,40 @@ body { } } } + + +form { + width: 100%; + * { + font-size: 14px; + line-height: 1.6em; + } + + label { + display: inline-block; + margin: 0.6em 0 0; + width: 100%; + + &:after { + content: ": "; + } + } + + input { + display: block; + margin: 0 0 0.6em; + padding: 5px; + } + + [type=submit]{ + margin: 0.6em 0; + } + + textarea{ + height: 5em; + max-width: 300px; + padding: 15px; + width: calc(100% - 30px); + } + +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4133060..d8f5ed6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,4 +4,10 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception respond_to :html, :json + + def current_user + # temp + Person.new(id: 9999) + end + helper_method :current_user end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 9491cb6..ef620f6 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -4,7 +4,15 @@ class PagesController < ApplicationController respond_with @pages end - def page; end + def page + @page = Page.new + person = Person.find(params[:id]) + @people = Person.pageable + + return if person.nil? + @page.person_id = person.id + @page.to = person.phone + end def send_page end diff --git a/app/models/person.rb b/app/models/person.rb index f51b4aa..409fc05 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -15,6 +15,8 @@ class Person < ActiveRecord::Base .uniq } + scope :pageable, -> { where('phone is not NULL').order(:first_name) } + scope :staff, -> { where(staff: true) } scope :admins, -> { where(admin: true) } diff --git a/app/views/pages/page.html.haml b/app/views/pages/page.html.haml index dfa7705..01b7282 100644 --- a/app/views/pages/page.html.haml +++ b/app/views/pages/page.html.haml @@ -1,2 +1,22 @@ -%p send page form -%p active class on main navs += form_for :page do |f| + = f.hidden_field :user_id, value: current_user.id + + = f.label :person_id + = f.select :person_id, options_from_collection_for_select(@people, :id, :name, @page.person_id) + + = f.label :to + = f.phone_field :to + + = f.label :message + = f.text_area :message + + = f.submit 'Send Page' + +:javascript + var people = #{@people.to_json}; + $('#page_person_id').on('change', function(){ + $('#page_to').val( getPersonPhone($(this).val(), people) ); + }); + + console.log(people); + diff --git a/app/views/parents/index.html.haml b/app/views/parents/index.html.haml index 679009f..0a182a0 100644 --- a/app/views/parents/index.html.haml +++ b/app/views/parents/index.html.haml @@ -2,7 +2,7 @@ - @parents.each do |parent| %ul - %li= parent.name + %li #{parent.name} #{page_link(parent)} %li= number_to_phone parent.phone %li= mail_to parent.email %li Children: diff --git a/db/migrate/20150904033833_init.rb b/db/migrate/20150904033833_init.rb index baa3f1b..d3850d7 100644 --- a/db/migrate/20150904033833_init.rb +++ b/db/migrate/20150904033833_init.rb @@ -1,5 +1,5 @@ class Init < ActiveRecord::Migration - def up + def change create_table :people do |t| t.string :first_name t.string :last_name @@ -21,5 +21,14 @@ class Init < ActiveRecord::Migration add_index :people, :phone add_index :parenthoods, [:person_id, :child_id], name: 'parentship' + + create_table :pages do |t| + t.integer :user_id + t.integer :person_id + t.string :to + t.string :message + t.string :status + t.timestamps null: false + end end end diff --git a/db/migrate/20150913220116_create_pages.rb b/db/migrate/20150913220116_create_pages.rb deleted file mode 100644 index fba03a6..0000000 --- a/db/migrate/20150913220116_create_pages.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreatePages < ActiveRecord::Migration - def change - create_table :pages do |t| - t.integer :user_id - t.integer :person_id - t.string :phone - t.string :message - t.string :status - t.timestamps null: false - end - end -end diff --git a/db/schema.rb b/db/schema.rb index e3e91f4..12333c0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150913220116) do +ActiveRecord::Schema.define(version: 20150904033833) do create_table "children", force: :cascade do |t| t.string "first_name", limit: 255 @@ -21,7 +21,6 @@ ActiveRecord::Schema.define(version: 20150913220116) do create_table "pages", force: :cascade do |t| t.integer "user_id", limit: 4 t.integer "person_id", limit: 4 - t.string "phone", limit: 255 t.string "to", limit: 255 t.string "message", limit: 255 t.string "status", limit: 255 diff --git a/test/fixtures/pages.yml b/test/fixtures/pages.yml index 73a7955..28a22f3 100644 --- a/test/fixtures/pages.yml +++ b/test/fixtures/pages.yml @@ -1,7 +1,7 @@ page01: user: admin person: sarah - phone: 5005550006 + to: 5005550006 message: "Yo! Kid needs help!" status: 'sent' created_at: <%= Date.today - 5.days %> @@ -9,7 +9,7 @@ page01: page02: user: admin person: sarah - phone: 5005550006 + to: 5005550006 message: "Yo! Kid needs help!" status: 'delivered' created_at: <%= Date.today - 10.days %> @@ -17,7 +17,7 @@ page02: page03: user: admin person: marlin - phone: 5005550006 + to: 5005550006 message: "Yo! Kid needs help!" status: 'sent' created_at: <%= Date.today - 0.days %> @@ -25,7 +25,7 @@ page03: page04: user: admin person: kimmy - phone: 5005550006 + to: 5005550006 message: "Yo! Kid needs help!" status: 'sent' created_at: <%= Date.today - 1.days %> @@ -33,7 +33,7 @@ page04: page05: user: admin person: wanda - phone: 5005550006 + to: 5005550006 message: "Time to work!" status: 'sent' created_at: <%= Date.today - 3.days %> @@ -41,7 +41,7 @@ page05: page06: user: admin person: basic - phone: 5005550006 + to: 5005550006 message: "Yo! Kid needs help!" status: 'sent' created_at: <%= Date.today - 2.days %> @@ -49,7 +49,7 @@ page06: page07: user: admin person: sarah - phone: 5005550006 + to: 5005550006 message: "Yo! Kid needs help!" status: 'sent' created_at: <%= Date.today - 8.days %> @@ -57,7 +57,7 @@ page07: page08: user: admin person: sarah - phone: 5005550006 + to: 5005550006 message: "Yo! Kid needs help!" status: 'sent' created_at: <%= Date.today - 7.days %> @@ -65,7 +65,7 @@ page08: page09: user: admin person: sarah - phone: 5005550006 + to: 5005550006 message: "Yo! Kid needs help!" status: 'sent' created_at: <%= Date.today - 1.days %> @@ -73,7 +73,7 @@ page09: page10: user: admin person: sarah - phone: 5005550006 + to: 5005550006 message: "Yo! Kid needs help!" status: 'sent' created_at: <%= Date.today - 5.days %> @@ -81,7 +81,7 @@ page10: page11: user: admin person: sarah - phone: 5005550006 + to: 5005550006 message: "Yo! Kid needs help!" status: 'sent' created_at: <%= Date.today - 5.days %> @@ -89,7 +89,7 @@ page11: page12: user: admin person: sarah - phone: 5005550006 + to: 5005550006 message: "Yo! Kid needs help!" status: 'sent' created_at: <%= Date.today - 1.days %> @@ -97,7 +97,7 @@ page12: page13: user: admin person: sarah - phone: 5005550006 + to: 5005550006 message: "Yo! Kid needs help!" status: 'sent' created_at: <%= Date.today - 25.days %>