bible270 1.13.3 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,6 +22,7 @@ module Bible270
22
22
  }.freeze
23
23
 
24
24
  before_action :require_admin!
25
+ before_action :require_admin_view!, except: %i[index update_view]
25
26
  before_action :load_reader,
26
27
  only: %i[show destroy update_start update_profile update_theme update_notifications update_completion_animation
27
28
  remove_avatar complete_through toggle_day]
@@ -62,7 +63,23 @@ module Bible270
62
63
  redirect_to admin_path, notice: notice
63
64
  end
64
65
 
66
+ def update_view
67
+ case params[:view]
68
+ when 'reader'
69
+ session[:bible270_reader_view_id] = current_reader.id
70
+ redirect_to root_path, status: :see_other,
71
+ notice: 'Non-admin view is on. Use Admin to return to admin view.'
72
+ when 'admin'
73
+ session.delete(:bible270_reader_view_id)
74
+ redirect_to admin_path, status: :see_other, notice: 'Admin view restored.'
75
+ else
76
+ redirect_to admin_path, status: :see_other, alert: 'Choose admin or non-admin view. Nothing was changed.'
77
+ end
78
+ end
79
+
65
80
  def index
81
+ return render :reader_view if b270_reader_view?
82
+
66
83
  @enrollment_closed = Setting.enrollment_closed?
67
84
  @enrollment_closed_at = Setting.enrollment_closed_at
68
85
  @days_completed = Reader.completed_days_by_id
@@ -377,7 +394,13 @@ module Bible270
377
394
  end
378
395
 
379
396
  def require_admin!
380
- return if Bible270.config.admin_configured? && Bible270.config.admin?(current_reader)
397
+ return if b270_admin?
398
+
399
+ raise ActionController::RoutingError, 'Not Found'
400
+ end
401
+
402
+ def require_admin_view!
403
+ return if b270_admin_view?
381
404
 
382
405
  raise ActionController::RoutingError, 'Not Found'
383
406
  end
@@ -28,7 +28,8 @@ module Bible270
28
28
 
29
29
  rescue_from ActionController::InvalidAuthenticityToken, with: :recover_from_stale_page
30
30
 
31
- helper_method :current_reader, :signed_in?, :b270_config, :enrollment_closed?
31
+ helper_method :current_reader, :signed_in?, :b270_config, :enrollment_closed?,
32
+ :b270_admin?, :b270_reader_view?, :b270_admin_view?
32
33
 
33
34
  private
34
35
 
@@ -103,6 +104,19 @@ module Bible270
103
104
  current_reader.present?
104
105
  end
105
106
 
107
+ def b270_admin?
108
+ Bible270.config.admin_configured? && Bible270.config.admin?(current_reader)
109
+ end
110
+
111
+ def b270_reader_view?
112
+ b270_admin? && session[:bible270_reader_view_id] == current_reader.id
113
+ end
114
+
115
+ # Keep real admin identity separate so preview mode always has a way back.
116
+ def b270_admin_view?
117
+ b270_admin? && !b270_reader_view?
118
+ end
119
+
106
120
  # A suspended mobile tab can outlive its Rails session cookie. The page still
107
121
  # contains the old session's CSRF token, so Rails would normally raise before
108
122
  # current_reader could restore the session from the remember cookie. Redirect
@@ -150,7 +150,7 @@ module Bible270
150
150
  # Scoped to the reader unless they are an administrator, so an ordinary reader
151
151
  # cannot use editing or deletion to discover someone else's reflection.
152
152
  def editable_comment
153
- return current_reader.comments.find_by(id: params[:id]) unless Bible270.config.admin?(current_reader)
153
+ return current_reader.comments.find_by(id: params[:id]) unless b270_admin_view?
154
154
 
155
155
  Comment.find_by(id: params[:id])
156
156
  end
@@ -33,7 +33,7 @@ module Bible270
33
33
  def editing_comment_id
34
34
  return nil if params[:edit].blank? || current_reader.nil?
35
35
 
36
- comments = Bible270.config.admin?(current_reader) ? Comment.all : current_reader.comments
36
+ comments = b270_admin_view? ? Comment.all : current_reader.comments
37
37
  comments.where(day: @day, id: params[:edit]).pick(:id)
38
38
  end
39
39
 
