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

WIP show only rated button #220

Closed
wants to merge 5 commits into from
Closed
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
22 changes: 22 additions & 0 deletions app/assets/javascripts/controllers/queriesCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
angular.module('QuepidApp')
.controller('queriesCtrl', [
'$scope',
'$rootScope',
'$log',
'$location',
'$routeParams',
Expand All @@ -16,6 +17,7 @@ angular.module('QuepidApp')
'customScorerSvc',
function (
$scope,
$rootScope,
$log,
$location,
$routeParams,
Expand Down Expand Up @@ -86,6 +88,7 @@ angular.module('QuepidApp')

$scope.pickCaseScorer = pickCaseScorer;
$scope.sortBy = sortBy;
$scope.toggleShowOnlyRated = toggleShowOnlyRated;

$scope.getScorer = getScorer;

Expand Down Expand Up @@ -355,5 +358,24 @@ angular.module('QuepidApp')
}
$location.search('reverse', $scope.reverse);
}

function toggleShowOnlyRated() {
var sor = $rootScope.showOnlyRated;
console.log('Toggle button pressed, sor= ' + sor);
if (sor === undefined) {
sor = false;
}
if (sor === 'false') {
sor = 'true';
} else {
sor = 'false';
}
$rootScope.showOnlyRated = sor.toString();
console.log('showOnlyRated is now toggled to ' + sor);
$scope.queries.showOnlyRated = sor.toString();
$location.search('showOnlyRated', sor.toString());
console.log('Reloading page for sor');
location.reload();
}
}
]);
21 changes: 19 additions & 2 deletions app/assets/javascripts/services/queriesSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ angular.module('QuepidApp')
'$timeout',
'$q',
'$log',
'$rootScope',
'$location',
'broadcastSvc',
'caseSvc',
'customScorerSvc',
Expand All @@ -26,6 +28,8 @@ angular.module('QuepidApp')
$timeout,
$q,
$log,
$rootScope,
$location,
broadcastSvc,
caseSvc,
customScorerSvc,
Expand Down Expand Up @@ -54,13 +58,22 @@ angular.module('QuepidApp')
svc.svcVersion++;
}

$rootScope.showOnlyRated = $location.search().showOnlyRated;
console.log('Initial showOnlyRated toggle is ' + $rootScope.showOnlyRated);

this.getCaseNo = getCaseNo;
this.createSearcherFromSettings = createSearcherFromSettings;

svc.bootstrapQueries = bootstrapQueries;

function createSearcherFromSettings(passedInSettings, query) {
function createSearcherFromSettings(passedInSettings, query, filterIds) {
var args = angular.copy(passedInSettings.selectedTry.args);
// TODO: This is Solr specific
console.log('showOnlyRated in createSearcherFromSettings() is ' + $rootScope.showOnlyRated);
if ($rootScope.showOnlyRated === 'true' && filterIds.length > 0) {
args['fq'] = '{!terms f=' + passedInSettings.createFieldSpec().id + '}' + filterIds.join(',');
console.log('showOnlyRated true, adding query filter for Solr');
}

if (passedInSettings && passedInSettings.selectedTry) {
return searchSvc.createSearcher(
Expand Down Expand Up @@ -156,6 +169,7 @@ angular.module('QuepidApp')
self.queryId,
ratings
);
self.ratings = ratings;

var resultsReturned = false;
var that = this;
Expand Down Expand Up @@ -302,10 +316,13 @@ angular.module('QuepidApp')
return $q(function(resolve, reject) {
self.markUnscored();

var ratedIds = Object.keys(self.ratings);
self.searcher = svc.createSearcherFromSettings(
currSettings,
self.queryText
self.queryText,
ratedIds
);
console.log('Ratings: ' + JSON.stringify(ratedIds, undefined, 2));
resultsReturned = false;

self.searcher.search()
Expand Down
8 changes: 8 additions & 0 deletions app/assets/templates/views/queries.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
</div>

<ul class="list-inline pull-right">
<li>
<input type="checkbox" ng-checked="showOnlyRated === 'true'" ng-click="toggleShowOnlyRated()"/>Show only rated
</li>

<li class="text-muted">
<span class="text-muted"> | </span>
</li>

<li>
<a ng-click="collapseAll()" href="">Collapse all</a>
</li>
Expand Down