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'
ruby "2.2.2"
gem 'figaro', '~> 1.1.1'
gem 'rails', '~> 4.2.4'
gem 'thin', '~> 1.6.3'
gem 'responders', '~> 2.1.0'

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ class PagesController < ApplicationController
def page
@page = Page.new
person = Person.find(params[:id])
person = Person.find_by(id: params[:id])
@people = Person.pageable
return if person.nil?
@ -15,5 +15,16 @@ class PagesController < ApplicationController
end
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
private
def page_params
params.require(:page).permit(:message, :to, :person_id)
end
end

View File

View File

@ -10,7 +10,7 @@
%body
= render partial: 'layouts/alerts'
= render partial: 'layouts/navigation'
= render partial: 'sub_nav' if lookup_context.find_all('sub_nav').any?
= render partial: 'sub_nav'
= yield
= render partial: 'layouts/footer'
= 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
- @pages.each do |page|
%ul
%li= raw(ap page)
%ul.page_listing
%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|
= f.hidden_field :user_id, value: current_user.id
= form_for :page, url: send_page_path do |f|
= 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.phone_field :to
@ -17,6 +15,3 @@
$('#page_person_id').on('change', function(){
$('#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
def initialize args_as_hash
@from = args_as_hash["from"] ||= ENV["twilio_number"]
@to = args_as_hash["to"]
@message = args_as_hash["message"]
@from = args_as_hash[:from] ||= ENV["twilio_number"]
@to = args_as_hash[:to]
@message = args_as_hash[:message]
end
def send!

View File

@ -1,5 +1,4 @@
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# 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 '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'
end

View File

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

View File

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