added config for default poll type

This commit is contained in:
Joshua Sangmeister 2020-05-13 11:27:45 +02:00 committed by Emanuel Schütze
parent b7b27d2e88
commit fa63ef0307
8 changed files with 98 additions and 11 deletions

View File

@ -10,7 +10,7 @@ import {
AssignmentPollMethod, AssignmentPollMethod,
AssignmentPollPercentBase AssignmentPollPercentBase
} from 'app/shared/models/assignments/assignment-poll'; } from 'app/shared/models/assignments/assignment-poll';
import { MajorityMethod, VOTE_UNDOCUMENTED } from 'app/shared/models/poll/base-poll'; import { MajorityMethod, PollType, VOTE_UNDOCUMENTED } from 'app/shared/models/poll/base-poll';
import { ParsePollNumberPipe } from 'app/shared/pipes/parse-poll-number.pipe'; import { ParsePollNumberPipe } from 'app/shared/pipes/parse-poll-number.pipe';
import { PollKeyVerbosePipe } from 'app/shared/pipes/poll-key-verbose.pipe'; import { PollKeyVerbosePipe } from 'app/shared/pipes/poll-key-verbose.pipe';
import { import {
@ -41,6 +41,8 @@ export class AssignmentPollService extends PollService {
public defaultPollMethod: AssignmentPollMethod; public defaultPollMethod: AssignmentPollMethod;
public defaultPollType: PollType;
private sortByVote: boolean; private sortByVote: boolean;
/** /**
@ -66,6 +68,7 @@ export class AssignmentPollService extends PollService {
config config
.get<AssignmentPollMethod>(AssignmentPoll.defaultPollMethodConfig) .get<AssignmentPollMethod>(AssignmentPoll.defaultPollMethodConfig)
.subscribe(method => (this.defaultPollMethod = method)); .subscribe(method => (this.defaultPollMethod = method));
config.get<PollType>('assignment_poll_default_type').subscribe(type => (this.defaultPollType = type));
config.get<boolean>('assignment_poll_sort_poll_result_by_votes').subscribe(sort => (this.sortByVote = sort)); config.get<boolean>('assignment_poll_sort_poll_result_by_votes').subscribe(sort => (this.sortByVote = sort));
} }

View File

@ -6,7 +6,7 @@ import { ConstantsService } from 'app/core/core-services/constants.service';
import { MotionPollRepositoryService } from 'app/core/repositories/motions/motion-poll-repository.service'; import { MotionPollRepositoryService } from 'app/core/repositories/motions/motion-poll-repository.service';
import { ConfigService } from 'app/core/ui-services/config.service'; import { ConfigService } from 'app/core/ui-services/config.service';
import { MotionPoll, MotionPollMethod } from 'app/shared/models/motions/motion-poll'; import { MotionPoll, MotionPollMethod } from 'app/shared/models/motions/motion-poll';
import { MajorityMethod, PercentBase } from 'app/shared/models/poll/base-poll'; import { MajorityMethod, PercentBase, PollType } from 'app/shared/models/poll/base-poll';
import { ParsePollNumberPipe } from 'app/shared/pipes/parse-poll-number.pipe'; import { ParsePollNumberPipe } from 'app/shared/pipes/parse-poll-number.pipe';
import { PollKeyVerbosePipe } from 'app/shared/pipes/poll-key-verbose.pipe'; import { PollKeyVerbosePipe } from 'app/shared/pipes/poll-key-verbose.pipe';
import { PollData, PollService, PollTableData, VotingResult } from 'app/site/polls/services/poll.service'; import { PollData, PollService, PollTableData, VotingResult } from 'app/site/polls/services/poll.service';
@ -38,6 +38,8 @@ export class MotionPollService extends PollService {
public defaultGroupIds: number[]; public defaultGroupIds: number[];
public defaultPollType: PollType;
/** /**
* Constructor. Subscribes to the configuration values needed * Constructor. Subscribes to the configuration values needed
* @param config ConfigService * @param config ConfigService
@ -57,6 +59,7 @@ export class MotionPollService extends PollService {
config config
.get<MajorityMethod>('motion_poll_default_majority_method') .get<MajorityMethod>('motion_poll_default_majority_method')
.subscribe(method => (this.defaultMajorityMethod = method)); .subscribe(method => (this.defaultMajorityMethod = method));
config.get<PollType>('motion_poll_default_type').subscribe(type => (this.defaultPollType = type));
config.get<number[]>(MotionPoll.defaultGroupsConfig).subscribe(ids => (this.defaultGroupIds = ids)); config.get<number[]>(MotionPoll.defaultGroupsConfig).subscribe(ids => (this.defaultGroupIds = ids));
} }

View File

@ -178,6 +178,11 @@ export abstract class PollService {
*/ */
public abstract defaultGroupIds: number[]; public abstract defaultGroupIds: number[];
/**
* The default poll type
*/
public abstract defaultPollType: PollType;
/** /**
* The majority method currently in use * The majority method currently in use
*/ */
@ -227,7 +232,7 @@ export abstract class PollService {
onehundred_percent_base: this.defaultPercentBase, onehundred_percent_base: this.defaultPercentBase,
majority_method: this.defaultMajorityMethod, majority_method: this.defaultMajorityMethod,
groups_id: this.defaultGroupIds, groups_id: this.defaultGroupIds,
type: PollType.Analog type: this.defaultPollType
}; };
} }

