send page start

This commit is contained in:
Mark Moser 2015-09-20 22:30:44 -05:00
parent 692446b97b
commit c425f63ee9
13 changed files with 117 additions and 41 deletions

View File

@ -30,6 +30,10 @@ Metrics/LineLength:
- lib/tasks/**/* - lib/tasks/**/*
- test/test_helper.rb - test/test_helper.rb
Metrics/AbcSize:
Exclude:
- db/migrate/**/*
Style/ClassAndModuleChildren: Style/ClassAndModuleChildren:
Exclude: Exclude:
- test/test_helper.rb - test/test_helper.rb

View File

@ -14,15 +14,8 @@ A simple api to send sms messages with [twillio](https://www.twilio.com/).
## TODO ## TODO
* lookup child * page person
* lookup parent * active class on main navs
* lookup child by parent
* lookup parent by child
* add parent
* add child
* edit parent
* edit child
* page parent
* sorcery or a lower oauth solution * sorcery or a lower oauth solution
* application log * application log
* app version file - milestone 0.9.0 * app version file - milestone 0.9.0

View File

@ -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() {
});

View File

@ -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);
}
}

View File

@ -4,4 +4,10 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception protect_from_forgery with: :exception
respond_to :html, :json respond_to :html, :json
def current_user
# temp
Person.new(id: 9999)
end
helper_method :current_user
end end

View File

@ -4,7 +4,15 @@ class PagesController < ApplicationController
respond_with @pages respond_with @pages
end 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 def send_page
end end

View File

@ -15,6 +15,8 @@ class Person < ActiveRecord::Base
.uniq .uniq
} }
scope :pageable, -> { where('phone is not NULL').order(:first_name) }
scope :staff, -> { where(staff: true) } scope :staff, -> { where(staff: true) }
scope :admins, -> { where(admin: true) } scope :admins, -> { where(admin: true) }

View File

@ -1,2 +1,22 @@
%p send page form = form_for :page do |f|
%p active class on main navs = 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);

View File

@ -2,7 +2,7 @@
- @parents.each do |parent| - @parents.each do |parent|
%ul %ul
%li= parent.name %li #{parent.name} #{page_link(parent)}
%li= number_to_phone parent.phone %li= number_to_phone parent.phone
%li= mail_to parent.email %li= mail_to parent.email
%li Children: %li Children:

View File

@ -1,5 +1,5 @@
class Init < ActiveRecord::Migration class Init < ActiveRecord::Migration
def up def change
create_table :people do |t| create_table :people do |t|
t.string :first_name t.string :first_name
t.string :last_name t.string :last_name
@ -21,5 +21,14 @@ class Init < ActiveRecord::Migration
add_index :people, :phone add_index :people, :phone
add_index :parenthoods, [:person_id, :child_id], name: 'parentship' 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
end end

View File

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

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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| create_table "children", force: :cascade do |t|
t.string "first_name", limit: 255 t.string "first_name", limit: 255
@ -21,7 +21,6 @@ ActiveRecord::Schema.define(version: 20150913220116) do
create_table "pages", force: :cascade do |t| create_table "pages", force: :cascade do |t|
t.integer "user_id", limit: 4 t.integer "user_id", limit: 4
t.integer "person_id", limit: 4 t.integer "person_id", limit: 4
t.string "phone", limit: 255
t.string "to", limit: 255 t.string "to", limit: 255
t.string "message", limit: 255 t.string "message", limit: 255
t.string "status", limit: 255 t.string "status", limit: 255

View File

