<commit_before>class Cu.Model.View extends Backbone.RelationalModel
  Cu.Boxable.mixin this

  idAttribute: 'box'
  relations: [
    {
      type: Backbone.HasOne
      key: 'tool'
      relatedModel: Cu.Model.Tool
      includeInJSON: 'name'
    }
  ]

  url: ->
    datasetId = @get('plugsInTo').get('box')
    if @isNew()
      "/api/#{window.user.effective.shortName}/datasets/#{datasetId}/views"
    else
      "/api/#{window.user.effective.shortName}/datasets/#{datasetId}/views/#{@get 'box'}"

  isVisible: ->
    @get('state') isnt 'deleted'

Cu.Model.View.setup()

class Cu.Collection.ViewList extends Backbone.Collection
  model: Cu.Model.View
  url: -> "/api/#{window.user.effective.shortName}/views"

  findById: (id) ->
    views = @find (t) -> t.id is id

  # returns first match
  findByToolName: (name, callback) ->
    tool = app.tools().findByName name
    callback @find (view) ->
      tool is tool and view.get('state') isnt 'deleted'

  visible: ->
    visibles = @filter (t) -> t.isVisible()
    new Cu.Collection.ViewList visibles

  comparator: (model) ->
    model.get 'displayName'
<commit_msg>fix default tool selection<commit_after>class Cu.Model.View extends Backbone.RelationalModel
  Cu.Boxable.mixin this

  idAttribute: 'box'
  relations: [
    {
      type: Backbone.HasOne
      key: 'tool'
      relatedModel: Cu.Model.Tool
      includeInJSON: 'name'
    }
  ]

  url: ->
    datasetId = @get('plugsInTo').get('box')
    if @isNew()
      "/api/#{window.user.effective.shortName}/datasets/#{datasetId}/views"
    else
      "/api/#{window.user.effective.shortName}/datasets/#{datasetId}/views/#{@get 'box'}"

  isVisible: ->
    @get('state') isnt 'deleted'

Cu.Model.View.setup()

class Cu.Collection.ViewList extends Backbone.Collection
  model: Cu.Model.View
  url: -> "/api/#{window.user.effective.shortName}/views"

  findById: (id) ->
    views = @find (t) -> t.id is id

  # returns first match
  findByToolName: (name, callback) ->
    tool = app.tools().findByName name
    callback @find (view) ->
      view.get('tool') is tool and view.get('state') isnt 'deleted'

  visible: ->
    visibles = @filter (t) -> t.isVisible()
    new Cu.Collection.ViewList visibles

  comparator: (model) ->
    model.get 'displayName'

{'fraction_non_alphanumeric': 0.15747684164093514, 'fraction_numerical': 0.0, 'mean_word_length': 3.0141592920353983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '1336048', 'n_tokens_mistral': 779, 'n_tokens_neox': 770, 'n_words': 159}