<commit_before>kd                      = require 'kd'
remote                  = require('app/remote').getInstance()
KDView                  = kd.View
KDListViewController    = kd.ListViewController
KDCustomHTMLView        = kd.CustomHTMLView
Machine                 = require 'app/providers/machine'
NavigationMachineItem   = require 'app/navigation/navigationmachineitem'
SidebarWorkspaceItem    = require './sidebarworkspaceitem'
MoreWorkspacesModal     = require 'app/activity/sidebar/moreworkspacesmodal'
AddWorkspaceView        = require 'app/addworkspaceview'
IDEAppController        = require 'ide'
environmentDataProvider = require 'app/userenvironmentdataprovider'
isKoding                = require 'app/util/isKoding'


module.exports = class SidebarMachineBox extends KDView

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

    options.cssClass = "sidebar-machine-box #{data.machine.label}"

    super options, data

    @machine = data.machine

    unless @machine instanceof Machine
      @machine = new Machine machine: remote.revive data.machine

    @workspaceListItemsById = {}

    @createMachineItem()

    @addSubView @unreadIndicator = new KDCustomHTMLView
      tagName  : 'cite'
      cssClass : 'count hidden'

    @createWorkspacesLabel()
    @createWorkspacesList()
    @watchMachineState()

    @machine.on 'MachineLabelUpdated', @bound 'handleMachineLabelUpdated'

    computeController = kd.getSingleton 'computeController'
    computeController.on "stateChanged-#{@machine._id}", @bound 'handleStateChanged'

    if stack = computeController.findStackFromMachineId @machine._id
      visibility = stack.config?.sidebar?[@machine.uid]?.visibility

    @setVisibility visibility ? on


  handleStateChanged: (state) ->

    if state is Machine.State.Running
      kd.singletons.mainView.sidebar.emit 'ShowCloseHandle'
      @machineItem.settingsIcon.show()


  createMachineItem: ->

    machineData = { @machine, workspaces: @getData().workspaces }

    @addSubView @machineItem = new NavigationMachineItem {}, machineData

    @machineItem.on 'click', =>
      if @isMachineRunning() then @toggleList()
      else kd.singletons.router.handleRoute @machineItem.machineRoute


  createWorkspacesList: -><commit_msg>SidebarMachineBox: Toggle list if machine is mine or accepted.<commit_after>kd                      = require 'kd'
remote                  = require('app/remote').getInstance()
KDView                  = kd.View
KDListViewController    = kd.ListViewController
KDCustomHTMLView        = kd.CustomHTMLView
Machine                 = require 'app/providers/machine'
NavigationMachineItem   = require 'app/navigation/navigationmachineitem'
SidebarWorkspaceItem    = require './sidebarworkspaceitem'
MoreWorkspacesModal     = require 'app/activity/sidebar/moreworkspacesmodal'
AddWorkspaceView        = require 'app/addworkspaceview'
IDEAppController        = require 'ide'
environmentDataProvider = require 'app/userenvironmentdataprovider'
isKoding                = require 'app/util/isKoding'


module.exports = class SidebarMachineBox extends KDView

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

    options.cssClass = "sidebar-machine-box #{data.machine.label}"

    super options, data

    @machine = data.machine

    unless @machine instanceof Machine
      @machine = new Machine machine: remote.revive data.machine

    @workspaceListItemsById = {}

    @createMachineItem()

    @addSubView @unreadIndicator = new KDCustomHTMLView
      tagName  : 'cite'
      cssClass : 'count hidden'

    @createWorkspacesLabel()
    @createWorkspacesList()
    @watchMachineState()

    @machine.on 'MachineLabelUpdated', @bound 'handleMachineLabelUpdated'

    computeController = kd.getSingleton 'computeController'
    computeController.on "stateChanged-#{@machine._id}", @bound 'handleStateChanged'

    if stack = computeController.findStackFromMachineId @machine._id
      visibility = stack.config?.sidebar?[@machine.uid]?.visibility

    @setVisibility visibility ? on


  handleStateChanged: (state) ->

    if state is Machine.State.Running
      kd.singletons.mainView.sidebar.emit 'ShowCloseHandle'
      @machineItem.settingsIcon.show()


  createMachineItem: ->

    machineData = { @machine, workspaces: @getData().workspaces }

    @addSubView @machineItem = new NavigationMachineItem {}, machineData

    @machineItem.on 'click', =>
      if @isMachineRunning()
        if @machine.isMine() then @toggleList()
        else
          if @machine.isApproved() then @toggleList()

      else kd.singletons.router.handleRoute @machineItem.machineRoute


  createWorkspacesList: ->
{'fraction_non_alphanumeric': 0.09597053726169844, 'fraction_numerical': 0.0, 'mean_word_length': 3.465183752417795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1560285', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1217, 'n_words': 263}