mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 11:47:56 +01:00
Add Boards
This commit is contained in:
34
app/controllers/admin/boards_controller.rb
Normal file
34
app/controllers/admin/boards_controller.rb
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
module Admin
|
||||||
|
class BoardsController < 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
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
before_action :configure_permitted_parameters, if: :devise_controller?
|
before_action :configure_permitted_parameters, if: :devise_controller?
|
||||||
|
before_action :load_boards
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
@@ -7,4 +8,8 @@ class ApplicationController < ActionController::Base
|
|||||||
devise_parameter_sanitizer.permit(:sign_up, keys: [:full_name])
|
devise_parameter_sanitizer.permit(:sign_up, keys: [:full_name])
|
||||||
devise_parameter_sanitizer.permit(:account_update, keys: [:full_name])
|
devise_parameter_sanitizer.permit(:account_update, keys: [:full_name])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load_boards
|
||||||
|
@boards = Board.all.only(:id, :name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
5
app/controllers/boards_controller.rb
Normal file
5
app/controllers/boards_controller.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
class BoardsController < ApplicationController
|
||||||
|
def show
|
||||||
|
@board = Board.find(params[:id])
|
||||||
|
end
|
||||||
|
end
|
||||||
64
app/dashboards/board_dashboard.rb
Normal file
64
app/dashboards/board_dashboard.rb
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
require "administrate/base_dashboard"
|
||||||
|
|
||||||
|
class BoardDashboard < 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,
|
||||||
|
description: Field::Text,
|
||||||
|
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
|
||||||
|
description
|
||||||
|
].freeze
|
||||||
|
|
||||||
|
# SHOW_PAGE_ATTRIBUTES
|
||||||
|
# an array of attributes that will be displayed on the model's show page.
|
||||||
|
SHOW_PAGE_ATTRIBUTES = %i[
|
||||||
|
id
|
||||||
|
name
|
||||||
|
description
|
||||||
|
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
|
||||||
|
description
|
||||||
|
].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 boards are displayed
|
||||||
|
# across all pages of the admin dashboard.
|
||||||
|
#
|
||||||
|
# def display_resource(board)
|
||||||
|
# "Board ##{board.id}"
|
||||||
|
# end
|
||||||
|
end
|
||||||
2
app/helpers/boards_helper.rb
Normal file
2
app/helpers/boards_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
module BoardsHelper
|
||||||
|
end
|
||||||
4
app/models/board.rb
Normal file
4
app/models/board.rb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
class Board < ApplicationRecord
|
||||||
|
validates :name, presence: true, uniqueness: true
|
||||||
|
validates :description, length: { in: 0..1024 }, allow_nil: true
|
||||||
|
end
|
||||||
2
app/views/boards/show.html.erb
Normal file
2
app/views/boards/show.html.erb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<h1><%= @board.name %></h1>
|
||||||
|
<p><%= @board.description %></p>
|
||||||
5
app/views/layouts/_boards_menu_section.html.erb
Normal file
5
app/views/layouts/_boards_menu_section.html.erb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<% boards.each do |board| %>
|
||||||
|
<li class="nav-item<%= board.id == @board.id ? ' active' : '' unless @board.nil? %>">
|
||||||
|
<%= link_to board.name, board_path(board), class: "nav-link" %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
@@ -6,6 +6,9 @@
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||||
|
<ul class="navbar-nav nav-pills mr-auto">
|
||||||
|
<%= render "layouts/boards_menu_section", boards: @boards unless @boards.nil? %>
|
||||||
|
</ul>
|
||||||
<ul class="navbar-nav ml-auto">
|
<ul class="navbar-nav ml-auto">
|
||||||
<% if user_signed_in? %>
|
<% if user_signed_in? %>
|
||||||
<% if current_user.moderator? || current_user.admin? %>
|
<% if current_user.moderator? || current_user.admin? %>
|
||||||
|
|||||||
@@ -2,9 +2,13 @@ Rails.application.routes.draw do
|
|||||||
root to: 'static_pages#home'
|
root to: 'static_pages#home'
|
||||||
|
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
root to: "users#index"
|
root to: "boards#index"
|
||||||
|
|
||||||
|
resources :boards
|
||||||
resources :users
|
resources :users
|
||||||
end
|
end
|
||||||
|
|
||||||
devise_for :users
|
devise_for :users
|
||||||
|
|
||||||
|
resources :boards, only: [:show]
|
||||||
end
|
end
|
||||||
|
|||||||
10
db/migrate/20190822140423_create_boards.rb
Normal file
10
db/migrate/20190822140423_create_boards.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class CreateBoards < ActiveRecord::Migration[6.0]
|
||||||
|
def change
|
||||||
|
create_table :boards do |t|
|
||||||
|
t.string :name
|
||||||
|
t.text :description
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddUniqueToNameOfBoards < ActiveRecord::Migration[6.0]
|
||||||
|
def change
|
||||||
|
add_index :boards, :name, unique: true
|
||||||
|
end
|
||||||
|
end
|
||||||
10
db/schema.rb
10
db/schema.rb
@@ -10,11 +10,19 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2019_08_19_131723) do
|
ActiveRecord::Schema.define(version: 2019_08_22_141109) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
|
create_table "boards", force: :cascade do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.text "description"
|
||||||
|
t.datetime "created_at", precision: 6, null: false
|
||||||
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
|
t.index ["name"], name: "index_boards_on_name", unique: true
|
||||||
|
end
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
t.string "email", default: "", null: false
|
t.string "email", default: "", null: false
|
||||||
t.string "encrypted_password", default: "", null: false
|
t.string "encrypted_password", default: "", null: false
|
||||||
|
|||||||
11
spec/factories/boards.rb
Normal file
11
spec/factories/boards.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
FactoryBot.define do
|
||||||
|
factory :board do
|
||||||
|
sequence(:name) { |n| "Board#{n}" }
|
||||||
|
description { "My fantastic board" }
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :noname_board, class: Board do
|
||||||
|
name { "" }
|
||||||
|
description { "This board has no name :O" }
|
||||||
|
end
|
||||||
|
end
|
||||||
27
spec/models/board_spec.rb
Normal file
27
spec/models/board_spec.rb
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Board, type: :model do
|
||||||
|
|
||||||
|
let(:board) { FactoryBot.create(:board) }
|
||||||
|
let(:noname_board) { FactoryBot.build(:noname_board) }
|
||||||
|
|
||||||
|
it 'has a non-nil name' do
|
||||||
|
expect(noname_board.valid?).to be_falsy
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has an unique name' do
|
||||||
|
board
|
||||||
|
board2 = Board.new(name: board.name, description: "This board has the same name as board!")
|
||||||
|
|
||||||
|
expect(board2.valid?).to be_falsy
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has a description that can be nil or empty' do
|
||||||
|
nildescription_board = Board.new(name: "nil board", description: nil)
|
||||||
|
emptydescription_board = Board.new(name: "empty board", description: "")
|
||||||
|
|
||||||
|
expect(nildescription_board.valid?).to be_truthy
|
||||||
|
expect(emptydescription_board.valid?).to be_truthy
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe "Session", type: :system do
|
# RSpec.describe "Session", type: :system do
|
||||||
|
|
||||||
# def log_in_as(user)
|
# def log_in_as(user)
|
||||||
# visit new_user_session_path
|
# visit new_user_session_path
|
||||||
@@ -17,4 +17,4 @@ RSpec.describe "Session", type: :system do
|
|||||||
# expect(current_path).to eq(edit_user_registration_path)
|
# expect(current_path).to eq(edit_user_registration_path)
|
||||||
# end
|
# end
|
||||||
|
|
||||||
end
|
# end
|
||||||
Reference in New Issue
Block a user