@@ -7,7 +7,7 @@ module Bible270
7
7
  # order predictable without implying that progress determines standing.
8
8
  @readers = Reader.with_avatar.to_a.sort_by(&:sort_name)
9
9
  @today_day = current_reader&.today_day
10
- @show_admin_progress = Bible270.config.admin?(current_reader)
10
+ @show_admin_progress = b270_admin_view?
11
11
  @days_completed = Reader.completed_days_by_id if @show_admin_progress
12
12
  end
13
13
 
@@ -209,13 +209,13 @@ module Bible270
209
209
  def b270_can_edit?(comment)
210
210
  return false unless signed_in?
211
211
 
212
- comment.reader_id == current_reader.id || Bible270.config.admin?(current_reader)
212
+ comment.reader_id == current_reader.id || b270_admin_view?
213
213
  end
214
214
 
215
215
  def b270_can_delete?(comment)
216
216
  return false unless signed_in?
217
217
 
218
- comment.reader_id == current_reader.id || Bible270.config.admin?(current_reader)
218
+ comment.reader_id == current_reader.id || b270_admin_view?
219
219
  end
220
220
 
221
221
  # One cell of the 270-day grid. Four views drew this by hand in four slightly
@@ -1,5 +1,9 @@
1
1
  <% content_for :title, "Admin — #{Bible270.config.app_name}" %>
2
- <p class="b270-eyebrow">Admin</p>
2
+ <div class="b270-admin-view-header">
3
+ <p class="b270-eyebrow">Admin</p>
4
+ <%= button_to 'View as non-admin', admin_view_path, method: :patch,
5
+ params: { view: 'reader' }, class: 'b270-btn', form: { data: { turbo: false } } %>
6
+ </div>
3
7
  <h1>Readers</h1>
4
8
  <p class="lede"><%= @readers.size %> reader<%= 's' unless @readers.size == 1 %> taking part.
5
9
  <%= link_to 'Moderate reflections →', admin_comments_path %></p>
@@ -75,10 +79,12 @@
75
79
  aria-controls="b270-reader-stats-dialog" data-b270-reader-stats-open hidden>Reader Stats</button>
76
80
  </div>
77
81
 
78
- <p class="b270-hint">
79
- Average daily score through yesterday: 100 on track, +5 per day ahead (max +35), −10 per day behind.
80
- Under 7 days is provisional; no history is unranked. Check-off or schedule changes can alter scores.
81
- </p>
82
+ <% if @reader_sort == 'consistency' %>
83
+ <p class="b270-hint b270-consistency-explanation">
84
+ Average through yesterday: 100 on track; +5/day ahead (up to +35), −10/day behind.
85
+ Provisional until 7 days; unranked without history. Scores reflect check-off and schedule changes.
86
+ </p>
87
+ <% end %>
82
88
 
83
89
  <div class="b270-list">
84
90
  <% @readers.each do |reader| %>
@@ -0,0 +1,8 @@
1
+ <% content_for :title, "Admin — #{Bible270.config.app_name}" %>
2
+ <div class="b270-admin-view-header">
3
+ <p class="b270-eyebrow">Admin</p>
4
+ <%= button_to 'Return to admin view', admin_view_path, method: :patch,
5
+ params: { view: 'admin' }, class: 'b270-btn', form: { data: { turbo: false } } %>
6
+ </div>
7
+ <h1>Non-admin view</h1>
8
+ <p class="lede">You're browsing as yourself without admin tools. Your own check-offs and reflections still work normally.</p>
@@ -19,7 +19,7 @@
19
19
  <%= render "bible270/shared/interaction_status" %>
20
20
  <%= render "bible270/shared/reflections", comments: @recent_comments,
21
21
  title: "Their reflections", empty_text: "No reflections yet.",
22
- conversations: true, editable: Bible270.config.admin?(current_reader) %>
22
+ conversations: true, editable: b270_admin_view? %>
23
23
  </div>
24
24
 
25
25
  <%= render "bible270/shared/day_index", reader: @reader, expanded: true %>
@@ -4,7 +4,7 @@
4
4
  <% if signed_in? %>
5
5
  <%= link_to "My Progress", progress_path %>
6
6
  <%= link_to "Profile", profile_path %>
