import ComboBox from 'compiled/widget/ComboBox'
import StudentInCourseRouter from '../StudentInCourse/StudentInCourseRouter'

// #
// A combobox representing the possible filters for the department view.
export default class StudentComboBox extends ComboBox {
  constructor(model) {
    {
      // Hack: trick Babel/TypeScript into allowing this before super.
      if (false) { super(); }
      let thisFn = (() => { return this; }).toString();
      let thisName = thisFn.match(/_this\d*/)[0];
      eval(`${thisName} = this;`);
    }

    this.model = model
    this.router = new StudentInCourseRouter(this.model)

    // construct combobox
    super(this.model.get('course').get('students').models, {
      value: student => student.get('id'),
      label: student => student.get('name'),
      selected: this.model.get('student').get('id')
    })

    // connect combobox to model
    this.on('change', this.push)
    this.model.on('change:student', this.pull)
  }

  // #
  // Push the current value of the combobox to the URL
  push = student => this.router.select(student.get('id'))

  // #
  // Pull the current value from the model to the combobox
  pull = () => this.select(this.model.get('student').get('id'))
}

import ComboBox from 'compiled/widget/ComboBox'
import StudentInCourseRouter from '../StudentInCourse/StudentInCourseRouter'

// #
// A combobox representing the possible filters for the department view.
export default class StudentComboBox extends ComboBox {
  constructor(model) {
    // construct combobox
    super(model.get('course').get('students').models, {
      value: student => student.get('id'),
      label: student => student.get('name'),
      selected: model.get('student').get('id')
    })
    this.model = model
    this.router = new StudentInCourseRouter(this.model)

    // connect combobox to model
    this.on('change', this.push)
    this.model.on('change:student', this.pull)
  }

  // #
  // Push the current value of the combobox to the URL
  push = student => this.router.select(student.get('id'))

  // #
  // Pull the current value from the model to the combobox
  pull = () => this.select(this.model.get('student').get('id'))
}

Remove another “trick babel” hack in analytics
Remove another “trick babel” hack in analytics

Test plan
* with or without the “Drop IE 11” commit applied
* bin/rspec ./gems/plugins/analytics/spec_canvas/selenium/analytics_spec.rb:250
  Should pass

Or to test manually:
* apply the “drop ie11” commit in canvas-lms
* check out this commit in gems/plugins/analytics
* go to /courses/x/analytics/users/y
* it should load successfully and not die on this error at page load:
  “Uncaught TypeError: Cannot read property '0' of null”

Change-Id: I3b7d098d2b6c1d13f3d623b366d591ac68778e7d
Reviewed-on: https://gerrit.instructure.com/204099
Reviewed-by: Steven Burnett <a0b450117c5d20a22d5c4d52bb8ae13adee003d8@instructure.com>
QA-Review: Steven Burnett <a0b450117c5d20a22d5c4d52bb8ae13adee003d8@instructure.com>
Tested-by: Jenkins
Product-Review: Ryan Shaw <ea3cd978650417470535f3a4725b6b5042a6ab59@instructure.com>
