diff --git a/Gemfile b/Gemfile index e9548ce..401f116 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 61c5907..4adab96 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/README.md b/README.md index 62720b9..91c46e2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss index 1b83046..2432f87 100644 --- a/app/assets/stylesheets/main.scss +++ b/app/assets/stylesheets/main.scss @@ -96,7 +96,7 @@ form { textarea{ height: 5em; max-width: 300px; - padding: 15px; + padding: 5px; width: calc(100% - 30px); } diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index ef620f6..d0fd038 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -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 diff --git a/app/views/docs/_sub_nav.html.haml b/app/views/docs/_sub_nav.html.haml new file mode 100644 index 0000000..e69de29 diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 13b0bda..3324ae1 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -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 diff --git a/app/views/pages/_sub_nav.html.haml b/app/views/pages/_sub_nav.html.haml new file mode 100644 index 0000000..a75d903 --- /dev/null +++ b/app/views/pages/_sub_nav.html.haml @@ -0,0 +1,4 @@ +%ul.sub-nav + %li= link_to 'View Past Pages', list_pages_path + %li= link_to 'Send Page', page_person_path + diff --git a/app/views/pages/index.html.haml b/app/views/pages/index.html.haml index a5a9f48..1156184 100644 --- a/app/views/pages/index.html.haml +++ b/app/views/pages/index.html.haml @@ -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") diff --git a/app/views/pages/page.html.haml b/app/views/pages/page.html.haml index 01b7282..dcd241e 100644 --- a/app/views/pages/page.html.haml +++ b/app/views/pages/page.html.haml @@ -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); - diff --git a/app/views/parents/_sub_nav.html.haml b/app/views/parents/_sub_nav.html.haml new file mode 100644 index 0000000..4ce1937 --- /dev/null +++ b/app/views/parents/_sub_nav.html.haml @@ -0,0 +1,2 @@ +%ul.sub-nav + diff --git a/app/views/staff/_sub_nav.html.haml b/app/views/staff/_sub_nav.html.haml new file mode 100644 index 0000000..4ce1937 --- /dev/null +++ b/app/views/staff/_sub_nav.html.haml @@ -0,0 +1,2 @@ +%ul.sub-nav + diff --git a/app/views/users/_sub_nav.html.haml b/app/views/users/_sub_nav.html.haml new file mode 100644 index 0000000..4ce1937 --- /dev/null +++ b/app/views/users/_sub_nav.html.haml @@ -0,0 +1,2 @@ +%ul.sub-nav + diff --git a/app/workers/sms.rb b/app/workers/sms_sender.rb similarity index 70% rename from app/workers/sms.rb rename to app/workers/sms_sender.rb index b1472a9..5079a1e 100644 --- a/app/workers/sms.rb +++ b/app/workers/sms_sender.rb @@ -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! diff --git a/config/application.rb b/config/application.rb index 02b815e..ceb147f 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,5 +1,4 @@ require File.expand_path('../boot', __FILE__) - require 'rails/all' # Require the gems listed in Gemfile, including any gems diff --git a/config/routes.rb b/config/routes.rb index 7ad1187..5cfe9cf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/lib/secrets.rb b/lib/secrets.rb index 1afbfd1..8d35f92 100644 --- a/lib/secrets.rb +++ b/lib/secrets.rb @@ -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 diff --git a/test/fixtures/person.yml b/test/fixtures/person.yml index b491636..e0a2f34 100644 --- a/test/fixtures/person.yml +++ b/test/fixtures/person.yml @@ -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