Skip to content

Commit

Permalink
Merge pull request #106 from insurancezebra/util-changes
Browse files Browse the repository at this point in the history
Added "Referenced By" and "Depends On" section for each SQL file
  • Loading branch information
jtcohen6 authored Aug 11, 2020
2 parents 3a8192b + 522207d commit 13feab1
Show file tree
Hide file tree
Showing 19 changed files with 306 additions and 33 deletions.
61 changes: 61 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
colorator (1.1.0)
concurrent-ruby (1.1.6)
em-websocket (0.5.1)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
eventmachine (1.2.7)
ffi (1.13.1)
forwardable-extended (2.6.0)
http_parser.rb (0.6.0)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
jekyll (3.8.7)
addressable (~> 2.4)
colorator (~> 1.0)
em-websocket (~> 0.5)
i18n (~> 0.7)
jekyll-sass-converter (~> 1.0)
jekyll-watch (~> 2.0)
kramdown (~> 1.14)
liquid (~> 4.0)
mercenary (~> 0.3.3)
pathutil (~> 0.9)
rouge (>= 1.7, < 4)
safe_yaml (~> 1.0)
jekyll-sass-converter (1.5.2)
sass (~> 3.4)
jekyll-watch (2.2.1)
listen (~> 3.0)
kramdown (1.17.0)
liquid (4.0.3)
listen (3.2.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.3.6)
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (4.0.5)
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
ffi (~> 1.0)
rouge (3.20.0)
safe_yaml (1.0.5)
sass (3.7.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)

PLATFORMS
ruby

DEPENDENCIES
jekyll (~> 3.8)

