Skip to content

Commit

Permalink
Merge pull request #372 from Qblack/feature/blueprint_dropdown
Browse files Browse the repository at this point in the history
Adding the ability to filter by 'blueprint' first word before .
  • Loading branch information
mircealungu committed Feb 10, 2021
2 parents e568e87 + 238b826 commit 555f90a
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
2 changes: 2 additions & 0 deletions flask_monitoringdashboard/controllers/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from flask_monitoringdashboard import config
from flask_monitoringdashboard.core import cache
from flask_monitoringdashboard.core.blueprints import get_blueprint
from flask_monitoringdashboard.core.colors import get_color
from flask_monitoringdashboard.core.measurement import add_decorator
from flask_monitoringdashboard.core.timezone import to_local_datetime, to_utc_datetime
Expand Down Expand Up @@ -60,6 +61,7 @@ def get_endpoint_overview(session):
{
'id': endpoint.id,
'name': endpoint.name,
'blueprint': get_blueprint(endpoint.name),
'monitor': endpoint.monitor_level,
'color': get_color(endpoint.name),
'hits-today': get_value(hits_today, endpoint.id),
Expand Down
5 changes: 5 additions & 0 deletions flask_monitoringdashboard/core/blueprints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def get_blueprint(endpoint_name):
blueprint = endpoint_name
if '.' in endpoint_name:
blueprint = endpoint_name.split('.')[0]
return blueprint
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,33 @@ export function OverviewController($scope, $http, $location, menuService, endpoi
$scope.searchQuery = '';
$scope.pageSize = '10';
$scope.currentPage = 0;
$scope.blueprints = [''];
$scope.slectedBlueprint = '';

$scope.toggleHits = function () {
$scope.isHits = !$scope.isHits;
};

$http.get('api/overview').then(function (response) {
response.data.forEach((endpoint) => {
if (!$scope.blueprints.includes(endpoint.blueprint)) {
$scope.blueprints.push(endpoint.blueprint)
}
})
$scope.table = response.data;
});

function getItemsForPage(pageNumber) {
const start = Number(pageNumber) * $scope.pageSize;
const end = (Number(pageNumber) + 1) * Number($scope.pageSize);

return $scope.table
let items = $scope.table
.filter(item => item.name.includes($scope.searchQuery))
.slice(start, end);
if ($scope.slectedBlueprint) {
items = items.filter(item => item.blueprint===$scope.slectedBlueprint)
}

return items.slice(start, end);
}

$scope.getFilteredItems = function () {
Expand Down
15 changes: 13 additions & 2 deletions flask_monitoringdashboard/static/pages/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</ul>

<div class="row" style="margin-bottom: 7px">
<div class="col-md-6 col-sm-12">
<div class="col-md-3 col-sm-12">
Show
<select style="width: 60px; display: inline-block;"
class='form-control form-control-sm' name="ddwa"
Expand All @@ -44,7 +44,18 @@
entries
</div>

<div class="col-md-6 col-sm-12" style="text-align: right">
<div class="col-md-6 col-sm-12">
Blueprint:
<select style='width: 180px; display: inline-block;' ng-model="slectedBlueprint"
class="form-control form-control-sm">
<option ng-repeat="blueprint in blueprints track by $index"
value="{{ blueprint }}">
{{ blueprint }}
</option>
</select>
</div>

<div class="col-md-3 col-sm-12" style="text-align: right">
Search:
<input ng-model="searchQuery"
style="display: inline-block; width: 180px"
Expand Down
1 change: 1 addition & 0 deletions tests/api/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def test_overview(dashboard_user, request_1, request_2, endpoint, session):

assert data['monitor'] == 3
assert data['name'] == endpoint.name
assert data['blueprint'] == endpoint.name


@pytest.mark.parametrize('request_1__group_by', ['42'])
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/core/test_blueprints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest

from flask_monitoringdashboard.core.blueprints import get_blueprint


@pytest.mark.parametrize('name', ['Fiddler'])
def test_get_blueprint(name):
actual = get_blueprint(name)
assert actual == 'Fiddler'


@pytest.mark.parametrize('name', ['Anomander.Purake'])
def test_get_blueprint_double_gives_first(name):
actual = get_blueprint(name)
assert actual == 'Anomander'


@pytest.mark.parametrize('name', ['Karsa.Orlong.Toblakai'])
def test_get_blueprint_triple_gives_first(name):
actual = get_blueprint(name)
assert actual == 'Karsa'


@pytest.mark.usefixtures('request_context')
@pytest.mark.parametrize('name', [''])
def test_get_blueprint_blank_gives_blank(name):
actual = get_blueprint(name)
assert actual == ''

0 comments on commit 555f90a

Please sign in to comment.