<commit_before>BaseController             = require 'zooniverse/controllers/base-controller'
User                       = require 'zooniverse/models/user'
Subject                    = require 'zooniverse/models/subject'
Classification             = require 'zooniverse/models/classification'
MiniCourse                 = require '../lib/mini-course'
NoUiSlider                 = require '../lib/jquery.nouislider.min'
translate                  = require 't7e'
{Tutorial}                 = require 'zootorial'
{Step}                     = require 'zootorial'
initialTutorialSteps       = require '../lib/initial-tutorial-steps'
supplementalTutorialSteps  = require '../lib/supplemental-tutorial-steps'
{CanvasGraph, Marks, Mark} = require "../lib/canvas-graph"
$ = window.jQuery

class Classifier extends BaseController
  className: 'classifier'
  template: require '../views/classifier'

  elements:
    '#zoom-button'                      : 'zoomButton'
    '#toggle-fav'                       : 'favButton'
    '#help'                             : 'helpButton'
    '#tutorial'                         : 'tutorialButton'
    'numbers-container'                 : 'numbersContainer'
    '#classify-summary'                 : 'classifySummary'
    '#comments'                         : 'comments'
    '#planet-num'                       : 'planetNum'
    '#alt-comments'                     : 'altComments'
    'button[name="no-transits"]'        : 'noTransitsButton'
    'button[name="finished-marking"]'   : 'finishedMarkingButton'
    'button[name="finished-feedback"]'  : 'finishedFeedbackButton'
    'button[name="next-subject"]'       : 'nextSubjectButton'
    'button[name="join-convo"]'         : 'joinConvoBtn'
    'button[name="alt-join-convo"]'     : 'altJoinConvoBtn'
    'textarea[name="talk-comment"]'     : 'talkComment'
    'textarea[name="alt-talk-comment"]' : 'altTalkComment'

  events:
    'click button[id="zoom-button"]'          : 'onClickZoom'
    'click button[id="toggle-fav"]'           : 'onToggleFav'
    'click button[id="help"]'                 : 'onClickHelp'
    'click button[id="tutorial"]'             : 'onClickTutorial'
    'click button[name="no-transits"]'        : 'onClickNoTransits'
    'click button[name="next-subject"]'       : 'onClickNextSubject'
    'click button[name="finished-marking"]'   : 'onClickFinishedMarking'
    'click button[name="finished-feedback"]'  : 'onClickFinishedFeedback'
    'slide #ui-slider'                        : 'onChangeScaleSlider'
    'click button[name="join-convo"]'         : 'onClickJoinConvo'
    'click button[name="alt-join-convo"]'     : 'onClickAltJoinConvo'
    'click button[name="submit-talk"]'        : 'onClickSubmitTalk'
    'click button[name="alt-submit-talk"]'    : 'onClickSubmitTalkAlt'
    'change #course-interval'                 : 'onChangeCourseInterval'
    'change #course-interval-sup-tut'         : 'onChangeCourseIntervalViaSupTut'
    'change .supplemental-option'             : 'onChangeSupplementalOption'
    'change input[name="mini-course-option"]' : 'onChangeMiniCourseOption'
    'change input[name="course-opt-out"]'     : 'onChangeCourseOptOut'
    
    # CODE FOR PROMPT (NOT CURRENTLY IN USE)
    # 'mouseenter #course-yes-container'        : 'onMouseoverCourseYes'
    # 'mouseleave  #course-yes-container'       : 'onMouseoutCourseYes'
    
  constructor: ->
    super    

    # if mobile device detected, go to verify mode
    if window.matchMedia("(min-device-width: 320px)").matches and window.matchMedia("(max-device-width: 480px)").matches
      location.hash = "#/verify"

    window.classifier = @
    @recordedClickEvents = [] # array to store all click events

    # zoom levels [days]: 2x, 10x, 20x
    @zoomRange = 15
    @zoomRanges = []
    @zoomLevel = 0
    isZoomed: false
    ifFaved: false

    # classification counts at which to display supplementary tutorial
    @whenToDisplayTips = [1, 7] # TODO: don't forget to add 4 after beta version
    @splitDesignation = null

    User.on 'change', @onUserChange
    Subject.on 'fetch', @onSubjectFetch
    Subject.on 'select', @onSubjectSelect
    @Subject = Subject

    $(document).on 'mark-change', => @updateButtons()
    @marksContainer = @el.find('#marks-container')[0]

    @initialTutorial = new Tutorial
      parent: window.classifier.el.children()[0]
      steps: initialTutorialSteps.steps

    @supplementalTutorial = new Tutorial
      parent: window.classifier.el.children()[0]
      steps: supplementalTutorialSteps.steps

    # mini course
    @course = new MiniCourse
    @el.find('#course-interval-setter').hide()

    # @verifyRate = 20

    @el.find('#no-transits').hide() #prop('disabled',true)
    @el.find('#finished-marking').hide() #prop('disabled',true)
    @el.find('#finished-feedback').hide() #prop('disabled',true)

  # CODE FOR PROMPT (NOT CURRENTLY IN USE)    
  # /////////////////////////////////////////////////
  # onMouseoverCourseYes: ->
  #   # console.log '*** ON ***'
  #   return unless User.current?
  #   return if @blockCourseIntervalDisplay
  #   @blockCourseIntervalDisplay = true
  #   @el.find('#course-interval-setter').show 400, =>
  #     @blockCourseIntervalHide = false

  # onMouseoutCourseYes: ->
  #   return unless User.current?
  #   # console.log '*** OUT ***'
  #   return if @blockCourseIntervalHide
  #   @blockCourseIntervalHide = true
  #   @el.find('#course-interval-setter').hide 400, =>
  #     @blockCourseIntervalDisplay = false
  # /////////////////////////////////////////////////

  onChangeSupplementalOption: ->
    # console.log 'onChangeSupplementalOption(): '
    return unless User.current?

  onChangeMiniCourseOption: ->
    console.log 'onChangeMiniCourseOption(): '
    return unless User.current?

    @courseEnabled = not @courseEnabled

    if @courseEnabled
      User.current?.setPreference 'course', 'yes'
      $("[name='course-opt-out']").prop 'checked', false 
    else
      User.current?.setPreference 'course', 'no'
      $("[name='course-opt-out']").prop 'checked', true  

    clickEvent = 
      event: 'courseEnabled' 
      value: @courseEnabled 
      timestamp: (new Date).toUTCString()
    @recordedClickEvents.push clickEvent

  # onChangeMiniCourseOption: ->
  #   console.log 'onChangeMiniCourseOption(): '
  #   return unless User.current?
  #   courseOption = User.current.preferences.planet_hunter.course

  #   # toggle course option
  #   if courseOption is 'yes'
  #     courseOption = 'no'
  #     # $("[name='course-opt-out']").prop 'checked', true 
  #   else
  #     courseOption = 'yes'
  #     $("[name='course-opt-out']").prop 'checked', false  

  #   clickEvent = 
  #     event: 'miniCourseOptionChanged' 
  #     value: courseOption 
  #     timestamp: (new Date).toUTCString()
  #   @recordedClickEvents.push clickEvent

  #   User.current?.setPreference 'course', courseOption

  onChangeCourseOptOut: ->
    console.log 'onChangeCourseOptOut(): '
    return unless User.current?
    opt_out = $("[name='course-opt-out']").prop 'checked'
    if opt_out
      User.current?.setPreference 'course', 'no'
      @courseEnabled = false # TODO: needs work!
    else
      User.current?.setPreference 'course', 'yes'
      @courseEnabled = true


    clickEvent = 
      event: 'courseOptedOut' 
      value: out_out 
      timestamp: (new Date).toUTCString()
    @recordedClickEvents.push clickEvent

  # CODE FOR PROMPT (NOT CURRENTLY BEING USED)
  # onChangeCourseInterval: ->
  #   # console.log 'VALUE: ', @el.find('#course-interval').val()
  #   defaultValue = 5
  #   value = +@el.find('#course-interval').val()

  #   # console.log 'VALUE IS NUMBER: ', (typeof value)

  #   # validate integer values
  #   unless (typeof value is 'number') and (value % 1 is 0) and value > 0 and value < 100
  #     value = defaultValue<commit_msg>fix typo<commit_after>BaseController             = require 'zooniverse/controllers/base-controller'
