Homegrown admin start for resumes
Not necessarily better yet, but easy to change now
This commit is contained in:
parent
e51bcfec17
commit
2ccae541de
|
@ -1,19 +1,13 @@
|
|||
module Admin
|
||||
class ResumesController < Admin::ApplicationController
|
||||
# To customize the behavior of this controller,
|
||||
# simply overwrite any of the RESTful actions. For example:
|
||||
#
|
||||
# def index
|
||||
# super
|
||||
# @resources = Resume.all.paginate(10, params[:page])
|
||||
# end
|
||||
class ResumesController < AdminController
|
||||
def index
|
||||
@q = Resume.search params[:q]
|
||||
@resume_scope = @q.result(:distinct => true)
|
||||
@resumes = @resume_scope.paginate( :page => params[:page],:per_page => 20)
|
||||
end
|
||||
|
||||
# Define a custom finder by overriding the `find_resource` method:
|
||||
# def find_resource(param)
|
||||
# Resume.find_by!(slug: param)
|
||||
# end
|
||||
|
||||
# See https://administrate-docs.herokuapp.com/customizing_controller_actions
|
||||
# for more information
|
||||
def show
|
||||
@resume = Resume.find(params[:id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,92 +0,0 @@
|
|||
<%#
|
||||
# Collection
|
||||
|
||||
This partial is used on the `index` and `show` pages
|
||||
to display a collection of resources in an HTML table.
|
||||
|
||||
## Local variables:
|
||||
|
||||
- `collection_presenter`:
|
||||
An instance of [Administrate::Page::Collection][1].
|
||||
The table presenter uses `ResourceDashboard::COLLECTION_ATTRIBUTES` to determine
|
||||
the columns displayed in the table
|
||||
- `resources`:
|
||||
An ActiveModel::Relation collection of resources to be displayed in the table.
|
||||
By default, the number of resources is limited by pagination
|
||||
or by a hard limit to prevent excessive page load times
|
||||
|
||||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
|
||||
%>
|
||||
|
||||
<table aria-labelledby="page-title">
|
||||
<thead>
|
||||
<tr>
|
||||
<% collection_presenter.attribute_types.each do |attr_name, attr_type| %>
|
||||
<th class="cell-label
|
||||
cell-label--<%= attr_type.html_class %>
|
||||
cell-label--<%= collection_presenter.ordered_html_class(attr_name) %>
|
||||
" scope="col">
|
||||
<%= link_to(sanitized_order_params.merge(
|
||||
collection_presenter.order_params_for(attr_name)
|
||||
)) do %>
|
||||
<%= t(
|
||||
"helpers.label.#{resource_name}.#{attr_name}",
|
||||
default: attr_name.to_s,
|
||||
).titleize %>
|
||||
|
||||
<% if collection_presenter.ordered_by?(attr_name) %>
|
||||
<span class="cell-label__sort-indicator cell-label__sort-indicator--<%= collection_presenter.ordered_html_class(attr_name) %>">
|
||||
<%= svg_tag(
|
||||
"administrate/sort_arrow.svg",
|
||||
"sort_arrow",
|
||||
width: "13",
|
||||
height: "13"
|
||||
) %>
|
||||
</span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</th>
|
||||
<% end %>
|
||||
<% [valid_action?(:edit), valid_action?(:destroy)].count(true).times do %>
|
||||
<th scope="col"></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% resources.each do |resource| %>
|
||||
<tr class="js-table-row"
|
||||
tabindex="0"
|
||||
<%= %(role=link data-url=#{polymorphic_path([namespace, resource])}) if valid_action? :show -%>
|
||||
>
|
||||
<% collection_presenter.attributes_for(resource).each do |attribute| %>
|
||||
<td class="cell-data cell-data--<%= attribute.html_class %>">
|
||||
<a href="<%= polymorphic_path([namespace, resource]) -%>"
|
||||
class="action-show"
|
||||
>
|
||||
<%= render_field attribute %>
|
||||
</a>
|
||||
</td>
|
||||
<% end %>
|
||||
|
||||
<% if valid_action? :edit %>
|
||||
<td><%= link_to(
|
||||
t("administrate.actions.edit"),
|
||||
[:edit, namespace, resource],
|
||||
class: "action-edit",
|
||||
) %></td>
|
||||
<% end %>
|
||||
|
||||
<% if valid_action? :destroy %>
|
||||
<td><%= link_to(
|
||||
t("administrate.actions.destroy"),
|
||||
[namespace, resource],
|
||||
class: "text-color-red",
|
||||
method: :delete,
|
||||
data: { confirm: t("administrate.actions.confirm") }
|
||||
) %></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
|
@ -1,20 +0,0 @@
|
|||
%table{"aria-labelledby" => "page-title"}
|
||||
%thead
|
||||
%tr
|
||||
- collection_presenter.attribute_types.each do |attr_name, attr_type|
|
||||
%th.cell-label.cell-label--
|
||||
= attr_type.html_class
|
||||
cell-label--#{collection_presenter.ordered_html_class(attr_name)}
|
||||
" scope="col">
|
||||
\#{link_to(sanitized_order_params.merge( collection_presenter.order_params_for(attr_name) )) do}
|
||||
= t( |
|
||||
helpers.label.#{resource_name}.#{attr_name}, |
|
||||
default: attr_name.to_s, |
|
||||
).titleize |
|
||||
- if collection_presenter.ordered_by?(attr_name)
|
||||
%span.cell-label__sort-indicator.cell-label__sort-indicator--
|
||||
= collection_presenter.ordered_html_class(attr_name)
|
||||
">
|
||||
\#{svg_tag( administrate/sort_arrow.svg, sort_arrow, width: 13, height: 13 )}
|
||||
- [valid_action?(:edit), valid_action?(:destroy)].count(true).times do
|
||||
%th{:scope => "col"}
|
|
@ -1,42 +0,0 @@
|
|||
<%#
|
||||
# Form Partial
|
||||
|
||||
This partial is rendered on a resource's `new` and `edit` pages,
|
||||
and renders all form fields for a resource's editable attributes.
|
||||
|
||||
## Local variables:
|
||||
|
||||
- `page`:
|
||||
An instance of [Administrate::Page::Form][1].
|
||||
Contains helper methods to display a form,
|
||||
and knows which attributes should be displayed in the resource's form.
|
||||
|
||||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form
|
||||
%>
|
||||
|
||||
<%= form_for([namespace, page.resource], html: { class: "form" }) do |f| %>
|
||||
<% if page.resource.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2>
|
||||
<%= pluralize(page.resource.errors.count, "error") %>
|
||||
prohibited this <%= page.resource_name %> from being saved:
|
||||
</h2>
|
||||
|
||||
<ul>
|
||||
<% page.resource.errors.full_messages.each do |message| %>
|
||||
<li class="flash-error"><%= message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% page.attributes.each do |attribute| -%>
|
||||
<div class="field-unit field-unit--<%= attribute.html_class %>">
|
||||
<%= render_field attribute, f: f %>
|
||||
</div>
|
||||
<% end -%>
|
||||
|
||||
<div class="form-actions">
|
||||
<%= f.submit %>
|
||||
</div>
|
||||
<% end %>
|
|
@ -1,14 +0,0 @@
|
|||
= form_for([namespace, page.resource], html: { class: "form" }) do |f|
|
||||
- if page.resource.errors.any?
|
||||
#error_explanation
|
||||
%h2
|
||||
= pluralize(page.resource.errors.count, "error")
|
||||
prohibited this #{page.resource_name} from being saved:
|
||||
%ul
|
||||
- page.resource.errors.full_messages.each do |message|
|
||||
%li.flash-error= message
|
||||
- page.attributes.each do |attribute|
|
||||
%div{:class => "field-unit field-unit--#{attribute.html_class}"}
|
||||
= render_field attribute, f: f
|
||||
.form-actions
|
||||
= f.submit
|
|
@ -1,36 +0,0 @@
|
|||
<%#
|
||||
# Edit
|
||||
|
||||
This view is the template for the edit page.
|
||||
|
||||
It displays a header, and renders the `_form` partial to do the heavy lifting.
|
||||
|
||||
## Local variables:
|
||||
|
||||
- `page`:
|
||||
An instance of [Administrate::Page::Form][1].
|
||||
Contains helper methods to help display a form,
|
||||
and knows which attributes should be displayed in the resource's form.
|
||||
|
||||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form
|
||||
%>
|
||||
|
||||
<% content_for(:title) { "#{t("administrate.actions.edit")} #{page.page_title}" } %>
|
||||
|
||||
<header class="main-content__header" role="banner">
|
||||
<h1 class="main-content__page-title">
|
||||
<%= content_for(:title) %>
|
||||
</h1>
|
||||
|
||||
<div>
|
||||
<%= link_to(
|
||||
"#{t("administrate.actions.show")} #{page.page_title}",
|
||||
[namespace, page.resource],
|
||||
class: "button",
|
||||
) if valid_action? :show %>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section class="main-content__body">
|
||||
<%= render "form", page: page %>
|
||||
</section>
|
|
@ -1,13 +0,0 @@
|
|||
%body
|
||||
- content_for(:title) { "#{t("administrate.actions.edit")} #{page.page_title}" }
|
||||
%header.main-content__header{:role => "banner"}
|
||||
%h1.main-content__page-title
|
||||
= content_for(:title)
|
||||
%div
|
||||
= link_to( |
|
||||
"#{t("administrate.actions.show")} #{page.page_title}", |
|
||||
[namespace, page.resource], |
|
||||
class: "button", |
|
||||
) if valid_action? :show |
|
||||
%section.main-content__body
|
||||
= render "form", page: page
|
|
@ -1,53 +0,0 @@
|
|||
<%#
|
||||
# Index
|
||||
|
||||
This view is the template for the index page.
|
||||
It is responsible for rendering the search bar, header and pagination.
|
||||
It renders the `_table` partial to display details about the resources.
|
||||
|
||||
## Local variables:
|
||||
|
||||
- `page`:
|
||||
An instance of [Administrate::Page::Collection][1].
|
||||
Contains helper methods to help display a table,
|
||||
and knows which attributes should be displayed in the resource's table.
|
||||
- `resources`:
|
||||
An instance of `ActiveRecord::Relation` containing the resources
|
||||
that match the user's search criteria.
|
||||
By default, these resources are passed to the table partial to be displayed.
|
||||
- `search_term`:
|
||||
A string containing the term the user has searched for, if any.
|
||||
- `show_search_bar`:
|
||||
A boolean that determines if the search bar should be shown.
|
||||
|
||||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
|
||||
%>
|
||||
|
||||
<% content_for(:title) do %>
|
||||
<%= display_resource_name(page.resource_name) %>
|
||||
<% end %>
|
||||
|
||||
<% content_for(:search) do %>
|
||||
<% if show_search_bar %>
|
||||
<%= render "search", search_term: search_term %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<header class="main-content__header" role="banner">
|
||||
<h1 class="main-content__page-title" id="page-title">
|
||||
<%= content_for(:title) %>
|
||||
</h1>
|
||||
|
||||
<div>
|
||||
<%= link_to(
|
||||
"#{t("administrate.actions.new")} #{page.resource_name.titleize.downcase}",
|
||||
[:new, namespace, page.resource_path],
|
||||
class: "button",
|
||||
) if valid_action? :new %>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section class="main-content__body main-content__body--flush">
|
||||
<%= render "collection", collection_presenter: page, resources: resources %>
|
||||
<%= paginate resources %>
|
||||
</section>
|
|
@ -1,18 +1,33 @@
|
|||
%body
|
||||
- content_for(:title) do
|
||||
= display_resource_name(page.resource_name)
|
||||
- content_for(:search) do
|
||||
- if show_search_bar
|
||||
= render "search", search_term: search_term
|
||||
%header.main-content__header{:role => "banner"}
|
||||
%h1#page-title.main-content__page-title
|
||||
= content_for(:title)
|
||||
.row.resumes_index_start
|
||||
.col-md-9.resumes
|
||||
.row
|
||||
.col-md-10
|
||||
%h2 Resumes
|
||||
= paginate @resumes
|
||||
.col-md-3
|
||||
= #image_tag "resumes.jpg" , :class => "img-responsive"
|
||||
.row
|
||||
.col-md-9
|
||||
%div
|
||||
= link_to( |
|
||||
"#{t("administrate.actions.new")} #{page.resource_name.titleize.downcase}", |
|
||||
[:new, namespace, page.resource_path], |
|
||||
class: "button", |
|
||||
) if valid_action? :new |
|
||||
%section.main-content__body.main-content__body--flush
|
||||
= render "collection", collection_presenter: page, resources: resources
|
||||
= paginate resources
|
||||
%table.table.table-striped.table-bordered.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%th=sort_link [:office,@q], :id
|
||||
%th{:colspan => "2"}
|
||||
%label.checkbox
|
||||
= @resume_scope.length.to_s + " Resumes"
|
||||
%tbody
|
||||
- @resumes.each do |resume|
|
||||
%tr{:class => "line-#{cycle("1","2")}"}
|
||||
%td=resume.id.to_s
|
||||
%td= link_to "Show" , admin_resume_path(resume), :title => t(:show)
|
||||
= paginate @resumes
|
||||
.col-md-3
|
||||
= search_form_for [:admin , @q], :html => { :class => "form-horizontal" }, :method => :get do |f|
|
||||
.form-group
|
||||
= f.text_field :id_cont , :class => "form-control" , :placeholder => "Id"
|
||||
.form-group
|
||||
= f.text_field :street_cont ,:class => "form-control" , :placeholder => "Street"
|
||||
= f.submit "Filter", :id => :filter , :class => "btn btn-success"
|
||||
= link_to "Cancel", admin_resumes_path, :class => "btn btn-warning"
|
||||
.resumes_index_end
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
<%#
|
||||
# New
|
||||
|
||||
This view is the template for the "new resource" page.
|
||||
It displays a header, and then renders the `_form` partial
|
||||
to do the heavy lifting.
|
||||
|
||||
## Local variables:
|
||||
|
||||
- `page`:
|
||||
An instance of [Administrate::Page::Form][1].
|
||||
Contains helper methods to help display a form,
|
||||
and knows which attributes should be displayed in the resource's form.
|
||||
|
||||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form
|
||||
%>
|
||||
|
||||
<% content_for(:title) { "#{t("administrate.actions.new")} #{page.resource_name.titleize}" } %>
|
||||
|
||||
<header class="main-content__header" role="banner">
|
||||
<h1 class="main-content__page-title">
|
||||
<%= content_for(:title) %>
|
||||
</h1>
|
||||
|
||||
<div>
|
||||
<%= link_to t("administrate.actions.back"), :back, class: "button" %>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section class="main-content__body">
|
||||
<%= render "form", page: page %>
|
||||
</section>
|
|
@ -1,9 +0,0 @@
|
|||
%body
|
||||
- content_for(:title) { "#{t("administrate.actions.new")} #{page.resource_name.titleize}" }
|
||||
%header.main-content__header{:role => "banner"}
|
||||
%h1.main-content__page-title
|
||||
= content_for(:title)
|
||||
%div
|
||||
= link_to t("administrate.actions.back"), :back, class: "button"
|
||||
%section.main-content__body
|
||||
= render "form", page: page
|
|
@ -1,49 +0,0 @@
|
|||
<%#
|
||||
# Show
|
||||
|
||||
This view is the template for the show page.
|
||||
It renders the attributes of a resource,
|
||||
as well as a link to its edit page.
|
||||
|
||||
## Local variables:
|
||||
|
||||
- `page`:
|
||||
An instance of [Administrate::Page::Show][1].
|
||||
Contains methods for accessing the resource to be displayed on the page,
|
||||
as well as helpers for describing how each attribute of the resource
|
||||
should be displayed.
|
||||
|
||||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Show
|
||||
%>
|
||||
|
||||
<% content_for(:title) { "#{t("administrate.actions.show")} #{page.page_title}" } %>
|
||||
|
||||
<header class="main-content__header" role="banner">
|
||||
<h1 class="main-content__page-title">
|
||||
<%= content_for(:title) %>
|
||||
</h1>
|
||||
|
||||
<div>
|
||||
<%= link_to(
|
||||
"#{t("administrate.actions.edit")} #{page.page_title}",
|
||||
[:edit, namespace, page.resource],
|
||||
class: "button",
|
||||
) if valid_action? :edit %>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section class="main-content__body">
|
||||
<dl>
|
||||
<% page.attributes.each do |attribute| %>
|
||||
<dt class="attribute-label">
|
||||
<%= t(
|
||||
"helpers.label.#{resource_name}.#{attribute.name}",
|
||||
default: attribute.name.titleize,
|
||||
) %>
|
||||
</dt>
|
||||
|
||||
<dd class="attribute-data attribute-data--<%=attribute.html_class%>"
|
||||
><%= render_field attribute %></dd>
|
||||
<% end %>
|
||||
</dl>
|
||||
</section>
|
|
@ -1,20 +1,9 @@
|
|||
%body
|
||||
- content_for(:title) { "#{t("administrate.actions.show")} #{page.page_title}" }
|
||||
%header.main-content__header{:role => "banner"}
|
||||
%h1.main-content__page-title
|
||||
= content_for(:title)
|
||||
%div
|
||||
= link_to( |
|
||||
"#{t("administrate.actions.edit")} #{page.page_title}", |
|
||||
[:edit, namespace, page.resource], |
|
||||
class: "button", |
|
||||
) if valid_action? :edit |
|
||||
%section.main-content__body
|
||||
%dl
|
||||
- page.attributes.each do |attribute|
|
||||
%dt.attribute-label
|
||||
= t( |
|
||||
"helpers.label.#{resource_name}.#{attribute.name}", |
|
||||
default: attribute.name.titleize, |
|
||||
) |
|
||||
%dd{:class => "attribute-data attribute-data--#{attribute.html_class}"}= render_field attribute
|
||||
%h2.resumes_show_start
|
||||
= "Resume : #{@resume.id}"
|
||||
|
||||
- @resume.attributes.each do |name , value|
|
||||
%p
|
||||
%b= "#{name} : " + value.to_s
|
||||
|
||||
= link_to "Back", admin_resumes_path, :class => "btn btn-warning"
|
||||
.resumes_show_end
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
describe "Admin Resume" do
|
||||
before(:each) do
|
||||
sign_admin_in
|
||||
end
|
||||
it "lists resumes" do
|
||||
visit_path admin_resumes_path
|
||||
end
|
||||
it "shows a resume" do
|
||||
resume = create(:resume)
|
||||
visit_path admin_resume_path(resume)
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
describe User do
|
||||
describe "Admin User" do
|
||||
before(:each) do
|
||||
sign_admin_in
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue