Angular: Added js-data models for assignment poll candidates

This commit is contained in:
Oskar Hahn 2015-11-28 00:27:14 +01:00
parent 6a4cc97469
commit 99ef185502
4 changed files with 34 additions and 7 deletions

View File

@ -24,4 +24,4 @@ class AssignmentsAppConfig(AppConfig):
# Register viewsets. # Register viewsets.
router.register('assignments/assignment', AssignmentViewSet) router.register('assignments/assignment', AssignmentViewSet)
router.register('assignments/assignmentpoll', AssignmentPollViewSet) router.register('assignments/poll', AssignmentPollViewSet)

View File

@ -50,7 +50,7 @@ class AssignmentOptionSerializer(ModelSerializer):
class Meta: class Meta:
model = AssignmentOption model = AssignmentOption
fields = ('candidate', 'votes',) fields = ('id', 'candidate', 'votes', 'poll')
class FilterPollListSerializer(ListSerializer): class FilterPollListSerializer(ListSerializer):

View File

@ -4,18 +4,45 @@
angular.module('OpenSlidesApp.assignments', []) angular.module('OpenSlidesApp.assignments', [])
.factory('AssignmentPollOption', [
'DS',
function (DS) {
return DS.defineResource({
name: 'assignments/polloption',
relations: {
belongsTo: {
'assignments/poll': {
localField: 'poll',
localKey: 'poll_id',
},
'users/user': {
localField: 'candidate',
localKey: 'candidate_id',
}
}
},
})
}
])
.factory('AssignmentPoll', [ .factory('AssignmentPoll', [
'DS', 'DS',
'Config', 'AssignmentPollOption',
function (DS, Config) { function (DS, AssignmentPollOption) {
return DS.defineResource({ return DS.defineResource({
name: 'assignments/assignmentpoll', name: 'assignments/poll',
relations: { relations: {
belongsTo: { belongsTo: {
'assignments/assignment': { 'assignments/assignment': {
localField: 'assignment', localField: 'assignment',
localKey: 'assignment_id', localKey: 'assignment_id',
} }
},
hasMany: {
'assignments/polloption': {
localField: 'options',
foreignKey: 'poll_id',
}
} }
}, },
}) })
@ -75,7 +102,7 @@ angular.module('OpenSlidesApp.assignments', [])
localField: 'assignment_related_users', localField: 'assignment_related_users',
foreignKey: 'assignment_id', foreignKey: 'assignment_id',
}, },
'assignments/assignmentpoll': { 'assignments/poll': {
localField: 'polls', localField: 'polls',
foreignKey: 'assignment_id', foreignKey: 'assignment_id',
} }

View File

@ -382,7 +382,7 @@ angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments'])
$scope.formFields.push( $scope.formFields.push(
{ {
noFormControl: true, noFormControl: true,
template: '<strong>User#' + option.candidate_id + '</strong>' template: '<strong>' + option.candidate.get_full_name() + '</strong>'
}, },
{ {
key: 'yes_' + option.candidate_id, key: 'yes_' + option.candidate_id,