User                       = require 'zooniverse/models/user'
Subject                    = require 'zooniverse/models/subject'
Classification             = require 'zooniverse/models/classification'
MiniCourse                 = require '../lib/mini-course'
NoUiSlider                 = require '../lib/jquery.nouislider.min'
translate                  = require 't7e'
{Tutorial}                 = require 'zootorial'
{Step}                     = require 'zootorial'
initialTutorialSteps       = require '../lib/initial-tutorial-steps'
supplementalTutorialSteps  = require '../lib/supplemental-tutorial-steps'
{CanvasGraph, Marks, Mark} = require "../lib/canvas-graph"
$ = window.jQuery

class Classifier extends BaseController
  className: 'classifier'
  template: require '../views/classifier'

  elements:
    '#zoom-button'                      : 'zoomButton'
    '#toggle-fav'                       : 'favButton'
    '#help'                             : 'helpButton'
    '#tutorial'                         : 'tutorialButton'
    'numbers-container'                 : 'numbersContainer'
    '#classify-summary'                 : 'classifySummary'
    '#comments'                         : 'comments'
    '#planet-num'                       : 'planetNum'
    '#alt-comments'                     : 'altComments'
    'button[name="no-transits"]'        : 'noTransitsButton'
    'button[name="finished-marking"]'   : 'finishedMarkingButton'
    'button[name="finished-feedback"]'  : 'finishedFeedbackButton'
    'button[name="next-subject"]'       : 'nextSubjectButton'
    'button[name="join-convo"]'         : 'joinConvoBtn'
    'button[name="alt-join-convo"]'     : 'altJoinConvoBtn'
    'textarea[name="talk-comment"]'     : 'talkComment'
    'textarea[name="alt-talk-comment"]' : 'altTalkComment'

  events:
    'click button[id="zoom-button"]'          : 'onClickZoom'
    'click button[id="toggle-fav"]'           : 'onToggleFav'
    'click button[id="help"]'                 : 'onClickHelp'
    'click button[id="tutorial"]'             : 'onClickTutorial'
    'click button[name="no-transits"]'        : 'onClickNoTransits'
    'click button[name="next-subject"]'       : 'onClickNextSubject'
    'click button[name="finished-marking"]'   : 'onClickFinishedMarking'
    'click button[name="finished-feedback"]'  : 'onClickFinishedFeedback'
    'slide #ui-slider'                        : 'onChangeScaleSlider'
    'click button[name="join-convo"]'         : 'onClickJoinConvo'
    'click button[name="alt-join-convo"]'     : 'onClickAltJoinConvo'
    'click button[name="submit-talk"]'        : 'onClickSubmitTalk'
    'click button[name="alt-submit-talk"]'    : 'onClickSubmitTalkAlt'
    'change #course-interval'                 : 'onChangeCourseInterval'
    'change #course-interval-sup-tut'         : 'onChangeCourseIntervalViaSupTut'
    'change .supplemental-option'             : 'onChangeSupplementalOption'
    'change input[name="mini-course-option"]' : 'onChangeMiniCourseOption'
    'change input[name="course-opt-out"]'     : 'onChangeCourseOptOut'
    
    # CODE FOR PROMPT (NOT CURRENTLY IN USE)
    # 'mouseenter #course-yes-container'        : 'onMouseoverCourseYes'
    # 'mouseleave  #course-yes-container'       : 'onMouseoutCourseYes'
    
  constructor: ->
    super    

    # if mobile device detected, go to verify mode
    if window.matchMedia("(min-device-width: 320px)").matches and window.matchMedia("(max-device-width: 480px)").matches
      location.hash = "#/verify"

    window.classifier = @
    @recordedClickEvents = [] # array to store all click events

    # zoom levels [days]: 2x, 10x, 20x
    @zoomRange = 15
    @zoomRanges = []
    @zoomLevel = 0
    isZoomed: false
    ifFaved: false

    # classification counts at which to display supplementary tutorial
    @whenToDisplayTips = [1, 7] # TODO: don't forget to add 4 after beta version
    @splitDesignation = null

    User.on 'change', @onUserChange
    Subject.on 'fetch', @onSubjectFetch
    Subject.on 'select', @onSubjectSelect
    @Subject = Subject

    $(document).on 'mark-change', => @updateButtons()
    @marksContainer = @el.find('#marks-container')[0]

    @initialTutorial = new Tutorial
      parent: window.classifier.el.children()[0]
      steps: initialTutorialSteps.steps

    @supplementalTutorial = new Tutorial
      parent: window.classifier.el.children()[0]
      steps: supplementalTutorialSteps.steps

    # mini course
    @course = new MiniCourse
    @el.find('#course-interval-setter').hide()

    # @verifyRate = 20

    @el.find('#no-transits').hide() #prop('disabled',true)
    @el.find('#finished-marking').hide() #prop('disabled',true)
    @el.find('#finished-feedback').hide() #prop('disabled',true)

  # CODE FOR PROMPT (NOT CURRENTLY IN USE)    
  # /////////////////////////////////////////////////
  # onMouseoverCourseYes: ->
  #   # console.log '*** ON ***'
  #   return unless User.current?
  #   return if @blockCourseIntervalDisplay
  #   @blockCourseIntervalDisplay = true
  #   @el.find('#course-interval-setter').show 400, =>
  #     @blockCourseIntervalHide = false

  # onMouseoutCourseYes: ->
  #   return unless User.current?
  #   # console.log '*** OUT ***'
  #   return if @blockCourseIntervalHide
  #   @blockCourseIntervalHide = true
  #   @el.find('#course-interval-setter').hide 400, =>
  #     @blockCourseIntervalDisplay = false
  # /////////////////////////////////////////////////

  onChangeSupplementalOption: ->
    # console.log 'onChangeSupplementalOption(): '
    return unless User.current?

  onChangeMiniCourseOption: ->
    console.log 'onChangeMiniCourseOption(): '
    return unless User.current?

    @courseEnabled = not @courseEnabled

    if @courseEnabled
      User.current?.setPreference 'course', 'yes'
      $("[name='course-opt-out']").prop 'checked', false 
    else
      User.current?.setPreference 'course', 'no'
      $("[name='course-opt-out']").prop 'checked', true  

    clickEvent = 
      event: 'courseEnabled' 
      value: @courseEnabled 
      timestamp: (new Date).toUTCString()
    @recordedClickEvents.push clickEvent

  # onChangeMiniCourseOption: ->
  #   console.log 'onChangeMiniCourseOption(): '
  #   return unless User.current?
  #   courseOption = User.current.preferences.planet_hunter.course

  #   # toggle course option
  #   if courseOption is 'yes'
  #     courseOption = 'no'
  #     # $("[name='course-opt-out']").prop 'checked', true 
  #   else
  #     courseOption = 'yes'
  #     $("[name='course-opt-out']").prop 'checked', false  

  #   clickEvent = 
  #     event: 'miniCourseOptionChanged' 
  #     value: courseOption 
  #     timestamp: (new Date).toUTCString()
  #   @recordedClickEvents.push clickEvent

  #   User.current?.setPreference 'course', courseOption

  onChangeCourseOptOut: ->
    console.log 'onChangeCourseOptOut(): '
    return unless User.current?
    opt_out = $("[name='course-opt-out']").prop 'checked'
    if opt_out
      User.current?.setPreference 'course', 'no'
      @courseEnabled = false # TODO: needs work!
    else
      User.current?.setPreference 'course', 'yes'
      @courseEnabled = true


    clickEvent = 
      event: 'courseOptedOut' 
      value: opt_out 
      timestamp: (new Date).toUTCString()
    @recordedClickEvents.push clickEvent

  # CODE FOR PROMPT (NOT CURRENTLY BEING USED)
  # onChangeCourseInterval: ->
  #   # console.log 'VALUE: ', @el.find('#course-interval').val()
  #   defaultValue = 5
  #   value = +@el.find('#course-interval').val()

  #   # console.log 'VALUE IS NUMBER: ', (typeof value)

  #   # validate integer values
  #   unless (typeof value is 'number') and (value % 1 is 0) and value > 0 and value < 100
  #     value = defaultValue
{'fraction_non_alphanumeric': 0.1466522265401032, 'fraction_numerical': 0.004586863731923297, 'mean_word_length': 2.6287563569116967, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '105739', 'n_tokens_mistral': 4921, 'n_tokens_neox': 4642, 'n_words': 902}