Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
add worker group forms
Browse files Browse the repository at this point in the history
  • Loading branch information
dmorina committed Oct 17, 2017
1 parent 1f48f61 commit c62f965
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 51 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions crowdsourcing/serializers/qualification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
87 changes: 81 additions & 6 deletions static/js/user/controllers/preferences.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
);
}
Expand All @@ -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();
}
);

}
}
})();
11 changes: 6 additions & 5 deletions static/templates/project/new-worker-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
<md-input-container class="md-block">
<label>Name</label>
<input name="group_name" required
ng-model="project.workerGroup.name">
ng-model="preferences.newWorkerGroup.name">
</md-input-container>
</div>
<div class="_ml-16 _mr-24">
<div class="_ml-16 _mr-24" ng-hide="true">
<span class="_sub-header">Workers:</span>
<md-chips ng-model="project.workerGroup.members" md-autocomplete-snap
<md-chips ng-model="preferences.workerGroup.members" md-autocomplete-snap
md-transform-chip="project.transformChip($chip)"
md-require-match="true">
<md-autocomplete md-selected-item="project.selectedWorker"
Expand All @@ -37,14 +37,15 @@
</md-chip-template>
</md-chips>
</div>
<div class="_ml-16 _mr-24 _error _small _mt-16">{{ project.workerGroup.error }}</div>
<div class="_ml-16 _mr-24 _error _small _mt-16">{{ preferences.workerGroup.error }}</div>
<div class="layout-align-end-end" layout="row">
<md-dialog-actions>
<md-button ng-click="project.addWorkerGroup();" class="publish">Done
<md-button ng-click="preferences.addWorkerGroup();" class="publish">Create
</md-button>
</md-dialog-actions>
</div>
</form>
</div>
</md-dialog-content>
</md-dialog>

112 changes: 76 additions & 36 deletions static/templates/project/preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,63 @@
</div>
<div class="_main-content-body">

<div style="padding: 16px">
<div class="layout-row layout-align-start-center">
<div class="_icon-left">
<md-icon style="margin-top: 6px" class="_icon-18" md-font-set="material-icons">group</md-icon>
</div>
<div style="color: rgba(0, 0, 0, 0.7); font-size: large; font-weight: 500">
Worker Groups

</div>
</div>

<div>
<div layout="row" layout-align="start-center">
<md-input-container ng-show="preferences.workerGroups.length">
<label>Select group</label>
<md-select md-change="preferences.onGroupSelected()"
class="_ml-16"
ng-model="preferences.workerGroup"
aria-label="worker group">
<md-option value="{{ option.id }}"
ng-repeat="option in preferences.workerGroups">
{{ option.name }}
</md-option>
</md-select>
</md-input-container>
<div style="padding-left: 8px"> or
<md-button class="md-accent" ng-click="preferences.openWorkerGroupNew($event)">Create a new
group
</md-button>
</div>
</div>

<div ng-if="preferences.workerGroup && preferences.workerGroup > 0">
<md-chips ng-model="preferences.groupMembers"
md-require-match=''
md-removable="true"
md-on-add="preferences.addWorkerToGroup($chip)"
md-on-remove="preferences.removeWorkerFromGroup($chip)">
<md-autocomplete md-selected-item='preferences.selectedGroupMember'
md-search-text='preferences.searchTextForGroup'
md-items='user in preferences.querySearch(preferences.searchTextForGroup)'
md-item-text='user.handle'
placeholder="Enter a screen name...">
<span md-highlight-text='preferences.searchTextForGroup'>{{ user.handle }}</span>
</md-autocomplete>
<md-chip-template>
<span>
<strong>{{$chip.handle}}</strong>
</span>
</md-chip-template>
</md-chips>

<div ng-class="{'_expanded': true}" style="padding: 16px;">
</div>
</div>

</div>
<div style="padding: 16px;">
<div class="layout-row layout-align-start-center">
<div class="_icon-left">
<md-icon style="margin-top: 6px" class="_icon-18" md-font-set="material-icons">block</md-icon>
Expand All @@ -22,48 +77,33 @@
<div class="_detail-text _margin-lr">Blocked workers will not be able to attempt your tasks in the
future
</div>
<div class="layout-row layout-align-start-center">
<md-autocomplete style="margin-top: 10px; margin-bottom: 10px; width: 256px;"
class="_margin-lr" ng-hide="inbox.newRecipients.length"
md-selected-item="preferences.selectedItem"
md-search-text="preferences.searchText"
md-items="user in preferences.querySearch(preferences.searchText)"
md-item-text="user.handle"
placeholder="Screen name..">
<span md-highlight-text="preferences.searchText">{{ user.handle }}</span>
</md-autocomplete>
<md-button class="md-accent" ng-click="preferences.blockWorker(preferences.selectedItem.id)">
Block
</md-button>
</div>
<md-divider class="_margin-lr"></md-divider>
<div class="_worker-list">
<div class="_margin-lr _user _blocked"
ng-repeat="entry in preferences.black_list_entries"
ng-class="{'_unblocked': entry.unblocked, '_clickable': !entry.unblocked}">
<div class="_md-chip">{{ entry.worker_alias }}
<md-icon ng-click="preferences.unblockWorker(entry)"
style="padding-top: 6px; text-align: center; cursor: pointer; outline: none"
class="_icon-18"
md-font-set="material-icons">close
</md-icon>
</div>
</div>
<div>
<md-chips ng-model="preferences.black_list_entries"
md-require-match=''
md-on-add="preferences.blockWorker($chip.id)"
md-on-remove="preferences.unblockWorker($chip)">
<md-autocomplete md-selected-item='preferences.selectedItem'
md-search-text='preferences.searchText'
md-items='user in preferences.querySearch(preferences.searchText)'
md-item-text='user.handle'
placeholder="Enter a screen name">
<span md-highlight-text='preferences.searchText'>{{ user.handle }}</span>
</md-autocomplete>
<md-chip-template>
<span>
<strong>{{$chip.handle}}</strong>
</span>
</md-chip-template>
</md-chips>
</div>

<div class="_sub-header" style="line-height: 36px"
ng-if="preferences.black_list_entries && preferences.black_list_entries.length==0 && !preferences.loading">
No workers found on this list.
</div>
<!--md-divider class="_margin-lr"></md-divider-->

</div>
<div style="margin-left: 16px" class="layout-row layout-align-start-center">
<div class="_icon-left">
<md-icon style="margin-top: 6px" class="_icon-18" md-font-set="material-icons">group</md-icon>
</div>
<div style="color: rgba(0, 0, 0, 0.7); font-size: large; font-weight: 500">
Worker Groups
</div>
</div>

</div>
</div>

0 comments on commit c62f965

Please sign in to comment.