mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 11:47:56 +01:00
Add post statuses admin panel
This commit is contained in:
34
app/controllers/admin/post_statuses_controller.rb
Normal file
34
app/controllers/admin/post_statuses_controller.rb
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
module Admin
|
||||||
|
class PostStatusesController < Admin::ApplicationController
|
||||||
|
# Overwrite any of the RESTful controller actions to implement custom behavior
|
||||||
|
# For example, you may want to send an email after a foo is updated.
|
||||||
|
#
|
||||||
|
# def update
|
||||||
|
# foo = Foo.find(params[:id])
|
||||||
|
# foo.update(params[:foo])
|
||||||
|
# send_foo_updated_email
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Override this method to specify custom lookup behavior.
|
||||||
|
# This will be used to set the resource for the `show`, `edit`, and `update`
|
||||||
|
# actions.
|
||||||
|
#
|
||||||
|
# def find_resource(param)
|
||||||
|
# Foo.find_by!(slug: param)
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Override this if you have certain roles that require a subset
|
||||||
|
# this will be used to set the records shown on the `index` action.
|
||||||
|
#
|
||||||
|
# def scoped_resource
|
||||||
|
# if current_user.super_admin?
|
||||||
|
# resource_class
|
||||||
|
# else
|
||||||
|
# resource_class.with_less_stuff
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
# See https://administrate-prototype.herokuapp.com/customizing_controller_actions
|
||||||
|
# for more information
|
||||||
|
end
|
||||||
|
end
|
||||||
64
app/dashboards/post_status_dashboard.rb
Normal file
64
app/dashboards/post_status_dashboard.rb
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
require "administrate/base_dashboard"
|
||||||
|
|
||||||
|
class PostStatusDashboard < Administrate::BaseDashboard
|
||||||
|
# ATTRIBUTE_TYPES
|
||||||
|
# a hash that describes the type of each of the model's fields.
|
||||||
|
#
|
||||||
|
# Each different type represents an Administrate::Field object,
|
||||||
|
# which determines how the attribute is displayed
|
||||||
|
# on pages throughout the dashboard.
|
||||||
|
ATTRIBUTE_TYPES = {
|
||||||
|
id: Field::Number,
|
||||||
|
name: Field::String,
|
||||||
|
color: ColorField,
|
||||||
|
created_at: Field::DateTime,
|
||||||
|
updated_at: Field::DateTime,
|
||||||
|
}.freeze
|
||||||
|
|
||||||
|
# COLLECTION_ATTRIBUTES
|
||||||
|
# an array of attributes that will be displayed on the model's index page.
|
||||||
|
#
|
||||||
|
# By default, it's limited to four items to reduce clutter on index pages.
|
||||||
|
# Feel free to add, remove, or rearrange items.
|
||||||
|
COLLECTION_ATTRIBUTES = %i[
|
||||||
|
name
|
||||||
|
color
|
||||||
|
].freeze
|
||||||
|
|
||||||
|
# SHOW_PAGE_ATTRIBUTES
|
||||||
|
# an array of attributes that will be displayed on the model's show page.
|
||||||
|
SHOW_PAGE_ATTRIBUTES = %i[
|
||||||
|
id
|
||||||
|
name
|
||||||
|
color
|
||||||
|
created_at
|
||||||
|
updated_at
|
||||||
|
].freeze
|
||||||
|
|
||||||
|
# FORM_ATTRIBUTES
|
||||||
|
# an array of attributes that will be displayed
|
||||||
|
# on the model's form (`new` and `edit`) pages.
|
||||||
|
FORM_ATTRIBUTES = %i[
|
||||||
|
name
|
||||||
|
color
|
||||||
|
].freeze
|
||||||
|
|
||||||
|
# COLLECTION_FILTERS
|
||||||
|
# a hash that defines filters that can be used while searching via the search
|
||||||
|
# field of the dashboard.
|
||||||
|
#
|
||||||
|
# For example to add an option to search for open resources by typing "open:"
|
||||||
|
# in the search field:
|
||||||
|
#
|
||||||
|
# COLLECTION_FILTERS = {
|
||||||
|
# open: ->(resources) { where(open: true) }
|
||||||
|
# }.freeze
|
||||||
|
COLLECTION_FILTERS = {}.freeze
|
||||||
|
|
||||||
|
# Overwrite this method to customize how post statuses are displayed
|
||||||
|
# across all pages of the admin dashboard.
|
||||||
|
#
|
||||||
|
# def display_resource(post_status)
|
||||||
|
# "PostStatus ##{post_status.id}"
|
||||||
|
# end
|
||||||
|
end
|
||||||
7
app/fields/color_field.rb
Normal file
7
app/fields/color_field.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require "administrate/field/base"
|
||||||
|
|
||||||
|
class ColorField < Administrate::Field::Base
|
||||||
|
def to_s
|
||||||
|
data.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
6
app/views/fields/color_field/_form.html.erb
Normal file
6
app/views/fields/color_field/_form.html.erb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<div class="field-unit__label">
|
||||||
|
<%= f.label field.attribute %>
|
||||||
|
</div>
|
||||||
|
<div class="field-unit__field">
|
||||||
|
<%= f.color_field field.attribute, style: "height: 40px" %>
|
||||||
|
</div>
|
||||||
1
app/views/fields/color_field/_index.html.erb
Normal file
1
app/views/fields/color_field/_index.html.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<div style="background-color: <%= field.to_s %>; width: 32px; height: 32px; border-radius: 32px;"></div>
|
||||||
2
app/views/fields/color_field/_show.html.erb
Normal file
2
app/views/fields/color_field/_show.html.erb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<div style="background-color: <%= field.to_s %>; width: 32px; height: 32px; border-radius: 32px;"></div>
|
||||||
|
(<%= field.to_s %>)
|
||||||
@@ -5,6 +5,7 @@ Rails.application.routes.draw do
|
|||||||
root to: "boards#index"
|
root to: "boards#index"
|
||||||
|
|
||||||
resources :boards
|
resources :boards
|
||||||
|
resources :post_statuses
|
||||||
resources :users
|
resources :users
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -44,4 +44,21 @@ RSpec.describe 'Requests to the admin panel', type: :request do
|
|||||||
get admin_boards_path
|
get admin_boards_path
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'requires at least a logged-in moderator to view PostStatuses admin panel' do
|
||||||
|
get admin_post_statuses_path
|
||||||
|
expect(response).to redirect_to(new_user_session_path)
|
||||||
|
|
||||||
|
sign_in user
|
||||||
|
get admin_post_statuses_path
|
||||||
|
expect(response).to redirect_to(root_path)
|
||||||
|
|
||||||
|
sign_in moderator
|
||||||
|
get admin_post_statuses_path
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
|
||||||
|
sign_in admin
|
||||||
|
get admin_post_statuses_path
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user