<commit_before>_ = require 'underscore'
flux = require 'flux-react'
{CrudConfig, makeSimpleStore, extendConfig} = require './helpers'
TaggingMixin = require './tagging-mixin'


VocabularyConfig = {

  _asyncStatusPublish: {}

  _loaded: (obj, exerciseId) -> @emit('loaded', exerciseId)

  _created:(obj, id) ->
    @emit('created', obj.uid)

  createBlank: (id) ->
    template = @exports.getTemplate.call(@)
    @loaded(template, id)

  updateDistractor: (id, oldValue, newValue) ->
    distractor_literals = @_get(id).distractor_literals
    index = _.indexOf distractor_literals, oldValue
    if -1 is index
      distractor_literals.push(newValue)
    else
      distractor_literals[index] = newValue
    @_change(id, {distractor_literals})

  change: (id, attrs) ->
    @_change(id, attrs)

  addBlankDistractor: (id) ->
    distractor_literals = _.clone(@_get(id).distractor_literals)
    distractor_literals.push('')
    @_change(id, {distractor_literals})

  publish: (id) ->
    @_asyncStatusPublish[id] = true
    @emitChange()

  published: (obj, id) ->
    @_asyncStatusPublish[id] = false
    @emit('published', id)
    @saved(obj, id)

  exports:
    getTemplate: (id) ->
      distractor_literals: []
      tags: []

    hasExercise: (id) -> @_get(id)?.exercise_uids?.length

    getExerciseIds: (id) -> @_get(id)?.exercise_uids

    isSavable: (id) ->
      @exports.isChanged.call(@, id) and
        @exports.validate.call(@, id).valid and
        not @exports.isSaving.call(@, id) and
        not @exports.isPublishing.call(@, id)

    isPublished: (id) -> !!@_get(id)?.published_at

    isPublishing: (id) -> !!@_asyncStatusPublish[id]

    isPublishable: (id) ->
      @exports.validate.call(@, id).valid and
        not @exports.isChanged.call(@, id) and
        not @exports.isSaving.call(@, id) and
        not @exports.isPublishing.call(@, id) and
        not @_get(id)?.published_at

    validate: (id) ->
      return {valid: false, part: 'vocab'} unless @_get(id)
      valid: true<commit_msg>adding in default tags for new vocab exercises<commit_after>_ = require 'underscore'
flux = require 'flux-react'
{CrudConfig, makeSimpleStore, extendConfig} = require './helpers'
TaggingMixin = require './tagging-mixin'


VocabularyConfig = {

  _asyncStatusPublish: {}

  _loaded: (obj, exerciseId) -> @emit('loaded', exerciseId)

  _created:(obj, id) ->
    @emit('created', obj.uid)

  createBlank: (id) ->
    template = @exports.getTemplate.call(@)
    @loaded(template, id)

  updateDistractor: (id, oldValue, newValue) ->
    distractor_literals = @_get(id).distractor_literals
    index = _.indexOf distractor_literals, oldValue
    if -1 is index
      distractor_literals.push(newValue)
    else
      distractor_literals[index] = newValue
    @_change(id, {distractor_literals})

  change: (id, attrs) ->
    @_change(id, attrs)

  addBlankDistractor: (id) ->
    distractor_literals = _.clone(@_get(id).distractor_literals)
    distractor_literals.push('')
    @_change(id, {distractor_literals})

  publish: (id) ->
    @_asyncStatusPublish[id] = true
    @emitChange()

  published: (obj, id) ->
    @_asyncStatusPublish[id] = false
    @emit('published', id)
    @saved(obj, id)

  exports:
    getTemplate: (id) ->
      distractor_literals: []
      tags: ['dok:1', 'blooms:1', 'time:short']

    hasExercise: (id) -> @_get(id)?.exercise_uids?.length

    getExerciseIds: (id) -> @_get(id)?.exercise_uids

    isSavable: (id) ->
      @exports.isChanged.call(@, id) and
        @exports.validate.call(@, id).valid and
        not @exports.isSaving.call(@, id) and
        not @exports.isPublishing.call(@, id)

    isPublished: (id) -> !!@_get(id)?.published_at

    isPublishing: (id) -> !!@_asyncStatusPublish[id]

    isPublishable: (id) ->
      @exports.validate.call(@, id).valid and
        not @exports.isChanged.call(@, id) and
        not @exports.isSaving.call(@, id) and
        not @exports.isPublishing.call(@, id) and
        not @_get(id)?.published_at

    validate: (id) ->
      return {valid: false, part: 'vocab'} unless @_get(id)
      valid: true
{'fraction_non_alphanumeric': 0.15367754505601558, 'fraction_numerical': 0.000974184120798831, 'mean_word_length': 3.3414376321353068, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '942843', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1420, 'n_words': 287}