diff --git a/bower.json b/bower.json index 5af2e48a..78b7e0f7 100644 --- a/bower.json +++ b/bower.json @@ -8,7 +8,7 @@ "angular-aria": "1.5.8", "angular-animate": "1.5.8", "angular-cookies": "1.5.8", - "angular-material": "1.1.1", + "angular-material": "1.1.5", "angular-ng-sortablejs": "~1.2.1", "angular-route": "1.5.8", "angular-sanitize": "1.5.8", diff --git a/crowdsourcing/serializers/qualification.py b/crowdsourcing/serializers/qualification.py index 14eed869..bc32e1ec 100644 --- a/crowdsourcing/serializers/qualification.py +++ b/crowdsourcing/serializers/qualification.py @@ -57,15 +57,15 @@ def create_with_entries(self, requester, entries, *args, **kwargs): class WorkerACESerializer(DynamicFieldsModelSerializer): - worker_alias = serializers.SerializerMethodField() + handle = serializers.SerializerMethodField() class Meta: model = WorkerAccessControlEntry - fields = ('id', 'worker', 'worker_alias', 'group', 'created_at') + fields = ('id', 'worker', 'handle', 'group', 'created_at') def create(self, *args, **kwargs): return WorkerAccessControlEntry.objects.create(**self.validated_data) @staticmethod - def get_worker_alias(obj): + def get_handle(obj): return obj.worker.profile.handle diff --git a/static/js/user/controllers/preferences.controller.js b/static/js/user/controllers/preferences.controller.js index 6d91e01b..28b6e196 100644 --- a/static/js/user/controllers/preferences.controller.js +++ b/static/js/user/controllers/preferences.controller.js @@ -9,12 +9,13 @@ .module('crowdsource.user.controllers') .controller('PreferencesController', PreferencesController); - PreferencesController.$inject = ['$state', '$scope', '$window', '$mdToast', 'User', '$filter', 'Authentication']; + PreferencesController.$inject = ['$state', '$scope', '$window', '$mdToast', 'User', '$filter', + 'Authentication', '$mdDialog']; /** * @namespace PreferencesController */ - function PreferencesController($state, $scope, $window, $mdToast, User, $filter, Authentication) { + function PreferencesController($state, $scope, $window, $mdToast, User, $filter, Authentication, $mdDialog) { var self = this; self.searchTextChange = searchTextChange; self.selectedItemChange = selectedItemChange; @@ -26,10 +27,25 @@ self.blockWorker = blockWorker; self.black_list_entries = []; self.workerGroups = []; + self.groupMembers = []; + self.workers = []; + self.newWorkerGroup = {}; self.black_list = null; self.loading = false; + self.openWorkerGroupNew = openWorkerGroupNew; + self.addWorkerGroup = addWorkerGroup; activate(); + $scope.$watch('preferences.workerGroup', function (newValue, oldValue) { + if (!angular.equals(newValue, oldValue)) { + self.groupMembers = []; + User.retrieveRequesterListEntries(newValue).then(function success(response) { + self.groupMembers = response[0]; + }); + } + + }); + function activate() { self.loading = true; @@ -100,7 +116,12 @@ }; User.createRequesterListEntry(data).then( function success(data) { - self.black_list_entries.unshift(data[0]); + var justAdded = $filter('filter')(self.black_list_entries, {'handle': data[0].handle}); + if (justAdded.length) { + justAdded[0].id = data[0].id; + justAdded[0].group = data[0].group; + } + // self.black_list_entries.unshift(data[0]); self.selectedItem = null; self.searchText = null; } @@ -110,9 +131,9 @@ function unblockWorker(entry) { User.deleteRequesterListEntry(entry.id).then( function success(data) { - var entry = $filter('filter')(self.black_list_entries, {'id': data[0].pk}); - var index = self.black_list_entries.indexOf(entry[0]); - self.black_list_entries.splice(index, 1); + // var entry = $filter('filter')(self.black_list_entries, {'id': data[0].pk}); + // var index = self.black_list_entries.indexOf(entry[0]); + // self.black_list_entries.splice(index, 1); } ); } @@ -124,5 +145,59 @@ } ); } + + function openWorkerGroupNew($event) { + var parent = angular.element(document.body); + $mdDialog.show({ + clickOutsideToClose: true, + scope: $scope, + preserveScope: true, + parent: parent, + targetEvent: $event, + templateUrl: '/static/templates/project/new-worker-group.html', + controller: DialogController + }); + } + + function DialogController($scope, $mdDialog) { + $scope.hide = function () { + $mdDialog.hide(); + }; + $scope.cancel = function () { + $mdDialog.cancel(); + }; + } + + function addWorkerGroup() { + // if (self.workerGroup.members.length == 0) { + // self.workerGroup.error = 'You must select at least one worker.'; + // return; + // } + if (!self.newWorkerGroup.name) { + self.newWorkerGroup.error = 'Enter a group name.'; + return; + } + // var entries = []; + // angular.forEach(self.workerGroup.members, function (obj) { + // entries.push(obj.id); + // }); + var data = { + name: self.newWorkerGroup.name, + type: 1, + is_global: false, + "entries": [] + }; + + User.createGroupWithMembers(data).then( + function success(data) { + self.workerGroups.push(data[0]); + self.newWorkerGroup.name = 'Untitled Group'; + self.newWorkerGroup.error = null; + self.newWorkerGroup.members = []; + $scope.cancel(); + } + ); + + } } })(); diff --git a/static/templates/project/new-worker-group.html b/static/templates/project/new-worker-group.html index 132185cd..33b66cb2 100644 --- a/static/templates/project/new-worker-group.html +++ b/static/templates/project/new-worker-group.html @@ -15,12 +15,12 @@ + ng-model="preferences.newWorkerGroup.name"> -
+
Workers: -
-
{{ project.workerGroup.error }}
+
{{ preferences.workerGroup.error }}
- Done + Create
+
diff --git a/static/templates/project/preferences.html b/static/templates/project/preferences.html index e07b33d5..77e7a76f 100644 --- a/static/templates/project/preferences.html +++ b/static/templates/project/preferences.html @@ -7,8 +7,63 @@
+
+
+
+ group +
+
+ Worker Groups + +
+
+ +
+
+ + + + + {{ option.name }} + + + +
or + Create a new + group + +
+
+ +
+ + + {{ user.handle }} + + + + {{$chip.handle}} + + + -
+
+
+ +
+
block @@ -22,48 +77,33 @@
Blocked workers will not be able to attempt your tasks in the future
-
- - {{ user.handle }} - - - Block - -
- -
-
-
{{ entry.worker_alias }} - close - -
-
+
+ + + {{ user.handle }} + + + + {{$chip.handle}} + + +
No workers found on this list.
+
-
-
- group -
-
- Worker Groups -
-
+