Skip to content

Commit

Permalink
now can create missing queries from a book
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Dec 21, 2023
1 parent 7ec13b6 commit f4bf1ad
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/components/frog_report/_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h4 style="margin-top: 60px;">Distribution of Queries Needing Ratings</h4>
</div>
<div class="modal-footer">
<a class="btn btn-default" ng-if="ctrl.theCase.bookName" ng-click="ctrl.refreshRatingsFromBook()" ng-disabled="processingPrompt.inProgress">
<i class="glyphicon glyphicon-refresh"></i>
<i class="glyphicon glyphicon-refresh" ng-class="{'fa-spin': processingPrompt.inProgress}"></i>
Refresh ratings from book <i>{{ctrl.theCase.bookName}}</i>
</a>
<button class="btn btn-primary" ng-click="ctrl.cancel()" ng-disabled="processingPrompt.inProgress">Close</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ angular.module('QuepidApp')
};

ctrl.refreshRatingsFromBook = function () {
//$uibModalInstance.close(ctrl.options);
$scope.processingPrompt.inProgress = true;
bookSvc.refreshCaseRatingsFromBook(ctrl.theCase.caseNo, ctrl.theCase.bookId, false)
.then(function() {
$scope.processingPrompt.inProgress = true;
$scope.processingPrompt.inProgress = false;
$uibModalInstance.close();

flash.success = 'Ratings have been refreshed.';
Expand Down
11 changes: 5 additions & 6 deletions app/assets/javascripts/components/judgements/_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h3 class="modal-title">Judgements</h3>
<i class='fa fa-spinner fa-spin'></i>
</p>
</div>
<div class="alert alert-warning" role="alert" ng-if="ctrl.share.acase.queriesCount === 0">
<div class="alert alert-warning" role="alert" ng-if="ctrl.populateBook && ctrl.share.acase.queriesCount === 0">
You do not have any queries to populate your book of judgements with.
</div>

Expand Down Expand Up @@ -82,8 +82,8 @@ <h3 class="modal-title">Judgements</h3>
</label>
<br/>
<label>
<input id="sync-queries" type="checkbox" ng-model='ctrl.syncQueries' ng-disabled="ctrl.share.books.length === 0 || ctrl.share.teams.length === 0"> Sync missing Queries
<span class="glyphicon glyphicon-question-sign" aria-hidden="true" popover-trigger="'mouseenter'" popover-placement="right" uib-popover="Sync all the queries in the Case with those defined in the Book."></span>
<input id="sync-queries" type="checkbox" ng-model='ctrl.createMissingQueries' ng-disabled="ctrl.share.books.length === 0 || ctrl.share.teams.length === 0"> Create missing Queries
<span class="glyphicon glyphicon-question-sign" aria-hidden="true" popover-trigger="'mouseenter'" popover-placement="right" uib-popover="Create queries in the Case thare are defined in the Book."></span>
</input>
</label>

Expand Down Expand Up @@ -120,11 +120,10 @@ <h3 class="modal-title">Judgements</h3>
<i class="glyphicon glyphicon-book"></i>
Make Judgements!
</a>

<a class="btn btn-default pull-left" ng-click="ctrl.refreshRatingsFromBook()" ng-disabled="processingPrompt.inProgress || ctrl.populateBook || !ctrl.activeBookId || ctrl.share.acase.bookId !== ctrl.activeBookId" >
<i class="glyphicon glyphicon-refresh"></i>
<i class="glyphicon glyphicon-refresh" ng-class="{'fa-spin': processingPrompt.inProgress}"></i>
Refresh ratings from book <i>{{ctrl.activeBookName}}</i>
<span ng-if="ctrl.syncQueries">and creating missing queries</span>
<span ng-if="ctrl.createMissingQueries">and creating missing queries</span>
</a>

<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ angular.module('QuepidApp')
ctrl.refreshOnly = false;
ctrl.updateAssociatedBook = false;
ctrl.populateJudgements = false;
ctrl.syncQueries = false;
ctrl.createMissingQueries = false;

$rootScope.$watch('currentUser', function() {
if ( $rootScope.currentUser ) {
Expand Down Expand Up @@ -129,14 +129,15 @@ angular.module('QuepidApp')

ctrl.refreshRatingsFromBook = function () {
//$uibModalInstance.close(ctrl.options);
bookSvc.refreshCaseRatingsFromBook(ctrl.share.acase.caseNo, ctrl.activeBookId, ctrl.syncQueries)
$scope.processingPrompt.inProgress = true;
bookSvc.refreshCaseRatingsFromBook(ctrl.share.acase.caseNo, ctrl.activeBookId, ctrl.createMissingQueries)
.then(function() {
$scope.processingPrompt.inProgress = true;
$scope.processingPrompt.inProgress = false;
$uibModalInstance.close();

flash.success = 'Ratings have been refreshed.';
}, function(response) {
$scope.processingPrompt.inProgress = false;

$scope.processingPrompt.error = response.data.statusText;
});
};
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/services/bookSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ angular.module('QuepidApp')
});
};

this.refreshCaseRatingsFromBook = function(caseId, bookId, syncQueries) {
// http POST api/books/<int:bookId>/case/<int:caseId>/refresh?sync_queries=<bool:syncQueries>
this.refreshCaseRatingsFromBook = function(caseId, bookId, createMissingQueries) {
// http POST api/books/<int:bookId>/case/<int:caseId>/refresh?sync_queries=<bool:createMissingQueries>

var payload = {
};

return $http.put('api/books/' + bookId + '/cases/' + caseId + '/refresh?sync_queries=' + syncQueries, payload)
return $http.put('api/books/' + bookId + '/cases/' + caseId + '/refresh?create_missing_queries=' + createMissingQueries, payload)
.then(function(response) {
console.log('refreshed ratings' + response.data);
});
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/api/v1/books/refresh_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class RefreshController < Api::ApiController
before_action :check_case, only: [ :update ]

def update
@export = 'true' == params[:export]
service = RatingsManager.new(@book)
@create_missing_queries = 'true' == params[:create_missing_queries]

service = RatingsManager.new(@book, { create_missing_queries: @create_missing_queries })
service.sync_ratings_for_case(@case)

@counts = {}
Expand Down
11 changes: 6 additions & 5 deletions test/controllers/api/v1/books/refresh_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ class RefreshControllerTest < ActionController::TestCase

describe 'refresh a case with no ratings' do
it 'creates all the ratings needed' do
assert_difference 'case_without_ratings.queries.count', 2 do
assert_difference 'case_without_ratings.queries.count', 1 do
assert_difference 'case_without_ratings.ratings.count', 3 do
put :update, params: { case_id: case_without_ratings.id, book_id: book.id }
put :update,
params: { case_id: case_without_ratings.id, book_id: book.id, create_missing_queries: true }

assert_response :success

body = response.parsed_body
assert_equal 2, body['queries_created']
assert_equal 1, body['queries_created']
assert_equal 3, body['ratings_created']
end
end
Expand Down Expand Up @@ -58,10 +59,10 @@ class RefreshControllerTest < ActionController::TestCase
end

describe 'refresh a case with existing ratings' do
it 'creates all the ratings needed' do
it 'creates all the ratings and queries needed' do
assert_difference 'case_with_ratings.queries.count', 1 do
assert_difference 'case_with_ratings.ratings.count', 3 do
put :update, params: { case_id: case_with_ratings.id, book_id: book.id }
put :update, params: { case_id: case_with_ratings.id, book_id: book.id, create_missing_queries: true }

assert_response :success
body = response.parsed_body
Expand Down
2 changes: 1 addition & 1 deletion test/models/query_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class QueryTest < ActiveSupport::TestCase
test 'we match on a multi word query' do
matching_query = Query.has_information_need.where(query_text: query_doc_pair.query_text).first
assert_not_nil matching_query
assert_equal query, matching_query
assert_equal query.query_text, matching_query.query_text
end
end
end

0 comments on commit f4bf1ad

Please sign in to comment.