<commit_before>class TerminalStartTab extends JView

  constructor:->

    super

    @vmWrapper = new KDCustomHTMLView tagName : 'ul'

    @vmSessions = new KDCustomHTMLView tagName : 'ul'


  viewAppended:->

    super

    @fetchVMs()


  fetchVMs:->

    {vmController, kontrol} = KD.singletons

    vmController.fetchVMs (err, vms)=>

      if err
        return new KDNotificationView title : "Couldn't fetch your VMs"

      vms.sort (a,b)-> a.hostnameAlias > b.hostnameAlias

      @listVMs vms
      @listVMSessions vms

      osKites =
        if KD.useNewKites
        then kontrol.kites.oskite
        else vmController.kites

      for own alias, kite of osKites
        if kite.recentState
          @vmWrapper[alias].handleVMInfo kite.recentState

    vmController.on 'vm.progress.start', ({alias, update}) => @vmWrapper[alias].handleVMStart update
    vmController.on 'vm.progress.stop',  ({alias, update}) => @vmWrapper[alias].handleVMStop update
    vmController.on 'vm.state.info',     ({alias, state})  => @vmWrapper[alias].handleVMInfo state
    vmController.on 'vm.progress.error', ({alias, error}) => @vmWrapper[alias].handleVMError error


  listVMs:(vms)->

    vms.forEach (vm)=>
      alias             = vm.hostnameAlias
      @vmWrapper[alias] = new TerminalStartTabVMItem {}, vm
      @vmWrapper.addSubView @vmWrapper[alias]
      appView = @getDelegate()
      appView.forwardEvent @vmWrapper[alias], 'VMItemClicked'


  listVMSessions: (vms) ->
    vmList = {}
    vms.forEach (vm) ->
      vmList[vm.hostnameAlias] = vm

    {vmController:{terminalKites : kites}} = KD.singletons
    for own alias, kite of kites
      vm = vmList[alias]
      @vmSessions.addSubView new SessionStackView {kite: kite, alias: alias, vm: vm, delegate: this}


  pistachio:->
    """
    <h1>This is where the magic happens!</h1>
    <h2>Terminal allows you to interact directly with your VM.</h2>
    <figure><iframe src="//www.youtube.com/embed/DmjWnmSlSu4?origin=https://koding.com&showinfo=0&rel=0&theme=dark&modestbranding=1&autohide=1&loop=1" width="100%" height="100%" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></figure>
    <h3>Your VMs</h3><commit_msg>Terminal: with vm creation/removal terminal start tab is updated<commit_after>class TerminalStartTab extends JView

  constructor:->

    super

    @vmWrapper = new KDCustomHTMLView tagName : 'ul'

    @vmSessions = new KDCustomHTMLView tagName : 'ul'

    @message = new KDCustomHTMLView

    KD.singletons.notificationController.on 'NotificationHasArrived', ({event}) =>
      if event in ["VMCreated", "VMRemoved"]
        @wmWrapper = {}
        @viewAppended()

  viewAppended:->

    super
    @wmWrapper = {}
    @fetchVMs()
    @prepareMessage()


  fetchVMs:->

    {vmController, kontrol} = KD.singletons

    vmController.fetchVMs yes, (err, vms)=>
      if err
        return new KDNotificationView title : "Couldn't fetch your VMs"

      vms.sort (a,b)-> a.hostnameAlias > b.hostnameAlias

      @listVMs vms
      @listVMSessions vms

      osKites =
        if KD.useNewKites
        then kontrol.kites.oskite
        else vmController.kites

      for own alias, kite of osKites
        if kite.recentState
          @vmWrapper[alias].handleVMInfo kite.recentState

    vmController.on 'vm.progress.start', ({alias, update}) => @vmWrapper[alias].handleVMStart update
    vmController.on 'vm.progress.stop',  ({alias, update}) => @vmWrapper[alias].handleVMStop update
    vmController.on 'vm.state.info',     ({alias, state})  => @vmWrapper[alias].handleVMInfo state
    vmController.on 'vm.progress.error', ({alias, error}) => @vmWrapper[alias].handleVMError error


  listVMs:(vms)->

    vms.forEach (vm)=>
      alias             = vm.hostnameAlias
      @vmWrapper[alias] = new TerminalStartTabVMItem {}, vm
      @vmWrapper.addSubView @vmWrapper[alias]
      appView = @getDelegate()
      appView.forwardEvent @vmWrapper[alias], 'VMItemClicked'


  listVMSessions: (vms) ->
    vmList = {}
    vms.forEach (vm) ->
      vmList[vm.hostnameAlias] = vm

    {vmController:{terminalKites : kites}} = KD.singletons
    {delegate} = @getOptions()
    for own alias, kite of kites
      vm = vmList[alias]
      @vmSessions.addSubView new SessionStackView {kite: kite, alias: alias, vm: vm, delegate}


  pistachio:->
    """
    <h1>This is where the magic happens!</h1>
    <h2>Terminal allows you to interact directly with your VM.</h2>
    <figure><iframe src="//www.youtube.com/embed/DmjWnmSlSu4?origin=https://koding.com&showinfo=0&rel=0&theme=dark&modestbranding=1&autohide=1&loop=1" width="100%" height="100%" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></figure>
    <h3>Your VMs</h3>
{'fraction_non_alphanumeric': 0.125367492650147, 'fraction_numerical': 0.007979840403191937, 'mean_word_length': 3.3143115942028984, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 54, 'https://': 2, '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': '3939222', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1539, 'n_words': 336}