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

Actually delete cases #288

Merged
merged 26 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7dbe45b
delete-case is actually an archive-case, so add that. Then, lets get…
Mar 12, 2021
84df460
tests now pass properly!
Mar 12, 2021
5f54c99
first cut of changinge this up
Mar 12, 2021
abc0dfc
what the heck does this method do, hey, we have a test, but no one us…
Mar 12, 2021
0605064
Fix up navigation from a case on a teams page to the case page where …
Mar 13, 2021
5a74955
clarify it's the number of the try. Ideally we would list name, but …
Mar 13, 2021
9f6af1e
format to be smarter on the name and the number
Mar 13, 2021
5a4ccf9
rubocop
Mar 13, 2021
cfcbe26
jshint
Mar 13, 2021
31320f7
Fix the messaging for this component!
Mar 14, 2021
dc43496
a issue with param permitting gave a bit of code clean up.
Mar 14, 2021
b0e5c96
deal wiht class path reloading issues in dev...
Mar 14, 2021
f6938b6
warn the next person
Mar 14, 2021
95668be
doc issue with this test for the next person!
Mar 14, 2021
9111ef4
follow convention that makes it easier to find these api methods
Mar 14, 2021
bcef700
we had a spurious "not permitted" parameters because we were using st…
Mar 14, 2021
d72b801
errant logging
Mar 14, 2021
270fb33
avoid spurious error by upgrading the reporter!
Mar 14, 2021
88436ba
letter_opener gem that intercepts emails wants to open the email in a…
Mar 14, 2021
3832d29
rubocop
Mar 14, 2021
3db0958
Now you can actually delete a Case! Still have our old archive capa…
Mar 14, 2021
c3f673d
having some loading issues of files in the /lib, I think post Rails 5?
Mar 14, 2021
6c5020f
doc fix
Mar 15, 2021
859748a
chase down the issue with try 0 showing up!
Mar 15, 2021
f524b25
typo1
Mar 15, 2021
cbd1740
Update CHANGELOG.md
Mar 15, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

* Turns out we had a [ERD](docs/erd.png) diagram all along, but it was hidden. Now you can see it on our [Data Mapping](docs/datamapping.md) page, plus we have how to recreate it documented and integrated. https://github.com/o19s/quepid/pull/287 by @epugh.

* You can now Delete a case altogether! Historically we had an Archive function, so that you could restore an old case. However, if you are like me, you create lots and lots of throwaway cases, so this allows you to clean up your Quepid setup. This PR also fixed some data modeling issues, and the problem of sometimes have a Try of zero, instead of the default first try of One! We also always include the Try number even if you have named the Try, since that is a big deal. https://github.com/o19s/quepid/pull/288 by @epugh fixes https://github.com/o19s/quepid/issues/250. Thanks @DmitryKey for help QA'ing this code.

### Bugs

* You can export a rating that has no actual rating value chosen! https://github.com/o19s/quepid/pull/266 by @epugh fixes https://github.com/o19s/quepid/issues/265.
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ GEM
mini_mime (1.0.2)
mini_portile2 (2.5.0)
minitest (5.14.4)
minitest-reporters (1.4.2)
minitest-reporters (1.4.3)
ansi
builder
minitest (>= 5.0)
Expand Down Expand Up @@ -257,7 +257,7 @@ GEM
rubocop (>= 0.90.0, < 2.0)
ruby-graphviz (1.2.5)
rexml
ruby-progressbar (1.10.1)
ruby-progressbar (1.11.0)
ruby-statistics (2.1.3)
sassc (2.4.0)
ffi (~> 1.9)
Expand Down
12 changes: 12 additions & 0 deletions app/assets/javascripts/components/archive_case/_modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="modal-header">
<button type="button" class="close" ng-click="ctrl.cancel()" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h3 class="modal-title">Archive This Case for Later?</h3>
</div>
<div class="modal-body">
<p ng-hide="ctrl.onlyCase">You're about to put this case into deep freeze. You'll be able to get to it through "Archived Cases" filter in the Relevancy Cases listing page.</p>
<p ng-show="ctrl.onlyCase">You can't archive the only case you have created! Consider adding a new case, or renaming this one.</p>
</div>
<div class="modal-footer">
<button class="btn btn-danger" ng-show="!ctrl.onlyCase" ng-click="ctrl.ok()">Archive</button>
<button class="btn btn-default" ng-click="ctrl.cancel()">Cancel</button>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<a class="action-icon" ng-click="ctrl.openArchiveModal()">
<i
class="fa fa-archive"
aria-hidden="true"
title="{{ ctrl.retrieveTooltip() }}"
alt="{{ ctrl.retrieveTooltip() }}"
></i>
</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use strict';

