<commit_before>require('app/styles/teachers/markdown-resource-view.sass')
RootView = require 'views/core/RootView'
api = require 'core/api'
ace = require('lib/aceContainer')
aceUtils = require 'core/aceUtils'
APCSPLanding = require('./APCSPLanding').default

module.exports = class DynamicAPCSPView extends RootView
  id: 'dynamic-apcsp-view'
  template: require 'app/templates/teachers/dynamic-apcsp-view'

  getMeta: ->
    title: $.i18n.t 'apcsp.title'
    meta: [
      { vmid: 'meta-description', name: 'description', content: $.i18n.t 'apcsp.meta_description' }
    ]

  initialize: (options, @name) ->
    super(options)
    @name ?= 'index'
    @content = ''
    @loadingData = true
    me.getClientCreatorPermissions()?.then(() => @render?())
    unless @cannotAccess()
      if _.string.startsWith(@name, 'markdown/')
        unless _.string.endsWith(@name, '.md')
          @name = @name + '.md'
        promise = api.markdown.getMarkdownFile(@name.replace('markdown/', ''))
      else
        promise = api.apcsp.getAPCSPFile(@name)

      promise.then((data) =>
        @content = marked(data, sanitize: false)
        @loadingData = false
        @render()
      ).catch((error) =>
        @loadingData = false
        if error.code is 404
          @notFound = true
          @render()
        else
          console.error(error)
          @error = error.message
          @render()
      )

  cannotAccess: ->
    return me.isAnonymous() or !me.isTeacher() or !me.get('verifiedTeacher')

  afterRender: ->
    super()
    if @cannotAccess()
      new APCSPLanding({
        el: @$('#apcsp-landing')[0]
      })<commit_msg>Make APCSP available without gate<commit_after>require('app/styles/teachers/markdown-resource-view.sass')
RootView = require 'views/core/RootView'
api = require 'core/api'
ace = require('lib/aceContainer')
aceUtils = require 'core/aceUtils'
APCSPLanding = require('./APCSPLanding').default

module.exports = class DynamicAPCSPView extends RootView
  id: 'dynamic-apcsp-view'
  template: require 'app/templates/teachers/dynamic-apcsp-view'

  getMeta: ->
    title: $.i18n.t 'apcsp.title'
    meta: [
      { vmid: 'meta-description', name: 'description', content: $.i18n.t 'apcsp.meta_description' }
    ]

  initialize: (options, @name) ->
    super(options)
    @name ?= 'index'
    @content = ''
    @loadingData = true
    me.getClientCreatorPermissions()?.then(() => @render?())
    unless @cannotAccess()
      if _.string.startsWith(@name, 'markdown/')
        unless _.string.endsWith(@name, '.md')
          @name = @name + '.md'
        promise = api.markdown.getMarkdownFile(@name.replace('markdown/', ''))
      else
        promise = api.apcsp.getAPCSPFile(@name)

      promise.then((data) =>
        @content = marked(data, sanitize: false)
        @loadingData = false
        @render()
      ).catch((error) =>
        @loadingData = false
        if error.code is 404
          @notFound = true
          @render()
        else
          console.error(error)
          @error = error.message
          @render()
      )

  cannotAccess: ->
    return false # me.isAnonymous() or !me.isTeacher() or !me.get('verifiedTeacher')

  afterRender: ->
    super()
    if @cannotAccess()
      new APCSPLanding({
        el: @$('#apcsp-landing')[0]
      })
{'fraction_non_alphanumeric': 0.15223970944309928, 'fraction_numerical': 0.004842615012106538, 'mean_word_length': 2.6927374301675977, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '4217585', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1055, 'n_words': 207}