<commit_before>class EnvironmentScene extends KDDiaScene

  containerMap =
    EnvironmentDomainContainer  : 'domains'
    EnvironmentMachineContainer : 'machines'
  itemMap      =
    EnvironmentDomainItem       : 'domain'
    EnvironmentMachineItem      : 'machine'

  constructor:->
    super
      cssClass  : 'environments-scene'
      lineWidth : 1

    @boxes = {}

    sc = KD.getSingleton 'appStorageController'
    @appStorage = sc.storage 'EnvironmentsScene', '1.0'

  disconnect:(dia, joint)->

    removeConnection = => KDDiaScene::disconnect.call this, dia, joint
    targetConnection = @findTargetConnection dia, joint
    return unless targetConnection
    {source, target} = targetConnection

    items = parseItems source, target
    {domain, machine} = items
    return unless domain

    @askForApprove items, 'delete', (modal)=>
      return unless machine? # Remove a domain from a machine
      jDomain = domain.dia.data.domain # JDomain
      vmName  = machine.dia.data.title # JVM.hostnameAlias
      jDomain.unbindVM hostnameAlias: vmName, (err)=>
        modal.destroy()
        return KD.showError err  if err
        jDomain.hostnameAlias.splice jDomain.hostnameAlias.indexOf(vmName), 1
        removeConnection()

  connect:(source, target, internal = no)->

    createConnection = => KDDiaScene::connect.call this, source, target
    return createConnection()  if internal

    items = parseItems source, target
    {domain, machine} = items
    return unless domain

    if machine?
      if domain.dia.data.domain.hostnameAlias.length > 0
        return new KDNotificationView
          title : "A domain name can only be bound to one VM."

    @askForApprove items, 'create', (modal)=>
      if machine? # Assign a domain to a machine
        jDomain = domain.dia.data.domain # JDomain
        vmName  = machine.dia.data.title # JVM.hostnameAlias
        jDomain.bindVM hostnameAlias: vmName, (err)=>
          modal.destroy()
          return KD.showError err  if err
          jDomain.hostnameAlias.push vmName
          createConnection()

  updateConnections:->
    for _mkey, machine of @boxes.machines.dias
      for _dkey, domain of @boxes.domains.dias
        if domain.data.aliases and machine.data.title in domain.data.aliases
          @connect {dia : domain , joint : 'right'}, \
                   {dia : machine, joint : 'left' }, yes
<commit_msg>Environments newui: removed approval on connecting items<commit_after>class EnvironmentScene extends KDDiaScene

  containerMap =
    EnvironmentDomainContainer  : 'domains'
    EnvironmentMachineContainer : 'machines'
  itemMap      =
    EnvironmentDomainItem       : 'domain'
    EnvironmentMachineItem      : 'machine'

  constructor:->
    super
      cssClass  : 'environments-scene'
      lineWidth : 1

    @boxes = {}

    sc = KD.getSingleton 'appStorageController'
    @appStorage = sc.storage 'EnvironmentsScene', '1.0'

  disconnect:(dia, joint)->

    removeConnection = => KDDiaScene::disconnect.call this, dia, joint
    targetConnection = @findTargetConnection dia, joint
    return unless targetConnection
    {source, target} = targetConnection

    items = parseItems source, target
    {domain, machine} = items
    return unless domain

    @askForApprove items, 'delete', (modal)=>
      return unless machine? # Remove a domain from a machine
      jDomain = domain.dia.data.domain # JDomain
      vmName  = machine.dia.data.title # JVM.hostnameAlias
      jDomain.unbindVM hostnameAlias: vmName, (err)=>
        modal.destroy()
        return KD.showError err  if err
        jDomain.hostnameAlias.splice jDomain.hostnameAlias.indexOf(vmName), 1
        removeConnection()

  connect:(source, target, internal = no)->

    createConnection = => KDDiaScene::connect.call this, source, target
    return createConnection()  if internal

    items = parseItems source, target
    {domain, machine} = items
    return unless domain

    if machine?
      if domain.dia.data.domain.hostnameAlias.length > 0
        return new KDNotificationView
          title : "A domain name can only be bound to one VM."

    if machine? # Assign a domain to a machine
      jDomain = domain.dia.data.domain # JDomain
      vmName  = machine.dia.data.title # JVM.hostnameAlias
      jDomain.bindVM hostnameAlias: vmName, (err)=>
        return KD.showError err  if err
        jDomain.hostnameAlias.push vmName
        createConnection()

  updateConnections:->
    for _mkey, machine of @boxes.machines.dias
      for _dkey, domain of @boxes.domains.dias
        if domain.data.aliases and machine.data.title in domain.data.aliases
          @connect {dia : domain , joint : 'right'}, \
                   {dia : machine, joint : 'left' }, yes

{'fraction_non_alphanumeric': 0.08953022961870655, 'fraction_numerical': 0.0021065936380872128, 'mean_word_length': 2.8321226795803067, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, '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': '2148639', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1303, 'n_words': 377}