Files
growstuff/app/views/crops/wrangle.html.haml
T
Brenda Wallace 6332f26c58 Merge pull request #4994 from Growstuff/crop-job-templates-admin
Admin for crop job templates, a tidier crop wrangling page, and crop and template seeds
2026-10-23 13:26:33 +10:30

96 lines
3.8 KiB
Plaintext

- content_for :title, "Crop Wrangling"
%h1 Crop Wrangling
%nav.nav
= link_to "Full crop hierarchy", hierarchy_crops_path, class: 'nav-link'
= link_to "Add Crop", new_crop_path, class: 'btn'
%section.crop_wranglers
%h2 Crop Wranglers
- @crop_wranglers.each do |crop_wrangler|
= render 'members/tiny', member: crop_wrangler
%hr/
%section
%h2 Crops
= form_with url: wrangle_crops_path, method: :get, class: 'row g-2 my-3', role: 'search' do |f|
= hidden_field_tag :approval_status, @approval_status if @approval_status.present?
= hidden_field_tag :level, 'all' if @all_levels
.col-sm-8.col-md-6
= f.search_field :q, value: @query, class: 'form-control', placeholder: 'Search crops by name', 'aria-label': 'Search crops'
.col-auto
= f.submit 'Search', class: 'btn btn-primary', name: nil
- if @query.present?
= link_to 'Clear', wrangle_crops_path(approval_status: @approval_status, level: ('all' if @all_levels)), class: 'btn btn-link'
- carry = { q: @query.presence, level: ('all' if @all_levels && @query.blank?) }
- tabs = [['Approved', nil], ['Pending approval', 'pending'], ['Rejected', 'rejected']]
%ul.nav.nav-tabs{ role: 'tablist' }
%li.nav-item= link_to 'Recently edited', admin_crops_path, class: 'nav-link'
- tabs.each do |label, status|
%li.nav-item
= link_to label, wrangle_crops_path(carry.merge(approval_status: status)), class: ['nav-link', ('active' if @approval_status.presence == status)]
-# A search looks at every level, so the choice only matters without one.
- if @query.blank?
%ul.nav.nav-pills.my-3
%li.nav-item
= link_to 'Top level crops', wrangle_crops_path(approval_status: @approval_status), class: ['nav-link', ('active' unless @all_levels)]
%li.nav-item
= link_to 'All crops', wrangle_crops_path(approval_status: @approval_status, level: 'all'), class: ['nav-link', ('active' if @all_levels)]
.table-responsive
%table.table.table-striped.table-bordered.table-sm.align-middle.wrangle-table{ id: @approval_status.blank? ? 'approved-crops' : "#{@approval_status}-crops" }
%thead
%tr
%th Name
%th Icon
%th.text-end Height
%th.text-end Spread
%th.text-end Row spacing
%th.text-end Growing degree days
%th YouTube
%th.text-end Scientific names
%th.text-end Alternate names
%th.text-end Child crops
%th.text-end Job templates
%th Updated
- if @approval_status == 'pending'
%th Requested by
- elsif @approval_status == 'rejected'
%th Rejected by
- else
%th Added by
%tbody
- @crops.each do |crop|
%tr
%td
= link_to edit_crop_path(crop) do
= crop.name
%td= crop_icon(crop)
%td.text-end= crop.height
%td.text-end= crop.spread
%td.text-end= crop.row_spacing
%td.text-end= crop.growing_degree_days
%td= crop.en_youtube_url.present? ? 'Yes' : '-'
%td.text-end= crop.scientific_names.size
%td.text-end= crop.alternate_names.size
%td.text-end= crop.varieties.size
%td.text-end
- if crop.crop_job_templates.any?
= link_to pluralize(crop.crop_job_templates.size, 'template'), admin_crop_crop_job_templates_path(crop)
- else
= link_to 'Add', new_admin_crop_crop_job_template_path(crop)
%td
= time_ago_in_words(crop.updated_at)
ago
%td
- person = @approval_status == 'pending' ? crop.requester : crop.creator
= person.present? ? link_to(person, person) : 'N/A'
= page_entries_info @crops
= will_paginate @crops