paging and a little styling

This commit is contained in:
Mark Moser 2015-09-21 20:40:07 -05:00
parent c425f63ee9
commit d123e63b76
18 changed files with 71 additions and 30 deletions

View File

@ -1,6 +1,7 @@
source 'https://rubygems.org' source 'https://rubygems.org'
ruby "2.2.2" ruby "2.2.2"
gem 'figaro', '~> 1.1.1'
gem 'rails', '~> 4.2.4' gem 'rails', '~> 4.2.4'
gem 'thin', '~> 1.6.3' gem 'thin', '~> 1.6.3'
gem 'responders', '~> 2.1.0' gem 'responders', '~> 2.1.0'

View File

@ -66,6 +66,8 @@ GEM
eventmachine (1.0.8) eventmachine (1.0.8)
execjs (2.6.0) execjs (2.6.0)
ffi (1.9.10) ffi (1.9.10)
figaro (1.1.1)
thor (~> 0.14)
formatador (0.2.5) formatador (0.2.5)
globalid (0.3.6) globalid (0.3.6)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
@ -240,6 +242,7 @@ DEPENDENCIES
awesome_print awesome_print
bcrypt (~> 3.1.7) bcrypt (~> 3.1.7)
binding_of_caller binding_of_caller
figaro (~> 1.1.1)
guard guard
guard-livereload guard-livereload
guard-minitest guard-minitest

View File

@ -14,7 +14,6 @@ A simple api to send sms messages with [twillio](https://www.twilio.com/).
## TODO ## TODO
* page person
* active class on main navs * active class on main navs
* sorcery or a lower oauth solution * sorcery or a lower oauth solution
* application log * application log

View File

@ -96,7 +96,7 @@ form {
textarea{ textarea{
height: 5em; height: 5em;
max-width: 300px; max-width: 300px;
padding: 15px; padding: 5px;
width: calc(100% - 30px); width: calc(100% - 30px);
} }

View File

@ -6,7 +6,7 @@ class PagesController < ApplicationController
def page def page
@page = Page.new @page = Page.new
person = Person.find(params[:id]) person = Person.find_by(id: params[:id])
@people = Person.pageable @people = Person.pageable
return if person.nil? return if person.nil?
@ -15,5 +15,16 @@ class PagesController < ApplicationController
end end
def send_page def send_page
page = Page.create page_params.merge(status: 'sent')
sms = ::SmsSender.new(to: page.to, message: page.message)
sms.send!
redirect_to list_pages_path, notice: "Page sent!"
end end
private
def page_params
params.require(:page).permit(:message, :to, :person_id)
end
end end

View File

View File

@ -10,7 +10,7 @@
%body %body
= render partial: 'layouts/alerts' = render partial: 'layouts/alerts'
= render partial: 'layouts/navigation' = render partial: 'layouts/navigation'
= render partial: 'sub_nav' if lookup_context.find_all('sub_nav').any? = render partial: 'sub_nav'
= yield = yield
= render partial: 'layouts/footer' = render partial: 'layouts/footer'
= yield :modals = yield :modals

View File

@ -0,0 +1,4 @@
%ul.sub-nav
%li= link_to 'View Past Pages', list_pages_path
%li= link_to 'Send Page', page_person_path

View File

@ -1,5 +1,25 @@
%h1 Pages %h1 Pages
- @pages.each do |page| - @pages.each do |page|
%ul %ul.page_listing
%li= raw(ap page) %li
sent by:
%span= page.user.name unless page.user.nil?
%li
to:
%span= page.person.name
%li
phone:
%span= page.to
%li
message:
%span= page.message
%li
status:
%span= page.status
%li
sent at:
%span= page.created_at.strftime("%m/%d/%Y %I:%M %p")
%li
last modified at:
%span= page.updated_at.strftime("%m/%d/%Y %I:%M %p")

View File

@ -1,8 +1,6 @@
= form_for :page do |f| = form_for :page, url: send_page_path do |f|
= f.hidden_field :user_id, value: current_user.id
= f.label :person_id = f.label :person_id
= f.select :person_id, options_from_collection_for_select(@people, :id, :name, @page.person_id) = f.select :person_id, options_from_collection_for_select(@people, :id, :name, @page.person_id), include_blank: true
= f.label :to = f.label :to
= f.phone_field :to = f.phone_field :to
@ -17,6 +15,3 @@
$('#page_person_id').on('change', function(){ $('#page_person_id').on('change', function(){
$('#page_to').val( getPersonPhone($(this).val(), people) ); $('#page_to').val( getPersonPhone($(this).val(), people) );
}); });
console.log(people);

View File

@ -0,0 +1,2 @@
%ul.sub-nav

View File

@ -0,0 +1,2 @@
%ul.sub-nav

View File

@ -0,0 +1,2 @@
%ul.sub-nav

View File

@ -4,9 +4,9 @@ class SmsSender
attr_accessor :message attr_accessor :message
def initialize args_as_hash def initialize args_as_hash
@from = args_as_hash["from"] ||= ENV["twilio_number"] @from = args_as_hash[:from] ||= ENV["twilio_number"]
@to = args_as_hash["to"] @to = args_as_hash[:to]
@message = args_as_hash["message"] @message = args_as_hash[:message]
end end
def send! def send!

View File

@ -1,5 +1,4 @@
require File.expand_path('../boot', __FILE__) require File.expand_path('../boot', __FILE__)
require 'rails/all' require 'rails/all'
# Require the gems listed in Gemfile, including any gems # Require the gems listed in Gemfile, including any gems

View File

@ -9,7 +9,8 @@ Rails.application.routes.draw do
get 'users', to: 'users#index', as: :list_users get 'users', to: 'users#index', as: :list_users
get 'pages', to: 'pages#index', as: :list_pages get 'pages', to: 'pages#index', as: :list_pages
get 'page/:id', to: 'pages#page', as: :page_person get 'page/(:id)', to: 'pages#page', as: :page_person
post 'page', to: 'pages#send_page', as: :send_page
root to: 'docs#index' root to: 'docs#index'
end end

View File

@ -1,11 +1,13 @@
require 'yaml' # require 'yaml'
module Secrets # module Secrets
def self.load # def self.load
return nil unless File.exist?("./config/application.yml") # binding.pry
#
secrets = YAML.load(File.read('./config/application.yml')) # return nil unless File.exist?("./config/application.yml")
secrets.each do |k, v| #
ENV[k] = v # secrets = YAML.load(File.read('./config/application.yml'))
end # secrets.each do |k, v|
end # ENV[k] = v
end # end
# end
# end

View File

@ -3,7 +3,7 @@ admin:
first_name: admin first_name: admin
last_name: user last_name: user
email: admin.user@mailinator.com email: admin.user@mailinator.com
phone: 5005550006 phone: 3093634474
admin: true admin: true
basic: basic:
first_name: basic first_name: basic