<commit_before>class MachineList extends KDView

  viewAppended: ->

    @addSubView @loader = new KDLoaderView
      cssClass    : "loader"
      showLoader  : yes
      size        :
        width     : 16

    @addSubView @container = new KDView
    @machineListController = new KDListViewController
      selection            : yes

      viewOptions          :
        wrapper            : yes
        itemClass          : MachineItemListView
        itemOptions        : @getOption 'itemOptions'
      noItemFoundWidget    : new KDView
        cssClass           : 'noitem-warning'
        partial            : "There is no machine to show for now."

    @container.addSubView \
      @machineListView = @machineListController.getView()

    @forwardEvent @machineListView, 'MachineSelected'

    @fetchMachines()


  fetchMachines: ->

    { query } = @getOptions()
    query    ?= {}

    @loader.show()

    {computeController} = KD.singletons
    computeController.queryMachines query, (err, machines)=>

      # TODO handle errors correctly
      return if KD.showError err

      @loader.hide()
      @machineListController.replaceAllItems machines


class MachineListModal extends KDModalView

  constructor: (options = {}, data)->

    options = $.extend
      title    : "Machine List"
      cssClass : "machines-modal"
      width    : 540
      overlay  : yes
    , options

    super options, data

    @once 'viewAppended', =>
      @addSubView new MachineList @getOption 'listOptions'<commit_msg>MachineListModal: it now provides selection list based on given query<commit_after>class MachineList extends KDView

  viewAppended: ->

    @addSubView @loader = new KDLoaderView
      cssClass    : "loader"
      showLoader  : yes
      size        :
        width     : 16

    @addSubView @container = new KDView
    @machineListController = new KDListViewController
      selection            : yes
      viewOptions          :
        wrapper            : yes
        itemClass          : MachineItemListView
        itemOptions        : @getOption 'itemOptions'
      noItemFoundWidget    : new KDView
        cssClass           : 'noitem-warning'
        partial            : "There is no machine to show for now."

    @container.addSubView \
      @machineListView = @machineListController.getView()

    @forwardEvent @machineListController, 'ItemSelectionPerformed'

    @fetchMachines()


  fetchMachines: ->

    { query } = @getOptions()
    query    ?= {}

    @loader.show()

    {computeController} = KD.singletons
    computeController.queryMachines query, (err, machines)=>

      # TODO handle errors correctly
      return if KD.showError err

      @loader.hide()
      @machineListController.replaceAllItems machines


class MachineListModal extends KDModalView

  constructor: (options = {}, data)->

    options = $.extend
      title        : "Machine List"
      subtitle     : "Select a running machine below to perform this action."
      cssClass     : "machines-modal"
      width        : 540
      overlay      : yes
      buttons      :
        "Continue" :
          disabled : yes
          callback : => @continueAction()
    , options

    super options, data

  viewAppended:->

    @addSubView machineList = new MachineList @getOption 'listOptions'

    machineList.on "ItemSelectionPerformed", (list, {items})=>

      @machine = items.first.getData()
      @buttons["Continue"][ \
        if @checkMachineState() then 'enable' else 'disable'
      ]()


  checkMachineState: ->

    # FIXME Make this check extendable
    @machine?.status.state is Machine.State.Running


  continueAction:->

    if @checkMachineState()
      @emit "MachineSelected", @machine
      @destroy()
{'fraction_non_alphanumeric': 0.08511777301927195, 'fraction_numerical': 0.0026766595289079227, 'mean_word_length': 2.20222793487575, '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': '7473722', 'n_tokens_mistral': 1052, 'n_tokens_neox': 964, 'n_words': 263}