Skip to content

Commit

Permalink
Fix confirmation dialogs and user list display
Browse files Browse the repository at this point in the history
Resolves #195
  • Loading branch information
mmcauliffe committed Jun 13, 2019
1 parent cd773fe commit 721d8da
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 32 deletions.
12 changes: 6 additions & 6 deletions iscan/api.py
Expand Up @@ -234,9 +234,9 @@ def start(self, request, pk=None):
return Response(status=status.HTTP_401_UNAUTHORIZED)
database = self.get_object()
if not request.user.is_superuser:
permissions = models.CorpusPermissions.objects.filter(user=request.user, corpus__database=database).all()
permissions = [x.can_access_database for x in permissions]
if not len(permissions) or not any(permissions):
permissions = models.CorpusPermissions.objects.filter(user=request.user, corpus__database=database,
can_access_database=True).all()
if not len(permissions):
return Response(status=status.HTTP_401_UNAUTHORIZED)
try:
success = database.start()
Expand All @@ -250,9 +250,9 @@ def stop(self, request, pk=None):
return Response(status=status.HTTP_401_UNAUTHORIZED)
database = self.get_object()
if not request.user.is_superuser:
permissions = models.CorpusPermissions.objects.filter(user=request.user, corpus__database=database).all()
permissions = [x.can_access_database for x in permissions]
if not len(permissions) or not any(permissions):
permissions = models.CorpusPermissions.objects.filter(user=request.user, corpus__database=database,
can_access_database=True).all()
if not len(permissions):
return Response(status=status.HTTP_401_UNAUTHORIZED)
try:
success = database.stop()
Expand Down
6 changes: 3 additions & 3 deletions iscan/static/iscan/enrichment/enrichment.html
Expand Up @@ -81,18 +81,18 @@ <h3 ng-if="corpus.busy" style="color: red">Corpus is currently busy!</h3>
</td>
<td md-cell>
<md-button class='md-raised md-primary' ng-if="!corpus.busy"
ng-disabled="enrichment.runnable != 'runnable'" ng-click="runEnrichment(enrichment.id)">
ng-disabled="enrichment.runnable != 'runnable'" ng-click="runEnrichment(enrichment, $event)">
<span> Run </span>
</md-button>
<md-button class='md-raised md-warn' ng-if="!corpus.busy"
ng-disabled="!enrichment.completed" ng-click="resetEnrichment(enrichment.id)">
ng-disabled="!enrichment.completed" ng-click="resetEnrichment(enrichment, $event)">
<span> Reset </span>
</md-button>
<md-button class='md-raised' ng-if="!corpus.busy" ng-click="editEnrichment(enrichment)">
<span> Edit </span>
</md-button>
<md-button class='md-raised md-warn' ng-if="!corpus.busy"
ng-click="deleteEnrichment(enrichment)">
ng-click="deleteEnrichment(enrichment, $event)">
<span> Delete </span>
</md-button>
</td>
Expand Down
63 changes: 53 additions & 10 deletions iscan/static/iscan/enrichment/enrichment.js
@@ -1,7 +1,7 @@
angular.module('enrichment', [
'iscan.corpora',
'iscan.enrichment'
]).controller('EnrichmentCtrl', function ($scope, $rootScope, Enrichment, Corpora, $state, $stateParams, $timeout, djangoAuth) {
]).controller('EnrichmentCtrl', function ($scope, $rootScope, Enrichment, Corpora, $mdDialog, $state, $stateParams, $timeout, djangoAuth) {

var loadTime = 10000, //Load the data every second
errorCount = 0, //Counter for the server errors
Expand Down Expand Up @@ -65,15 +65,47 @@ angular.module('enrichment', [
cancelNextLoad();
});

$scope.runEnrichment = function (enrichment_id) {
Enrichment.run($stateParams.corpus_id, enrichment_id).then(function (res) {
$scope.runEnrichment = function (enrichment, ev) {
if (enrichment.completed){


var confirm = $mdDialog.confirm()
.title('Rerun enrichment')
.textContent('Are you sure you want to rerun "' + enrichment.name + '"?')
.ariaLabel('Rerun enrichment')
.targetEvent(ev)
.ok('Rerun')
.cancel('Cancel');

$mdDialog.show(confirm).then(function () {
Enrichment.run($stateParams.corpus_id, enrichment.id).then(function (res) {
getData();
});
};
$scope.resetEnrichment = function (enrichment_id) {
Enrichment.reset($stateParams.corpus_id, enrichment_id).then(function (res) {

});
}
else{
Enrichment.run($stateParams.corpus_id, enrichment.id).then(function (res) {
getData();
});
}
};
$scope.resetEnrichment = function (enrichment, ev) {

var confirm = $mdDialog.confirm()
.title('Reset enrichment')
.textContent('Are you sure you want to reset "' + enrichment.name + '"?')
.ariaLabel('Reset enrichment')
.targetEvent(ev)
.ok('Reset')
.cancel('Cancel');

$mdDialog.show(confirm).then(function () {
Enrichment.reset($stateParams.corpus_id, enrichment.id).then(function (res) {
getData();
});

});
};


Expand Down Expand Up @@ -127,9 +159,18 @@ angular.module('enrichment', [
});
}
};
$scope.deleteEnrichment = function (enrichment) {
if (confirm("Are you sure you want to delete \"" + enrichment.name + "\" ?")) {
console.log("Deleting " + enrichment.name + "...");
$scope.deleteEnrichment = function (enrichment, ev) {


var confirm = $mdDialog.confirm()
.title('Reset enrichment')
.textContent('Are you sure you want to delete "' + enrichment.name + '"?')
.ariaLabel('Reset enrichment')
.targetEvent(ev)
.ok('Reset')
.cancel('Cancel');

$mdDialog.show(confirm).then(function () {
Enrichment.destroy($stateParams.corpus_id, enrichment.id).then(function (res) {

$scope.enrichments = $scope.enrichments.filter(function (e) {
Expand All @@ -138,7 +179,9 @@ angular.module('enrichment', [
}).catch(function (res) {
console.log(res);
})
}

});

};

$scope.createUtterances = function () {
Expand Down
17 changes: 15 additions & 2 deletions iscan/static/iscan/user-list/user-list.js
Expand Up @@ -15,6 +15,10 @@ angular.module('userList', [
Users.all().then(function (res) {
$scope.users = res.data;
});
Users.roles().then(function(res) {

$scope.roles = res.data;
});

$scope.editUser = function (user_id) {

Expand All @@ -25,11 +29,20 @@ angular.module('userList', [
$state.go('user-create');
};

$scope.display_user_type = function(user){
for (i=0; i<$scope.roles.length;i++){
if ($scope.roles[i].id === user.user_type){
return $scope.roles[i].name
}
}
return 'Unknown'
};

$scope.deleteUser = function (user, ev) {

var confirm = $mdDialog.confirm()
.title('Would you like to delete ' + user.username + '?')
.textContent('Delete user')
.title('Delete user')
.textContent('Are you sure you want to delete "' + user.username + '"?')
.ariaLabel('Delete user')
.targetEvent(ev)
.ok('Delete')
Expand Down
6 changes: 3 additions & 3 deletions iscan/static/iscan/user-list/user_list.html
Expand Up @@ -28,11 +28,11 @@ <h1>All users</h1>
{{ u.username }}
</td>
<td md-cell>
{{ u.user_type }}
{{ display_user_type(u) }}
</td>
<td md-cell>
<md-button class='md-raised md-primary' ng-click="editUser(u.id)" ng-disabled="busy">Edit</md-button>
<md-button class='md-raised md-primary' ng-click="addTutorialCorpus(u)" ng-disabled="busy">Create tutorial corpus</md-button>
<md-button class='md-raised md-primary' ng-click="editUser(u.id, $event)" ng-disabled="busy">Edit</md-button>
<md-button class='md-raised md-primary' ng-click="addTutorialCorpus(u, $event)" ng-disabled="busy">Create tutorial corpus</md-button>
<md-button class='md-raised md-warn' ng-click="deleteUser(u, $event)" ng-disabled="busy">Delete</md-button>
</td>
</tr>
Expand Down

0 comments on commit 721d8da

Please sign in to comment.