<commit_before>kd              = require 'kd'
nick            = require 'app/util/nick'
remote          = require('app/remote').getInstance()
actions         = require 'app/flux/environment/actions'
Machine         = require 'app/providers/machine'
lazyrouter      = require 'app/lazyrouter'
dataProvider    = require 'app/userenvironmentdataprovider'
isTeamReactSide = require 'app/util/isTeamReactSide'


selectWorkspaceOnSidebar = (data) ->

  return no  unless data

  { machine, workspace } = data

  return no if not machine or not workspace

  if isTeamReactSide()
    actions.setSelectedWorkspaceId workspace._id
  else
    kd.getSingleton('mainView').activitySidebar.selectWorkspace data

  storage = kd.singletons.localStorageController.storage 'IDE'

  workspaceData    =
    machineLabel   : machine.slug or machine.label
    workspaceSlug  : workspace.slug
    channelId      : workspace.channelId

  storage.setValue 'LatestWorkspace', workspaceData
  storage.setValue "LatestWorkspace_#{machine.uid}", workspaceData


getLatestWorkspace = (machine) ->

  storage   = kd.getSingleton('localStorageController').storage 'IDE'
  if machine
    workspace = storage.getValue "LatestWorkspace_#{machine.uid}"

  return no  unless workspace

  { machineLabel, workspaceSlug, channelId } = workspace

  if dataProvider.findWorkspace machineLabel, workspaceSlug, channelId
    return workspace


loadIDENotFound = ->

  { appManager } = kd.singletons
  appManager.open 'IDE', { forceNew: yes }, (app) ->
    app.amIHost = yes
    appManager.tell 'IDE', 'showNoMachineState'


loadIDE = (data) ->

  { selectWorkspaceOnSidebar, findInstance } = module.exports

  { machine, workspace, username, channelId } = data
  selectWorkspaceOnSidebar data
  actions.setSelectedMachineId machine._id

  if machine.data.generatedFrom?
    actions.setSelectedTemplateId machine.data.generatedFrom.templateId<commit_msg>ide/routes: select only machine with data for templates<commit_after>kd              = require 'kd'
nick            = require 'app/util/nick'
remote          = require('app/remote').getInstance()
actions         = require 'app/flux/environment/actions'
Machine         = require 'app/providers/machine'
lazyrouter      = require 'app/lazyrouter'
dataProvider    = require 'app/userenvironmentdataprovider'
isTeamReactSide = require 'app/util/isTeamReactSide'


selectWorkspaceOnSidebar = (data) ->

  return no  unless data

  { machine, workspace } = data

  return no if not machine or not workspace

  if isTeamReactSide()
    actions.setSelectedWorkspaceId workspace._id
  else
    kd.getSingleton('mainView').activitySidebar.selectWorkspace data

  storage = kd.singletons.localStorageController.storage 'IDE'

  workspaceData    =
    machineLabel   : machine.slug or machine.label
    workspaceSlug  : workspace.slug
    channelId      : workspace.channelId

  storage.setValue 'LatestWorkspace', workspaceData
  storage.setValue "LatestWorkspace_#{machine.uid}", workspaceData


getLatestWorkspace = (machine) ->

  storage   = kd.getSingleton('localStorageController').storage 'IDE'
  if machine
    workspace = storage.getValue "LatestWorkspace_#{machine.uid}"

  return no  unless workspace

  { machineLabel, workspaceSlug, channelId } = workspace

  if dataProvider.findWorkspace machineLabel, workspaceSlug, channelId
    return workspace


loadIDENotFound = ->

  { appManager } = kd.singletons
  appManager.open 'IDE', { forceNew: yes }, (app) ->
    app.amIHost = yes
    appManager.tell 'IDE', 'showNoMachineState'


loadIDE = (data) ->

  { selectWorkspaceOnSidebar, findInstance } = module.exports

  { machine, workspace, username, channelId } = data
  selectWorkspaceOnSidebar data
  actions.setSelectedMachineId machine._id

  if machine.data?.generatedFrom?
    actions.setSelectedTemplateId machine.data.generatedFrom.templateId
{'fraction_non_alphanumeric': 0.0898265596686513, 'fraction_numerical': 0.0, 'mean_word_length': 3.897338403041825, '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': '4304616', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1109, 'n_words': 248}