diff --git a/Guardfile b/Guardfile index ef1f7f4..10fb748 100644 --- a/Guardfile +++ b/Guardfile @@ -29,13 +29,15 @@ guard :minitest do end guard 'livereload' do + watch(%r{app/assets/.+\.(scss|css|js)}) watch(%r{app/views/.+\.(erb|haml|slim)$}) + watch(%r{app/controllers/.+\.rb}) watch(%r{app/helpers/.+\.rb}) watch(%r{public/.+\.(css|js|html)}) watch(%r{config/locales/.+\.yml}) # Rails Assets Pipeline - watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html|png|jpg))).*}) do |m| + watch(%r{(app|vendor)(/assets/\w+/(.+\.(scss|css|js|html|png|jpg))).*}) do |m| "/assets/#{m[3]}" end end diff --git a/README.md b/README.md index c3b1a16..73a2154 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,6 @@ A simple api to send sms messages with [twillio](https://www.twilio.com/). ## TODO -* list parents -* list children * lookup child * lookup parent * lookup child by parent diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss new file mode 100644 index 0000000..2a4a025 --- /dev/null +++ b/app/assets/stylesheets/main.scss @@ -0,0 +1,66 @@ +// maybe this? => https://color.adobe.com/Theme-1-color-theme-6893131/edit/?copy=true +$white: #F2E8DF; +$light: #C7C9CD; +$grey: #8E969D; +$dark: #646267; + +@mixin inline-ul { + display: inline-block; + list-style: none; + margin: 0; + padding: 0; + + li { + display: inline-block; + float: left; + margin: 0; + padding: 0; + + a { + display: inline-block; + padding: 15px; + text-decoration: none; + } + } +} + +html { + color: $dark; + background-color: $white; + margin: 0; + padding: 0; +} + +body { + margin: 15px; + padding: 0; +} + +.nav { + @include inline-ul; + background-color: $dark; + color: $light; + margin: -15px -15px 15px; + width: calc(100% + 30px); + + li { + &:hover { + background-color: $grey; + } + + a { + color: $light; + } + } +} + +.sub-nav { + @include inline-ul; + margin: -19px -15px 0; + a { + color: $dark; + &:hover { + background-color: $light; + } + } +} diff --git a/app/controllers/children_controller.rb b/app/controllers/children_controller.rb index 167d85f..0195aa0 100644 --- a/app/controllers/children_controller.rb +++ b/app/controllers/children_controller.rb @@ -3,4 +3,6 @@ class ChildrenController < ApplicationController @children = Child.all.order(:last_name, :first_name) respond_with @children end + + def lookup; end end diff --git a/app/controllers/docs_controller.rb b/app/controllers/docs_controller.rb index 5613213..7d77aef 100644 --- a/app/controllers/docs_controller.rb +++ b/app/controllers/docs_controller.rb @@ -1,10 +1,9 @@ class DocsController < ApplicationController def index - doc = { + @doc = { name: "sms-pager-api", documentation: "https://bitbucket.org/markamoser/sms-pager-api" - }.to_json - - render json: doc + } + respond_with @doc end end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index ce3bf58..9491cb6 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -1,2 +1,11 @@ class PagesController < ApplicationController + def index + @pages = Page.last_ten + respond_with @pages + end + + def page; end + + def send_page + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..01c0b6e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,7 @@ module ApplicationHelper + def page_link(person) + return if person.phone.blank? + + link_to 'page', page_person_path(person) + end end diff --git a/app/models/page.rb b/app/models/page.rb new file mode 100644 index 0000000..6c5f649 --- /dev/null +++ b/app/models/page.rb @@ -0,0 +1,6 @@ +class Page < ActiveRecord::Base + belongs_to :user, class_name: Person + belongs_to :person + + scope :last_ten, -> { order(updated_at: :desc).limit(10) } +end diff --git a/app/views/children/_sub_nav.html.haml b/app/views/children/_sub_nav.html.haml new file mode 100644 index 0000000..0942d83 --- /dev/null +++ b/app/views/children/_sub_nav.html.haml @@ -0,0 +1,3 @@ +%ul.sub-nav + %li= link_to 'look up', lookup_child_path + diff --git a/app/views/children/index.haml b/app/views/children/index.html.haml similarity index 65% rename from app/views/children/index.haml rename to app/views/children/index.html.haml index 1b47c6e..1dd0ccd 100644 --- a/app/views/children/index.haml +++ b/app/views/children/index.html.haml @@ -5,4 +5,4 @@ %li= child.name %ul - child.parents.each do |parent| - %li #{parent.name}: #{number_to_phone parent.phone} + %li #{parent.name} #{page_link(parent)} diff --git a/app/views/children/lookup.html.haml b/app/views/children/lookup.html.haml new file mode 100644 index 0000000..7d48100 --- /dev/null +++ b/app/views/children/lookup.html.haml @@ -0,0 +1 @@ +build search form here diff --git a/app/views/docs/index.html.haml b/app/views/docs/index.html.haml new file mode 100644 index 0000000..05fb133 --- /dev/null +++ b/app/views/docs/index.html.haml @@ -0,0 +1,4 @@ +%h2 Something helpful later + +%p= raw( ap @doc ) + diff --git a/app/views/layouts/_alerts.html.haml b/app/views/layouts/_alerts.html.haml new file mode 100644 index 0000000..12f9532 --- /dev/null +++ b/app/views/layouts/_alerts.html.haml @@ -0,0 +1,18 @@ +- unless flash.empty? + - if flash[:notice].present? + .container{'data-id' => 'alertbox', 'data-alert' => 'auto-close'} + .row + .col-md-6.col-md-offset-3.col-xs-12 + .alertbox + .alertbox.box_blue + .box_close{'data-id'=> 'alert-close'} + = flash[:notice] + + - if flash[:alert].present? + .container{'data-id' => 'alertbox'} + .row + .col-md-6.col-md-offset-3.col-xs-12 + .alertbox + .alertbox.box_red + .box_close{'data-id'=> 'alert-close'} + %b= flash[:alert] diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml new file mode 100644 index 0000000..e69de29 diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml new file mode 100644 index 0000000..264ef49 --- /dev/null +++ b/app/views/layouts/_navigation.html.haml @@ -0,0 +1,7 @@ +%ul.nav + %li= link_to 'Home', root_path + %li= link_to 'Parents', list_parents_path + %li= link_to 'Children', list_children_path + %li= link_to 'Staff', list_staff_path + %li= link_to 'Users', list_users_path + %li= link_to 'Pages', list_pages_path diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 1aed3d9..13b0bda 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -6,5 +6,12 @@ = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true = javascript_include_tag 'application', 'data-turbolinks-track' => true = csrf_meta_tags + = yield :custom_head %body + = render partial: 'layouts/alerts' + = render partial: 'layouts/navigation' + = render partial: 'sub_nav' if lookup_context.find_all('sub_nav').any? = yield + = render partial: 'layouts/footer' + = yield :modals + = yield :custom_scripts diff --git a/app/views/pages/index.html.haml b/app/views/pages/index.html.haml new file mode 100644 index 0000000..a5a9f48 --- /dev/null +++ b/app/views/pages/index.html.haml @@ -0,0 +1,5 @@ +%h1 Pages + +- @pages.each do |page| + %ul + %li= raw(ap page) diff --git a/app/views/pages/page.html.haml b/app/views/pages/page.html.haml new file mode 100644 index 0000000..dfa7705 --- /dev/null +++ b/app/views/pages/page.html.haml @@ -0,0 +1,2 @@ +%p send page form +%p active class on main navs diff --git a/app/views/parents/index.haml b/app/views/parents/index.html.haml similarity index 100% rename from app/views/parents/index.haml rename to app/views/parents/index.html.haml diff --git a/app/views/staff/index.haml b/app/views/staff/index.html.haml similarity index 100% rename from app/views/staff/index.haml rename to app/views/staff/index.html.haml diff --git a/app/views/users/index.haml b/app/views/users/index.html.haml similarity index 100% rename from app/views/users/index.haml rename to app/views/users/index.html.haml diff --git a/config/routes.rb b/config/routes.rb index da78177..7ad1187 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,13 +1,15 @@ Rails.application.routes.draw do - get 'parents', to: 'parents#index', as: :list_parents + get 'parents', to: 'parents#index', as: :list_parents - get 'children', to: 'children#index', as: :list_children + get 'children', to: 'children#index', as: :list_children + get 'children/lookup', to: 'children#lookup', as: :lookup_child - get 'staff', to: 'staff#index', as: :list_staff + get 'staff', to: 'staff#index', as: :list_staff - 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 root to: 'docs#index' end diff --git a/db/migrate/20150913220116_create_pages.rb b/db/migrate/20150913220116_create_pages.rb new file mode 100644 index 0000000..fba03a6 --- /dev/null +++ b/db/migrate/20150913220116_create_pages.rb @@ -0,0 +1,12 @@ +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/test/fixtures/pages.yml b/test/fixtures/pages.yml new file mode 100644 index 0000000..73a7955 --- /dev/null +++ b/test/fixtures/pages.yml @@ -0,0 +1,104 @@ +page01: + user: admin + person: sarah + phone: 5005550006 + message: "Yo! Kid needs help!" + status: 'sent' + created_at: <%= Date.today - 5.days %> + updated_at: <%= Date.today - 5.days %> +page02: + user: admin + person: sarah + phone: 5005550006 + message: "Yo! Kid needs help!" + status: 'delivered' + created_at: <%= Date.today - 10.days %> + updated_at: <%= Date.today - 10.days %> +page03: + user: admin + person: marlin + phone: 5005550006 + message: "Yo! Kid needs help!" + status: 'sent' + created_at: <%= Date.today - 0.days %> + updated_at: <%= Date.today - 0.days %> +page04: + user: admin + person: kimmy + phone: 5005550006 + message: "Yo! Kid needs help!" + status: 'sent' + created_at: <%= Date.today - 1.days %> + updated_at: <%= Date.today - 1.days %> +page05: + user: admin + person: wanda + phone: 5005550006 + message: "Time to work!" + status: 'sent' + created_at: <%= Date.today - 3.days %> + updated_at: <%= Date.today - 3.days %> +page06: + user: admin + person: basic + phone: 5005550006 + message: "Yo! Kid needs help!" + status: 'sent' + created_at: <%= Date.today - 2.days %> + updated_at: <%= Date.today - 2.days %> +page07: + user: admin + person: sarah + phone: 5005550006 + message: "Yo! Kid needs help!" + status: 'sent' + created_at: <%= Date.today - 8.days %> + updated_at: <%= Date.today - 8.days %> +page08: + user: admin + person: sarah + phone: 5005550006 + message: "Yo! Kid needs help!" + status: 'sent' + created_at: <%= Date.today - 7.days %> + updated_at: <%= Date.today - 7.days %> +page09: + user: admin + person: sarah + phone: 5005550006 + message: "Yo! Kid needs help!" + status: 'sent' + created_at: <%= Date.today - 1.days %> + updated_at: <%= Date.today - 1.days %> +page10: + user: admin + person: sarah + phone: 5005550006 + message: "Yo! Kid needs help!" + status: 'sent' + created_at: <%= Date.today - 5.days %> + updated_at: <%= Date.today - 5.days %> +page11: + user: admin + person: sarah + phone: 5005550006 + message: "Yo! Kid needs help!" + status: 'sent' + created_at: <%= Date.today - 5.days %> + updated_at: <%= Date.today - 5.days %> +page12: + user: admin + person: sarah + phone: 5005550006 + message: "Yo! Kid needs help!" + status: 'sent' + created_at: <%= Date.today - 1.days %> + updated_at: <%= Date.today - 1.days %> +page13: + user: admin + person: sarah + phone: 5005550006 + message: "Yo! Kid needs help!" + status: 'sent' + created_at: <%= Date.today - 25.days %> + updated_at: <%= Date.today - 25.days %> diff --git a/test/models/page_test.rb b/test/models/page_test.rb new file mode 100644 index 0000000..d118a29 --- /dev/null +++ b/test/models/page_test.rb @@ -0,0 +1,18 @@ +require 'test_helper' + +class PageTest < ActiveSupport::TestCase + def test_pages + pages = Page.all + + assert pages.count > 10, "Fixture did not load" + end + + def test_last_10_order + pages = Page.last_ten + times = pages.map(&:updated_at) + + assert_equal 10, times.count + assert_equal times.sort.reverse, times + assert times.last < times.first, 'Sort order should be descending' + end +end