diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-04 01:24:55 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-04 01:24:55 +0200 |
| commit | 206dc5c50a73c5402b90d7fdc8945d3ba9356758 (patch) | |
| tree | b2c98c48248c878da4344e61734bfa89130f18d1 /app | |
| parent | d9461bae0b6232d618dde118360b44bb80f962b8 (diff) | |
Add self-service event creation from nodes#show
nodes#show's events table now renders unconditionally (previously
hidden entirely for a zero-event node) and gains an "add event" link.
The suggested tag_list is derived from the page's own category tags
via NodesHelper::DEFAULT_EVENT_TAG_BY_PAGE_TAG (erfa-detail/
chaostreff-detail -> open-day) rather than hardcoded, and degrades to
a blank field for any node whose tags don't match - deliberately
universal, not chapter-specific, since Updates have historically
carried event dates the same way.
events#new surfaces *why* the tag was pre-filled via flash.now (not
flash - this is a same-request render, not a redirect), using an
explicit auto_tag_source param passed alongside tag_list rather than
having the controller re-derive the reason from node_id.
No destroy link added to nodes#show's events list - deliberate, per
existing subnav-semantics convention (destructive actions live on the
resource's own views). Covered directly by test.
Adds real coverage for EventsController, previously 100% commented-out
scaffold, plus unit tests for the new tag-mapping helper and the
weekday-abbreviation helpers from the prior commit.
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/events_controller.rb | 4 | ||||
| -rw-r--r-- | app/helpers/nodes_helper.rb | 14 | ||||
| -rw-r--r-- | app/views/nodes/show.html.erb | 4 |
3 files changed, 20 insertions, 2 deletions
diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 9bed5dd..b98a38e 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb | |||
| @@ -37,6 +37,10 @@ class EventsController < ApplicationController | |||
| 37 | tag_list: params[:tag_list] | 37 | tag_list: params[:tag_list] |
| 38 | ) | 38 | ) |
| 39 | 39 | ||
| 40 | if params[:tag_list].present? && params[:auto_tag_source].present? | ||
| 41 | flash.now[:notice] = "Tag '#{params[:tag_list]}' was pre-filled because this page is tagged '#{params[:auto_tag_source]}'. You can remove it below." | ||
| 42 | end | ||
| 43 | |||
| 40 | respond_to do |format| | 44 | respond_to do |format| |
| 41 | format.html # new.html.erb | 45 | format.html # new.html.erb |
| 42 | format.xml { render :xml => @event } | 46 | format.xml { render :xml => @event } |
diff --git a/app/helpers/nodes_helper.rb b/app/helpers/nodes_helper.rb index 329bcc5..093bfc6 100644 --- a/app/helpers/nodes_helper.rb +++ b/app/helpers/nodes_helper.rb | |||
| @@ -44,6 +44,20 @@ module NodesHelper | |||
| 44 | ]) | 44 | ]) |
| 45 | end | 45 | end |
| 46 | 46 | ||
| 47 | DEFAULT_EVENT_TAG_BY_PAGE_TAG = { | ||
| 48 | 'erfa-detail' => 'open-day', | ||
| 49 | 'chaostreff-detail' => 'open-day' | ||
| 50 | }.freeze | ||
| 51 | |||
| 52 | def default_event_tag_mapping(page) | ||
| 53 | page_tags = page.tag_list | ||
| 54 | DEFAULT_EVENT_TAG_BY_PAGE_TAG.find { |page_tag, _| page_tags.include?(page_tag) } | ||
| 55 | end | ||
| 56 | |||
| 57 | def default_event_tag_list(page) | ||
| 58 | default_event_tag_mapping(page)&.last | ||
| 59 | end | ||
| 60 | |||
| 47 | def event_schedule_text(event) | 61 | def event_schedule_text(event) |
| 48 | if event.rrule.present? | 62 | if event.rrule.present? |
| 49 | recurrence = event.humanize_rrule(I18n.locale) | 63 | recurrence = event.humanize_rrule(I18n.locale) |
diff --git a/app/views/nodes/show.html.erb b/app/views/nodes/show.html.erb index 2ce3853..c533a55 100644 --- a/app/views/nodes/show.html.erb +++ b/app/views/nodes/show.html.erb | |||
| @@ -42,7 +42,6 @@ | |||
| 42 | <td class="description">Tagged with:</td> | 42 | <td class="description">Tagged with:</td> |
| 43 | <td><%= @page.tag_list %></td> | 43 | <td><%= @page.tag_list %></td> |
| 44 | </tr> | 44 | </tr> |
| 45 | <% if @node.events.any? %> | ||
| 46 | <tr> | 45 | <tr> |
| 47 | <td class="description">Events</td> | 46 | <td class="description">Events</td> |
| 48 | <td> | 47 | <td> |
| @@ -55,9 +54,10 @@ | |||
| 55 | </li> | 54 | </li> |
| 56 | <% end %> | 55 | <% end %> |
| 57 | </ul> | 56 | </ul> |
| 57 | <% mapping = default_event_tag_mapping(@page) %> | ||
| 58 | <%= link_to 'add event', new_event_path(node_id: @node.id, tag_list: mapping&.last, auto_tag_source: mapping&.first, return_to: request.path) %> | ||
| 58 | </td> | 59 | </td> |
| 59 | </tr> | 60 | </tr> |
| 60 | <% end %> | ||
| 61 | <tr> | 61 | <tr> |
| 62 | <td class="description"><strong>Title</strong></td> | 62 | <td class="description"><strong>Title</strong></td> |
| 63 | <td><%= sanitize( @page.title ) %></td> | 63 | <td><%= sanitize( @page.title ) %></td> |
