<commit_before>#
# Copyright (C) 2012 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#

define [
  'i18n!outcomes'
  'jquery'
  'underscore'
  'Backbone'
  '../../models/Outcome'
  '../../models/OutcomeGroup'
  './OutcomesDirectoryView'
  './FindDirectoryView'
], (I18n, $, _, Backbone, Outcome, OutcomeGroup, OutcomesDirectoryView, FindDirectoryView) ->

  findDialog = undefined

  # Manages the directory views.
  class SidebarView extends Backbone.View

    directoryWidth: 200
    entryHeight: 30

    events:
      'click .outcome-level': 'clickOutcomeLevel'

    # options must include rootOutcomeGroup or directoryView
    initialize: (opts) ->
      super
      @inFindDialog = opts.inFindDialog
      @readOnly = opts.readOnly
      @selectFirstItem = opts.selectFirstItem
      @directories = []
      @cachedDirectories = {}
      @$sidebar = @$el.parent()
      @$sidebar.width @directoryWidth
      if @rootOutcomeGroup = opts.rootOutcomeGroup
        @addDirFor @rootOutcomeGroup
      else
        @addDir opts.directoryView
      @render()

    clickOutcomeLevel: (e) ->
      clickedOutside = e.target is e.currentTarget
      return unless clickedOutside
      dir = $(e.target).data 'view'
      @selectDir dir

    resetSidebar: () =>
      _.each @directories, (d) -> d.remove()
      @directories = []
      @cachedDirectories = {}
      @addDirFor @rootOutcomeGroup

    # Adds a directory view for an outcome group.
    # Returns the directory view.
    addDirFor: (outcomeGroup) ->
      if @cachedDirectories[outcomeGroup.id]
        dir = @cachedDirectories[outcomeGroup.id]
      else
        parent = _.last @directories
        directoryClass = outcomeGroup.get('directoryClass') || OutcomesDirectoryView
        i = _.indexOf @directories, @selectedDir()
        dir = new directoryClass {outcomeGroup, parent, @readOnly, selectFirstItem: @selectFirstItem, inFindDialog: @inFindDialog, directoryDepth: i + 1}
        @firstDir = false
      @addDir dir

    # Adds a directory view.
    # Returns the directory view.
    addDir: (dir) ->
      @cachedDirectories[dir.outcomeGroup.id] = dir if dir.outcomeGroup
      dir.off 'select'
      dir.on 'select', @selectDir
      dir.sidebar = this
      dir.clearSelection()
      @directories.push dir
      @updateSidebarWidth()
      @renderDir dir
      dir

    # Insert and select a newly created/imported outcome or group.
    addAndSelect: (model) =>
      # verify outcomeGroup is set
      if model instanceof Outcome
        model.outcomeGroup = @selectedGroup().toJSON()
      else
        model.set 'parent_outcome_group', @selectedGroup().toJSON()

      # add to collection
      dir = @_findLastDir (d) -> ! d.selectedModel or d.selectedModel instanceof Outcome<commit_msg>only select first item in outcomes browser if loading root groups<commit_after>#
# Copyright (C) 2012 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#

define [
  'i18n!outcomes'
  'jquery'
  'underscore'
  'Backbone'
  '../../models/Outcome'
  '../../models/OutcomeGroup'
  './OutcomesDirectoryView'
  './FindDirectoryView'
], (I18n, $, _, Backbone, Outcome, OutcomeGroup, OutcomesDirectoryView, FindDirectoryView) ->

  findDialog = undefined

  # Manages the directory views.
  class SidebarView extends Backbone.View

    directoryWidth: 200
    entryHeight: 30

    events:
      'click .outcome-level': 'clickOutcomeLevel'

    # options must include rootOutcomeGroup or directoryView
    initialize: (opts) ->
      super
      @inFindDialog = opts.inFindDialog
      @readOnly = opts.readOnly
      @selectFirstItem = opts.selectFirstItem
      @directories = []
      @cachedDirectories = {}
      @$sidebar = @$el.parent()
      @$sidebar.width @directoryWidth
      if @rootOutcomeGroup = opts.rootOutcomeGroup
        @addDirFor @rootOutcomeGroup, true
      else
        @addDir opts.directoryView
      @render()

    clickOutcomeLevel: (e) ->
      clickedOutside = e.target is e.currentTarget
      return unless clickedOutside
      dir = $(e.target).data 'view'
      @selectDir dir

    resetSidebar: () =>
      _.each @directories, (d) -> d.remove()
      @directories = []
      @cachedDirectories = {}
      @addDirFor @rootOutcomeGroup, true

    # Adds a directory view for an outcome group.
    # Returns the directory view.
    addDirFor: (outcomeGroup, isRoot = false) ->
      if @cachedDirectories[outcomeGroup.id]
        dir = @cachedDirectories[outcomeGroup.id]
      else
        parent = _.last @directories
        directoryClass = outcomeGroup.get('directoryClass') || OutcomesDirectoryView
        i = _.indexOf @directories, @selectedDir()
        dir = new directoryClass {outcomeGroup, parent, @readOnly, selectFirstItem: isRoot && @selectFirstItem, inFindDialog: @inFindDialog, directoryDepth: i + 1}
        @firstDir = false
      @addDir dir

    # Adds a directory view.
    # Returns the directory view.
    addDir: (dir) ->
      @cachedDirectories[dir.outcomeGroup.id] = dir if dir.outcomeGroup
      dir.off 'select'
      dir.on 'select', @selectDir
      dir.sidebar = this
      dir.clearSelection()
      @directories.push dir
      @updateSidebarWidth()
      @renderDir dir
      dir

    # Insert and select a newly created/imported outcome or group.
    addAndSelect: (model) =>
      # verify outcomeGroup is set
      if model instanceof Outcome
        model.outcomeGroup = @selectedGroup().toJSON()
      else
        model.set 'parent_outcome_group', @selectedGroup().toJSON()

      # add to collection
      dir = @_findLastDir (d) -> ! d.selectedModel or d.selectedModel instanceof Outcome
{'fraction_non_alphanumeric': 0.09534951740274934, 'fraction_numerical': 0.004387247733255338, 'mean_word_length': 2.994742990654206, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6535145', 'n_tokens_mistral': 1971, 'n_tokens_neox': 1920, 'n_words': 616}