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

Fix some bit rot in Tries! #967

Merged
merged 7 commits into from
Mar 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ angular.module('QuepidApp')
queriesSvc.moveQuery(ctrl.query, selectedItem)
.then(function() {
flash.success = 'Query moved successfully!';
$log.info('rescoring queries after moving query');
queriesSvc.updateScores();
}, function() {
flash.error = 'Unable to move query.';
});
Expand Down
26 changes: 16 additions & 10 deletions app/assets/javascripts/controllers/queryParamsDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ angular.module('QuepidApp')
.controller('QueryParamsDetailsCtrl', [
'$scope', '$uibModalInstance',
'flash',
'aTry', 'settingsSvc',
'aTry', 'settingsSvc', 'caseTryNavSvc',
function(
$scope, $uibModalInstance,
flash,
aTry, settingsSvc
aTry, settingsSvc, caseTryNavSvc
) {
$scope.aTry = aTry;

Expand All @@ -28,14 +28,20 @@ angular.module('QuepidApp')
};

$scope.deleteTry = function(aTry) {
settingsSvc.deleteTry(aTry.tryNo)
.then(function() {
$uibModalInstance.dismiss();
flash.success = 'Successfully deleted try!';
}, function() {
$uibModalInstance.dismiss();
flash.error = 'Unable to delete try!';
});
if (aTry.tryNo === caseTryNavSvc.getTryNo()){
$uibModalInstance.dismiss();
flash.error = 'You can not delete the currently active try (' + aTry.name + ')! Please select another try first.';
}
else {
settingsSvc.deleteTry(aTry.tryNo)
.then(function() {
$uibModalInstance.dismiss();
flash.success = 'Successfully deleted try!';
}, function() {
$uibModalInstance.dismiss();
flash.error = 'Unable to delete try!';
});
}
};

$scope.duplicateTry = function(aTry) {
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/controllers/queryParamsHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ angular.module('QuepidApp')
modalInstance.result.then(function (data) {
if (data && data.action === 'clone') {
$scope.settings.duplicateTry(data.aTry.tryNo)
.then(function() {
flash.success = 'Try duplicated successfully.';
.then(function(newTry) {
flash.success = 'Try ' + data.aTry.name + ' duplicated successfully as ' + newTry.name + '.';
}, function() {
flash.error = 'Unable to duplicate try.';
});
Expand Down
6 changes: 5 additions & 1 deletion app/assets/javascripts/controllers/searchResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ angular.module('QuepidApp')
var confirm = $window.confirm('Are you absolutely sure you want to delete?');

if (confirm) {
queriesSvc.deleteQuery(queryId);
queriesSvc.deleteQuery(queryId).then(function() {
$log.info('rescoring queries after removing query');
queriesSvc.updateScores();
});

}
};

Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/factories/SettingsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
var jsonTry = response.data;
var theTry = new Try(jsonTry);

self.tries.push(theTry);
self.tries.unshift(theTry);
self.settingsId++;

return theTry;
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/api/v1/tries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ def try_params
end

def search_endpoint_params
# we do not REQUIRE a search_endpoint on a try
if params[:search_endpoint].nil?
return {}
end
params.require(:search_endpoint).permit(
:name,
:api_method,
Expand Down
5 changes: 4 additions & 1 deletion app/services/case_score_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def update score_data
return nil if empty_score? score_data

last_score = @the_case.last_score

if same_score_source last_score, score_data
if user_ratings_docs? last_score, score_data
update_params = {
Expand Down Expand Up @@ -59,6 +59,9 @@ def same_score_source last_score, score_data
return false if last_score.blank?
return false if last_score.try_id.blank?

# we have an issue where the case_score.try_id table references tries.id and
# the try doesn't exist. So the last_score.try is nil. Maybe related to deleting a try?
return false if last_score.try.nil?
return false if last_score.try.try_number != score_data[:try_number].to_i
return false if last_score.user_id != score_data[:user_id].to_i

Expand Down
3 changes: 1 addition & 2 deletions test/controllers/api/v1/tries_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ def assert_curator_vars_equal vars, response_vars

test 'renames try successfully' do
put :update,
params: { case_id: the_case.id, try_number: the_try.try_number, try: { name: 'New Name' },
search_endpoint: { search_engine: 'solr' } }
params: { case_id: the_case.id, try_number: the_try.try_number, try: { name: 'New Name' } }

assert_response :ok

Expand Down