7
- <% if Bible270.config.admin?(current_reader) %><%= link_to "Admin", admin_path %><% end %>
7
+ <% if b270_admin? %><%= link_to "Admin", admin_path %><% end %>
8
8
  <%= button_to "Sign out", sign_out_path, method: :delete, class: "b270-linkbtn",
9
9
  form: { style: "display:inline" } %>
10
10
  <% elsif Bible270.config.any_sign_in_method? %>
@@ -542,6 +542,8 @@
542
542
  .b270 .b270-btn:hover{background:var(--button-hover)}
543
543
 
544
544
  /* community */
545
+ .b270-admin-view-header{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:10px}
546
+ .b270-admin-view-header .b270-eyebrow,.b270-admin-view-header form,.b270 .b270-admin-view-header .b270-btn{margin:0}
545
547
  .b270-admin-reader-tools{display:flex;align-items:flex-end;justify-content:flex-end;gap:8px;margin:0 0 10px;flex-wrap:wrap}
546
548
  .b270-admin-reader-sort{display:flex;align-items:flex-end;gap:8px}
547
549
  .b270-admin-reader-sort label{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}
data/config/routes.rb CHANGED
@@ -20,6 +20,7 @@ Bible270::Engine.routes.draw do
20
20
 
21
21
  # Admin panel — 404s unless config.admin_emails / admin_resolver allows you.
22
22
  get 'admin', to: 'admin#index', as: :admin
23
+ patch 'admin/view', to: 'admin#update_view', as: :admin_view
23
24
  get 'admin/readers/:id', to: 'admin#show', as: :admin_reader
24
25
  delete 'admin/readers/:id', to: 'admin#destroy'
25
26
  patch 'admin/readers/:id/profile', to: 'admin#update_profile', as: :admin_reader_profile
data/lib/bible270/plan.rb CHANGED
@@ -15,8 +15,8 @@ module Bible270
15
15
  # grouped so each day is ~equal in verses (~73/day)
16
16
  # * New Testament – read once, one reading every day; the 10 longest chapters
17
17
  # (Luke 1 and friends) are divided in two so 260 chapters fill 270 days
18
- # * Psalms/Proverbs – Psalms and Proverbs once, interleaved in one track.
19
- # Longer psalms are divided so the two fill exactly 270 days;
18
+ # * Psalms/Proverbs – Psalms and Proverbs once, interleaved over 269 days,
19
+ # then Psalm 1 again on the final day.
20
20
  # Psalm 119 is pinned to 11 sections of 16 verses.
21
21
  #
22
22
  # Genesis → Malachi, Revelation 22, Psalm 150 and the second Proverbs 31 all land
@@ -368,9 +368,9 @@ module Bible270
368
368
 
369
369
  # ---- Psalms & Proverbs -------------------------------------------------
370
370
  #
371
- # Psalms once and Proverbs once, interleaved in one daily track.
371
+ # Psalms once and Proverbs once, interleaved, then Psalm 1 again on day 270.
372
372
  #
373
- # 150 + 31 = 181 chapters have to cover 270 days, so 89 of them are divided.
373
+ # 150 + 31 = 181 chapters cover the first 269 days using 88 extra divisions.
374
374
  # Two rules shape which:
375
375
  #
376
376
  # * A psalm of PSALM_WHOLE_MAX_VERSES verses or fewer is never divided.
@@ -406,7 +406,7 @@ module Bible270
406
406
  ['Psalm', 44] => [], ['Psalm', 49] => [], ['Psalm', 50] => [], ['Psalm', 51] => [], # Stay whole
407
407
  ['Psalm', 55] => [], ['Psalm', 59] => [], ['Psalm', 65] => [], ['Psalm', 66] => [], # Stay whole
408
408
  ['Psalm', 68] => [18], # => Psalm 68:1–18, 68:19–35
409
- ['Psalm', 69] => [18], # => Psalm 69:1–18, 69:19–36
409
+ ['Psalm', 69] => [19], # => Psalm 69:1–19, 69:20–36
410
410
  ['Psalm', 78] => [20, 39, 55], # => 78:1–20, 21–39, 40–55, 56–72
411
411
  ['Psalm', 37] => [20], # => Psalm 37:1–20, 37:21–40
412
412
  ['Matthew', 26] => [35], # => Matthew 26:1–35, 26:36–75
@@ -421,7 +421,7 @@ module Bible270
421
421
 
