<commit_before>kd                           = require 'kd'
nick                         = require '../util/nick'
JView                        = require '../jview'
Machine                      = require '../providers/machine'
globals                      = require 'globals'
htmlencode                   = require 'htmlencode'
groupifyLink                 = require '../util/groupifyLink'
KDCustomHTMLView             = kd.CustomHTMLView
KDProgressBarView            = kd.ProgressBarView
MachineSettingsModal         = require '../providers/machinesettingsmodal'
SidebarMachineSharePopup     = require 'app/activity/sidebar/sidebarmachinesharepopup'
userEnvironmentDataProvider  = require 'app/userenvironmentdataprovider'
SidebarMachineConnectedPopup = require 'app/activity/sidebar/sidebarmachineconnectedpopup'


module.exports = class NavigationMachineItem extends JView

  {Running, Stopped} = Machine.State

  stateClasses  = 'reconnecting '
  stateClasses += "#{state.toLowerCase()} " for state in Object.keys Machine.State


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

    { machine, workspaces } = data

    @alias           = machine.slug or machine.label
    machineOwner     = machine.getOwner()
    isMyMachine      = machine.isMine()
    machineRoutes    =
      own            : "/IDE/#{@alias}"
      collaboration  : "/IDE/#{@getChannelId data}"
      permanentShare : "/IDE/#{machine.uid}"

    machineType = 'own'

    unless isMyMachine
      machineType = if machine.isPermanent() then 'permanentShare' else 'collaboration'

    @machineRoute = groupifyLink machineRoutes[machineType]

    options.tagName    = 'a'
    options.cssClass   = "vm #{machine.status.state.toLowerCase()} #{machine.provider}"
    options.attributes =
      href             : '#'
      title            : "Open IDE for #{@alias}"

    unless isMyMachine
      options.attributes.title += " (shared by @#{htmlencode.htmlDecode machineOwner})"

    super options, data

    { computeController } = kd.singletons

    { @machine } = @getData()
    labelPartial = machine.label or @alias

    unless isMyMachine
      labelPartial = """
        #{labelPartial}
        <cite class='shared-by'>
          (@#{htmlencode.htmlDecode machineOwner})
        </cite>
      """

    @label     = new KDCustomHTMLView
      partial  : labelPartial

    @progress  = new KDProgressBarView
      cssClass : 'hidden'

    @createSettingsIcon()

    computeController
      .on "reconnecting-#{@machine.uid}", =>
        @setState 'reconnecting'

      .on "public-#{@machine._id}", (event) =>
        @handleMachineEvent event

    computeController.ready =>

      if stack = computeController.findStackFromMachineId @machine._id
        computeController.on "public-#{stack._id}", (event) =>
          @handleMachineEvent event

    if not @machine.isMine() and not @machine.isApproved()
      @showSharePopup()

    @subscribeMachineShareEvent()


  createSettingsIcon: -><commit_msg>NavigationMachineItem: use uid for machine links of reassigned machines<commit_after>kd                           = require 'kd'
nick                         = require '../util/nick'
JView                        = require '../jview'
Machine                      = require '../providers/machine'
globals                      = require 'globals'
htmlencode                   = require 'htmlencode'
groupifyLink                 = require '../util/groupifyLink'
KDCustomHTMLView             = kd.CustomHTMLView
KDProgressBarView            = kd.ProgressBarView
MachineSettingsModal         = require '../providers/machinesettingsmodal'
SidebarMachineSharePopup     = require 'app/activity/sidebar/sidebarmachinesharepopup'
userEnvironmentDataProvider  = require 'app/userenvironmentdataprovider'
SidebarMachineConnectedPopup = require 'app/activity/sidebar/sidebarmachineconnectedpopup'


module.exports = class NavigationMachineItem extends JView

  {Running, Stopped} = Machine.State

  stateClasses  = 'reconnecting '
  stateClasses += "#{state.toLowerCase()} " for state in Object.keys Machine.State


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

    { machine, workspaces } = data

    @alias           = machine.slug or machine.label
    machineOwner     = machine.getOwner()
    reassigned       = machine.jMachine.meta?.oldOwner?
    oldOwner         = machine.jMachine.meta?.oldOwner ? machineOwner
    isMyMachine      = machine.isMine()
    machineRoutes    =
      own            : "/IDE/#{@alias}"
      collaboration  : "/IDE/#{@getChannelId data}"
      permanentShare : "/IDE/#{machine.uid}"
      reassigned     : "/IDE/#{machine.uid}"

    machineType = 'own'

    if reassigned
      machineType = 'reassigned'
    else if not isMyMachine
      machineType = if machine.isPermanent() then 'permanentShare' else 'collaboration'

    @machineRoute = groupifyLink machineRoutes[machineType]

    options.tagName    = 'a'
    options.cssClass   = "vm #{machine.status.state.toLowerCase()} #{machine.provider}"
    options.attributes =
      href             : '#'
      title            : "Open IDE for #{@alias}"

    unless isMyMachine
      options.attributes.title += " (shared by @#{htmlencode.htmlDecode machineOwner})"

    super options, data

    { computeController } = kd.singletons

    { @machine } = @getData()
    labelPartial = machine.label or @alias

    if not isMyMachine or reassigned
      labelPartial = """
        #{labelPartial}
        <cite class='shared-by'>
          (@#{htmlencode.htmlDecode oldOwner})
        </cite>
      """

    @label     = new KDCustomHTMLView
      partial  : labelPartial

    @progress  = new KDProgressBarView
      cssClass : 'hidden'

    @createSettingsIcon()

    computeController
      .on "reconnecting-#{@machine.uid}", =>
        @setState 'reconnecting'

      .on "public-#{@machine._id}", (event) =>
        @handleMachineEvent event

    computeController.ready =>

      if stack = computeController.findStackFromMachineId @machine._id
        computeController.on "public-#{stack._id}", (event) =>
          @handleMachineEvent event

    if not @machine.isMine() and not @machine.isApproved()
      @showSharePopup()

    @subscribeMachineShareEvent()


  createSettingsIcon: ->
{'fraction_non_alphanumeric': 0.10746987951807228, 'fraction_numerical': 0.0, 'mean_word_length': 2.4801565120178872, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3745501', 'n_tokens_mistral': 1714, 'n_tokens_neox': 1677, 'n_words': 364}