<commit_before><link rel="import" href="noflo-node-menu.html">
<link rel="import" href="noflo-node-inspector.html">
<link rel="import" href="noflo-edge-menu.html">
<link rel="import" href="noflo-edge-inspector.html">
<link rel="import" href="../bower_components/the-card/the-card/the-card.html">
<link rel="import" href="../bower_components/the-panel/the-panel/the-panel.html">
<polymer-element name="noflo-context" attributes="project graphs component node edge search">
  <template>
    <section id="context"></section>
    <the-panel id="fixed" edge="right" size="324" handle="36" automatic="false">
      <header></header>
      <main></main>
      <footer></footer>
    </the-panel>
  </template>
  <script>
    Polymer('noflo-context', {
      project: null,
      search: '',
      editor: null,
      graphs: [],
      edges: [],
      nodes: [],
      component: '',
      enteredView: function () {
        this.graphObserver = new ArrayObserver(this.graphs);
        this.graphObserver.open(this.graphsModified.bind(this));
        this.contextBar = this.$.context;
        window.addEventListener('keyup', function (e) {
          if (e.keyCode === 27) {
            var edge, node;
            // Clear selections on Esc
            while (this.edges.length) {
              edge = this.edges.pop();
              edge.selected = false;
            }
            while (this.nodes.length) {
              node = this.nodes.pop();
              node.selected = false;
            }
          }
        }.bind(this));
      },
      getpanel: function () {
        this.fire('toolpanel', this.$.fixed);
        this.fire('contextpanel', this.$.context);
      },
      editorChanged: function () {
        if (!this.editor) {
          return;
        }
        this.editor.addMenuAction('node', 'n4', {
          icon: 'search',
          iconLabel: 'inspect',
          action: function (graph, itemKey, item) {
            if (this.nodes.indexOf(item) !== -1) {
              this.nodes.splice(this.nodes.indexOf(item), 1);
              return;
            }
            this.nodes.push(item);
          }.bind(this)
        });
        this.editor.addMenuAction('edge', 'n4', {
          icon: 'search',
          iconLabel: 'inspect',
          action: function (graph, itemKey, item) {
            if (this.edges.indexOf(item) !== -1) {
              this.edges.splice(this.edges.indexOf(item), 1);
              return;
            }
            this.edges.push(item);
          }.bind(this)
        });
      },
      projectChanged: function () {
        this.fire('project', this.project);
      },
      graphsModified: function () {
        this.fire('graphs', this.graphs);
        if (this.graphs.length) {
          this.fire('currentgraph', this.graphs[this.graphs.length - 1]);
        }
        this.search = '';
      },
      nodesChanged: function () {
        this.fire('nodes', this.nodes);
        if (this.nodes.length) {
          this.showNodeCards();
        } else {
          this.hideNodeCards();
        }
      },
      nodeInspectors: {},
      showNodeCards: function () {
        if (!this.nodeMenu) {
          var menu = document.createElement('noflo-node-menu');
          menu.nodes = this.nodes;
          menu.graph = this.graphs[this.graphs.length - 1];
          this.nodeMenu = document.createElement('the-card');
          this.nodeMenu.type = 'node-menu';
          this.nodeMenu.appendChild(menu);
          this.nodeMenu.addTo(this.contextBar);
          this.nodeMenu.addEventListener('newgraph', function (event) {
            this.project.graphs.push(event.detail);
            this.fire('newgraph', event.detail);
          }.bind(this));
        }

        this.nodes.forEach(function (node) {
          var id = node.id;
          if (this.nodeInspectors[id]) {
            return;
          }
          var inspector = document.createElement('noflo-node-inspector');
          inspector.node = node;
          inspector.component = this.editor.getComponent(node.component);
          inspector.graph = this.graphs[this.graphs.length - 1];
          this.nodeInspectors[id] = document.createElement('the-card');
          this.nodeInspectors[id].type = 'node-inspector';
          this.nodeInspectors[id].appendChild(inspector);
          this.nodeInspectors[id].addTo(this.contextBar);
        }.bind(this));

        var found;
        Object.keys(this.nodeInspectors).forEach(function (id) {
          found = false;
          this.nodes.forEach(function (node) {
            if (node.id === id) {
              found = true;
            }
          });
          if (!found) {
            this.nodeInspectors[id].parentNode.removeChild(this.nodeInspectors[id]);
            delete this.nodeInspectors[id];
          }
        }.bind(this));
      },
      hideNodeCards: function () {
        if (this.nodeMenu) {
          this.nodeMenu.parentNode.removeChild(this.nodeMenu);
          this.nodeMenu = null;
        }

        for (var id in this.nodeInspectors) {
          this.nodeInspectors[id].parentNode.removeChild(this.nodeInspectors[id]);
          delete this.nodeInspectors[id];
        }
      },
      edgesChanged: function () {
        this.fire('edges', this.edges);
        if (this.edges.length) {
          this.showEdgeCards();
        } else {
          this.hideEdgeCards();
        }
      },
      edgeInspectors: {},
      showEdgeCards: function () {
        if (!this.edgeMenu) {
          var menu = document.createElement('noflo-edge-menu');
          menu.edges = this.edges;
          menu.graph = this.graphs[this.graphs.length - 1];
          this.edgeMenu = document.createElement('the-card');
          this.edgeMenu.type = 'edge-menu';
          this.edgeMenu.appendChild(menu);
          this.edgeMenu.addTo(this.contextBar);
        }

        this.edges.forEach(function (edge) {
          var id = edge.pathId;
          if (this.edgeInspectors[id]) {
            return;
          }
          var inspector = document.createElement('noflo-edge-inspector');
          inspector.edge = edge;
          inspector.graph = this.graphs[this.graphs.length - 1];
          this.edgeInspectors[id] = document.createElement('the-card');
          this.edgeInspectors[id].type = 'edge-inspector';
          this.edgeInspectors[id].appendChild(inspector);
          this.edgeInspectors[id].addTo(this.contextBar);
        }.bind(this));

        var found;
        Object.keys(this.edgeInspectors).forEach(function (id) {
          found = false;
          this.edges.forEach(function (edge) {
            if (edge.pathId === id) {
              found = true;
            }
          });
          if (!found) {
            this.edgeInspectors[id].parentNode.removeChild(this.edgeInspectors[id]);
            delete this.edgeInspectors[id];
          }
        }.bind(this));
      },
      hideEdgeCards: function () {
        if (this.edgeMenu) {
          this.edgeMenu.parentNode.removeChild(this.edgeMenu);
          this.edgeMenu = null;
        }
        for (var id in this.edgeInspectors) {
          this.edgeInspectors[id].parentNode.removeChild(this.edgeInspectors[id]);
          delete this.edgeInspectors[id];
        }
      },
      componentChanged: function () {
        this.fire('component', this.component);
      },
      clear: function () {
        this.project = null;
        this.graphs.splice(0, this.graphs.length);
        this.nodes.splice(0, this.nodes.length);
        this.edges.splice(0, this.edges.length);
      }
    });
  </script>