422
422
  # -- Psalms over 25 verses, divided at their turns of thought ----------
423
423
  ['Psalm', 35] => [], # kept whole
424
- ['Psalm', 73] => [14], # the envious lament | the sanctuary
424
+ ['Psalm', 73] => [], # kept whole
425
425
  ['Psalm', 89] => [18, 37], # hymn | covenant oracle | lament
426
426
  ['Psalm', 102] => [17], # affliction | Zion restored
427
427
  ['Psalm', 104] => [18], # creation ordered | creation sustained
@@ -472,14 +472,13 @@ module Bible270
472
472
 
473
473
  def pp_chapters = memo(:pp_chapters) { psalm_chapters + proverbs_chapters }
474
474
 
475
- # Psalms and Proverbs are divided together against a single budget of DAYS
476
- # readings, so the two books balance against each other by verse load rather
477
- # than each being squeezed into a fixed number of days.
475
+ # Reserve the final day for rereading Psalm 1. The first pass through Psalms
476
+ # and Proverbs shares the remaining budget, balanced by verse load.
478
477
  def pp_parts
479
478
  memo(:pp_parts) do
480
479
  chapters = pp_chapters
481
480
  weights = chapters.map { |b, c| verses_for(b, c) }
482
- divide_to_fill(weights, DAYS, pp_pinned_parts(chapters, weights))
481
+ divide_to_fill(weights, DAYS - 1, pp_pinned_parts(chapters, weights))
483
482
  end
484
483
  end
485
484
 
@@ -498,6 +497,7 @@ module Bible270
498
497
  def psalm_parts = memo(:psalm_parts) { pp_parts.first(psalm_chapters.size) }
499
498
  def proverbs_parts = memo(:proverbs_parts) { pp_parts.last(proverbs_chapters.size) }
500
499
 
500
+ # First-pass readings; the closing rereading is appended in pp_readings.
501
501
  def psalm_readings = memo(:psalm_readings) { expand_readings(psalm_chapters, psalm_parts) }
502
502
  def proverbs_readings = memo(:proverbs_readings) { expand_readings(proverbs_chapters, proverbs_parts) }
503
503
 
@@ -528,7 +528,7 @@ module Bible270
528
528
  end
529
529
  end
530
530
  days.concat(proverbs[placed..].to_a.flatten(1)) if placed < proverbs.size
531
- days
531
+ days << ['Psalm', 1]
532
532
  end
533
533
  end
534
534
 
@@ -673,13 +673,13 @@ module Bible270
673
673
  nt_readings: nt_readings.size, # 270 - one every day
674
674
  nt_divided: divided_nt_chapters.size, # 10 long chapters halved
675
675
  psalms: Versification.chapter_count('Psalm'), # 150
676
- psalm_readings: psalm_readings.size, # 208
676
+ psalm_readings: pp_readings.count { |seg| seg[0] == 'Psalm' },
677
677
  proverbs: Versification.chapter_count('Proverbs'), # 31
678
678
  proverbs_readings: proverbs_readings.size,
679
679
  proverbs_divided: divided_proverbs.size,
680
680
  psalms_whole_max_verses: PSALM_WHOLE_MAX_VERSES,
681
681
  pp: flatten(PP).size, # 181 chapters
682
- pp_verses: flatten(PP).sum { |b, c| verses_for(b, c) },
682
+ pp_verses: pp_verse_loads.sum,
683
683
  ot_verses: flatten(OT).sum { |b, c| verses_for(b, c) },
684
684
  nt_verses: flatten(NT).sum { |b, c| verses_for(b, c) },
685
685
  days: DAYS
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bible270
4
- VERSION = '1.13.3'
4
+ VERSION = '1.14.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bible270
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.3
4
+ version: 1.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew vonderLuft
@@ -166,6 +166,7 @@ files:
166
166
  - app/models/bible270/sign_in_token.rb
167
167
  - app/views/bible270/admin/comments.html.erb
168
168
  - app/views/bible270/admin/index.html.erb
169
+ - app/views/bible270/admin/reader_view.html.erb
169
170
  - app/views/bible270/admin/show.html.erb
170
171
  - app/views/bible270/checkoffs/toggle.turbo_stream.erb
171
172
  - app/views/bible270/comments/_body.html.erb