<commit_before>{Controller} = require 'spine'
template = require 'views/classify_page'
ClassificationTools = require 'controllers/classification_tools'
MarkingSurface = require 'controllers/marking_surface'
FanTool = require 'controllers/fan_tool'
$ = require 'jqueryify'
User = require 'zooniverse/lib/models/user'
Subject = require 'models/subject'
Classification = require 'models/classification'
{Tutorial} = require 'zootorial'
tutorialSteps = require 'lib/tutorial_steps'

html = $(document.body.parentNode)

class ClassifyPage extends Controller
  className: 'classify-page'

  classificationTools: null
  markingSurface: null

  events:
    'click button[name="start-tutorial"]': 'startTutorial'
    'click button[name="sign-in"]': 'onClickSignIn'

  elements:
    '.subject-container': 'subjectContainer'
    '.subject-container .subject': 'subjectImg'

  constructor: ->
    super

    @html template @

    @classificationTools = new ClassificationTools
      classifier: @

    @markingSurface = new MarkingSurface
      el: @subjectContainer
      classifier: @

    @markingSurface.bind 'create-mark', @onCreateMark

    @tutorial = new Tutorial
      steps: tutorialSteps

    User.bind 'sign-in', @onUserSignIn

    Subject.bind 'selected', @onSubjectSelect

  onUserSignIn: =>
    @el.toggleClass 'signed-in', User.current?
    tutorialDone = User.current?.project.classification_count > 0
    doingTutorial = Subject.current?.metadata.tutorial

    if tutorialDone
      @tutorial?.end()
      @selectNextSubject() if doingTutorial or not Subject.current?
    else
      if @tutorial?
        @startTutorial()
        unless @el.hasClass 'active'
          @tutorial.dialog.el.hide()
      else
        @selectNextSubject()

  startTutorial: ->
    Subject.selectTutorial()
    @tutorial?.start()

  selectNextSubject: ->
    @el.addClass 'loading'
    next = Subject.next()
    next.fail @onSubjectError

  onSubjectSelect: =>
    @el.removeClass 'loading'
    @markingSurface.marks[0].destroy() until @markingSurface.marks.length is 0
    @classification = new Classification subject: Subject.current
    @subjectImg.attr src: Subject.current.location.standard

  onSubjectError: =>
    @el.removeClass 'loading'
    alert 'Error fetching subjects. Maybe we\'re out!'

  onCreateMark: (mark) =>
    # Re-assign the "type" property.
    mark.set type: @classificationTools.tool

    @classification.marks.push mark

    mark.bind 'destroy', =>
      @classification.marks.splice i, 1 for m, i in @classification.marks when m is mark

  finishClassification: ->
    @classification.send()

  onClickSignIn: ->
    $(window).trigger 'request-login-dialog'

  activate: ->
    super
    html.addClass 'on-classify'
    if Subject.current?.metadata.tutorial
      @tutorial.dialog.el.show()
      @tutorial.dialog.attach()

  deactivate: ->
    super
    html.removeClass 'on-classify'
    @tutorial.dialog.el.hide() if Subject.current?.metadata.tutorial

module.exports = ClassifyPage
<commit_msg>Close the tutorial dialog on login<commit_after>{Controller} = require 'spine'
template = require 'views/classify_page'
ClassificationTools = require 'controllers/classification_tools'
MarkingSurface = require 'controllers/marking_surface'
FanTool = require 'controllers/fan_tool'
$ = require 'jqueryify'
User = require 'zooniverse/lib/models/user'
Subject = require 'models/subject'
Classification = require 'models/classification'
{Tutorial} = require 'zootorial'
tutorialSteps = require 'lib/tutorial_steps'

html = $(document.body.parentNode)

class ClassifyPage extends Controller
  className: 'classify-page'

  classificationTools: null
  markingSurface: null

  events:
    'click button[name="start-tutorial"]': 'startTutorial'
    'click button[name="sign-in"]': 'onClickSignIn'

  elements:
    '.subject-container': 'subjectContainer'
    '.subject-container .subject': 'subjectImg'

  constructor: ->
    super

    @html template @

    @classificationTools = new ClassificationTools
      classifier: @

    @markingSurface = new MarkingSurface
      el: @subjectContainer
      classifier: @

    @markingSurface.bind 'create-mark', @onCreateMark

    @tutorial = new Tutorial
      steps: tutorialSteps

    User.bind 'sign-in', @onUserSignIn

    Subject.bind 'selected', @onSubjectSelect

  onUserSignIn: =>
    @el.toggleClass 'signed-in', User.current?
    tutorialDone = User.current?.project.classification_count > 0
    doingTutorial = Subject.current?.metadata.tutorial

    if tutorialDone
      @tutorial?.end()
      @tutorial?.dialog.close()
      @selectNextSubject() if doingTutorial or not Subject.current?
    else
      if @tutorial?
        @startTutorial()
        unless @el.hasClass 'active'
          @tutorial.dialog.el.hide()
      else
        @selectNextSubject()

  startTutorial: ->
    Subject.selectTutorial()
    @tutorial?.start()

  selectNextSubject: ->
    @el.addClass 'loading'
    next = Subject.next()
    next.fail @onSubjectError

  onSubjectSelect: =>
    @el.removeClass 'loading'
    @markingSurface.marks[0].destroy() until @markingSurface.marks.length is 0
    @classification = new Classification subject: Subject.current
    @subjectImg.attr src: Subject.current.location.standard

  onSubjectError: =>
    @el.removeClass 'loading'
    alert 'Error fetching subjects. Maybe we\'re out!'

  onCreateMark: (mark) =>
    # Re-assign the "type" property.
    mark.set type: @classificationTools.tool

    @classification.marks.push mark

    mark.bind 'destroy', =>
      @classification.marks.splice i, 1 for m, i in @classification.marks when m is mark

  finishClassification: ->
    @classification.send()

  onClickSignIn: ->
    $(window).trigger 'request-login-dialog'

  activate: ->
    super
    html.addClass 'on-classify'
    if Subject.current?.metadata.tutorial
      @tutorial.dialog.el.show()
      @tutorial.dialog.attach()

  deactivate: ->
    super
    html.removeClass 'on-classify'
    @tutorial.dialog.el.hide() if Subject.current?.metadata.tutorial

module.exports = ClassifyPage

{'fraction_non_alphanumeric': 0.11317650929429182, 'fraction_numerical': 0.0013160059220266491, 'mean_word_length': 3.616552771450266, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '4315220', 'n_tokens_mistral': 1873, 'n_tokens_neox': 1761, 'n_words': 398}