Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added search by columns. #23

Merged
merged 3 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions src/app/components/search/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
.search-result-match {
background-color: #eee;
}
.spacing {
margin-right: 0.25em;
}
.columns {
margin-left: 36px;
}
</style>

<div class="app-title">
Expand All @@ -16,24 +22,33 @@ <h1>
<div class="app-details">
<div class="app-frame app-pad">
<div class="results">
<a ui-sref="dbt.model({unique_id: result.model.unique_id})"
class="result search-result"
ng-click="onSelect()"
ng-repeat="result in results | filter:limit_search | orderBy:'-model.name':true track by result.model.unique_id ">

<div class="result-content">
<div class="result-icn">
<svg class="icn "><use xlink:href="#icn-doc"></use></svg>
</div>
<div class="result-body">
<h4 class="a">
<span ng-bind-html="highlight(getModelName(result.model))"></span>
<small>{{result.model.resource_type}}</small>
</h4>
<p ng-bind-html="highlight(result.model.description)"></p>
<div ng-repeat="result in results | filter:limit_search | orderBy:'-model.name':true track by result.model.unique_id"
ui-sref="dbt.model({unique_id: result.model.unique_id})"
ng-click="onSelect()"
class="result search-result a">
<div class="result-content">
<div class="result-icn">
<svg class="icn "><use xlink:href="#icn-doc"></use></svg>
</div>
<div class="result-body">
<h4 class="a">
<span ng-bind-html="highlight(getModelName(result.model))"></span>
<small>{{result.model.resource_type}}</small>
</h4>
<p ng-bind-html="highlight(result.model.description)"></p>
</div>
</div>
<div class="columns" 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>
<span ng-bind-html="highlight(column)" ng-show="$last === true"></span>
</span>
<a
ng-show="columnFilter(result.model.columns).length > max_results_columns && !limit_columns[result.model.unique_id]"
ng-click="$event.stopPropagation(); limit_columns[result.model.unique_id] = 100">Show {{ columnFilter(result.model.columns).length - max_results_columns }} more</a>
</div>
</a>
</div>
<a
ng-show="results.length >= max_results && !show_all"
ng-click="show_all = true">Show {{ results.length - max_results }} more</a>
Expand Down
17 changes: 17 additions & 0 deletions src/app/components/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ angular
link: function(scope) {
scope.max_results = 20;
scope.show_all = false;
scope.max_results_columns = 3;
scope.limit_columns = {};

scope.limit_search = function(res, index, results) {
return (index < scope.max_results || scope.show_all);
Expand All @@ -40,8 +42,23 @@ angular
scope.$watch("query", function(nv, ov) {
if (nv.length == 0) {
scope.show_all = false;
scope.limit_columns = {};
}
});

scope.columnFilter = function(columns) {
var matches = [];
for (var column in columns) {
if (column.toLowerCase().indexOf(scope.query.toLowerCase()) != -1) {
matches.push(column);
}
}
return matches;
}

scope.limitColumns = function(id) {
return scope.limit_columns[id] !== undefined? scope.limit_columns[id] : 3;
}
}
}
}]);
10 changes: 8 additions & 2 deletions src/app/services/project_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,21 @@ angular

function fuzzySearchObj(val, obj) {
var objects = [];
var search_keys = {'name':null, 'description':null};
var search_keys = {'name':'string', 'description':'string', 'columns':'object'};

var search = new RegExp(val, "i")

for (var i in search_keys) {
if (!obj[i]) {
continue;
} else if (obj[i].toLowerCase().indexOf(val.toLowerCase()) != -1) {
} else if (search_keys[i] === 'string' && obj[i].toLowerCase().indexOf(val.toLowerCase()) != -1) {
objects.push({key: i, value: val});
} else if (search_keys[i] === 'object') {
for (var column_name in obj[i]) {
if (obj[i][column_name]["name"].toLowerCase().indexOf(val.toLowerCase()) != -1) {
objects.push({key: i, value: val});
}
}
}
}

Expand Down