</polymer-element>
<commit_msg>We don't need an observer here<commit_after><link rel="import" href="noflo-node-menu.html">
<link rel="import" href="noflo-node-inspector.html">
<link rel="import" href="noflo-edge-menu.html">
<link rel="import" href="noflo-edge-inspector.html">
<link rel="import" href="../bower_components/the-card/the-card/the-card.html">
<link rel="import" href="../bower_components/the-panel/the-panel/the-panel.html">
<polymer-element name="noflo-context" attributes="project graphs component node edge search">
  <template>
    <section id="context"></section>
    <the-panel id="fixed" edge="right" size="324" handle="36" automatic="false">
      <header></header>
      <main></main>
      <footer></footer>
    </the-panel>
  </template>
  <script>
    Polymer('noflo-context', {
      project: null,
      search: '',
      editor: null,
      graphs: [],
      edges: [],
      nodes: [],
      component: '',
      enteredView: function () {
        this.contextBar = this.$.context;
        window.addEventListener('keyup', function (e) {
          if (e.keyCode === 27) {
            var edge, node;
            // Clear selections on Esc
            while (this.edges.length) {
              edge = this.edges.pop();
              edge.selected = false;
            }
            while (this.nodes.length) {
              node = this.nodes.pop();
              node.selected = false;
            }
          }
        }.bind(this));
      },
      getpanel: function () {
        this.fire('toolpanel', this.$.fixed);
        this.fire('contextpanel', this.$.context);
      },
      editorChanged: function () {
        if (!this.editor) {
          return;
        }
        this.editor.addMenuAction('node', 'n4', {
          icon: 'search',
          iconLabel: 'inspect',
          action: function (graph, itemKey, item) {
            if (this.nodes.indexOf(item) !== -1) {
              this.nodes.splice(this.nodes.indexOf(item), 1);
              return;
            }
            this.nodes.push(item);
          }.bind(this)
        });
        this.editor.addMenuAction('edge', 'n4', {
          icon: 'search',
          iconLabel: 'inspect',
          action: function (graph, itemKey, item) {
            if (this.edges.indexOf(item) !== -1) {
              this.edges.splice(this.edges.indexOf(item), 1);
              return;
            }
            this.edges.push(item);
          }.bind(this)
        });
      },
      projectChanged: function () {
        this.fire('project', this.project);
      },
      graphsChanged: function () {
        this.fire('graphs', this.graphs);
        if (this.graphs.length) {
          this.fire('currentgraph', this.graphs[this.graphs.length - 1]);
        }
        this.search = '';
      },
      nodesChanged: function () {
        this.fire('nodes', this.nodes);
        if (this.nodes.length) {
          this.showNodeCards();
        } else {
          this.hideNodeCards();
        }
      },
      nodeInspectors: {},
      showNodeCards: function () {
        if (!this.nodeMenu) {
          var menu = document.createElement('noflo-node-menu');
          menu.nodes = this.nodes;
          menu.graph = this.graphs[this.graphs.length - 1];
          this.nodeMenu = document.createElement('the-card');
          this.nodeMenu.type = 'node-menu';
          this.nodeMenu.appendChild(menu);
          this.nodeMenu.addTo(this.contextBar);
          this.nodeMenu.addEventListener('newgraph', function (event) {
            this.project.graphs.push(event.detail);
            this.fire('newgraph', event.detail);
          }.bind(this));
        }

        this.nodes.forEach(function (node) {
          var id = node.id;
          if (this.nodeInspectors[id]) {
            return;
          }
          var inspector = document.createElement('noflo-node-inspector');
          inspector.node = node;
          inspector.component = this.editor.getComponent(node.component);
          inspector.graph = this.graphs[this.graphs.length - 1];
          this.nodeInspectors[id] = document.createElement('the-card');
          this.nodeInspectors[id].type = 'node-inspector';
          this.nodeInspectors[id].appendChild(inspector);
          this.nodeInspectors[id].addTo(this.contextBar);
        }.bind(this));

        var found;
        Object.keys(this.nodeInspectors).forEach(function (id) {
          found = false;
          this.nodes.forEach(function (node) {
            if (node.id === id) {
              found = true;
            }
          });
          if (!found) {
            this.nodeInspectors[id].parentNode.removeChild(this.nodeInspectors[id]);
            delete this.nodeInspectors[id];
          }
        }.bind(this));
      },
      hideNodeCards: function () {
        if (this.nodeMenu) {
          this.nodeMenu.parentNode.removeChild(this.nodeMenu);
          this.nodeMenu = null;
        }

        for (var id in this.nodeInspectors) {
          this.nodeInspectors[id].parentNode.removeChild(this.nodeInspectors[id]);
          delete this.nodeInspectors[id];
        }
      },
      edgesChanged: function () {
        this.fire('edges', this.edges);
        if (this.edges.length) {
          this.showEdgeCards();
        } else {
          this.hideEdgeCards();
        }
      },
      edgeInspectors: {},
      showEdgeCards: function () {
        if (!this.edgeMenu) {
          var menu = document.createElement('noflo-edge-menu');
          menu.edges = this.edges;
          menu.graph = this.graphs[this.graphs.length - 1];
          this.edgeMenu = document.createElement('the-card');
          this.edgeMenu.type = 'edge-menu';
          this.edgeMenu.appendChild(menu);
          this.edgeMenu.addTo(this.contextBar);
        }

        this.edges.forEach(function (edge) {
          var id = edge.pathId;
          if (this.edgeInspectors[id]) {
            return;
          }
          var inspector = document.createElement('noflo-edge-inspector');
          inspector.edge = edge;
          inspector.graph = this.graphs[this.graphs.length - 1];
          this.edgeInspectors[id] = document.createElement('the-card');
          this.edgeInspectors[id].type = 'edge-inspector';
          this.edgeInspectors[id].appendChild(inspector);
          this.edgeInspectors[id].addTo(this.contextBar);
        }.bind(this));

        var found;
        Object.keys(this.edgeInspectors).forEach(function (id) {
          found = false;
          this.edges.forEach(function (edge) {
            if (edge.pathId === id) {
              found = true;
            }
          });
          if (!found) {
            this.edgeInspectors[id].parentNode.removeChild(this.edgeInspectors[id]);
            delete this.edgeInspectors[id];
          }
        }.bind(this));
      },
      hideEdgeCards: function () {
        if (this.edgeMenu) {
          this.edgeMenu.parentNode.removeChild(this.edgeMenu);
          this.edgeMenu = null;
        }
        for (var id in this.edgeInspectors) {
          this.edgeInspectors[id].parentNode.removeChild(this.edgeInspectors[id]);
          delete this.edgeInspectors[id];
        }
      },
      componentChanged: function () {
        this.fire('component', this.component);
      },
      clear: function () {
        this.project = null;
        this.graphs.splice(0, this.graphs.length);
        this.nodes.splice(0, this.nodes.length);
        this.edges.splice(0, this.edges.length);
      }
    });
  </script>
</polymer-element>

{'fraction_non_alphanumeric': 0.1454497284408531, 'fraction_numerical': 0.0027818254073387204, 'mean_word_length': 1.893082966085457, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, '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': '488773', 'n_tokens_mistral': 4477, 'n_tokens_neox': 4377, 'n_words': 687}