superadmin can display list of procedures without zone

This commit is contained in:
Christophe Robillard 2021-12-23 11:34:22 +01:00
parent 9a38d5e049
commit 6e36fee7b3
3 changed files with 108 additions and 3 deletions

View file

@ -12,9 +12,13 @@ module Manager
# 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
def find_resource(param)
if param == "nil"
NullZone.new
else
Zone.find(param)
end
end
# The result of this lookup will be available as `requested_resource`

31
app/models/null_zone.rb Normal file
View file

@ -0,0 +1,31 @@
class NullZone
include ActiveModel::Model
def procedures
Procedure.where(zone: nil).where.not(published_at: nil).order(published_at: :desc)
end
def self.reflect_on_association(association)
OpenStruct.new(class_name: "Procedure") if association == :procedures
end
def label
"non renseignée"
end
def id
-1
end
def acronym
"NA"
end
def created_at
"NA"
end
def updated_at
"NA"
end
end

View file

@ -0,0 +1,70 @@
<%#
# 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 %>
<header class="main-content__header" role="banner">
<h1 class="main-content__page-title" id="page-title">
<%= content_for(:title) %>
</h1>
<div>
<%= link_to "Procedures sans zone renseignée", manager_zone_path(id: 'nil') %>
</div>
<% if show_search_bar %>
<%= render(
"search",
search_term: search_term,
resource_name: display_resource_name(page.resource_name)
) %>
<% end %>
<div>
<%= link_to(
t(
"administrate.actions.new_resource",
name: display_resource_name(page.resource_name, singular: true).downcase
),
[:new, namespace, page.resource_path.to_sym],
class: "button",
) if valid_action?(:new) && show_action?(:new, new_resource) %>
</div>
</header>
<section class="main-content__body main-content__body--flush">
<%= render(
"collection",
collection_presenter: page,
collection_field_name: resource_name,
page: page,
resources: resources,
table_title: "page-title"
) %>
<%= paginate resources, param_name: '_page' %>
</section>