diff --git a/client/src/app/core/services/choice.service.ts b/client/src/app/core/services/choice.service.ts index 0dda9ebdd..76fa7f4b6 100644 --- a/client/src/app/core/services/choice.service.ts +++ b/client/src/app/core/services/choice.service.ts @@ -36,7 +36,7 @@ export class ChoiceService extends OpenSlidesComponent { ): Promise { const dialogRef = this.dialog.open(ChoiceDialogComponent, { minWidth: '250px', - maxHeight:'90vh', + maxHeight: '90vh', data: { title: title, choices: choices, multiSelect: multiSelect } }); return dialogRef.afterClosed().toPromise(); diff --git a/client/src/app/shared/components/choice-dialog/choice-dialog.component.html b/client/src/app/shared/components/choice-dialog/choice-dialog.component.html index ca7c51c71..b3f8cce8b 100644 --- a/client/src/app/shared/components/choice-dialog/choice-dialog.component.html +++ b/client/src/app/shared/components/choice-dialog/choice-dialog.component.html @@ -28,5 +28,5 @@ Ok - - \ No newline at end of file + + diff --git a/client/src/app/shared/components/choice-dialog/choice-dialog.component.scss b/client/src/app/shared/components/choice-dialog/choice-dialog.component.scss index a99f46fc3..d504e250f 100644 --- a/client/src/app/shared/components/choice-dialog/choice-dialog.component.scss +++ b/client/src/app/shared/components/choice-dialog/choice-dialog.component.scss @@ -13,5 +13,5 @@ mat-radio-group { } .scrollmenu-outer { - max-height:inherit; -} \ No newline at end of file + max-height: inherit; +} diff --git a/client/src/app/shared/components/choice-dialog/choice-dialog.component.ts b/client/src/app/shared/components/choice-dialog/choice-dialog.component.ts index 6ae8f2088..c728bbb59 100644 --- a/client/src/app/shared/components/choice-dialog/choice-dialog.component.ts +++ b/client/src/app/shared/components/choice-dialog/choice-dialog.component.ts @@ -14,9 +14,23 @@ type ChoiceDialogOption = (Identifiable & Displayable) | (Identifiable & { label */ export type ChoiceDialogOptions = (Identifiable & Displayable)[] | (Identifiable & { label: string })[]; +/** + * All data needed for this dialog + */ interface ChoiceDialogData { + /** + * A title to display + */ title: string; + + /** + * The choices to display + */ choices: ChoiceDialogOptions; + + /** + * Select, if this should be a multiselect choice + */ multiSelect: boolean; } @@ -50,6 +64,12 @@ export class ChoiceDialogComponent { @Inject(MAT_DIALOG_DATA) public data: ChoiceDialogData ) {} + /** + * Get the title from a choice. Maybe saved in a label property or using getTitle(). + * + * @param choice The choice + * @return the title + */ public getChoiceTitle(choice: ChoiceDialogOption): string { if ('label' in choice) { return choice.label; diff --git a/client/src/app/shared/models/motions/motion.ts b/client/src/app/shared/models/motions/motion.ts index f44e4523d..a6b06d847 100644 --- a/client/src/app/shared/models/motions/motion.ts +++ b/client/src/app/shared/models/motions/motion.ts @@ -23,7 +23,6 @@ export class Motion extends AgendaBaseModel { public motion_block_id: number; public origin: string; public submitters: MotionSubmitter[]; - public submitters_id: number[]; public supporters_id: number[]; public comments: MotionComment[]; public workflow_id: number; diff --git a/client/src/app/site/motions/components/amendment-create-wizard/amendment-create-wizard.component.ts b/client/src/app/site/motions/components/amendment-create-wizard/amendment-create-wizard.component.ts index 9161f8713..3482cb1e0 100644 --- a/client/src/app/site/motions/components/amendment-create-wizard/amendment-create-wizard.component.ts +++ b/client/src/app/site/motions/components/amendment-create-wizard/amendment-create-wizard.component.ts @@ -9,8 +9,8 @@ import { TranslateService } from '@ngx-translate/core'; import { MotionRepositoryService } from '../../services/motion-repository.service'; import { ViewMotion } from '../../models/view-motion'; import { LinenumberingService } from '../../services/linenumbering.service'; -import { Motion } from '../../../../shared/models/motions/motion'; import { BaseViewComponent } from '../../../base/base-view'; +import { CreateMotion } from '../../models/create-motion'; /** * Describes the single paragraphs from the base motion. @@ -167,10 +167,10 @@ export class AmendmentCreateWizardComponent extends BaseViewComponent { amendment_paragraphs: amendedParagraphs }; - const fromForm = new Motion(); - fromForm.deserialize(newMotionValues); + const motion = new CreateMotion(); + motion.deserialize(newMotionValues); - const response = await this.repo.create(fromForm); + const response = await this.repo.create(motion); this.router.navigate(['./motions/' + response.id]); } } 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 bc01dd23a..7f77a963e 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 @@ -29,6 +29,8 @@ import { ConfigService } from '../../../../core/services/config.service'; import { Workflow } from 'app/shared/models/motions/workflow'; import { take, takeWhile, multicast, skipWhile } from 'rxjs/operators'; import { LocalPermissionsService } from '../../services/local-permissions.service'; +import { ViewCreateMotion } from '../../models/view-create-motion'; +import { CreateMotion } from '../../models/create-motion'; /** * Component for the motion detail view @@ -260,28 +262,10 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit { } }); // load config variables - this.configService.get('motions_statutes_enabled').subscribe( - (enabled: boolean): void => { - this.statutesEnabled = enabled; - } - ); - this.configService.get('motions_min_supporters').subscribe( - (supporters: number): void => { - this.minSupporters = supporters; - } - ); - - this.configService.get('motions_preamble').subscribe( - (preamble: string): void => { - this.preamble = preamble; - } - ); - - this.configService.get('motions_amendments_enabled').subscribe( - (enabled: boolean): void => { - this.amendmentsEnabled = enabled; - } - ); + this.configService.get('motions_statutes_enabled').subscribe(enabled => (this.statutesEnabled = enabled)); + this.configService.get('motions_min_supporters').subscribe(supporters => (this.minSupporters = supporters)); + this.configService.get('motions_preamble').subscribe(preamble => (this.preamble = preamble)); + this.configService.get('motions_amendments_enabled').subscribe(enabled => (this.amendmentsEnabled = enabled)); } /** @@ -327,8 +311,8 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit { // creates a new motion this.newMotion = true; this.editMotion = true; - this.motion = new ViewMotion(); - this.motionCopy = new ViewMotion(); + this.motion = new ViewCreateMotion(); + this.motionCopy = new ViewCreateMotion(); } else { // load existing motion this.route.params.subscribe(params => { @@ -393,7 +377,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit { state_id: [''], recommendation_id: [''], submitters_id: [], - supporters_id: [], + supporters_id: [[]], workflow_id: [], origin: [''] }); @@ -419,45 +403,65 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit { } /** - * Save a motion. Calls the "patchValues" function in the MotionObject - * - * http:post the motion to the server. - * The AutoUpdate-Service should see a change once it arrives and show it - * in the list view automatically + * Before updating or creating, the motions needs to be prepared for paragraph based amendments. + * A motion of type T is created, prepared and deserialized from the given motionValues * + * @param motionValues valus for the new motion + * @param ctor The motion constructor, so different motion types can be created. */ - public async saveMotion(): Promise { - const newMotionValues = { ...this.metaInfoForm.value, ...this.contentForm.value }; - - const fromForm = new Motion(); + private prepareMotionForSave(motionValues: any, ctor: new (...args: any[]) => T): T { + const motion = new ctor(); if (this.motion.isParagraphBasedAmendment()) { - fromForm.amendment_paragraphs = this.motion.amendment_paragraphs.map( - (para: string): string => { - if (para === null) { + motion.amendment_paragraphs = this.motion.amendment_paragraphs.map( + (paragraph: string): string => { + if (paragraph === null) { return null; } else { - return newMotionValues.text; + return motionValues.text; } } ); - newMotionValues.text = ''; + motionValues.text = ''; } - fromForm.deserialize(newMotionValues); + motion.deserialize(motionValues); + return motion; + } + + /** + * Creates a motion. Calls the "patchValues" function in the MotionObject + */ + public async createMotion(): Promise { + const newMotionValues = { ...this.metaInfoForm.value, ...this.contentForm.value }; + const motion = this.prepareMotionForSave(newMotionValues, CreateMotion); try { - if (this.newMotion) { - const response = await this.repo.create(fromForm); - this.router.navigate(['./motions/' + response.id]); - } else { - await this.repo.update(fromForm, this.motionCopy); - // if the motion was successfully updated, change the edit mode. - this.editMotion = false; - } + const response = await this.repo.create(motion); + this.router.navigate(['./motions/' + response.id]); } catch (e) { this.raiseError(e); } } + /** + * Save a motion. Calls the "patchValues" function in the MotionObject + */ + public async updateMotion(): Promise { + const newMotionValues = { ...this.metaInfoForm.value, ...this.contentForm.value }; + const motion = this.prepareMotionForSave(newMotionValues, Motion); + this.repo.update(motion, this.motionCopy).then(() => (this.editMotion = false), this.raiseError); + } + + /** + * In the ui are no distinct buttons for update or create. This is decided here. + */ + public saveMotion(): void { + if (this.newMotion) { + this.createMotion(); + } else { + this.updateMotion(); + } + } + /** * get the formated motion text from the repository. */ diff --git a/client/src/app/site/motions/components/motion-list/motion-list.component.html b/client/src/app/site/motions/components/motion-list/motion-list.component.html index a009f5260..13695f52d 100644 --- a/client/src/app/site/motions/components/motion-list/motion-list.component.html +++ b/client/src/app/site/motions/components/motion-list/motion-list.component.html @@ -42,7 +42,10 @@
{{ motion.title }}
- by {{ motion.submitters }}
+ + by {{ motion.submitters }} + +
+ - - - - - -