From 2bdf08a52342583fe271d543be7b4df6f3a991b8 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 28 Dec 2020 09:32:04 +0100 Subject: [PATCH] Add admin layout with admin navigation And remove the hacky link list from the dashboard. --- app/assets/stylesheets/_variables.scss | 3 ++ app/assets/stylesheets/admin.scss | 22 +++++++++ app/assets/stylesheets/layout.scss | 4 ++ app/controllers/admin/base_controller.rb | 2 + app/controllers/admin/dashboard_controller.rb | 1 + app/controllers/admin/donations_controller.rb | 5 +++ .../admin/ldap_users_controller.rb | 6 +++ app/controllers/dashboard_controller.rb | 2 +- app/controllers/donations_controller.rb | 2 +- app/controllers/invitations_controller.rb | 2 +- app/views/admin/dashboard/index.html.erb | 9 +--- app/views/layouts/admin.html.erb | 45 +++++++++++++++++++ app/views/shared/_admin_nav.html.erb | 18 ++++++++ app/views/shared/_main_nav.html.erb | 6 +-- 14 files changed, 114 insertions(+), 13 deletions(-) create mode 100644 app/assets/stylesheets/admin.scss create mode 100644 app/views/layouts/admin.html.erb create mode 100644 app/views/shared/_admin_nav.html.erb diff --git a/app/assets/stylesheets/_variables.scss b/app/assets/stylesheets/_variables.scss index d2a9d21..04f158f 100644 --- a/app/assets/stylesheets/_variables.scss +++ b/app/assets/stylesheets/_variables.scss @@ -6,5 +6,8 @@ $text-color-discreet: #888; $background-color-notice: #efffc4; $background-color-alert: #fff4c2; + $color-blue: #0d4f99; $color-purple: #8955a0; +$color-red-bright: #c00; +$color-red-dark: #990c0e; diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss new file mode 100644 index 0000000..6013c66 --- /dev/null +++ b/app/assets/stylesheets/admin.scss @@ -0,0 +1,22 @@ +@import "variables"; + +body#admin-panel { + #wrapper { + > header { + background: $color-red-bright; + background: linear-gradient(35deg, $color-purple 0, $color-red-dark 100%); + } + } + + #main-nav { + ul { + li { + a { + &.active { + border-bottom: 2px solid $color-red-bright; + } + } + } + } + } +} diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 3182e82..41ff821 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -170,3 +170,7 @@ main { } } } + +.text-centered { + text-align: center; +} diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb index 883c829..8688535 100644 --- a/app/controllers/admin/base_controller.rb +++ b/app/controllers/admin/base_controller.rb @@ -3,4 +3,6 @@ class Admin::BaseController < ApplicationController before_action :authenticate_user! before_action :authorize_admin + layout "admin" + end diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index 311d077..9cf8114 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -1,4 +1,5 @@ class Admin::DashboardController < Admin::BaseController def index + @current_section = :dashboard end end diff --git a/app/controllers/admin/donations_controller.rb b/app/controllers/admin/donations_controller.rb index 7b00bac..e6c37cc 100644 --- a/app/controllers/admin/donations_controller.rb +++ b/app/controllers/admin/donations_controller.rb @@ -1,5 +1,6 @@ class Admin::DonationsController < Admin::BaseController before_action :set_donation, only: [:show, :edit, :update, :destroy] + before_action :set_current_section, only: [:index, :show, :new, :edit] # GET /donations # GET /donations.json @@ -71,4 +72,8 @@ class Admin::DonationsController < Admin::BaseController def donation_params params.require(:donation).permit(:user_id, :amount_sats, :amount_eur, :amount_usd, :public_name, :paid_at) end + + def set_current_section + @current_section = :donations + end end diff --git a/app/controllers/admin/ldap_users_controller.rb b/app/controllers/admin/ldap_users_controller.rb index def46f4..1dfea57 100644 --- a/app/controllers/admin/ldap_users_controller.rb +++ b/app/controllers/admin/ldap_users_controller.rb @@ -1,4 +1,6 @@ class Admin::LdapUsersController < Admin::BaseController + before_action :set_current_section + def index attributes = %w{dn cn uid mail admin} filter = Net::LDAP::Filter.eq("uid", "*") @@ -38,4 +40,8 @@ class Admin::LdapUsersController < Admin::BaseController def ldap_config ldap_config ||= YAML.load(ERB.new(File.read("#{Rails.root}/config/ldap.yml")).result)[Rails.env] end + + def set_current_section + @current_section = :ldap_users + end end diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index ff44b1f..49c0764 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -2,6 +2,6 @@ class DashboardController < ApplicationController before_action :require_user_signed_in def index - @current_section = "dashboard" + @current_section = :dashboard end end diff --git a/app/controllers/donations_controller.rb b/app/controllers/donations_controller.rb index b4ec3b9..7800e09 100644 --- a/app/controllers/donations_controller.rb +++ b/app/controllers/donations_controller.rb @@ -5,6 +5,6 @@ class DonationsController < ApplicationController # GET /donations.json def index @donations = current_user.donations.completed - @current_section = "contributions" + @current_section = :contributions end end diff --git a/app/controllers/invitations_controller.rb b/app/controllers/invitations_controller.rb index 88603c3..72743e5 100644 --- a/app/controllers/invitations_controller.rb +++ b/app/controllers/invitations_controller.rb @@ -8,7 +8,7 @@ class InvitationsController < ApplicationController def index @invitations_unused = current_user.invitations.unused @invitations_used = current_user.invitations.used - @current_section = "invitations" + @current_section = :invitations end # GET /invitations/a-random-invitation-token diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb index 34a898c..2e04a10 100644 --- a/app/views/admin/dashboard/index.html.erb +++ b/app/views/admin/dashboard/index.html.erb @@ -1,8 +1,3 @@ -

Admin Panel

-

- Ohai there, admin human. +

+ With great power comes great responsibility.

- diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb new file mode 100644 index 0000000..ac24d75 --- /dev/null +++ b/app/views/layouts/admin.html.erb @@ -0,0 +1,45 @@ + + + + Admin Panel | Kosmos Accounts + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> + + + +
+
+

+ Kosmos + Akkounts + beta +

+ <% if user_signed_in? %> +

+ Signed in as <%= current_user.cn %>@kosmos.org. + <%= link_to "Log out", destroy_user_session_path, method: :delete %> +

+ <% end %> +
+ + <% if user_signed_in? && current_user.confirmed? %> + <%= render partial: 'shared/admin_nav' %> + <% end %> + + <% flash.each do |type, msg| %> +
+

<%= msg %>

+
+ <% end %> + +
+ <%= yield %> +
+
+ + diff --git a/app/views/shared/_admin_nav.html.erb b/app/views/shared/_admin_nav.html.erb new file mode 100644 index 0000000..c907b60 --- /dev/null +++ b/app/views/shared/_admin_nav.html.erb @@ -0,0 +1,18 @@ + diff --git a/app/views/shared/_main_nav.html.erb b/app/views/shared/_main_nav.html.erb index 719a723..3b1d5b9 100644 --- a/app/views/shared/_main_nav.html.erb +++ b/app/views/shared/_main_nav.html.erb @@ -3,15 +3,15 @@