<commit_before>class ResourcesController extends KDListViewController

  constructor:(options = {}, data)->
    options       = $.extend
      view        : new ResourcesView
      wrapper     : no
      scrollView  : no
    , options

    super options, data

    @getView().on 'DeselectAllItems', @bound 'deselectAllItems'
    KD.getSingleton("vmController").on 'VMListChanged', @bound 'reset'

  reset:->
    # FIXME ~ BK
    # cmp = (a, b)->
    #   [groupA, vmA] = a.split('~')
    #   [groupB, vmB] = b.split('~')
    #   if groupA is groupB
    #   then vmA    > vmB
    #   else groupA > groupB

    finder = KD.getSingleton('finderController')
    finder.emit 'EnvironmentsTabHide'

    @removeAllItems()

    vmController = KD.getSingleton("vmController")
    vmController.resetVMData()
    vmController.fetchVMs (err, vms)=>
      log "Found these vms:", err, vms
      return  unless vms
      # vms.sort cmp
      stack   = []
      vms.forEach (hostname)=>
        group = hostname.replace('.kd.io','').split('.').last or KD.defaultSlug
        stack.push (cb)->
          KD.remote.cacheable group, (err, res)->
            if err or not res
              warn "Fetching group info failed for '#{group}' Group."
              cb null
            else
              group = res?.first or KD.defaultSlug
              cb null,
                vmName     : hostname
                groupSlug  : group?.slug  or KD.defaultSlug
                groupTitle : group?.title or 'Koding'

      async.parallel stack, (err, result)=>
        warn err  if err
        @instantiateListItems result
        @deselectAllItems()
        finder.emit 'EnvironmentsTabShow'

  instantiateListItems:(items)->
    items = [item for item in items when item][0]<commit_msg>the "reset" button should force reload<commit_after>class ResourcesController extends KDListViewController

  constructor:(options = {}, data)->
    options       = $.extend
      view        : new ResourcesView
      wrapper     : no
      scrollView  : no
    , options

    super options, data

    @getView().on 'DeselectAllItems', @bound 'deselectAllItems'
    KD.getSingleton("vmController").on 'VMListChanged', @bound 'reset'

  reset:->
    # FIXME ~ BK
    # cmp = (a, b)->
    #   [groupA, vmA] = a.split('~')
    #   [groupB, vmB] = b.split('~')
    #   if groupA is groupB
    #   then vmA    > vmB
    #   else groupA > groupB

    finder = KD.getSingleton('finderController')
    finder.emit 'EnvironmentsTabHide'

    @removeAllItems()

    vmController = KD.getSingleton("vmController")
    vmController.resetVMData()
    vmController.fetchVMs yes, (err, vms)=>
      log "Found these vms:", err, vms
      return  unless vms
      # vms.sort cmp
      stack   = []
      vms.forEach (hostname)=>
        group = hostname.replace('.kd.io','').split('.').last or KD.defaultSlug
        stack.push (cb)->
          KD.remote.cacheable group, (err, res)->
            if err or not res
              warn "Fetching group info failed for '#{group}' Group."
              cb null
            else
              group = res?.first or KD.defaultSlug
              cb null,
                vmName     : hostname
                groupSlug  : group?.slug  or KD.defaultSlug
                groupTitle : group?.title or 'Koding'

      async.parallel stack, (err, result)=>
        warn err  if err
        @instantiateListItems result
        @deselectAllItems()
        finder.emit 'EnvironmentsTabShow'

  instantiateListItems:(items)->
    items = [item for item in items when item][0]
{'fraction_non_alphanumeric': 0.11439010680157392, 'fraction_numerical': 0.0005621135469364812, 'mean_word_length': 2.065460809646856, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '3956329', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1050, 'n_words': 281}