From 52a98021d2fc5e858031a48d636a4f259e24494b Mon Sep 17 00:00:00 2001 From: Markus Graf Date: Mon, 18 Apr 2016 08:45:50 +0200 Subject: [PATCH] added admin part with password protected map and supporter list UNTESTED --- .../admin/application_controller.rb | 3 +++ app/controllers/admin/pages_controller.rb | 5 +++++ .../admin/supporters_controller.rb | 5 +++++ app/views/{ => admin}/pages/map.slim | 0 app/views/admin/supporters/index.slim | 21 +++++++++++++++++++ config/routes.rb | 7 ++++++- 6 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/application_controller.rb create mode 100644 app/controllers/admin/pages_controller.rb create mode 100644 app/controllers/admin/supporters_controller.rb rename app/views/{ => admin}/pages/map.slim (100%) create mode 100644 app/views/admin/supporters/index.slim diff --git a/app/controllers/admin/application_controller.rb b/app/controllers/admin/application_controller.rb new file mode 100644 index 0000000..c1aa16c --- /dev/null +++ b/app/controllers/admin/application_controller.rb @@ -0,0 +1,3 @@ +class Admin::ApplicationController < ApplicationController + http_basic_authenticate_with name: "admin", password: ENV['ADMIN_PASSWORD'] unless Rails.env.development? +end diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb new file mode 100644 index 0000000..addb77d --- /dev/null +++ b/app/controllers/admin/pages_controller.rb @@ -0,0 +1,5 @@ +class Admin::PagesController < Admin::ApplicationController + def map + @supporters = Supporter.where(:coordinates.ne => nil).only(:coordinates, :support) + end +end diff --git a/app/controllers/admin/supporters_controller.rb b/app/controllers/admin/supporters_controller.rb new file mode 100644 index 0000000..03f4af2 --- /dev/null +++ b/app/controllers/admin/supporters_controller.rb @@ -0,0 +1,5 @@ +class Admin::SupportersController < Admin::ApplicationController + def index + @supporters = Supporter.desc(:created_at) + end +end diff --git a/app/views/pages/map.slim b/app/views/admin/pages/map.slim similarity index 100% rename from app/views/pages/map.slim rename to app/views/admin/pages/map.slim diff --git a/app/views/admin/supporters/index.slim b/app/views/admin/supporters/index.slim new file mode 100644 index 0000000..1434954 --- /dev/null +++ b/app/views/admin/supporters/index.slim @@ -0,0 +1,21 @@ +h1 #{@supporters.count} Unterstützer +table.table + tr + th Eingeschrieben + th Adresse + th Unterstützung + th width="20%" Kommentar + - @supporters.each do |supporter| + tr + td = distance_of_time_in_words_to_now(supporter.created_at) + td + address + = "#{supporter.first_name} #{supporter.last_name}" + = + br + = supporter.street + br + = "#{supporter.zip} #{supporter.city}" + td = supporter.support + td = supporter.comments + diff --git a/config/routes.rb b/config/routes.rb index 3ab456a..551fc81 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,5 +5,10 @@ Rails.application.routes.draw do get '/thanks', to: 'pages#thanks', as: :thanks get '/cities_autocomplete', to: 'cities_autocomplete#index', as: :cities_autocomplete - get '/map', to: 'pages#map', as: :map + + namespace :admin do + get '/map', to: 'pages#map', as: :map + + resources :supporters, only: :index + end end