<commit_before>'use babel';
var url = require('url');
var _ = require('underscore');

import ConcourseVisView from './concourse-vis-view';
import { CompositeDisposable } from 'atom';

var isConcourseVisView = function(object) {
  if (isConcourseVisView == null) {
    isConcourseVisView = require('./concourse-vis-view');
  }
  return object instanceof ConcourseVisView;
};

export default {

  concourseVisView: null,
  modalPanel: null,
  subscriptions: null,

  activate(state) {
    this.concourseVisView = new ConcourseVisView(state.concourseVisViewState);
    this.concourseVisView.vis = this;
    this.activeEditor = atom.workspace.getActiveTextEditor();

    var _self = this;

    // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
    this.subscriptions = new CompositeDisposable();

    // Register command that toggles this view
    this.subscriptions.add(atom.commands.add('atom-workspace', {
      'concourse-vis:toggle': () => this.toggle()
    }));

    atom.workspace.addOpener(function(uri) {
      ref = url.parse(uri), protocol = ref.protocol, host = ref.host, pathname = ref.pathname;
      if (protocol !== 'concourse-vis:') {
        return;
      }

      return(_self.concourseVisView);

    });

    this.linkJobsAndResource = function() {

      var _self = this;

      // add click for jobs and resources
      $('.node.job a').click(function(e) {
        var jobName = _.find(e.currentTarget.children, function(c) { return c.tagName == "text"; }).innerHTML;
        var buffer = _self.activeEditor.getBuffer();
        var lines = buffer.lines.slice(0);

        var jobsLine = _.findIndex(lines, function(line) {
          return(line.match(/jobs:/) !== null);
        });

        lines = lines.slice(jobsLine)

        var jobLine = _.findIndex(lines, function(line) {
          jobNameRe = new RegExp("name: " + jobName)
          return(line.match(jobNameRe) !== null);
        });

        var absLinePos = jobLine + jobsLine;
        _self.activeEditor.setCursorBufferPosition([absLinePos, 0]);
      });

      $('.node.input a, .node.output a, .node.constrained-input a').click(function(e) {
        var resourceName = _.find(e.currentTarget.children, function(c) { return c.tagName == "text"; }).innerHTML;

        var buffer = _self.activeEditor.getBuffer();
        var lines = buffer.lines.slice(0);

        var resourcesLine = _.findIndex(lines, function(line) {
          return(line.match(/resources:/) !== null);
        });

        lines = lines.slice(resourcesLine)

        var resourceLine = _.findIndex(lines, function(line) {
          resourceNameRe = new RegExp("name: " + resourceName)
          return(line.match(resourceNameRe) !== null);
        });

        var absLinePos = resourceLine + resourcesLine;
        _self.activeEditor.setCursorBufferPosition([absLinePos, 0]);
      });<commit_msg>Fix for issue #5<commit_after>'use babel';
var url = require('url');
var _ = require('underscore');

import ConcourseVisView from './concourse-vis-view';
import { CompositeDisposable } from 'atom';

var isConcourseVisView = function(object) {
  if (isConcourseVisView == null) {
    isConcourseVisView = require('./concourse-vis-view');
  }
  return object instanceof ConcourseVisView;
};

export default {

  concourseVisView: null,
  modalPanel: null,
  subscriptions: null,

  activate(state) {
    this.concourseVisView = new ConcourseVisView(state.concourseVisViewState);
    this.concourseVisView.vis = this;
    this.activeEditor = atom.workspace.getActiveTextEditor();

    var _self = this;

    // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
    this.subscriptions = new CompositeDisposable();

    // Register command that toggles this view
    this.subscriptions.add(atom.commands.add('atom-workspace', {
      'concourse-vis:toggle': () => this.toggle()
    }));

    atom.workspace.addOpener(function(uri) {
      ref = url.parse(uri), protocol = ref.protocol, host = ref.host, pathname = ref.pathname;
      if (protocol !== 'concourse-vis:') {
        return;
      }

      return(_self.concourseVisView);

    });

    this.linkJobsAndResource = function() {

      var _self = this;

      // add click for jobs and resources
      $('.node.job a').click(function(e) {
        var jobName = _.find(e.currentTarget.children, function(c) { return c.tagName == "text"; }).innerHTML;
        var buffer = _self.activeEditor.getBuffer();
        var lines = buffer.getLines().slice(0);

        var jobsLine = _.findIndex(lines, function(line) {
          return(line.match(/jobs:/) !== null);
        });

        lines = lines.slice(jobsLine)

        var jobLine = _.findIndex(lines, function(line) {
          jobNameRe = new RegExp("name: " + jobName)
          return(line.match(jobNameRe) !== null);
        });

        var absLinePos = jobLine + jobsLine;
        _self.activeEditor.setCursorBufferPosition([absLinePos, 0]);
      });

      $('.node.input a, .node.output a, .node.constrained-input a').click(function(e) {
        var resourceName = _.find(e.currentTarget.children, function(c) { return c.tagName == "text"; }).innerHTML;

        var buffer = _self.activeEditor.getBuffer();
        var lines = buffer.getLines().slice(0);

        var resourcesLine = _.findIndex(lines, function(line) {
          return(line.match(/resources:/) !== null);
        });

        lines = lines.slice(resourcesLine)

        var resourceLine = _.findIndex(lines, function(line) {
          resourceNameRe = new RegExp("name: " + resourceName)
          return(line.match(resourceNameRe) !== null);
        });

        var absLinePos = resourceLine + resourcesLine;
        _self.activeEditor.setCursorBufferPosition([absLinePos, 0]);
      });
{'fraction_non_alphanumeric': 0.13573025976260106, 'fraction_numerical': 0.0015482539136418372, 'mean_word_length': 2.9767441860465116, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2807694', 'n_tokens_mistral': 1747, 'n_tokens_neox': 1686, 'n_words': 365}