<commit_before>class ClassroomAppView extends KDScrollView

  constructor: (options = {}, data) ->

    options.cssClass = "classroom-app-view"

    super options, data

    @cdnRoot     = "http://fatihacet.kd.io/cdn/courses"
    @appStorage  = new AppStorage "Classroom", "1.0"

    @emit "ready"

  fetchCourses: ->
    @appStorage.fetchStorage (storage) =>
      @enrolledCourses    = @appStorage.getValue("EnrolledCourses") or []
      @relatedCourses     = []
      enrolledCourseNames = []

      enrolledCourseNames.push enrolled.name for enrolled in @enrolledCourses

      for courseDetails in @getPredefinedCourses()
        courseName = courseDetails.name
        if @enrolledCourses.length is 0 or enrolledCourseNames.indexOf(courseName) is -1
          @relatedCourses.push courseDetails

      @addSubView @coursesView = new ClassroomCoursesView
        delegate : this
      ,
        enrolled : @enrolledCourses
        related  : @relatedCourses

  createHeader: ->
    @addSubView @header = new KDView
      cssClass : "container"
      partial  : """
        <div class="banner">
          <h1>&lt;classroom /&gt;</h1>
          <h2>Start learning, teaching and sharing together. <br /> It's your classroom and it's online and it's free!</h2>
          <img src="http://hindiurduflagship.org/wp-content/uploads/2010/11/ImportanceVideoThumbnail.jpg" />
        </div>
      """

  enrollToCourse: (courseData) ->
    @enrolledCourses.push courseData
    @appStorage.setValue "EnrolledCourses", @enrolledCourses

  cancelEnrollment: (courseData) ->
    pos = i for enrolled, i in @enrolledCourses when enrolled.name is courseData.name
    @enrolledCourses.splice pos, 1
    @appStorage.setValue "EnrolledCourses", @enrolledCourses
    if @coursesView.enrolledContainer.getSubViews().length is 1
      @coursesView.noEnrolledCourse.show()

  goToCourse: (courseName, callback = noop) ->
    @readFileContent "/#{courseName}.kdcourse/manifest.json", (manifest) =>
      manifest.startWithSplashView = yes
      @createCoursesView manifest
      callback()

  goToChapter: ->
    log "handle go to chapter"

  createCoursesView: (manifest) ->
    @addSubView new ClassroomCourseView { delegate: this }, manifest

  handleQuery: (query) ->
    @destroySubViews()
    unless query.course
      @createHeader()
      @fetchCourses()
    else
      if query.chapter
        @goToChapter query.course, query.chapter
      else
        @goToCourse query.course

  getPredefinedCourses: ->
    [
      {
        devMode    : true
        version    : "0.1"
        name       : "CoffeeScript"
        author     : "<NAME>"
        authorNick : "fatihacet"<commit_msg>Classroom: Implemented goToChapter.<commit_after>class ClassroomAppView extends KDScrollView

  constructor: (options = {}, data) ->

    options.cssClass = "classroom-app-view"

    super options, data

    @cdnRoot     = "http://fatihacet.kd.io/cdn/courses"
    @appStorage  = new AppStorage "Classroom", "1.0"

    @emit "ready"

  fetchCourses: ->
    @appStorage.fetchStorage (storage) =>
      @enrolledCourses    = @appStorage.getValue("EnrolledCourses") or []
      @relatedCourses     = []
      enrolledCourseNames = []

      enrolledCourseNames.push enrolled.name for enrolled in @enrolledCourses

      for courseDetails in @getPredefinedCourses()
        courseName = courseDetails.name
        if @enrolledCourses.length is 0 or enrolledCourseNames.indexOf(courseName) is -1
          @relatedCourses.push courseDetails

      @addSubView @coursesView = new ClassroomCoursesView
        delegate : this
      ,
        enrolled : @enrolledCourses
        related  : @relatedCourses

  createHeader: ->
    @addSubView @header = new KDView
      cssClass : "container"
      partial  : """
        <div class="banner">
          <h1>&lt;classroom /&gt;</h1>
          <h2>Start learning, teaching and sharing together. <br /> It's your classroom and it's online and it's free!</h2>
          <img src="http://hindiurduflagship.org/wp-content/uploads/2010/11/ImportanceVideoThumbnail.jpg" />
        </div>
      """

  enrollToCourse: (courseData) ->
    @enrolledCourses.push courseData
    @appStorage.setValue "EnrolledCourses", @enrolledCourses

  cancelEnrollment: (courseData) ->
    pos = i for enrolled, i in @enrolledCourses when enrolled.name is courseData.name
    @enrolledCourses.splice pos, 1
    @appStorage.setValue "EnrolledCourses", @enrolledCourses
    if @coursesView.enrolledContainer.getSubViews().length is 1
      @coursesView.noEnrolledCourse.show()

  goToCourse: (courseName, callback = noop) ->
    @readFileContent "/#{courseName}.kdcourse/manifest.json", (@manifest) =>
      manifest.startWithSplashView = yes
      @createCoursesView manifest
      callback()

  goToChapter: (courseName, chapter) ->
    if @manifest
      @handleGoToChapter chapter
    else
      @readFileContent "/#{courseName}.kdcourse/manifest.json", (@manifest) =>
        @handleGoToChapter chapter

  handleGoToChapter: (chapterIndex) ->
    courseManifest   = @manifest
    {chapters}       = courseManifest
    return unless chapters

    configFilePath = chapters[chapterIndex].resourcesPath
    @readFileContent "/#{courseManifest.name}.kdcourse/#{configFilePath}", (config) =>
      new ClassroomChapterView { container: @ }, { config, courseManifest }

  createCoursesView: (manifest) ->
    @addSubView new ClassroomCourseView { delegate: this }, manifest

  handleQuery: (query) ->
    @destroySubViews()
    unless query.course
      @createHeader()
      @fetchCourses()
    else
      if query.chapter
        @goToChapter query.course, query.chapter
      else
        @goToCourse query.course

  getPredefinedCourses: ->
    [
      {
        devMode    : true
        version    : "0.1"
        name       : "CoffeeScript"
        author     : "<NAME>"
        authorNick : "fatihacet"
{'fraction_non_alphanumeric': 0.10737913486005089, 'fraction_numerical': 0.0061068702290076335, 'mean_word_length': 2.876397107166338, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 48, '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': '6817449', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1733, 'n_words': 379}