BUNDLED WITH
2.1.4
2 changes: 2 additions & 0 deletions src/app/components/references/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ angular
return 'Snapshots'
} else if (type == 'analysis') {
return 'Analyses';
} else if (type == 'macro') {
return 'Macros';
} else {
return 'Nodes';
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/search/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h4 class="a">
<p ng-bind-html="highlight(shorten(result.model.description))"></p>
</div>
</div>
<div class="sub-results" ng-show="query.length > 0">
<div class="sub-results" ng-show="query.length > 0">
<span ng-repeat="column in columnFilter(result.model.columns) | limitTo:limitColumns(result.model.unique_id)">
<span ng-show="$first === true">columns:</span>
<span ng-bind-html="highlight(column + ',')" ng-show="$last === false"></span>
Expand All @@ -68,7 +68,7 @@ <h4 class="a">
<span ng-bind-html="highlight(tag + ',')" ng-show="$last === false"></span>
<span ng-bind-html="highlight(tag)" ng-show="$last === true"></span>
</span>
</div>
</div>
</div>
<a
ng-show="results.length >= max_results && !show_all"
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ angular
templateUrl: template,

link: function(scope) {
scope.max_results = 20;
scope.max_results = 20; //# of results on the page at once
scope.show_all = false;
scope.max_results_columns = 3;
scope.limit_columns = {};
Expand Down
22 changes: 20 additions & 2 deletions src/app/docs/analysis.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ <h1>
</div>
<div class="app-frame app-pad-h">
<ul class="nav nav-tabs">
<li ui-sref-active='active'><a ui-sref="dbt.seed({'#': 'description'})">Description</a></li>
<li ui-sref-active='active'><a ui-sref="dbt.seed({'#': 'sql'})">SQL</a></li>
<li ui-sref-active='active'><a ui-sref="dbt.analysis({'#': 'description'})">Description</a></li>
<li ui-sref-active='active' ng-show = "referencesLength != 0"><a ui-sref="dbt.analysis({'#': 'referenced_by'})">Referenced By</a></li>
<li ui-sref-active='active' ng-show = "parentsLength != 0"><a ui-sref="dbt.analysis({'#': 'depends_on'})">Depends On</a></li>
<li ui-sref-active='active'><a ui-sref="dbt.analysis({'#': 'sql'})">SQL</a></li>
</ul>
</div>
</div>
Expand All @@ -54,6 +56,22 @@ <h6>Description</h6>
</div>
</section>

<section class="section" ng-show = "referencesLength != 0">
<div class="section-target" id="referenced_by"></div>
<div class="section-content">
<h6>Referenced By</h6>
<reference-list references="references" />
</div>
</section>

<section class="section" ng-show = "parentsLength != 0">
<div class="section-target" id="depends_on"></div>
<div class="section-content">
<h6>Depends On</h6>
<reference-list references="parents" />
</div>
</section>

<section class="section">
<div class="section-target" id="sql"></div>
<div class="section-content">
Expand Down
8 changes: 7 additions & 1 deletion src/app/docs/analysis.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const angular = require('angular');
const dag_utils = require('./dag_utils')
require("./styles.css");

angular
Expand All @@ -20,7 +21,12 @@ angular

$scope.model = {};
projectService.ready(function(project) {
$scope.model = project.nodes[$scope.model_uid];
let mod = project.nodes[$scope.model_uid];
$scope.model = mod;
$scope.references = dag_utils.getReferences(project, mod);
$scope.referencesLength = Object.keys($scope.references).length;
$scope.parents = dag_utils.getParents(project, mod);
$scope.parentsLength = Object.keys($scope.parents).length;

$scope.versions = {
'Source': $scope.model.raw_sql,
Expand Down
70 changes: 70 additions & 0 deletions src/app/docs/dag_utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const _ = require('underscore');
export function getReferences(project, model) {
let references = _.filter(project.nodes, function(node) {
if (node.depends_on && node.depends_on.nodes && node.depends_on.nodes.length) {
if (_.contains(node.depends_on.nodes, model.unique_id)) {
return true;
}
}
return false;
});

return _.groupBy(references, 'resource_type');
}

export function getParents (project, model) {
let parents = _.filter(project.nodes, function(node) {
if (model.depends_on && model.depends_on.nodes && model.depends_on.nodes.length) {
if (_.contains(model.depends_on.nodes, node.unique_id)) {
return true;
}
}
return false;
});

let macroParents = _.filter(project.macros, function(macro) {
if (model.depends_on && model.depends_on.macros && model.depends_on.macros.length) {
if (_.contains(model.depends_on.macros, macro.unique_id)) {
return true;
}
}
return false;
});

return _.groupBy(parents.concat(macroParents), 'resource_type');
}

export function getMacroReferences(project, self) {
let references = _.filter(project.nodes, function(node) {
if (node.depends_on && node.depends_on.macros && node.depends_on.macros.length) {
if (_.contains(node.depends_on.macros, self.unique_id)) {
return true;
}
}
return false;
});

let macroReferences = _.filter(project.macros, function(macro) {
if (macro.depends_on && macro.depends_on.macros && macro.depends_on.macros.length) {
if (_.contains(macro.depends_on.macros, self.unique_id)) {
return true;
}
}
return false;
});

return _.groupBy(references.concat(macroReferences), 'resource_type');
}

export function getMacroParents (project, self) {
let macroParents = _.filter(project.macros, function(macro) {
if (self.depends_on && self.depends_on.macros && self.depends_on.macros.length) {
if (_.contains(self.depends_on.macros, macro.unique_id)) {
return true;
}
}
return false;
});

return _.groupBy(macroParents, 'resource_type');
}
15 changes: 12 additions & 3 deletions src/app/docs/macro.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ <h1>
<ul class="nav nav-tabs">
<li ui-sref-active='active'><a ui-sref="dbt.macro({'#': 'description'})">Description</a></li>
<li ui-sref-active='active'><a ui-sref="dbt.macro({'#': 'arguments'})">Arguments</a></li>
<li ui-sref-active='active'><a ui-sref="dbt.macro({'#': 'referenced_by'})">Referenced By</a></li>
<li ui-sref-active='active' ng-show = "referencesLength != 0"><a ui-sref="dbt.macro({'#': 'referenced_by'})">Referenced By</a></li>
<li ui-sref-active='active' ng-show = "parentsLength != 0"><a ui-sref="dbt.macro({'#': 'depends_on'})">Depends On</a></li>
<li ui-sref-active='active'><a ui-sref="dbt.macro({'#': 'code'})">Code</a></li>
</ul>
</div>
Expand All @@ -51,21 +52,29 @@ <h6>Description</h6>
</section>

<section class="section">
<div class="section-target" id="columns"></div>
<div class="section-target" id="arguments"></div>
<div class="section-content">
<h6>Arguments</h6>
<macro-arguments macro="macro"></macro-arguments>
</div>
</section>

<section class="section">
<section class="section" ng-show = "referencesLength != 0">
<div class="section-target" id="referenced_by"></div>
<div class="section-content">
<h6>Referenced By</h6>
<reference-list references="references" />
</div>
</section>

<section class="section" ng-show = "parentsLength != 0">
<div class="section-target" id="depends_on"></div>
<div class="section-content">
<h6>Depends On</h6>
<reference-list references="parents" />
</div>
</section>

<section class="section">
<div class="section-target" id="code"></div>
<div class="section-content">
Expand Down
23 changes: 6 additions & 17 deletions src/app/docs/macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const angular = require('angular');
const _ = require('underscore');
const dag_utils = require('./dag_utils')

require("./styles.css");

Expand All @@ -14,26 +15,14 @@ angular
$scope.tab = $state.params.tab;
$scope.project = projectService;
$scope.codeService = codeService;

function getReferences(project, macro) {
var references = _.filter(project.nodes, function(node) {
if (node.depends_on && node.depends_on.macros && node.depends_on.macros.length) {
if (_.contains(node.depends_on.macros, macro.unique_id)) {
return true;
}
}
return false;
});

// TODO : include macros?
return _.groupBy(references, 'resource_type');
}

$scope.macro = {};
projectService.ready(function(project) {
var macro = project.macros[$scope.model_uid];
let macro = project.macros[$scope.model_uid];
$scope.macro = macro;
$scope.references = getReferences(project, macro);
$scope.references = dag_utils.getMacroReferences(project, macro);
$scope.referencesLength = Object.keys($scope.references).length;
$scope.parents = dag_utils.getMacroParents(project, macro);
$scope.parentsLength = Object.keys($scope.parents).length;

// adapter macros
if ($scope.macro.is_adapter_macro) {
Expand Down
18 changes: 18 additions & 0 deletions src/app/docs/model.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ <h1>
<li ui-sref-active='active'><a ui-sref="dbt.model({'#': 'details'})">Details</a></li>
<li ui-sref-active='active'><a ui-sref="dbt.model({'#': 'description'})">Description</a></li>
<li ui-sref-active='active'><a ui-sref="dbt.model({'#': 'columns'})">Columns</a></li>
<li ui-sref-active='active' ng-show = "referencesLength != 0"><a ui-sref="dbt.model({'#': 'referenced_by'})">Referenced By</a></li>
<li ui-sref-active='active' ng-show = "parentsLength != 0"><a ui-sref="dbt.model({'#': 'depends_on'})">Depends On</a></li>
<li ui-sref-active='active'><a ui-sref="dbt.model({'#': 'code'})">SQL</a></li>
</ul>
</div>
Expand Down Expand Up @@ -68,6 +70,22 @@ <h6>Columns</h6>
</div>
</section>

<section class="section" ng-show = "referencesLength != 0">
<div class="section-target" id="referenced_by"></div>
<div class="section-content">
<h6>Referenced By</h6>
<reference-list references="references" />
</div>
</section>

<section class="section" ng-show = "parentsLength != 0">
<div class="section-target" id="depends_on"></div>
<div class="section-content">
<h6>Depends On</h6>
<reference-list references="parents" />
</div>
</section>

<section class="section">
<div class="section-target" id="code"></div>
<div class="section-content">
Expand Down
10 changes: 7 additions & 3 deletions src/app/docs/model.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const angular = require('angular');
const dag_utils = require('./dag_utils')
require("./styles.css");

angular
Expand All @@ -12,7 +13,6 @@ angular
$scope.tab = $state.params.tab;
$scope.project = projectService;
$scope.codeService = codeService;

$scope.versions = {}

$scope.copied = false;
Expand All @@ -28,8 +28,12 @@ angular

$scope.model = {};
projectService.ready(function(project) {
$scope.model = project.nodes[$scope.model_uid];

let mod = project.nodes[$scope.model_uid];
$scope.model = mod;
$scope.references = dag_utils.getReferences(project, mod);
$scope.referencesLength = Object.keys($scope.references).length;
$scope.parents = dag_utils.getParents(project, mod);
$scope.parentsLength = Object.keys($scope.parents).length;
var default_compiled = '\n-- compiled SQL not found for this model\n';
$scope.versions = {
'Source': $scope.model.raw_sql,
Expand Down
Loading

0 comments on commit 13feab1

Please sign in to comment.