Skip to content

Commit bba20fc

Browse files
authored
Distinguish between accepted puzzles used puzzles (#37)
* Add a state of archived * Add archived puzzles to controller
1 parent afc9907 commit bba20fc

File tree

5 files changed

+9
-2
lines changed

5 files changed

+9
-2
lines changed

app/controllers/puzzles_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ def index
77
@pending_puzzles = Puzzle.pending
88
@approved_puzzles = Puzzle.approved
99
@rejected_puzzles = Puzzle.rejected
10+
@archived_puzzles = Puzzle.archived
1011
end
1112
end

app/jobs/daily_puzzle_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def perform
2222
)
2323
end
2424

25-
puzzle.update!(sent_at: Time.current)
25+
puzzle.update!(sent_at: Time.current, state: :archived)
2626
end
2727

2828
private

app/models/puzzle.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Puzzle < ApplicationRecord
22
enum :answer, ruby: 0, rails: 1
3-
enum :state, { approved: 0, rejected: 1, pending: 2 }
3+
enum :state, { approved: 0, rejected: 1, pending: 2, archived: 3 }
44
has_many :answers
55
end

app/views/puzzles/_puzzles_table.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
<% elsif actions == :rejected %>
3131
<%= button_to 'Approve', puzzle_state_path(puzzle, state: :approved), method: :patch, form_class: 'inline-form', class: 'btn approve-btn' %>
3232
<%= button_to 'Pending', puzzle_state_path(puzzle, state: :pending), method: :patch, form_class: 'inline-form', class: 'btn pending-btn' %>
33+
<% elsif actions == :archived %>
34+
<%= button_to 'Un-Archive', puzzle_state_path(puzzle, state: :pending), method: :patch, form_class: 'inline-form', class: 'btn pending-btn' %>
3335
<% end %>
3436
</td>
3537
</tr>

app/views/puzzles/index.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010

1111
<h1>Rejected Puzzles</h1>
1212
<%= render partial: 'puzzles_table', locals: { puzzles: @rejected_puzzles, actions: :rejected } %>
13+
14+
<h1>Archive Puzzles</h1>
15+
<p>These puzzles have already been sent to the users.</p>
16+
<%= render partial: 'puzzles_table', locals: { puzzles: @archived_puzzles, actions: :archived } %>

0 commit comments

Comments
 (0)