Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
blocknotes committed Nov 15, 2019
1 parent f08518a commit c2143a0
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ $(document).ready(function() {
let node = {
name: currentNode.name,
example: currentNode.example,
is_file_name: currentNode.is_file_name,
path: currentNode.path,
expanded: true,
children: traverseTreeData([], paths.slice(1))
};
Expand All @@ -170,19 +172,21 @@ $(document).ready(function() {

$('.source_table.highlighted li.covered').live('click', function() {
const exampleRefs = $(this).children('.reverse_coverage')[0].dataset.exampleRefs.split(",");
if(!$(this).children('.reverse_coverage').is(':visible')){
if(!$(this).children('.reverse_coverage').is(':visible')) {
let treeData = [];
const self = this;
exampleRefs.forEach(function(ref) {
const example = window.examples[ref]
const treeNodes = []
example["file_path"].split('/').slice(1).forEach(function(node_path){
treeNodes.push({ name: node_path })
const example = window.examples[ref];
const treeNodes = [];
const parts = example['file_path'].split('/').slice(1);
parts.forEach(function(node_path, i) {
var node = { name: node_path, is_file_name: (parts.length - 1 == i) };
if(node.is_file_name) node.path = example['file_path'];
treeNodes.push(node);
});
treeNodes.push({ example: example, name: example['full_description'] });

treeData = traverseTreeData(treeData, treeNodes)
})
treeData = traverseTreeData(treeData, treeNodes);
});

const domElement = self.querySelector('.reverse_coverage');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,18 @@
var expando = document.createElement('div');

leaf.setAttribute('class', 'tree-leaf');
content.setAttribute('class', 'tree-leaf-content');
content.setAttribute('class', 'tree-leaf-content' + (item.is_file_name ? ' file_name' : ''));
content.setAttribute('data-item', JSON.stringify(item));
text.setAttribute('class', 'tree-leaf-text');
text.textContent = item.name;
expando.setAttribute('class', 'tree-expando ' + (item.expanded ? 'expanded' : ''));
if(item.is_file_name) {
var copyURL = document.createElement('a');
copyURL.setAttribute('href', 'Javascript:void(0)');
copyURL.setAttribute('class', 'copy-example-path');
copyURL.setAttribute('data-path', item.path);
text.appendChild(copyURL);
}
expando.setAttribute('class', 'tree-expando' + (item.expanded ? ' expanded' : ''));
expando.textContent = item.expanded ? '-' : '+';
content.appendChild(expando);
content.appendChild(text);
Expand Down Expand Up @@ -140,6 +147,14 @@
forEach(container.querySelectorAll('.tree-expando'), function (node) {
node.onclick = click;
});
forEach(container.querySelectorAll('.copy-example-path'), function (node) {
node.onclick = function(e) {
var el = (e.target || e.currentTarget);
event.stopPropagation();
var path = el.getAttribute('data-path');
navigator.clipboard.writeText(path);
};
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,10 @@ td

&:before
content: ''

a.copy-example-path
background: url('./clipboard.gif') no-repeat
display: inline-block
width: 11px
height: 13px
margin-left: 12px
7 changes: 7 additions & 0 deletions lib/reverse_coverage/formatters/html/public/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,13 @@ td {
.tree-expando.hidden + .tree-leaf-text:before {
content: "↳ "; }

a.copy-example-path {
background: url("./clipboard.gif") no-repeat;
display: inline-block;
width: 11px;
height: 13px;
margin-left: 12px; }




39 changes: 29 additions & 10 deletions lib/reverse_coverage/formatters/html/public/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -1663,11 +1663,18 @@ jQuery.url = function()
var expando = document.createElement('div');

leaf.setAttribute('class', 'tree-leaf');
content.setAttribute('class', 'tree-leaf-content');
content.setAttribute('class', 'tree-leaf-content' + (item.is_file_name ? ' file_name' : ''));
content.setAttribute('data-item', JSON.stringify(item));
text.setAttribute('class', 'tree-leaf-text');
text.textContent = item.name;
expando.setAttribute('class', 'tree-expando ' + (item.expanded ? 'expanded' : ''));
if(item.is_file_name) {
var copyURL = document.createElement('a');
copyURL.setAttribute('href', 'Javascript:void(0)');
copyURL.setAttribute('class', 'copy-example-path');
copyURL.setAttribute('data-path', item.path);
text.appendChild(copyURL);
}
expando.setAttribute('class', 'tree-expando' + (item.expanded ? ' expanded' : ''));
expando.textContent = item.expanded ? '-' : '+';
content.appendChild(expando);
content.appendChild(text);
Expand Down Expand Up @@ -1720,6 +1727,14 @@ jQuery.url = function()
forEach(container.querySelectorAll('.tree-expando'), function (node) {
node.onclick = click;
});
forEach(container.querySelectorAll('.copy-example-path'), function (node) {
node.onclick = function(e) {
var el = (e.target || e.currentTarget);
event.stopPropagation();
var path = el.getAttribute('data-path');
navigator.clipboard.writeText(path);
};
});
}

/**
Expand Down Expand Up @@ -1994,6 +2009,8 @@ $(document).ready(function() {
let node = {
name: currentNode.name,
example: currentNode.example,
is_file_name: currentNode.is_file_name,
path: currentNode.path,
expanded: true,
children: traverseTreeData([], paths.slice(1))
};
Expand All @@ -2011,19 +2028,21 @@ $(document).ready(function() {

$('.source_table.highlighted li.covered').live('click', function() {
const exampleRefs = $(this).children('.reverse_coverage')[0].dataset.exampleRefs.split(",");
if(!$(this).children('.reverse_coverage').is(':visible')){
if(!$(this).children('.reverse_coverage').is(':visible')) {
let treeData = [];
const self = this;
exampleRefs.forEach(function(ref) {
const example = window.examples[ref]
const treeNodes = []
example["file_path"].split('/').slice(1).forEach(function(node_path){
treeNodes.push({ name: node_path })
const example = window.examples[ref];
const treeNodes = [];
const parts = example['file_path'].split('/').slice(1);
parts.forEach(function(node_path, i) {
var node = { name: node_path, is_file_name: (parts.length - 1 == i) };
if(node.is_file_name) node.path = example['file_path'];
treeNodes.push(node);
});
treeNodes.push({ example: example, name: example['full_description'] });

treeData = traverseTreeData(treeData, treeNodes)
})
treeData = traverseTreeData(treeData, treeNodes);
});

const domElement = self.querySelector('.reverse_coverage');

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c2143a0

Please sign in to comment.