<commit_before># policies.coffee describes the following situations.
# This should handle the 4 different states an Exercise can be in:
# 1. `not(free_response)`: Show the question stem and a text area
# 2. `free_response and not(is_completed)`: Show stem, your free_response, and the multiple choice options
# 3. `correct_answer`: review how you did and show feedback (if any)
# 4. `task.is_completed and answer` show your answer choice but no option to change it

# This should also handle when an Exercise format is a True-False:
# 5.  `question.formats` does not have 'free-response' and not(is_completed): Show stem and true-false options
# 6.  `question.formats` does not have 'free-response' and `correct_answer`: review how you did and show feedback (if any)

# Also, also, also, this should handle with an exercise is part of a homework
# 7. Before due -- does not show feedback and moves on to the next question on question finish
# 8. After due -- does show feedback before moving on

_ = require 'underscore'
moment = require 'moment'
flux = require 'flux-react'

{TaskStepStore} = require '../../flux/task-step'
{TaskStore} = require '../../flux/task'

utils = require './utils'

defaultTask =
  type: 'default'

defaultStep =
  type: 'placeholder'

getTaskStepPanels = (stepId) ->
  step = TaskStepStore.get stepId
  step ?= defaultStep

  task = TaskStore.get step.task_id
  task ?= defaultTask

  panels = utils._getPanels task, step
  {panels, step, task}

getPanelsWithStatus = (stepId) ->
  {task, step, panels} = getTaskStepPanels stepId
  panelsWithStatus = utils._arePanelsPassed task, step, panels


StepPanel =
  getPanelsWithStatus: getPanelsWithStatus

  getPanel: (stepId) ->
    panelsWithStatus = getPanelsWithStatus stepId
    panel = utils._getPanel panelsWithStatus

    panel.name

  getRemainingActions: (stepId) ->
    panelsWithStatus = getPanelsWithStatus stepId
    remainingPanels = _.where panelsWithStatus, {passed: false}

    _.chain(remainingPanels).pluck('actions').flatten().value()

  canReview: (stepId) ->
    {panels} = getTaskStepPanels stepId
    utils._canReview panels

  canWrite: (stepId) ->
    {panels} = getTaskStepPanels stepId
    utils._canWrite panels

  canContinue: (stepId) ->
    step = TaskStepStore.get stepId

    mostCurrentStep = TaskStore.getCurrentStep step.task_id
    isMostCurrentStep = step.id is mostCurrentStep.id

    # Steps can be continued if it's writable.
    # If it's not writable and the most current step,
    # then you cannot continue.
    @canWrite(stepId) or not isMostCurrentStep

module.exports = {StepPanel}<commit_msg>handle placeholder steps and continuing as well<commit_after># policies.coffee describes the following situations.
# This should handle the 4 different states an Exercise can be in:
# 1. `not(free_response)`: Show the question stem and a text area
# 2. `free_response and not(is_completed)`: Show stem, your free_response, and the multiple choice options
# 3. `correct_answer`: review how you did and show feedback (if any)
# 4. `task.is_completed and answer` show your answer choice but no option to change it

# This should also handle when an Exercise format is a True-False:
# 5.  `question.formats` does not have 'free-response' and not(is_completed): Show stem and true-false options
# 6.  `question.formats` does not have 'free-response' and `correct_answer`: review how you did and show feedback (if any)

# Also, also, also, this should handle with an exercise is part of a homework
# 7. Before due -- does not show feedback and moves on to the next question on question finish
# 8. After due -- does show feedback before moving on

_ = require 'underscore'
moment = require 'moment'
flux = require 'flux-react'

{TaskStepStore} = require '../../flux/task-step'
{TaskStore} = require '../../flux/task'

utils = require './utils'

defaultTask =
  type: 'default'

defaultStep =
  type: 'placeholder'

getTaskStepPanels = (stepId) ->
  step = TaskStepStore.get stepId
  step ?= defaultStep

  task = TaskStore.get step.task_id
  task ?= defaultTask

  panels = utils._getPanels task, step
  {panels, step, task}

getPanelsWithStatus = (stepId) ->
  {task, step, panels} = getTaskStepPanels stepId
  panelsWithStatus = utils._arePanelsPassed task, step, panels


StepPanel =
  getPanelsWithStatus: getPanelsWithStatus

  getPanel: (stepId) ->
    panelsWithStatus = getPanelsWithStatus stepId
    panel = utils._getPanel panelsWithStatus

    panel.name

  getRemainingActions: (stepId) ->
    panelsWithStatus = getPanelsWithStatus stepId
    remainingPanels = _.where panelsWithStatus, {passed: false}

    _.chain(remainingPanels).pluck('actions').flatten().value()

  canReview: (stepId) ->
    {panels} = getTaskStepPanels stepId
    utils._canReview panels

  canWrite: (stepId) ->
    {panels} = getTaskStepPanels stepId
    utils._canWrite panels

  canContinue: (stepId) ->
    step = TaskStepStore.get stepId
    # if step is falsy, this step is a placeholder step and
    # can be continued from
    return true unless step?

    mostCurrentStep = TaskStore.getCurrentStep step.task_id
    isMostCurrentStep = mostCurrentStep? and (step.id is mostCurrentStep.id)

    # Steps can be continued if it's writable.
    # If it's not writable and the most current step,
    # then you cannot continue.
    @canWrite(stepId) or not isMostCurrentStep

module.exports = {StepPanel}
{'fraction_non_alphanumeric': 0.09082500924898261, 'fraction_numerical': 0.003329633740288568, 'mean_word_length': 3.997227356746765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7537360', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1596, 'n_words': 580}