Browse Source

Initial Setup for `sidenav` component.

pull/2/head
Alexander D. Bondoc 4 years ago committed by Angel Aviel Domaoan
parent
commit
3e67c53c9c
  1. 14
      app/components/base_component.rb
  2. 5
      app/components/pagination_component.rb
  3. 17
      app/components/pagination_component/pagination_component.html.erb
  4. 4
      app/components/sidenav_component.rb
  5. 10
      app/components/sidenav_component/sidenav_component.html.erb
  6. 17
      app/controllers/case_doctrines_controller.rb
  7. 17
      app/controllers/decisions_controller.rb
  8. 2
      app/controllers/home_controller.rb
  9. 17
      app/controllers/subject_indexes_controller.rb
  10. 9
      app/javascript/src/application.scss
  11. 13
      app/javascript/src/application/sidenav.scss
  12. 25
      app/models/ability.rb
  13. 0
      app/views/case_doctrines/edit.html.erb
  14. 0
      app/views/case_doctrines/index.html.erb
  15. 0
      app/views/case_doctrines/new.html.erb
  16. 0
      app/views/case_doctrines/show.html.erb
  17. 0
      app/views/decisions/edit.html.erb
  18. 0
      app/views/decisions/index.html.erb
  19. 0
      app/views/decisions/new.html.erb
  20. 0
      app/views/decisions/show.html.erb
  21. 11
      app/views/kaminari/_first_page.html.erb
  22. 8
      app/views/kaminari/_gap.html.erb
  23. 11
      app/views/kaminari/_last_page.html.erb
  24. 11
      app/views/kaminari/_next_page.html.erb
  25. 12
      app/views/kaminari/_page.html.erb
  26. 25
      app/views/kaminari/_paginator.html.erb
  27. 11
      app/views/kaminari/_prev_page.html.erb
  28. 0
      app/views/subject_indexes/edit.html.erb
  29. 0
      app/views/subject_indexes/index.html.erb
  30. 0
      app/views/subject_indexes/new.html.erb
  31. 0
      app/views/subject_indexes/show.html.erb
  32. 14
      config/initializers/kaminari_config.rb
  33. 6
      config/routes.rb

14
app/components/base_component.rb

@ -0,0 +1,14 @@
class BaseComponent < ViewComponent::Base
attr_reader :ability, :current_user
def initialize(current_user:)
@current_user = current_user
@ability = Ability.new(current_user)
end
def can?(action, klass)
return if action.blank? || klass.blank?
ability.can?(action, klass)
end
end

5
app/components/pagination_component.rb

@ -0,0 +1,5 @@
class PaginationComponent < BaseComponent
def initialize(data:)
@data = data
end
end

17
app/components/pagination_component/pagination_component.html.erb

@ -0,0 +1,17 @@
<div class="col col-md-12">
<header class="header bg-white b-b clearfix">
<div class="row m-t-sm">
<div class="col-md-4">
<h4 style="color: darkred">Search Results</h4>
<small style="color: darkred">
<%= page_entries_info @data, entry_name: 'records' if @data.present? %>
</small>
</div>
<div class="col-md-8">
<div class="text-center paginator pull-right">
<%= (paginate @data) if @data.present? %>
</div>
</div>
</div>
</header>
</div>

4
app/components/sidenav_component.rb

@ -0,0 +1,4 @@
class SidenavComponent < BaseComponent
def initialize(current_user:)
end
end

10
app/components/sidenav_component/sidenav_component.html.erb

@ -0,0 +1,10 @@
<nav class="navbar navbar-light bg-light flex-column align-items-stretch p-3 sidenav">
<nav class="nav nav-pills flex-column">
<a class="nav-link" href="<%= root_path %>"> Home </a>
<a class="nav-link" href="#"> Search </a>
<a class="nav-link" href="<%= decisions_path %>"> Desicions </a>
<a class="nav-link" href="<%= case_doctrines_path %>"> Case Doctrines </a>
<a class="nav-link" href="<%= subject_indexes_path %>"> Subject Indexes </a>
<a class="nav-link" href="#"> Logout </a>
</nav>
</nav>

17
app/controllers/case_doctrines_controller.rb

@ -0,0 +1,17 @@
# frozen_string_literal: true
class CaseDoctrinesController < ApplicationController
def index; end
def new; end
def edit; end
def show; end
def create; end
def update; end
def destroy; end
end

17
app/controllers/decisions_controller.rb

@ -0,0 +1,17 @@
# frozen_string_literal: true
class DecisionsController < ApplicationController
def index; end
def new; end
def edit; end
def show; end
def create; end
def update; end
def destroy; end
end

2
app/controllers/home_controller.rb

@ -1,3 +1,5 @@
# frozen_string_literal: true
class HomeController < ApplicationController class HomeController < ApplicationController
def index def index
end end

17
app/controllers/subject_indexes_controller.rb

