Merge pull request #4336 from FinnStutzenstein/cleanup

Fixes submitters
This commit is contained in:
Emanuel Schütze 2019-02-14 10:49:42 +01:00 committed by GitHub
commit 3172f0a532
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 46 additions and 71 deletions

View File

@ -39,7 +39,7 @@ export class AssignmentRepositoryService extends BaseRepository<ViewAssignment,
} }
public createViewModel(assignment: Assignment): ViewAssignment { public createViewModel(assignment: Assignment): ViewAssignment {
const relatedUser = this.viewModelStoreService.getMany(ViewUser, assignment.candidateIds); const relatedUser = this.viewModelStoreService.getMany(ViewUser, assignment.candidates_id);
const agendaItem = this.viewModelStoreService.get(ViewItem, assignment.agenda_item_id); const agendaItem = this.viewModelStoreService.get(ViewItem, assignment.agenda_item_id);
const tags = this.viewModelStoreService.getMany(ViewTag, assignment.tags_id); const tags = this.viewModelStoreService.getMany(ViewTag, assignment.tags_id);

View File

@ -70,6 +70,7 @@ export abstract class BaseRepository<V extends BaseViewModel, M extends BaseMode
this.DS.getAll(this.baseModelCtor).forEach((model: M) => { this.DS.getAll(this.baseModelCtor).forEach((model: M) => {
this.viewModelStore[model.id] = this.createViewModel(model); this.viewModelStore[model.id] = this.createViewModel(model);
}); });
// Update the list and then all models on their own // Update the list and then all models on their own
this.updateViewModelListObservable(); this.updateViewModelListObservable();
this.DS.getAll(this.baseModelCtor).forEach((model: M) => { this.DS.getAll(this.baseModelCtor).forEach((model: M) => {

View File

@ -102,7 +102,7 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
*/ */
protected createViewModel(motion: Motion): ViewMotion { protected createViewModel(motion: Motion): ViewMotion {
const category = this.viewModelStoreService.get(ViewCategory, motion.category_id); const category = this.viewModelStoreService.get(ViewCategory, motion.category_id);
const submitters = this.viewModelStoreService.getMany(ViewUser, motion.submitterIds); const submitters = this.viewModelStoreService.getMany(ViewUser, motion.submitters_id);
const supporters = this.viewModelStoreService.getMany(ViewUser, motion.supporters_id); const supporters = this.viewModelStoreService.getMany(ViewUser, motion.supporters_id);
const workflow = this.viewModelStoreService.get(ViewWorkflow, motion.workflow_id); const workflow = this.viewModelStoreService.get(ViewWorkflow, motion.workflow_id);
const item = this.viewModelStoreService.get(ViewItem, motion.agenda_item_id); const item = this.viewModelStoreService.get(ViewItem, motion.agenda_item_id);

View File

@ -1,4 +1,4 @@
import { Speaker, SpeakerState } from './speaker'; import { Speaker } from './speaker';
import { BaseModel } from '../base/base-model'; import { BaseModel } from '../base/base-model';
/** /**
@ -55,35 +55,4 @@ export class Item extends BaseModel<Item> {
}); });
} }
} }
/**
* Gets the amount of waiting speakers
*/
public get waitingSpeakerAmount(): number {
return this.speakers.filter(speaker => speaker.state === SpeakerState.WAITING).length;
}
/**
* Gets the string representation of the item type
* @returns The visibility for this item, as defined in {@link itemVisibilityChoices}
*/
public get verboseType(): string {
if (!this.type) {
return '';
}
const type = itemVisibilityChoices.find(choice => choice.key === this.type);
return type ? type.name : '';
}
/**
* Gets a shortened string for CSV export
* @returns empty string if it is a public item, 'internal' or 'hidden' otherwise
*/
public get verboseCsvType(): string {
if (!this.type) {
return '';
}
const type = itemVisibilityChoices.find(choice => choice.key === this.type);
return type ? type.csvName : '';
}
} }

View File

@ -29,7 +29,7 @@ export class Assignment extends BaseModel<Assignment> {
super(Assignment.COLLECTIONSTRING, input); super(Assignment.COLLECTIONSTRING, input);
} }
public get candidateIds(): number[] { public get candidates_id(): number[] {
return this.assignment_related_users return this.assignment_related_users
.sort((a: AssignmentUser, b: AssignmentUser) => { .sort((a: AssignmentUser, b: AssignmentUser) => {
return a.weight - b.weight; return a.weight - b.weight;
@ -42,16 +42,14 @@ export class Assignment extends BaseModel<Assignment> {
this.assignment_related_users = []; this.assignment_related_users = [];
if (input.assignment_related_users instanceof Array) { if (input.assignment_related_users instanceof Array) {
input.assignment_related_users.forEach(assignmentUserData => { this.assignment_related_users = input.assignment_related_users.map(
this.assignment_related_users.push(new AssignmentUser(assignmentUserData)); assignmentUserData => new AssignmentUser(assignmentUserData)
}); );
} }
this.polls = []; this.polls = [];
if (input.polls instanceof Array) { if (input.polls instanceof Array) {
input.polls.forEach(pollData => { this.polls = input.polls.map(pollData => new Poll(pollData));
this.polls.push(new Poll(pollData));
});
} }
} }
} }

View File

@ -30,9 +30,7 @@ export class Poll extends Deserializer {
this.options = []; this.options = [];
if (input.options instanceof Array) { if (input.options instanceof Array) {
input.options.forEach(pollOptionData => { this.options = input.options.map(pollOptionData => new PollOption(pollOptionData));
this.options.push(new PollOption(pollOptionData));
});
} }
} }
} }

View File

@ -48,9 +48,9 @@ export class Motion extends BaseModel {
} }
/** /**
* returns the motion submitters userIDs * returns the motion submitters user ids
*/ */
public get submitterIds(): number[] { public get submitters_id(): number[] {
return this.submitters return this.submitters
.sort((a: MotionSubmitter, b: MotionSubmitter) => { .sort((a: MotionSubmitter, b: MotionSubmitter) => {
return a.weight - b.weight; return a.weight - b.weight;

View File

@ -29,20 +29,14 @@ export class Workflow extends BaseModel<Workflow> {
id = obj; id = obj;
} }
return this.states.some(state => { return this.states.some(state => state.id === id);
if (state.id === id) {
return true;
}
});
} }
public deserialize(input: any): void { public deserialize(input: any): void {
Object.assign(this, input); Object.assign(this, input);
if (input.states instanceof Array) { if (input.states instanceof Array) {
this.states = []; this.states = input.states.map(workflowStateData => new WorkflowState(workflowStateData));
input.states.forEach(workflowStateData => {
this.states.push(new WorkflowState(workflowStateData));
});
} }
} }
} }

View File

@ -33,8 +33,4 @@ export class User extends BaseModel<User> {
public constructor(input?: any) { public constructor(input?: any) {
super(User.COLLECTIONSTRING, input); super(User.COLLECTIONSTRING, input);
} }
public containsGroupId(id: number): boolean {
return this.groups_id.some(groupId => groupId === id);
}
} }

View File

@ -19,7 +19,7 @@
<mat-form-field *ngIf="projectors && projectors.length > 0"> <mat-form-field *ngIf="projectors && projectors.length > 0">
<mat-select [value]="projectors[0]" (selectionChange)="onSelectProjector($event)"> <mat-select [value]="projectors[0]" (selectionChange)="onSelectProjector($event)">
<mat-option *ngFor="let projector of projectors" [value]="projector"> <mat-option *ngFor="let projector of projectors" [value]="projector">
{{ projector.name }} {{ projector.name | translate }}
</mat-option> </mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>

View File

@ -2,6 +2,7 @@ import { ActivatedRoute } from '@angular/router';
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms'; import { FormGroup, FormControl } from '@angular/forms';
import { MatSnackBar, MatSelectChange } from '@angular/material'; import { MatSnackBar, MatSelectChange } from '@angular/material';
import { Title } from '@angular/platform-browser';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { BehaviorSubject, Subscription } from 'rxjs'; import { BehaviorSubject, Subscription } from 'rxjs';
@ -13,7 +14,6 @@ import { OperatorService } from 'app/core/core-services/operator.service';
import { ProjectorRepositoryService } from 'app/core/repositories/projector/projector-repository.service'; import { ProjectorRepositoryService } from 'app/core/repositories/projector/projector-repository.service';
import { PromptService } from 'app/core/ui-services/prompt.service'; import { PromptService } from 'app/core/ui-services/prompt.service';
import { SpeakerState } from 'app/shared/models/agenda/speaker'; import { SpeakerState } from 'app/shared/models/agenda/speaker';
import { Title } from '@angular/platform-browser';
import { ViewItem } from '../../models/view-item'; import { ViewItem } from '../../models/view-item';
import { ViewSpeaker } from '../../models/view-speaker'; import { ViewSpeaker } from '../../models/view-speaker';
import { ViewProjector } from 'app/site/projector/models/view-projector'; import { ViewProjector } from 'app/site/projector/models/view-projector';

View File

@ -1,6 +1,6 @@
import { BaseViewModel } from '../../base/base-view-model'; import { BaseViewModel } from '../../base/base-view-model';
import { Item } from 'app/shared/models/agenda/item'; import { Item, itemVisibilityChoices } from 'app/shared/models/agenda/item';
import { Speaker } from 'app/shared/models/agenda/speaker'; import { Speaker, SpeakerState } from 'app/shared/models/agenda/speaker';
import { BaseAgendaViewModel, isAgendaBaseModel } from 'app/site/base/base-agenda-view-model'; import { BaseAgendaViewModel, isAgendaBaseModel } from 'app/site/base/base-agenda-view-model';
export class ViewItem extends BaseViewModel { export class ViewItem extends BaseViewModel {
@ -42,8 +42,11 @@ export class ViewItem extends BaseViewModel {
return this.item.duration; return this.item.duration;
} }
/**
* Gets the amount of waiting speakers
*/
public get waitingSpeakerAmount(): number { public get waitingSpeakerAmount(): number {
return this.item.waitingSpeakerAmount; return this.item.speakers.filter(speaker => speaker.state === SpeakerState.WAITING).length;
} }
public get type(): number { public get type(): number {
@ -58,12 +61,28 @@ export class ViewItem extends BaseViewModel {
return this.item.comment; return this.item.comment;
} }
/**
* Gets the string representation of the item type
* @returns The visibility for this item, as defined in {@link itemVisibilityChoices}
*/
public get verboseType(): string { public get verboseType(): string {
return this.item.verboseType; if (!this.type) {
return '';
}
const type = itemVisibilityChoices.find(choice => choice.key === this.type);
return type ? type.name : '';
} }
/**
* Gets a shortened string for CSV export
* @returns empty string if it is a public item, 'internal' or 'hidden' otherwise
*/
public get verboseCsvType(): string { public get verboseCsvType(): string {
return this.item.verboseCsvType; if (!this.type) {
return '';
}
const type = itemVisibilityChoices.find(choice => choice.key === this.type);
return type ? type.csvName : '';
} }
/** /**

View File

@ -948,8 +948,8 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
public updateWorkflowIdForCreateForm(): void { public updateWorkflowIdForCreateForm(): void {
const isStatuteAmendment = !!this.contentForm.get('statute_amendment').value; const isStatuteAmendment = !!this.contentForm.get('statute_amendment').value;
const configKey = isStatuteAmendment ? 'motions_statute_amendments_workflow' : 'motions_workflow'; const configKey = isStatuteAmendment ? 'motions_statute_amendments_workflow' : 'motions_workflow';
const workflowID = this.configService.instant<string>(configKey); const workflowId = this.configService.instant<string>(configKey);
this.contentForm.patchValue({ workflow_id: +workflowID }); this.contentForm.patchValue({ workflow_id: +workflowId });
} }
/** /**

View File

@ -129,7 +129,7 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable {
} }
public get submitters_id(): number[] { public get submitters_id(): number[] {
return this.motion.submitterIds; return this.motion.submitters_id;
} }
public get supporters(): ViewUser[] { public get supporters(): ViewUser[] {
@ -482,7 +482,7 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable {
*/ */
public updateUser(update: ViewUser): void { public updateUser(update: ViewUser): void {
if (this.motion.submitters && this.motion.submitters.find(user => user.user_id === update.id)) { if (this.motion.submitters && this.motion.submitters.find(user => user.user_id === update.id)) {
const userIndex = this.submitters.findIndex(user => user.id === update.id); const userIndex = this.motion.submitters.findIndex(submitter => submitter.user_id === update.id);
this.submitters[userIndex] = update; this.submitters[userIndex] = update;
} }
if (this.motion.supporters_id && this.motion.supporters_id.includes(update.id)) { if (this.motion.supporters_id && this.motion.supporters_id.includes(update.id)) {

View File

@ -533,7 +533,7 @@ export class MotionPdfService {
const callListRows: object[] = []; const callListRows: object[] = [];
let currentTitle = ''; let currentTitle = '';
motions.map(motion => { motions.forEach(motion => {
if (!motion.sort_parent_id) { if (!motion.sort_parent_id) {
const heading = motion.tags ? motion.tags.map(tag => tag.name).join(', ') : ''; const heading = motion.tags ? motion.tags.map(tag => tag.name).join(', ') : '';
if (heading !== currentTitle) { if (heading !== currentTitle) {