This repository has been archived by the owner on May 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a state machine to manage states and transitions
- Loading branch information
Showing
22 changed files
with
325 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# State-based workflow: The primary workflow is to start at pending, and | ||
# progress through metadata_review and final_review to complete. There are | ||
# two exceptional workflows: between complete/takedown (for issues requiring | ||
# an item be suppressed), and between complete/flagged (for issues where an | ||
# item can remain accessible). | ||
class StateWorkflow | ||
include AASM | ||
|
||
def initialize(state) | ||
aasm.current_state = state.to_sym unless state.nil? | ||
end | ||
|
||
aasm do | ||
state :pending, initial: true | ||
state :metadata_review | ||
state :final_review | ||
state :complete | ||
state :takedown | ||
state :flagged | ||
|
||
# ingest workflow | ||
event :finalize_digitization do | ||
transitions from: :pending, to: :metadata_review | ||
end | ||
event :finalize_metadata do | ||
transitions from: :metadata_review, to: :final_review | ||
end | ||
event :complete do | ||
transitions from: :final_review, to: :complete | ||
end | ||
|
||
# takedown/restore workflow | ||
event :takedown do | ||
transitions from: :complete, to: :takedown | ||
end | ||
event :restore do | ||
transitions from: :takedown, to: :complete | ||
end | ||
|
||
# flag/unflag workflow | ||
event :flag do | ||
transitions from: :complete, to: :flagged | ||
end | ||
event :unflag do | ||
transitions from: :flagged, to: :complete | ||
end | ||
end | ||
|
||
def suppressed? | ||
pending? || metadata_review? || final_review? || takedown? | ||
end | ||
|
||
def valid_transitions | ||
aasm.states(permitted: true).map(&:name) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
class CurationConcernsShowPresenter < CurationConcerns::WorkShowPresenter | ||
delegate :date_created, :viewing_hint, :viewing_direction, :state, :identifier, :workflow_note, to: :solr_document | ||
delegate :date_created, :viewing_hint, :viewing_direction, :state, :type, :identifier, :workflow_note, to: :solr_document | ||
|
||
def state_badge | ||
StateBadge.new(solr_document).render | ||
StateBadge.new(type, state).render | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,63 @@ | ||
class StateBadge | ||
include ActionView::Context | ||
include ActionView::Helpers::TagHelper | ||
|
||
def initialize(solr_document) | ||
@solr_document = solr_document | ||
def initialize(type, state = nil) | ||
@type = type.underscore | ||
@state = StateWorkflow.new state | ||
end | ||
|
||
def render | ||
content_tag(:span, link_title, title: link_title, class: "label #{dom_label_class}") | ||
label = I18n.t("state.#{current_state}.label") | ||
content_tag(:span, label, title: label, class: "label #{dom_label_class}") | ||
end | ||
|
||
def render_buttons | ||
html = render_radio_button(current_state, checked: true) | ||
@state.valid_transitions.each do |valid_state| | ||
html += render_radio_button(valid_state) | ||
end | ||
html | ||
end | ||
|
||
def render_hidden | ||
tag :input, id: "#{field_id}", name: field_name, type: :hidden, value: current_state | ||
end | ||
|
||
private | ||
|
||
def dom_label_class | ||
if complete? | ||
'label-success' | ||
elsif review? | ||
'label-info' | ||
else | ||
'label-warning' | ||
def render_radio_button(state, checked = false) | ||
content_tag :label, class: 'radio' do | ||
tag(:input, id: field_id(state), name: field_name, type: :radio, value: state, checked: checked) + | ||
content_tag(:span, I18n.t("state.#{state}.label"), class: "label #{dom_label_class(state)}", for: field_id(state)) + | ||
" " + I18n.t("state.#{state}.desc") | ||
end | ||
end | ||
|
||
def link_title | ||
if complete? | ||
'Complete' | ||
elsif review? | ||
'Review' | ||
else | ||
'Pending' | ||
end | ||
def dom_label_class(state = current_state) | ||
state_classes[state] | ||
end | ||
|
||
def state_classes | ||
@state_classes ||= { | ||
pending: 'label-default', | ||
metadata_review: 'label-info', | ||
final_review: 'label-primary', | ||
complete: 'label-success', | ||
flagged: 'label-warning', | ||
takedown: 'label-danger' | ||
} | ||
end | ||
|
||
def current_state | ||
@state.aasm.current_state | ||
end | ||
|
||
def complete? | ||
@solr_document.state == 'complete' | ||
def field_name | ||
"#{@type}[state]" | ||
end | ||
|
||
def review? | ||
@solr_document.state == 'review' | ||
def field_id(state = current_state) | ||
"#{@type}_state_#{state}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,10 @@ | ||
<% unless curation_concern.new_record? %> | ||
<% if curation_concern.new_record? %> | ||
<%= StateBadge.new(curation_concern.class.to_s).render_hidden %> | ||
<% else %> | ||
<fieldset id="set-state"> | ||
<legend>State</legend> | ||
<div class="form-group"> | ||
<label class="radio"> | ||
<%= f.radio_button :state, 'pending', checked: curation_concern.state != 'complete' && curation_concern.state != 'review' %> | ||
<%= f.label 'Pending', class: 'label label-warning', for: 'scanned_resource_state_pending' %> | ||
In progress and suppressed from public display | ||
</label> | ||
<label class="radio"> | ||
<%= f.radio_button :state, 'review', checked: curation_concern.state == 'review' %> | ||
<%= f.label 'Review', class: 'label label-info', for: 'scanned_resource_state_review' %> | ||
In need of review | ||
</label> | ||
<label class="radio"> | ||
<%= f.radio_button :state, 'complete', checked: curation_concern.state == 'complete' %> | ||
<%= f.label 'Complete', class: 'label label-success', for: 'scanned_resource_state_complete' %> | ||
Finished work, visibility determined by Access Rights | ||
</label> | ||
<%= StateBadge.new(curation_concern.class.to_s, curation_concern.state).render_buttons %> | ||
</div> | ||
</fieldset> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.