Skip to content

Commit

Permalink
Update and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
lazaronixon committed Mar 1, 2023
1 parent a3e1dc2 commit 5f898e0
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 46 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ The purpose of administration zero is to generate a pre-built administration pan

## Installation

Add this line to your application's Gemfile:

```ruby
gem "administration-zero"
bundle add administration-zero
```

Then run `bundle install`

You'll need to create a model to be administrated, if you don't have one. for this example let's use the following:

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ class Admin::BaseController < ActionController::Base
before_action :set_time_zone
before_action :authenticate

def set_time_zone
Time.zone = cookies[:time_zone]
end
private
def set_time_zone
Time.zone = cookies[:time_zone]
end

def authenticate
if user = Admin::User.find_by_id(session[:admin_user_id])
Admin::Current.user = user
else
redirect_to admin_sign_in_path
def authenticate
if user = Admin::User.find_by_id(session[:admin_user_id])
Admin::Current.user = user
else
redirect_to admin_sign_in_path
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def edit

def create
if @user = Admin::User.find_by(email: params[:email])
Admin::UserMailer.with(user: @user).password_reset.deliver_later
send_password_reset_email
redirect_to admin_sign_in_path, notice: "Check your email for reset instructions"
else
redirect_to new_admin_password_reset_path, alert: "Sorry, we didn't recognize that email address"
Expand All @@ -38,4 +38,8 @@ def set_user
def user_params
params.permit(:password, :password_confirmation)
end

def send_password_reset_email
Admin::UserMailer.with(user: @user).password_reset.deliver_later
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- Tabler Core -->
<script src="https://cdn.jsdelivr.net/npm/@tabler/[email protected]beta11/dist/js/tabler.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tabler/[email protected]beta17/dist/js/tabler.min.js"></script>

<!-- Time zone cookie -->
<script type="module">
Expand All @@ -12,15 +12,16 @@
<script type="module">
document.addEventListener("click", (event) => {
if (!event.target.matches("[data-confirm]")) return
if (!window.confirm(event.target.dataset["confirm"])) event.preventDefault()
if (!confirm(event.target.dataset["confirm"])) event.preventDefault()
})
</script>

<!-- Stimulus controllers -->
<script type="module">
import { Application, Controller } from "https://cdn.jsdelivr.net/npm/@hotwired/stimulus@3.1.0/dist/stimulus.min.js"
import { Application, Controller } from "https://cdn.jsdelivr.net/npm/stimulus@3.2.1/dist/stimulus.min.js"
window.Stimulus = Application.start()

// Flash message
Stimulus.register("flash-message", class extends Controller {
connect() {
new bootstrap.Toast(this.element).show()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- Tabler Core -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tabler/[email protected]beta11/dist/css/tabler.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tabler/[email protected]beta17/dist/css/tabler.min.css">

<!-- Customize tabler here -->
<style>body {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,10 @@ def title
content_for(:title) || Rails.application.class.to_s.split("::").first
end

def active_nav_item(controller, actions = %w( index show new edit create update))
"active" if active_actions?(controller, actions)
def active_nav_item(controller, actions = %w(index show new edit create update))
active_actions?(controller, actions) ? "active" : ""
end

def np(number, options = {})
number_with_precision number, options
end

def nd(number, options = {})
number_with_delimiter number, options
end

def localize(object, **options)
super(object, **options) if object
end

alias :l :localize

private
def active_actions?(controller, actions)
params[:controller].include?(controller) && actions.include?(params[:action])
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/admin/install/templates/models/admin/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Admin::User < Admin::ApplicationRecord
validates :email, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
validates :password, allow_nil: true, length: { minimum: 12 }, format: { with: /(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])/ }

before_validation do
self.email = email.try(:downcase).try(:strip)
before_validation if: -> { email.present? } do
self.email = email.downcase.strip
end
end

0 comments on commit 5f898e0

Please sign in to comment.