/*jshint latedef:false*/

angular.module('QuepidApp')
.controller('ArchiveCaseCtrl', [
'$scope',
'$uibModal',
'flash',
'caseSvc',
function (
$scope,
$uibModal,
flash,
caseSvc
) {
var ctrl = this;

ctrl.thisCase = $scope.thisCase;
ctrl.checkIfOnlyCase = checkIfOnlyCase;
ctrl.archiveCase = archiveCase;
ctrl.openArchiveModal = openArchiveModal;
ctrl.retrieveTooltip = retrieveTooltip;

function archiveCase() {
caseSvc.archiveCase(ctrl.thisCase).then(
function () {
flash.success = 'Case archived successfully.';
}, function (data) {
var message = 'Oooops! Could not archive the case. ';
message += data.message;
flash.error = message;
}
);
}

function checkIfOnlyCase() {
var ownedCases = caseSvc.filterCases(caseSvc.allCases, true);

if( ownedCases.length <= 1 ){
return true;
}

return false;
}

function retrieveTooltip() {
if(ctrl.checkIfOnlyCase()){
return 'Can\'t archive the only case';
} else {
return 'Archive';
}
}

function openArchiveModal() {
var modalInstance = $uibModal.open({
templateUrl: 'archive_case/_modal.html',
controller: 'ArchiveCaseModalInstanceCtrl',
controllerAs: 'ctrl',
size: 'sm',
resolve: {
onlyCase: function() {
return ctrl.checkIfOnlyCase();
}
}
});

modalInstance.result.then(function (archiveClicked) {
if( archiveClicked ){
ctrl.archiveCase();
}
});
}
}
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

angular.module('QuepidApp')
.directive('archiveCase', [
function () {
return {
restrict: 'E',
controller: 'ArchiveCaseCtrl',
controllerAs: 'ctrl',
templateUrl: 'archive_case/archive_case.html',
scope: {
thisCase: '=',
},
};
}
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

angular.module('QuepidApp')
.controller('ArchiveCaseModalInstanceCtrl', [
'$uibModalInstance',
'onlyCase',
function ($uibModalInstance, onlyCase) {
var ctrl = this;

ctrl.onlyCase = onlyCase;

ctrl.ok = function () {
$uibModalInstance.close(true);
};

ctrl.cancel = function () {
$uibModalInstance.close(false);
};

}
]);
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<action-icon title="'Rename'" icon-class="'fa fa-edit'" fn-call="ctrl.rename()"></action-icon>

<delete-case this-case="ctrl.thisCase"></delete-case>
<archive-case this-case="ctrl.thisCase"></archive-case>
</span>

<span>
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/components/delete_case/_modal.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div class="modal-header">
<button type="button" class="close" ng-click="ctrl.cancel()" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h3 class="modal-title">Archive This Case for Later?</h3>
<h3 class="modal-title">Delete This Case</h3>
</div>
<div class="modal-body">
<p ng-hide="ctrl.onlyCase">You're about to put this case into deep freeze. You'll be able to get to it through "Archived Cases" filter in the Relevancy Cases listing page.</p>
<p ng-hide="ctrl.onlyCase">You're about to delete this case forever! If you might want it later, use the Archive function instead.</p>
<p ng-show="ctrl.onlyCase">You can't delete the only case you have created! Consider adding a new case, or renaming this one.</p>
</div>
<div class="modal-footer">
<button class="btn btn-danger" ng-show="!ctrl.onlyCase" ng-click="ctrl.ok()">Archive</button>
<button class="btn btn-danger" ng-show="!ctrl.onlyCase" ng-click="ctrl.ok()">Delete</button>
<button class="btn btn-default" ng-click="ctrl.cancel()">Cancel</button>
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<a class="action-icon" ng-click="ctrl.openDeleteModal()">
<i
class="fa fa-archive"
class="fa fa-trash"
aria-hidden="true"
title="{{ ctrl.retrieveTooltip() }}"
alt="{{ ctrl.retrieveTooltip() }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ angular.module('QuepidApp')
function deleteCase() {
caseSvc.deleteCase(ctrl.thisCase).then(
function () {
flash.success = 'Case archived successfully.';
flash.success = 'Case deleted successfully.';
}, function (data) {
var message = 'Oooops! Could not archive the case. ';
var message = 'Oooops! Could not delete the case. ';
message += data.message;
flash.error = message;
}
Expand All @@ -46,9 +46,9 @@ angular.module('QuepidApp')

function retrieveTooltip() {
if(ctrl.checkIfOnlyCase()){
return 'Can\'t archive the only case';
return 'Can\'t delete the only case';
} else {
return 'Archive';
return 'Delete';
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/controllers/unarchiveCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ angular.module('QuepidApp')
};

$scope.addBackCase = function(aCase) {
caseSvc.undeleteCase(aCase)
caseSvc.unarchiveCase(aCase)
.then(function() {
$uibModalInstance.dismiss('addBackCase');
});
Expand Down
14 changes: 10 additions & 4 deletions app/assets/javascripts/factories/TryFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
var Try = function(data) {
// This method converts the response from the API to angular objects.
var self = this;
if ( data.searchEngine !== undefined ) {
console.log('Data object creating Try has a searchEngine!');
console.log(data);
}

if ( angular.isUndefined(data.search_engine) ) {
console.log('We have an undefined data.search_engine so setting to Solr, should this ever happen?');
Expand Down Expand Up @@ -51,6 +47,7 @@
self.curatorVars = ngFriendlyCuratorVars;

// Functions
self.formattedName = formattedName;
self.createFieldSpec = createFieldSpec;
self.curatorVarsDict = curatorVarsDict;
self.hasVar = hasVar;
Expand All @@ -64,6 +61,15 @@
// Bootstrap
self.updateVars();

function formattedName() {
if (self.name.includes('Try ' + self.tryNo)){
return self.name;
}
else {
return self.name + ' - Try ' + self.tryNo;
}
}

// Create a field spec from the string I'm
// carrying around that stores that info
function createFieldSpec() {
Expand Down
28 changes: 23 additions & 5 deletions app/assets/javascripts/services/caseSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ angular.module('QuepidApp')
};

this.createCase = function(caseName, queries, tries) {
// http post /cases/
// returns as if we did http get /cases/<caseNo>
// HTTP POST /api/cases
// returns as if we did HTTP GET /cases/<caseNo>
// on success, sets current case number to case number
var data = {'case_name': 'Case: ' + this.casesCount};
if (caseName) {
Expand All @@ -172,7 +172,6 @@ angular.module('QuepidApp')

// TODO: see if this is still necessary!
settingsSvc.setSettings(caseTries, newCase.lastTry);

caseTryNavSvc.navigateTo(caseTryObj);
}, function(){
caseTryNavSvc.notFound();
Expand All @@ -194,8 +193,27 @@ angular.module('QuepidApp')
});
};

this.undeleteCase = function(caseToUndelete) {
var caseNumber = caseToUndelete.caseNo;
this.archiveCase = function(caseToArchive) {
var caseNumber = caseToArchive.caseNo;
var url = '/api/cases/' + caseNumber;
var data = { archived: true };

return $http.put(url, data)
.then(function(response) {
var data = response.data;
var newCase = new Case(data);

svc.allCases.push(newCase);
svc.archived = svc.archived.filter( function(acase) {
acase.caseNo !== newCase.caseNo;
});

broadcastSvc.send('updatedCasesList', svc.allCases);
});
};

this.unarchiveCase = function(caseToUnarchive) {
var caseNumber = caseToUnarchive.caseNo;
var url = '/api/cases/' + caseNumber;
var data = { archived: false };

Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/services/caseTryNavSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ angular.module('QuepidApp')
navTryNo = parseInt(caseTryObj.tryNo, 10);
}
else if (caseTryObj.hasOwnProperty('caseNo')) {
navTryNo = 0;
navTryNo = 1;
}

$location.search({'sort': sortBy, 'reverse': sortOrder});
Expand Down
20 changes: 10 additions & 10 deletions app/assets/javascripts/services/customScorerSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@
return angular.equals(first, second);
}

function create(data) {
function create(scorer) {
// http POST /api/scorers
var url = '/api/scorers';
var data = {
'name': scorer.name,
'code': scorer.code,
'scale': scorer.scale,
'manual_max_score': scorer.manualMaxScore,
'manual_max_score_value': scorer.manualMaxScoreValue,
'show_scale_labels': scorer.showScaleLabels,
'scale_with_labels': scorer.scaleWithLabels,
};

data.manual_max_score = data.manualMaxScore;
data.manual_max_score_value = data.manualMaxScoreValue;
data.show_scale_labels = data.showScaleLabels;
data.scale_with_labels = data.scaleWithLabels;

delete data.manualMaxScore;
delete data.manualMaxScoreValue;
delete data.showScaleLabels;
delete data.scaleWithLabels;

return $http.post(url, { 'scorer': data })
.then(function(response) {
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/services/ratingsStoreSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ angular.module('QuepidApp')

// This takes a single rating and applies it to a list of docIds
this.rateBulkDocuments = function(docIds, rating) {
var url = basePath() + '/bulk' + '/ratings';
var url = basePath() + '/bulk/ratings';
var data = {
doc_ids: docIds,
rating: rating,
Expand Down Expand Up @@ -86,7 +86,7 @@ angular.module('QuepidApp')
};

this.resetBulkRatings = function(docIds) {
var url = basePath() + '/bulk' + '/ratings/delete';
var url = basePath() + '/bulk/ratings/delete';
var data = {
doc_ids: docIds,
};
Expand Down
2 changes: 1 addition & 1 deletion app/assets/templates/views/cases/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ <h2>
<div class="row">
<span class="col-xs-1">ID</span>
<span class="col-xs-3">Case Title</span>
<span class="col-xs-1">Last Try</span>
<span class="col-xs-1">Last Try #</span>
<span class="col-xs-1"># of Queries</span>
<span class="col-xs-1">Last Score</span>
<span class="col-xs-1">Last Run On</span>
Expand Down
2 changes: 1 addition & 1 deletion app/assets/templates/views/queriesLayout.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h1 class="">
&mdash;
<span ng-dblclick="tryNameEditModeToggle()">
<span ng-hide="tryName.startRename">
{{ currentTry.selectedTry().name }}
{{ currentTry.selectedTry().formattedName() }}
</span>
</span>
<span ng-show="tryName.startRename">
Expand Down
2 changes: 1 addition & 1 deletion app/assets/templates/views/queryParamsHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ng-repeat="try in settings.tries"
ng-style="{'background-color': ['#666', '#64647D', '#667A66'][urlBucket(try.searchUrl, 3)]}" >
<button ng-click="tryDetails(try); $event.stopPropagation()" type="button" class="btn btn-circle try-details">...</button>
<span>{{try.name}}</span>
<span>{{try.formattedName()}}</span>
{{try.queryParams.slice(0,200)}}...
<span>using {{ try.searchEngine | searchEngineName }} {{urlBucket(try.searchUrl, 30) + 1}}</span>
</li>
Expand Down
Loading