<commit_before>class PlaygroundTeamwork extends TeamworkWorkspace

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

    super options, data

    @container.setClass options.playground

  handleRun: (panel) ->
    options      = @getOptions()
    {playground} = options
    runConfig    = options.playgroundManifest.run

    return warn "Missing run config for #{playground}."  unless runConfig

    unless runConfig.handler
      return warn "Missing handler for #{playground} run config."

    {handler, command} = runConfig

    if handler is "terminal"
      unless command
        return warn "Missing command for #{playground} run config"

      {path}         = panel.getPaneByName("editor").getActivePaneFileData()
      plainPath      = FSHelper.plainPath path
      command        = command.replace "$ACTIVE_FILE_PATH", """ "#{plainPath}" """
      {paneLauncher} = panel

      if paneLauncher.paneVisibilityState.terminal is no
        paneLauncher.handleLaunch "terminal"

      paneLauncher.terminalPane.runCommand command
    else
      warn "Unimplemented run hanldler for #{playground}"<commit_msg>Teamwork: Implemented Playground features.<commit_after>class PlaygroundTeamwork extends TeamworkWorkspace

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

    super options, data

    @container.setClass options.playground

    @on "ContentIsReady", =>
      return unless @amIHost()
      manifest = @getOptions().playgroundManifest
      {prerequisite, initialState} = manifest
      if prerequisite
        if prerequisite.type is "sh"
          if initialState
          then @doPrerequisite prerequisite.command, => @setUpInitialState initialState
          else @doPrerequisite prerequisite.command
        else
          warn "Unhandled prerequisite type."
      else if initialState
        @setUpInitialState initialState

  handleRun: (panel) ->
    options      = @getOptions()
    {playground} = options
    runConfig    = options.playgroundManifest.run

    return warn "Missing run config for #{playground}."  unless runConfig

    {handler, command} = runConfig
    {paneLauncher}     = panel

    if not handler or not command
      return warn "Missing parameter for #{playground} run config. You must pass a handler and a command"

    if handler is "terminal"
      {path}    = panel.getPaneByName("editor").getActivePaneFileData()
      plainPath = FSHelper.plainPath path
      command   = command.replace "$ACTIVE_FILE_PATH", """ "#{plainPath}" """
      if paneLauncher.paneVisibilityState.terminal is no
        paneLauncher.handleLaunch "terminal"
      paneLauncher.terminalPane.runCommand command
    else if handler is "preview"
      @handlePreview command
    else
      warn "Unimplemented run hanldler for #{playground}"

  doPrerequisite: (command, callback = noop) ->
    return warn "no command passed for prerequisite"  unless command
    KD.getSingleton("vmController").run command, (err, res) =>
      return warn err  if err
      callback()

  setUpInitialState: (initialState) ->
    if initialState.preview
      @handlePreview initialState.preview.url

    if initialState.editor
      @openFiles initialState.editor.files

  handlePreview: (url) ->
    {paneLauncher} = @getActivePanel()
    url            = url.replace "$USERNAME", @getHost()

    if paneLauncher.paneVisibilityState.preview is no
      paneLauncher.handleLaunch "preview"
    paneLauncher.previewPane.openUrl url

  openFiles: (files) ->
    editor = @getActivePanel().getPaneByName "editor"

    for path in files
      filePath = "Web/Teamwork/#{@getOptions().playground}/#{path.replace /^.\//, ''}"
      file     = FSHelper.createFileFromPath filePath

      file.fetchContents (err, contents) =>
        editor.openFile file, contents
{'fraction_non_alphanumeric': 0.09144228205811783, 'fraction_numerical': 0.0, 'mean_word_length': 3.1005464480874316, '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': '2279783', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1004, 'n_words': 280}