<commit_before>require('app/styles/teachers/teacher-student-view.sass')
RootView = require 'views/core/RootView'
Campaigns = require 'collections/Campaigns'
Classroom = require 'models/Classroom'
State = require 'models/State'
Courses = require 'collections/Courses'
Levels = require 'collections/Levels'
LevelSession = require 'models/LevelSession'
LevelSessions = require 'collections/LevelSessions'
User = require 'models/User'
Users = require 'collections/Users'
CourseInstances = require 'collections/CourseInstances'
require 'd3/d3.js'
utils = require 'core/utils'
aceUtils = require 'core/aceUtils'
fullPageTemplate = require 'templates/teachers/teacher-student-view-full'
viewTemplate = require 'templates/teachers/teacher-student-view'

module.exports = class TeacherStudentView extends RootView
  id: 'teacher-student-view'

  events:
    'change #course-dropdown': 'onChangeCourseChart'
    'change .course-select': 'onChangeCourseSelect'
    'click .progress-dot a': 'onClickProgressDot'
    'click .level-progress-dot': 'onClickStudentProgressDot'
    'click .nav-link': 'onClickSolutionTab'

  getMeta: -> { title: "#{$.i18n.t('teacher.student_profile')} | #{me?.broadName()} | #{$.i18n.t('common.ozaria')}" }
  
  onClickSolutionTab: (e) ->
    link = $(e.target).closest('a')
    levelSlug = link.data('level-slug')
    solutionIndex = link.data('solution-index')
    tracker.trackEvent('Click Teacher Student Solution Tab', {levelSlug, solutionIndex})

  initialize: (options, classroomID, @studentID) ->
    @state = new State({
      'renderOnlyContent': options.renderOnlyContent
    })

    if (options.renderOnlyContent)
      @template = viewTemplate
    else
      @template = fullPageTemplate

    @classroom = new Classroom({_id: classroomID})
    @listenToOnce @classroom, 'sync', @onClassroomSync
    @supermodel.trackRequest(@classroom.fetch())

    if @studentID
      @user = new User({ _id: @studentID })
      @supermodel.trackRequest(@user.fetch())

    @courses = new Courses()
    @supermodel.trackRequest(@courses.fetch({data: { project: 'name,i18n,slug' }}))

    @courseInstances = new CourseInstances()
    @supermodel.trackRequest @courseInstances.fetchForClassroom(classroomID)

    # TODO: fetch only necessary thang data (i.e. levels with student progress, via separate API instead of complicated data.project values)
    @levels = new Levels()
    @supermodel.trackRequest(@levels.fetchForClassroom(classroomID, {data: {project: 'name,displayName,original,i18n,primerLanguage,thangs.id,thangs.components.config.programmableMethods.plan.solutions,thangs.components.config.programmableMethods.plan.context'}}))
    @urls = require('core/urls')

    # wrap templates so they translate when called
    translateTemplateText = (template, context) => $('<div />').html(template(context)).i18n().html()
    @singleStudentLevelProgressDotTemplate = _.wrap(require('templates/teachers/hovers/progress-dot-single-student-level'), translateTemplateText)
    @levelProgressMap = {}
    me.getClientCreatorPermissions()?.then(() => @render?())
    super(options)

  onLoaded: ->
    @selectedCourseId = @courses.first().id if @courses.loaded and @courses.length > 0 and not @selectedCourseId
    if @students.loaded and not @destroyed
      @user = _.find(@students.models, (s)=> s.id is @studentID)
      @updateLastPlayedInfo()
      @updateLevelProgressMap()
      @updateLevelDataMap()<commit_msg>:bug: Set student name on student page title instead of logged in user (#177)<commit_after>require('app/styles/teachers/teacher-student-view.sass')
RootView = require 'views/core/RootView'
Campaigns = require 'collections/Campaigns'
Classroom = require 'models/Classroom'
State = require 'models/State'
Courses = require 'collections/Courses'
Levels = require 'collections/Levels'
LevelSession = require 'models/LevelSession'
LevelSessions = require 'collections/LevelSessions'
User = require 'models/User'
Users = require 'collections/Users'
CourseInstances = require 'collections/CourseInstances'
require 'd3/d3.js'
utils = require 'core/utils'
aceUtils = require 'core/aceUtils'
fullPageTemplate = require 'templates/teachers/teacher-student-view-full'
viewTemplate = require 'templates/teachers/teacher-student-view'

module.exports = class TeacherStudentView extends RootView
  id: 'teacher-student-view'

  events:
    'change #course-dropdown': 'onChangeCourseChart'
    'change .course-select': 'onChangeCourseSelect'
    'click .progress-dot a': 'onClickProgressDot'
    'click .level-progress-dot': 'onClickStudentProgressDot'
    'click .nav-link': 'onClickSolutionTab'

  getMeta: -> { title: "#{$.i18n.t('teacher.student_profile')} | #{$.i18n.t('common.ozaria')}" }
  
  onClickSolutionTab: (e) ->
    link = $(e.target).closest('a')
    levelSlug = link.data('level-slug')
    solutionIndex = link.data('solution-index')
    tracker.trackEvent('Click Teacher Student Solution Tab', {levelSlug, solutionIndex})

  initialize: (options, classroomID, @studentID) ->
    @state = new State({
      'renderOnlyContent': options.renderOnlyContent
    })

    if (options.renderOnlyContent)
      @template = viewTemplate
    else
      @template = fullPageTemplate

    @classroom = new Classroom({_id: classroomID})
    @listenToOnce @classroom, 'sync', @onClassroomSync
    @supermodel.trackRequest(@classroom.fetch())

    if @studentID
      @user = new User({ _id: @studentID })
      @supermodel.trackRequest(@user.fetch())

    @courses = new Courses()
    @supermodel.trackRequest(@courses.fetch({data: { project: 'name,i18n,slug' }}))

    @courseInstances = new CourseInstances()
    @supermodel.trackRequest @courseInstances.fetchForClassroom(classroomID)

    # TODO: fetch only necessary thang data (i.e. levels with student progress, via separate API instead of complicated data.project values)
    @levels = new Levels()
    @supermodel.trackRequest(@levels.fetchForClassroom(classroomID, {data: {project: 'name,displayName,original,i18n,primerLanguage,thangs.id,thangs.components.config.programmableMethods.plan.solutions,thangs.components.config.programmableMethods.plan.context'}}))
    @urls = require('core/urls')

    # wrap templates so they translate when called
    translateTemplateText = (template, context) => $('<div />').html(template(context)).i18n().html()
    @singleStudentLevelProgressDotTemplate = _.wrap(require('templates/teachers/hovers/progress-dot-single-student-level'), translateTemplateText)
    @levelProgressMap = {}
    me.getClientCreatorPermissions()?.then(() => @render?())
    super(options)

  onLoaded: ->
    @selectedCourseId = @courses.first().id if @courses.loaded and @courses.length > 0 and not @selectedCourseId
    if @students.loaded and not @destroyed
      @user = _.find(@students.models, (s)=> s.id is @studentID)
      @setMeta({ title: "#{$.i18n.t('teacher.student_profile')} | #{@user.broadName()} | #{$.i18n.t('common.ozaria')}" })
      @updateLastPlayedInfo()
      @updateLevelProgressMap()
      @updateLevelDataMap()
{'fraction_non_alphanumeric': 0.1365381880244631, 'fraction_numerical': 0.0046935002133409185, 'mean_word_length': 4.879598662207358, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '2263436', 'n_tokens_mistral': 2178, 'n_tokens_neox': 2120, 'n_words': 432}