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.
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:
model = AssignmentOption
fields = ('candidate', 'votes',)
fields = ('id', 'candidate', 'votes', 'poll')
class FilterPollListSerializer(ListSerializer):

View File

@ -4,18 +4,45 @@
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', [
'DS',
'Config',
function (DS, Config) {
'AssignmentPollOption',
function (DS, AssignmentPollOption) {
return DS.defineResource({
name: 'assignments/assignmentpoll',
name: 'assignments/poll',
relations: {
belongsTo: {
'assignments/assignment': {
localField: 'assignment',
localKey: 'assignment_id',
}
},
hasMany: {
'assignments/polloption': {
localField: 'options',
foreignKey: 'poll_id',
}
}
},
})
@ -75,7 +102,7 @@ angular.module('OpenSlidesApp.assignments', [])
localField: 'assignment_related_users',
foreignKey: 'assignment_id',
},
'assignments/assignmentpoll': {
'assignments/poll': {
localField: 'polls',
foreignKey: 'assignment_id',
}

View File

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