View File

@ -13,7 +13,7 @@ def get_config_variables():
# Voting # Voting
yield ConfigVariable( yield ConfigVariable(
name="assignment_poll_method", name="assignment_poll_method",
default_value="votes", default_value=AssignmentPoll.POLLMETHOD_VOTES,
input_type="choice", input_type="choice",
label="Default election method", label="Default election method",
choices=tuple( choices=tuple(
@ -25,9 +25,22 @@ def get_config_variables():
subgroup="Ballot", subgroup="Ballot",
) )
yield ConfigVariable(
name="assignment_poll_default_type",
default_value=AssignmentPoll.TYPE_ANALOG,
input_type="choice",
label="Default type for assignment polls",
choices=tuple(
{"value": type[0], "display_name": type[1]} for type in AssignmentPoll.TYPES
),
weight=403,
group="Elections",
subgroup="Ballot",
)
yield ConfigVariable( yield ConfigVariable(
name="assignment_poll_default_100_percent_base", name="assignment_poll_default_100_percent_base",
default_value="valid", default_value=AssignmentPoll.PERCENT_BASE_VALID,
input_type="choice", input_type="choice",
label="Default 100 % base of an election result", label="Default 100 % base of an election result",
choices=tuple( choices=tuple(
@ -51,7 +64,7 @@ def get_config_variables():
yield ConfigVariable( yield ConfigVariable(
name="assignment_poll_default_majority_method", name="assignment_poll_default_majority_method",
default_value="simple", default_value=AssignmentPoll.MAJORITY_SIMPLE,
input_type="choice", input_type="choice",
choices=tuple( choices=tuple(
{"value": method[0], "display_name": method[1]} {"value": method[0], "display_name": method[1]}

View File

@ -0,0 +1,25 @@
# Generated by Django 2.2.9 on 2020-05-13 09:23
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("assignments", "0012_assignment_vote_unique_together"),
]
operations = [
migrations.AlterField(
model_name="assignmentpoll",
name="type",
field=models.CharField(
choices=[
("analog", "analog"),
("named", "nominal"),
("pseudoanonymous", "non-nominal"),
],
max_length=64,
),
),
]

View File

@ -331,9 +331,22 @@ def get_config_variables():
# Voting and ballot papers # Voting and ballot papers
yield ConfigVariable(
name="motion_poll_default_type",
default_value=MotionPoll.TYPE_ANALOG,
input_type="choice",
label="Default type for motion polls",
choices=tuple(
{"value": type[0], "display_name": type[1]} for type in MotionPoll.TYPES
),
weight=367,
group="Motions",
subgroup="Voting and ballot papers",
)
yield ConfigVariable( yield ConfigVariable(
name="motion_poll_default_100_percent_base", name="motion_poll_default_100_percent_base",
default_value="YNA", default_value=MotionPoll.PERCENT_BASE_YNA,
input_type="choice", input_type="choice",
label="Default 100 % base of a voting result", label="Default 100 % base of a voting result",
choices=tuple( choices=tuple(
@ -347,7 +360,7 @@ def get_config_variables():
yield ConfigVariable( yield ConfigVariable(
name="motion_poll_default_majority_method", name="motion_poll_default_majority_method",
default_value="simple", default_value=MotionPoll.MAJORITY_SIMPLE,
input_type="choice", input_type="choice",
choices=tuple( choices=tuple(
{"value": method[0], "display_name": method[1]} {"value": method[0], "display_name": method[1]}

View File

@ -0,0 +1,25 @@
# Generated by Django 2.2.9 on 2020-05-13 09:23
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("motions", "0035_motion_vote_unique_together"),
]
operations = [
migrations.AlterField(
model_name="motionpoll",
name="type",
field=models.CharField(
choices=[
("analog", "analog"),
("named", "nominal"),
("pseudoanonymous", "non-nominal"),
],
max_length=64,
),
),
]

View File

@ -116,9 +116,9 @@ class BasePoll(models.Model):
TYPE_NAMED = "named" TYPE_NAMED = "named"
TYPE_PSEUDOANONYMOUS = "pseudoanonymous" TYPE_PSEUDOANONYMOUS = "pseudoanonymous"
TYPES = ( TYPES = (
(TYPE_ANALOG, "Analog"), (TYPE_ANALOG, "analog"),
(TYPE_NAMED, "Named"), (TYPE_NAMED, "nominal"),
(TYPE_PSEUDOANONYMOUS, "Pseudoanonymous"), (TYPE_PSEUDOANONYMOUS, "non-nominal"),
) )
type = models.CharField(max_length=64, blank=False, null=False, choices=TYPES) type = models.CharField(max_length=64, blank=False, null=False, choices=TYPES)