<commit_before>class NVMToggleButtonView extends JView

  constructor:(options, data)->
    super cssClass: 'vm-toggle-menu', data

    @vm = KD.getSingleton 'vmController'
    @vm.on 'StateChanged', @bound 'checkVMState'

    @toggle = new KDOnOffSwitch
      cssClass : "tiny vm-toggle-item"
      callback : (state)=>
        if state
        then @vm.start @getData().vmName
        else @vm.stop  @getData().vmName

  checkVMState:(err, vm, info)->
    return unless vm is @getData().vmName

    if err or not info
      @toggle.setDefaultValue no
      KD.utils.notifyAndEmailVMTurnOnFailureToSysAdmin vm, err.message
      return warn err

    if info.state is "RUNNING"
    then @toggle.setDefaultValue yes
    else @toggle.setDefaultValue no

  pistachio:->
    """<span>Change state</span> {{> @toggle}}"""

  viewAppended:->
    super
    @vm.info @getData().vmName, @bound 'checkVMState'<commit_msg>added a notification when vm cannot be started - https://app.asana.com/0/3716548652471/7348827130975<commit_after>class NVMToggleButtonView extends JView

  constructor:(options, data)->
    super cssClass: 'vm-toggle-menu', data

    @vm = KD.getSingleton 'vmController'
    @vm.on 'StateChanged', @bound 'checkVMState'

    @toggle = new KDOnOffSwitch
      cssClass : "tiny vm-toggle-item"
      callback : (state)=>
        if state
        then @vm.start @getData().vmName
        else @vm.stop  @getData().vmName

  checkVMState:(err, vm, info)->
    return unless vm is @getData().vmName

    if err or not info

      @notify?.destroy()
      @notify = new KDNotificationView
        type    : "mini"
        cssClass: "error"
        duration: 5000
        title   : "I cannot turn this machine on, please give it a few seconds."

      @toggle.setDefaultValue no
      KD.utils.notifyAndEmailVMTurnOnFailureToSysAdmin vm, err.message
      return warn err

    if info.state is "RUNNING"
    then @toggle.setDefaultValue yes
    else @toggle.setDefaultValue no

  pistachio:->
    """<span>Change state</span> {{> @toggle}}"""

  viewAppended:->
    super
    @vm.info @getData().vmName, @bound 'checkVMState'
{'fraction_non_alphanumeric': 0.11549295774647887, 'fraction_numerical': 0.01455399061032864, 'mean_word_length': 2.9390018484288354, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 1, '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': '6722548', 'n_tokens_mistral': 698, 'n_tokens_neox': 662, 'n_words': 180}