@ -0,0 +1,17 @@
# frozen_string_literal: true
class SubjectIndexesController < ApplicationController
def index; end
def new; end
def edit; end
def show; end
def create; end
def update; end
def destroy; end
end

9
app/javascript/src/application.scss

@ -0,0 +1,9 @@
@import "~bootstrap/scss/bootstrap";
@import "./application/sidenav";
.main-layout {
padding-bottom: 10px !important;
position: absolute;
right: 0 !important;
top: 0 !important;
}

13
app/javascript/src/application/sidenav.scss

@ -0,0 +1,13 @@
.sidenav {
font-feature-settings: 'liga';
height: 100%;
height: -moz-calc(100%);
left: 0 !important;
position: fixed;
padding-top: 120px;
margin-top: 0;
overflow: auto;
text-rendering: optimizeLegibility;
width: inherit;
top: 0;
}

25
app/models/ability.rb

@ -0,0 +1,25 @@
class Ability
include CanCan::Ability
def initialize(user)
clear_aliased_actions
user ||= User.new
end
def clear_aliased_actions
super
# override cancan default aliasing (we don't want to differentiate
# between read and index)
alias_action :destroy, to: :delete
alias_action :edit, to: :update
alias_action :new, to: :create
alias_action :show, to: :read
alias_action :search, to: :index
alias_action :index, :read, to: :display
alias_action :create, :update, to: :modify
alias_action :display, :modify, to: :basic_manage
end
end

0
app/views/case_doctrines/edit.html.erb

0
app/views/case_doctrines/index.html.erb

0
app/views/case_doctrines/new.html.erb

0
app/views/case_doctrines/show.html.erb

0
app/views/decisions/edit.html.erb

0
app/views/decisions/index.html.erb

0
app/views/decisions/new.html.erb

0
app/views/decisions/show.html.erb

11
app/views/kaminari/_first_page.html.erb

@ -0,0 +1,11 @@
<%# Link to the "First" page
- available local variables
url: url to the first page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="first">
<%= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, remote: remote %>
</span>

8
app/views/kaminari/_gap.html.erb

@ -0,0 +1,8 @@
<%# Non-link tag that stands for skipped pages...
- available local variables
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="page gap"><%= t('views.pagination.truncate').html_safe %></span>

11
app/views/kaminari/_last_page.html.erb

@ -0,0 +1,11 @@
<%# Link to the "Last" page
- available local variables
url: url to the last page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="last">
<%= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, remote: remote %>
</span>

11
app/views/kaminari/_next_page.html.erb

@ -0,0 +1,11 @@
<%# Link to the "Next" page
- available local variables
url: url to the next page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="next">
<%= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, rel: 'next', remote: remote %>
</span>

12
app/views/kaminari/_page.html.erb

@ -0,0 +1,12 @@
<%# Link showing page number
- available local variables
page: a page object for "this" page
url: url to this page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="page<%= ' current' if page.current? %>">
<%= link_to_unless page.current?, page, url, {remote: remote, rel: page.rel} %>
</span>

25
app/views/kaminari/_paginator.html.erb

@ -0,0 +1,25 @@
<%# The container tag
- available local variables
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
paginator: the paginator that renders the pagination tags inside
-%>
<%= paginator.render do -%>
<nav class="pagination" role="navigation" aria-label="pager">
<%= first_page_tag unless current_page.first? %>
<%= prev_page_tag unless current_page.first? %>
<% each_page do |page| -%>
<% if page.display_tag? -%>
<%= page_tag page %>
<% elsif !page.was_truncated? -%>
<%= gap_tag %>
<% end -%>
<% end -%>
<% unless current_page.out_of_range? %>
<%= next_page_tag unless current_page.last? %>
<%= last_page_tag unless current_page.last? %>
<% end %>
</nav>
<% end -%>

11
app/views/kaminari/_prev_page.html.erb

@ -0,0 +1,11 @@
<%# Link to the "Previous" page
- available local variables
url: url to the previous page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="prev">
<%= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, rel: 'prev', remote: remote %>
</span>

0
app/views/subject_indexes/edit.html.erb

0
app/views/subject_indexes/index.html.erb

0
app/views/subject_indexes/new.html.erb

0
app/views/subject_indexes/show.html.erb

14
config/initializers/kaminari_config.rb

@ -0,0 +1,14 @@
# frozen_string_literal: true
Kaminari.configure do |config|
# config.default_per_page = 25
# config.max_per_page = nil
# config.window = 4
# config.outer_window = 0
# config.left = 0
# config.right = 0
# config.page_method_name = :page
# config.param_name = :page
# config.max_pages = nil
# config.params_on_first_page = false
end

6
config/routes.rb

@ -1,5 +1,9 @@
Rails.application.routes.draw do Rails.application.routes.draw do
devise_for :users
root to: "home#index" root to: "home#index"
devise_for :users resources :case_doctrines
resources :decisions
resources :subject_indexes
end end

Loading…
Cancel
Save