<commit_before>kd                     = require 'kd'
JView                  = require 'app/jview'
isKoding               = require 'app/util/isKoding'

MachinesList           = require './machineslist'
MachinesListController = require './machineslistcontroller'

ComputeHelpers         = require '../providers/computehelpers'
ComputeController_UI   = require '../providers/computecontroller.ui'


module.exports = class EnvironmentListItem extends kd.ListItemView

  JView.mixin @prototype

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

    options.cssClass = kd.utils.curry 'environment-item', options.cssClass

    super options, data

    @createButtons()
    @createExtraViews()

    listView     = new MachinesList
    controller   = new MachinesListController
      view       : listView
      wrapper    : no
      scrollView : no
    ,
      items      : @getData().machines

    @machinesList = controller.getView()


  createButtons: ->

    @reinitButton     = new kd.CustomHTMLView cssClass: 'hidden'
    @addVMButton      = new kd.CustomHTMLView cssClass: 'hidden'
    @addManagedButton = new kd.CustomHTMLView cssClass: 'hidden'

    unless isKoding()
      @reinitButton = new kd.ButtonView
        cssClass    : 'solid compact red'
        title       : 'RE-INIT STACK'
        callback    : =>
          ComputeController_UI.askFor 'reinitStack', {}, =>
            @getDelegate().emit 'StackReinitRequested', @getData()

    if isKoding()
      @addVMButton = new kd.ButtonView
        title      : 'Add a Koding VM'
        cssClass   : 'add-vm-button solid green compact'
        callback   : => @handleMachineRequest 'koding'

    @addManagedButton = new kd.ButtonView
      title           : 'Add Your Own Machine'
      cssClass        : 'add-managed-button solid green compact'
      callback        : => @handleMachineRequest 'managed'


  handleMachineRequest: (provider) ->

      ComputeHelpers.handleNewMachineRequest { provider }
      @getDelegate().emit 'ModalDestroyRequested'


  createExtraViews: ->

    { group, stackRevision, _revisionStatus, machines, title } = @getData()

<commit_msg>Prevent race condition for close event<commit_after>kd                     = require 'kd'
JView                  = require 'app/jview'
isKoding               = require 'app/util/isKoding'

MachinesList           = require './machineslist'
MachinesListController = require './machineslistcontroller'

ComputeHelpers         = require '../providers/computehelpers'
ComputeController_UI   = require '../providers/computecontroller.ui'


module.exports = class EnvironmentListItem extends kd.ListItemView

  JView.mixin @prototype

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

    options.cssClass = kd.utils.curry 'environment-item', options.cssClass

    super options, data

    @createButtons()
    @createExtraViews()

    listView     = new MachinesList
    controller   = new MachinesListController
      view       : listView
      wrapper    : no
      scrollView : no
    ,
      items      : @getData().machines

    @machinesList = controller.getView()


  createButtons: ->

    @reinitButton     = new kd.CustomHTMLView cssClass: 'hidden'
    @addVMButton      = new kd.CustomHTMLView cssClass: 'hidden'
    @addManagedButton = new kd.CustomHTMLView cssClass: 'hidden'

    unless isKoding()
      @reinitButton = new kd.ButtonView
        cssClass    : 'solid compact red'
        title       : 'RE-INIT STACK'
        callback    : =>
          ComputeController_UI.askFor 'reinitStack', {}, =>
            @getDelegate().emit 'StackReinitRequested', @getData()

    if isKoding()
      @addVMButton = new kd.ButtonView
        title      : 'Add a Koding VM'
        cssClass   : 'add-vm-button solid green compact'
        callback   : => @handleMachineRequest 'koding'

    @addManagedButton = new kd.ButtonView
      title           : 'Add Your Own Machine'
      cssClass        : 'add-managed-button solid green compact'
      callback        : => @handleMachineRequest 'managed'


  handleMachineRequest: (provider) ->

      @getDelegate().emit 'ModalDestroyRequested'
      ComputeHelpers.handleNewMachineRequest { provider }


  createExtraViews: ->

    { group, stackRevision, _revisionStatus, machines, title } = @getData()


{'fraction_non_alphanumeric': 0.09570724841660802, 'fraction_numerical': 0.0, 'mean_word_length': 2.5065789473684212, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '3627562', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1179, 'n_words': 279}