Skip to content

Commit

Permalink
HTML5 Report: add sorting by tags with values (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Schäfer committed Jun 23, 2015
1 parent fbd3033 commit 81a1380
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
60 changes: 48 additions & 12 deletions jgiven-html5-report/src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ jgivenReportApp.controller('JGivenReportCtrl', function ($scope, $rootScope, $ti

$scope.applyOptions = function applyOptions() {
var page = $scope.currentPage;
var filteredSorted = getSelectedSortOption( page ).apply(
var selectedSortOption = getSelectedSortOption(page);
var filteredSorted = selectedSortOption.apply(
_.filter( page.scenarios, getFilterFunction( page )) );
page.groupedScenarios = getSelectedGroupOption( page ).apply( filteredSorted );
page.statistics = $scope.gatherStatistics( filteredSorted );
Expand Down Expand Up @@ -569,12 +570,14 @@ jgivenReportApp.controller('JGivenReportCtrl', function ($scope, $rootScope, $ti
}

function getDefaultOptions( scenarios ) {
var uniqueSortedTags = getUniqueSortedTags( scenarios);

return {
sortOptions: getDefaultSortOptions(),
sortOptions: getDefaultSortOptions( uniqueSortedTags ),
groupOptions: getDefaultGroupOptions(),
statusOptions: getDefaultStatusOptions( ),
tagOptions: getDefaultTagOptions( scenarios ),
classOptions: getDefaultClassOptions( scenarios ),
tagOptions: getDefaultTagOptions( uniqueSortedTags ),
classOptions: getDefaultClassOptions( scenarios )
}
}

Expand Down Expand Up @@ -605,10 +608,10 @@ jgivenReportApp.controller('JGivenReportCtrl', function ($scope, $rootScope, $ti
];
}

function getDefaultTagOptions( scenarios ) {
var uniqueSortedTags = getUniqueSortedTags( scenarios)
, result = new Array();
_.forEach( uniqueSortedTags, function( tagName ) {
function getDefaultTagOptions( uniqueSortedTags ) {
var result = new Array();
_.forEach( uniqueSortedTags, function( tag ) {
var tagName = tagToString(tag);
result.push( {
selected: false,
name: tagName,
Expand Down Expand Up @@ -652,10 +655,12 @@ jgivenReportApp.controller('JGivenReportCtrl', function ($scope, $rootScope, $ti
var allTags = {};
_.forEach( scenarios, function( scenario ) {
_.forEach( scenario.tags, function( tag ) {
allTags[ tagToString( tag )] = true;
allTags[ tagToString( tag )] = tag;
});
});
return ownProperties(allTags).sort();
return _.map( ownProperties(allTags).sort(), function( tagName ) {
return allTags[ tagName ];
});
}

function getDefaultGroupOptions() {
Expand Down Expand Up @@ -728,8 +733,8 @@ jgivenReportApp.controller('JGivenReportCtrl', function ($scope, $rootScope, $ti
}
}

function getDefaultSortOptions() {
return [
function getDefaultSortOptions( uniqueSortedTags ) {
var result= [
{
selected: true,
name: 'A-Z',
Expand Down Expand Up @@ -781,6 +786,37 @@ jgivenReportApp.controller('JGivenReportCtrl', function ($scope, $rootScope, $ti
},

];

return result.concat( getTagSortOptions( uniqueSortedTags ))
}

function getTagSortOptions( uniqueSortedTags ) {
var result = new Array();

var tagTypes = groupTagsByType( uniqueSortedTags );

_.forEach( tagTypes, function( tagType ) {
if (tagType.tags.length > 1) {
result.push( {
selected: false,
name: tagType.type,
apply: function( scenarios ) {
return _.sortBy( scenarios, function( scenario ) {
var x = getTagOfType( scenario.tags, tagType.type )[0];
return x ? x.value : undefined;
});
}
} );
}
});

return result;
}

function getTagOfType( tags, type ) {
return _.filter( tags, function( tag ) {
return tag.name === type;
});
}

function toArrayOfGroups( obj ) {
Expand Down
3 changes: 2 additions & 1 deletion jgiven-html5-report/src/app/css/jgivenreport.css
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ ul.tags {
margin-bottom: 0;
margin-left: 0.5rem;
font-size: 80%;
background-color: lightgray;
background-color: rgb(151, 151, 151);
color: white;
}

.nav-count {
Expand Down

0 comments on commit 81a1380

Please sign in to comment.