<commit_before>class IDE.MachineStateModal extends IDE.ModalView

  {
    Stopped, Running, NotInitialized, Terminated, Unknown,
    Starting, Building, Stopping, Rebooting, Terminating, Updating
  } = Machine.State

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

    options.cssClass or= 'ide-machine-state'
    options.width      = 440
    # options.height   = 270

    super options, data

    @addSubView @container = new KDCustomHTMLView cssClass: 'content-container'
    @machine = @getData()

    return @handleNoMachineFound()  unless @machine

    {jMachine}   = @machine
    @machineName = jMachine.label
    @machineId   = jMachine._id
    {@state}     = @machine.status

    @buildInitial()

    computeController = KD.getSingleton 'computeController'

    computeController.on "start-#{@machineId}", @bound 'updateStatus'
    computeController.on "build-#{@machineId}", @bound 'updateStatus'
    computeController.on "stop-#{@machineId}",  @bound 'updateStatus'

    computeController.on "reinit-#{@machineId}",(event)=>
      @updateStatus event, 'reinit'

    computeController.on "error-#{@machineId}", =>
      @hasError = yes
      @updateStatus status: Unknown

    @show()

    computeController.followUpcomingEvents @machine

  updateStatus: (event, task) ->

    {status, percentage, error} = event

    if status is @state
      if percentage?
        @progressBar?.updateBar Math.max percentage, 10
        @progressBar?.show()

    else

      @state = status
      @hasError = error?.length > 0

      if percentage?

        if percentage is 100

          if status is Running
            @prepareIDE()
            @destroy()

          else
            @progressBar?.updateBar 100
            @progressBar?.show()

            KD.utils.wait 500, => @buildViews()

        else if task is 'reinit'
          @buildViews { percentage }<commit_msg>MachineStateModa: if task is reinit, do not destroy subviews just update them<commit_after>class IDE.MachineStateModal extends IDE.ModalView

  {
    Stopped, Running, NotInitialized, Terminated, Unknown,
    Starting, Building, Stopping, Rebooting, Terminating, Updating
  } = Machine.State

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

    options.cssClass or= 'ide-machine-state'
    options.width      = 440
    # options.height   = 270

    super options, data

    @addSubView @container = new KDCustomHTMLView cssClass: 'content-container'
    @machine = @getData()

    return @handleNoMachineFound()  unless @machine

    {jMachine}   = @machine
    @machineName = jMachine.label
    @machineId   = jMachine._id
    {@state}     = @machine.status

    @buildInitial()

    computeController = KD.getSingleton 'computeController'

    computeController.on "start-#{@machineId}", @bound 'updateStatus'
    computeController.on "build-#{@machineId}", @bound 'updateStatus'
    computeController.on "stop-#{@machineId}",  @bound 'updateStatus'

    computeController.on "reinit-#{@machineId}",(event)=>
      @updateStatus event, 'reinit'

    computeController.on "error-#{@machineId}", =>
      @hasError = yes
      @updateStatus status: Unknown

    @show()

    computeController.followUpcomingEvents @machine

  updateStatus: (event, task) ->

    {status, percentage, error} = event

    if status is @state
      if percentage?
        @progressBar?.updateBar Math.max percentage, 10
        @progressBar?.show()

    else

      @state = status
      @hasError = error?.length > 0

      if percentage?

        if percentage is 100

          if status is Running
            @prepareIDE()
            @destroy()

          else
            @progressBar?.updateBar 100
            @progressBar?.show()

            KD.utils.wait 500, => @buildViews()

        else if task is 'reinit'

          @progressBar?.updateBar Math.max percentage, 10
          @progressBar?.show()
          @label?.updatePartial @getStateLabel()
{'fraction_non_alphanumeric': 0.11153846153846154, 'fraction_numerical': 0.009743589743589744, 'mean_word_length': 2.729445506692161, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1684168', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1080, 'n_words': 276}