From d932d6e90754d0b0cc0639ff861b5bda449687a7 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Thu, 14 Feb 2019 10:07:42 +0100 Subject: [PATCH] Fixes submitters --- .../assignment-repository.service.ts | 2 +- .../app/core/repositories/base-repository.ts | 1 + .../motions/motion-repository.service.ts | 2 +- client/src/app/shared/models/agenda/item.ts | 33 +------------------ .../shared/models/assignments/assignment.ts | 12 +++---- .../src/app/shared/models/assignments/poll.ts | 4 +-- .../src/app/shared/models/motions/motion.ts | 4 +-- .../src/app/shared/models/motions/workflow.ts | 12 ++----- client/src/app/shared/models/users/user.ts | 4 --- .../speaker-list/speaker-list.component.html | 2 +- .../speaker-list/speaker-list.component.ts | 2 +- .../src/app/site/agenda/models/view-item.ts | 29 +++++++++++++--- .../motion-detail/motion-detail.component.ts | 4 +-- .../app/site/motions/models/view-motion.ts | 4 +-- .../motions/services/motion-pdf.service.ts | 2 +- 15 files changed, 46 insertions(+), 71 deletions(-) diff --git a/client/src/app/core/repositories/assignments/assignment-repository.service.ts b/client/src/app/core/repositories/assignments/assignment-repository.service.ts index 536c81dee..b2dc482ca 100644 --- a/client/src/app/core/repositories/assignments/assignment-repository.service.ts +++ b/client/src/app/core/repositories/assignments/assignment-repository.service.ts @@ -39,7 +39,7 @@ export class AssignmentRepositoryService extends BaseRepository { this.viewModelStore[model.id] = this.createViewModel(model); }); + // Update the list and then all models on their own this.updateViewModelListObservable(); this.DS.getAll(this.baseModelCtor).forEach((model: M) => { diff --git a/client/src/app/core/repositories/motions/motion-repository.service.ts b/client/src/app/core/repositories/motions/motion-repository.service.ts index 871684856..233409a94 100644 --- a/client/src/app/core/repositories/motions/motion-repository.service.ts +++ b/client/src/app/core/repositories/motions/motion-repository.service.ts @@ -102,7 +102,7 @@ export class MotionRepositoryService extends BaseRepository */ protected createViewModel(motion: Motion): ViewMotion { 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 workflow = this.viewModelStoreService.get(ViewWorkflow, motion.workflow_id); const item = this.viewModelStoreService.get(ViewItem, motion.agenda_item_id); diff --git a/client/src/app/shared/models/agenda/item.ts b/client/src/app/shared/models/agenda/item.ts index c5d501f9f..a28c9c04b 100644 --- a/client/src/app/shared/models/agenda/item.ts +++ b/client/src/app/shared/models/agenda/item.ts @@ -1,4 +1,4 @@ -import { Speaker, SpeakerState } from './speaker'; +import { Speaker } from './speaker'; import { BaseModel } from '../base/base-model'; /** @@ -55,35 +55,4 @@ export class Item extends BaseModel { }); } } - - /** - * 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 : ''; - } } diff --git a/client/src/app/shared/models/assignments/assignment.ts b/client/src/app/shared/models/assignments/assignment.ts index c5442d384..b63473f96 100644 --- a/client/src/app/shared/models/assignments/assignment.ts +++ b/client/src/app/shared/models/assignments/assignment.ts @@ -29,7 +29,7 @@ export class Assignment extends BaseModel { super(Assignment.COLLECTIONSTRING, input); } - public get candidateIds(): number[] { + public get candidates_id(): number[] { return this.assignment_related_users .sort((a: AssignmentUser, b: AssignmentUser) => { return a.weight - b.weight; @@ -42,16 +42,14 @@ export class Assignment extends BaseModel { this.assignment_related_users = []; if (input.assignment_related_users instanceof Array) { - input.assignment_related_users.forEach(assignmentUserData => { - this.assignment_related_users.push(new AssignmentUser(assignmentUserData)); - }); + this.assignment_related_users = input.assignment_related_users.map( + assignmentUserData => new AssignmentUser(assignmentUserData) + ); } this.polls = []; if (input.polls instanceof Array) { - input.polls.forEach(pollData => { - this.polls.push(new Poll(pollData)); - }); + this.polls = input.polls.map(pollData => new Poll(pollData)); } } } diff --git a/client/src/app/shared/models/assignments/poll.ts b/client/src/app/shared/models/assignments/poll.ts index 9ec0ab57b..268c377c9 100644 --- a/client/src/app/shared/models/assignments/poll.ts +++ b/client/src/app/shared/models/assignments/poll.ts @@ -30,9 +30,7 @@ export class Poll extends Deserializer { this.options = []; if (input.options instanceof Array) { - input.options.forEach(pollOptionData => { - this.options.push(new PollOption(pollOptionData)); - }); + this.options = input.options.map(pollOptionData => new PollOption(pollOptionData)); } } } diff --git a/client/src/app/shared/models/motions/motion.ts b/client/src/app/shared/models/motions/motion.ts index feb9803f3..01645192a 100644 --- a/client/src/app/shared/models/motions/motion.ts +++ b/client/src/app/shared/models/motions/motion.ts @@ -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 .sort((a: MotionSubmitter, b: MotionSubmitter) => { return a.weight - b.weight; diff --git a/client/src/app/shared/models/motions/workflow.ts b/client/src/app/shared/models/motions/workflow.ts index 9b45f8a0b..4f50f71c8 100644 --- a/client/src/app/shared/models/motions/workflow.ts +++ b/client/src/app/shared/models/motions/workflow.ts @@ -29,20 +29,14 @@ export class Workflow extends BaseModel { id = obj; } - return this.states.some(state => { - if (state.id === id) { - return true; - } - }); + return this.states.some(state => state.id === id); } public deserialize(input: any): void { Object.assign(this, input); + if (input.states instanceof Array) { - this.states = []; - input.states.forEach(workflowStateData => { - this.states.push(new WorkflowState(workflowStateData)); - }); + this.states = input.states.map(workflowStateData => new WorkflowState(workflowStateData)); } } } diff --git a/client/src/app/shared/models/users/user.ts b/client/src/app/shared/models/users/user.ts index 3334c5e7b..7676b81ce 100644 --- a/client/src/app/shared/models/users/user.ts +++ b/client/src/app/shared/models/users/user.ts @@ -33,8 +33,4 @@ export class User extends BaseModel { public constructor(input?: any) { super(User.COLLECTIONSTRING, input); } - - public containsGroupId(id: number): boolean { - return this.groups_id.some(groupId => groupId === id); - } } diff --git a/client/src/app/site/agenda/components/speaker-list/speaker-list.component.html b/client/src/app/site/agenda/components/speaker-list/speaker-list.component.html index 3a65af79f..6f1edbe31 100644 --- a/client/src/app/site/agenda/components/speaker-list/speaker-list.component.html +++ b/client/src/app/site/agenda/components/speaker-list/speaker-list.component.html @@ -19,7 +19,7 @@ - {{ projector.name }} + {{ projector.name | translate }} diff --git a/client/src/app/site/agenda/components/speaker-list/speaker-list.component.ts b/client/src/app/site/agenda/components/speaker-list/speaker-list.component.ts index 85317d4aa..eb49250b7 100644 --- a/client/src/app/site/agenda/components/speaker-list/speaker-list.component.ts +++ b/client/src/app/site/agenda/components/speaker-list/speaker-list.component.ts @@ -2,6 +2,7 @@ import { ActivatedRoute } from '@angular/router'; import { Component, OnInit } from '@angular/core'; import { FormGroup, FormControl } from '@angular/forms'; import { MatSnackBar, MatSelectChange } from '@angular/material'; +import { Title } from '@angular/platform-browser'; import { TranslateService } from '@ngx-translate/core'; 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 { PromptService } from 'app/core/ui-services/prompt.service'; import { SpeakerState } from 'app/shared/models/agenda/speaker'; -import { Title } from '@angular/platform-browser'; import { ViewItem } from '../../models/view-item'; import { ViewSpeaker } from '../../models/view-speaker'; import { ViewProjector } from 'app/site/projector/models/view-projector'; diff --git a/client/src/app/site/agenda/models/view-item.ts b/client/src/app/site/agenda/models/view-item.ts index b0e244e68..9ae32df35 100644 --- a/client/src/app/site/agenda/models/view-item.ts +++ b/client/src/app/site/agenda/models/view-item.ts @@ -1,6 +1,6 @@ import { BaseViewModel } from '../../base/base-view-model'; -import { Item } from 'app/shared/models/agenda/item'; -import { Speaker } from 'app/shared/models/agenda/speaker'; +import { Item, itemVisibilityChoices } from 'app/shared/models/agenda/item'; +import { Speaker, SpeakerState } from 'app/shared/models/agenda/speaker'; import { BaseAgendaViewModel, isAgendaBaseModel } from 'app/site/base/base-agenda-view-model'; export class ViewItem extends BaseViewModel { @@ -42,8 +42,11 @@ export class ViewItem extends BaseViewModel { return this.item.duration; } + /** + * Gets the amount of waiting speakers + */ public get waitingSpeakerAmount(): number { - return this.item.waitingSpeakerAmount; + return this.item.speakers.filter(speaker => speaker.state === SpeakerState.WAITING).length; } public get type(): number { @@ -58,12 +61,28 @@ export class ViewItem extends BaseViewModel { 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 { - 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 { - return this.item.verboseCsvType; + if (!this.type) { + return ''; + } + const type = itemVisibilityChoices.find(choice => choice.key === this.type); + return type ? type.csvName : ''; } /** diff --git a/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts b/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts index 297fa0065..a52568876 100644 --- a/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts +++ b/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts @@ -948,8 +948,8 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit { public updateWorkflowIdForCreateForm(): void { const isStatuteAmendment = !!this.contentForm.get('statute_amendment').value; const configKey = isStatuteAmendment ? 'motions_statute_amendments_workflow' : 'motions_workflow'; - const workflowID = this.configService.instant(configKey); - this.contentForm.patchValue({ workflow_id: +workflowID }); + const workflowId = this.configService.instant(configKey); + this.contentForm.patchValue({ workflow_id: +workflowId }); } /** diff --git a/client/src/app/site/motions/models/view-motion.ts b/client/src/app/site/motions/models/view-motion.ts index f5b1bb5a3..76ec1f50d 100644 --- a/client/src/app/site/motions/models/view-motion.ts +++ b/client/src/app/site/motions/models/view-motion.ts @@ -129,7 +129,7 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable { } public get submitters_id(): number[] { - return this.motion.submitterIds; + return this.motion.submitters_id; } public get supporters(): ViewUser[] { @@ -482,7 +482,7 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable { */ public updateUser(update: ViewUser): void { 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; } if (this.motion.supporters_id && this.motion.supporters_id.includes(update.id)) { diff --git a/client/src/app/site/motions/services/motion-pdf.service.ts b/client/src/app/site/motions/services/motion-pdf.service.ts index 7c5bb79d0..8ced48730 100644 --- a/client/src/app/site/motions/services/motion-pdf.service.ts +++ b/client/src/app/site/motions/services/motion-pdf.service.ts @@ -533,7 +533,7 @@ export class MotionPdfService { const callListRows: object[] = []; let currentTitle = ''; - motions.map(motion => { + motions.forEach(motion => { if (!motion.sort_parent_id) { const heading = motion.tags ? motion.tags.map(tag => tag.name).join(', ') : ''; if (heading !== currentTitle) {