@ -1,7 +1,7 @@
page01: page01:
user: admin user: admin
person: sarah person: sarah
phone: 5005550006 to: 5005550006
message: "Yo! Kid needs help!" message: "Yo! Kid needs help!"
status: 'sent' status: 'sent'
created_at: <%= Date.today - 5.days %> created_at: <%= Date.today - 5.days %>
@ -9,7 +9,7 @@ page01:
page02: page02:
user: admin user: admin
person: sarah person: sarah
phone: 5005550006 to: 5005550006
message: "Yo! Kid needs help!" message: "Yo! Kid needs help!"
status: 'delivered' status: 'delivered'
created_at: <%= Date.today - 10.days %> created_at: <%= Date.today - 10.days %>
@ -17,7 +17,7 @@ page02:
page03: page03:
user: admin user: admin
person: marlin person: marlin
phone: 5005550006 to: 5005550006
message: "Yo! Kid needs help!" message: "Yo! Kid needs help!"
status: 'sent' status: 'sent'
created_at: <%= Date.today - 0.days %> created_at: <%= Date.today - 0.days %>
@ -25,7 +25,7 @@ page03:
page04: page04:
user: admin user: admin
person: kimmy person: kimmy
phone: 5005550006 to: 5005550006
message: "Yo! Kid needs help!" message: "Yo! Kid needs help!"
status: 'sent' status: 'sent'
created_at: <%= Date.today - 1.days %> created_at: <%= Date.today - 1.days %>
@ -33,7 +33,7 @@ page04:
page05: page05:
user: admin user: admin
person: wanda person: wanda
phone: 5005550006 to: 5005550006
message: "Time to work!" message: "Time to work!"
status: 'sent' status: 'sent'
created_at: <%= Date.today - 3.days %> created_at: <%= Date.today - 3.days %>
@ -41,7 +41,7 @@ page05:
page06: page06:
user: admin user: admin
person: basic person: basic
phone: 5005550006 to: 5005550006
message: "Yo! Kid needs help!" message: "Yo! Kid needs help!"
status: 'sent' status: 'sent'
created_at: <%= Date.today - 2.days %> created_at: <%= Date.today - 2.days %>
@ -49,7 +49,7 @@ page06:
page07: page07:
user: admin user: admin
person: sarah person: sarah
phone: 5005550006 to: 5005550006
message: "Yo! Kid needs help!" message: "Yo! Kid needs help!"
status: 'sent' status: 'sent'
created_at: <%= Date.today - 8.days %> created_at: <%= Date.today - 8.days %>
@ -57,7 +57,7 @@ page07:
page08: page08:
user: admin user: admin
person: sarah person: sarah
phone: 5005550006 to: 5005550006
message: "Yo! Kid needs help!" message: "Yo! Kid needs help!"
status: 'sent' status: 'sent'
created_at: <%= Date.today - 7.days %> created_at: <%= Date.today - 7.days %>
@ -65,7 +65,7 @@ page08:
page09: page09:
user: admin user: admin
person: sarah person: sarah
phone: 5005550006 to: 5005550006
message: "Yo! Kid needs help!" message: "Yo! Kid needs help!"
status: 'sent' status: 'sent'
created_at: <%= Date.today - 1.days %> created_at: <%= Date.today - 1.days %>
@ -73,7 +73,7 @@ page09:
page10: page10:
user: admin user: admin
person: sarah person: sarah
phone: 5005550006 to: 5005550006
message: "Yo! Kid needs help!" message: "Yo! Kid needs help!"
status: 'sent' status: 'sent'
created_at: <%= Date.today - 5.days %> created_at: <%= Date.today - 5.days %>
@ -81,7 +81,7 @@ page10:
page11: page11:
user: admin user: admin
person: sarah person: sarah
phone: 5005550006 to: 5005550006
message: "Yo! Kid needs help!" message: "Yo! Kid needs help!"
status: 'sent' status: 'sent'
created_at: <%= Date.today - 5.days %> created_at: <%= Date.today - 5.days %>
@ -89,7 +89,7 @@ page11:
page12: page12:
user: admin user: admin
person: sarah person: sarah
phone: 5005550006 to: 5005550006
message: "Yo! Kid needs help!" message: "Yo! Kid needs help!"
status: 'sent' status: 'sent'
created_at: <%= Date.today - 1.days %> created_at: <%= Date.today - 1.days %>
@ -97,7 +97,7 @@ page12:
page13: page13:
user: admin user: admin
person: sarah person: sarah
phone: 5005550006 to: 5005550006
message: "Yo! Kid needs help!" message: "Yo! Kid needs help!"
status: 'sent' status: 'sent'
created_at: <%= Date.today - 25.days %> created_at: <%= Date.today - 25.days %>