Add admin layout with admin navigation #21
@ -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;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										22
									
								
								app/assets/stylesheets/admin.scss
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								app/assets/stylesheets/admin.scss
									
									
									
									
									
										Normal file
									
								
							@ -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;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -170,3 +170,7 @@ main {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.text-centered {
 | 
			
		||||
  text-align: center;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -3,4 +3,6 @@ class Admin::BaseController < ApplicationController
 | 
			
		||||
  before_action :authenticate_user!
 | 
			
		||||
  before_action :authorize_admin
 | 
			
		||||
 | 
			
		||||
  layout "admin"
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,5 @@
 | 
			
		||||
class Admin::DashboardController < Admin::BaseController
 | 
			
		||||
  def index
 | 
			
		||||
    @current_section = :dashboard
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,6 @@ class DashboardController < ApplicationController
 | 
			
		||||
  before_action :require_user_signed_in
 | 
			
		||||
 | 
			
		||||
  def index
 | 
			
		||||
    @current_section = "dashboard"
 | 
			
		||||
    @current_section = :dashboard
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -1,8 +1,3 @@
 | 
			
		||||
<h2>Admin Panel</h2>
 | 
			
		||||
<p>
 | 
			
		||||
  Ohai there, admin human.
 | 
			
		||||
<p class="text-centered">
 | 
			
		||||
  With great power comes great responsibility.
 | 
			
		||||
</p>
 | 
			
		||||
<ul>
 | 
			
		||||
  <li><%= link_to 'LDAP users', admin_ldap_users_path %></li>
 | 
			
		||||
  <li><%= link_to 'Donations', admin_donations_path %></li>
 | 
			
		||||
</ul>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										45
									
								
								app/views/layouts/admin.html.erb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								app/views/layouts/admin.html.erb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,45 @@
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html>
 | 
			
		||||
  <head>
 | 
			
		||||
    <title>Admin Panel | Kosmos Accounts</title>
 | 
			
		||||
    <%= csrf_meta_tags %>
 | 
			
		||||
    <%= csp_meta_tag %>
 | 
			
		||||
 | 
			
		||||
    <meta name="viewport" content="width=device-width, initial-scale=1">
 | 
			
		||||
 | 
			
		||||
    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
 | 
			
		||||
    <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
 | 
			
		||||
  </head>
 | 
			
		||||
 | 
			
		||||
  <body id="admin-panel">
 | 
			
		||||
    <div id="wrapper">
 | 
			
		||||
      <header>
 | 
			
		||||
        <h1>
 | 
			
		||||
          <span class ="project-name">Kosmos</span>
 | 
			
		||||
          <span class ="site-name">Akkounts</span>
 | 
			
		||||
          <span class="beta"><span class="bolt">⚡</span> beta</span>
 | 
			
		||||
        </h1>
 | 
			
		||||
        <% if user_signed_in? %>
 | 
			
		||||
          <p class="current-user">
 | 
			
		||||
            Signed in as <strong><%= current_user.cn %>@kosmos.org</strong>.
 | 
			
		||||
            <%= link_to "Log out", destroy_user_session_path, method: :delete %>
 | 
			
		||||
          </p>
 | 
			
		||||
        <% end %>
 | 
			
		||||
      </header>
 | 
			
		||||
 | 
			
		||||
      <% if user_signed_in? && current_user.confirmed? %>
 | 
			
		||||
        <%= render partial: 'shared/admin_nav' %>
 | 
			
		||||
      <% end %>
 | 
			
		||||
 | 
			
		||||
      <% flash.each do |type, msg| %>
 | 
			
		||||
        <div class="flash-msg <%= type %>">
 | 
			
		||||
          <p><%= msg %></p>
 | 
			
		||||
        </div>
 | 
			
		||||
      <% end %>
 | 
			
		||||
 | 
			
		||||
      <main>
 | 
			
		||||
        <%= yield %>
 | 
			
		||||
      </main>
 | 
			
		||||
    </div>
 | 
			
		||||
  </body>
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										18
									
								
								app/views/shared/_admin_nav.html.erb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								app/views/shared/_admin_nav.html.erb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
			
		||||
<nav id="main-nav">
 | 
			
		||||
  <div class="wrapper">
 | 
			
		||||
    <ul class="pages">
 | 
			
		||||
      <li>
 | 
			
		||||
        <%= link_to "Dashboard", admin_root_path,
 | 
			
		||||
             class: @current_section == :dashboard ? "active" : nil %>
 | 
			
		||||
      </li>
 | 
			
		||||
      <li>
 | 
			
		||||
        <%= link_to "Donations", admin_donations_path,
 | 
			
		||||
              class: @current_section == :donations ? "active" : nil %>
 | 
			
		||||
      </li>
 | 
			
		||||
      <li>
 | 
			
		||||
        <%= link_to "LDAP Users", admin_ldap_users_path,
 | 
			
		||||
              class: @current_section == :ldap_users ? "active" : nil %>
 | 
			
		||||
      </li>
 | 
			
		||||
    </ul>
 | 
			
		||||
  </div>
 | 
			
		||||
</nav>
 | 
			
		||||
@ -3,15 +3,15 @@
 | 
			
		||||
    <ul class="pages">
 | 
			
		||||
      <li>
 | 
			
		||||
        <%= link_to "Services", root_path,
 | 
			
		||||
             class: @current_section == "dashboard" ? "active" : nil %>
 | 
			
		||||
             class: @current_section == :dashboard ? "active" : nil %>
 | 
			
		||||
      </li>
 | 
			
		||||
      <li>
 | 
			
		||||
        <%= link_to "Donations", donations_path,
 | 
			
		||||
              class: @current_section == "contributions" ? "active" : nil %>
 | 
			
		||||
              class: @current_section == :contributions ? "active" : nil %>
 | 
			
		||||
      </li>
 | 
			
		||||
      <li>
 | 
			
		||||
        <%= link_to "Invitations", invitations_path,
 | 
			
		||||
              class: @current_section == "invitations" ? "active" : nil %>
 | 
			
		||||
              class: @current_section == :invitations ? "active" : nil %>
 | 
			
		||||
      </li>
 | 
			
		||||
    </ul>
 | 
			
		||||
  </div>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user