From a56d850f511311b257004acdc50b6af8a25c2234 Mon Sep 17 00:00:00 2001 From: GabrielMeyer Date: Thu, 19 Sep 2019 11:58:06 +0200 Subject: [PATCH] Separates the menu for multi-select of motions - Adds a new component for the list. - Adds the component to amendment-list and motion-list. --- .../amendment-list.component.html | 6 + .../amendment-list.component.spec.ts | 3 +- .../amendment-list.component.ts | 15 ++- .../motion-list/motion-list.component.html | 120 +++--------------- .../motion-list/motion-list.component.spec.ts | 3 +- .../motion-list/motion-list.component.ts | 8 +- .../motion-multiselect-actions.component.html | 85 +++++++++++++ .../motion-multiselect-actions.component.scss | 0 ...tion-multiselect-actions.component.spec.ts | 27 ++++ .../motion-multiselect-actions.component.ts | 111 ++++++++++++++++ .../shared-motion/shared-motion.module.ts | 4 +- 11 files changed, 271 insertions(+), 111 deletions(-) create mode 100644 client/src/app/site/motions/modules/shared-motion/motion-multiselect-actions/motion-multiselect-actions.component.html create mode 100644 client/src/app/site/motions/modules/shared-motion/motion-multiselect-actions/motion-multiselect-actions.component.scss create mode 100644 client/src/app/site/motions/modules/shared-motion/motion-multiselect-actions/motion-multiselect-actions.component.spec.ts create mode 100644 client/src/app/site/motions/modules/shared-motion/motion-multiselect-actions/motion-multiselect-actions.component.ts diff --git a/client/src/app/site/motions/modules/amendment-list/amendment-list.component.html b/client/src/app/site/motions/modules/amendment-list/amendment-list.component.html index c1181c414..bab4014c1 100644 --- a/client/src/app/site/motions/modules/amendment-list/amendment-list.component.html +++ b/client/src/app/site/motions/modules/amendment-list/amendment-list.component.html @@ -136,5 +136,11 @@ clear Deselect all + + + + + + diff --git a/client/src/app/site/motions/modules/amendment-list/amendment-list.component.spec.ts b/client/src/app/site/motions/modules/amendment-list/amendment-list.component.spec.ts index 3dc4601d6..dbded7b39 100644 --- a/client/src/app/site/motions/modules/amendment-list/amendment-list.component.spec.ts +++ b/client/src/app/site/motions/modules/amendment-list/amendment-list.component.spec.ts @@ -3,6 +3,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { E2EImportsModule } from 'e2e-imports.module'; import { AmendmentListComponent } from './amendment-list.component'; +import { MotionMultiselectActionsComponent } from '../shared-motion/motion-multiselect-actions/motion-multiselect-actions.component'; describe('AmendmentListComponent', () => { let component: AmendmentListComponent; @@ -11,7 +12,7 @@ describe('AmendmentListComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ imports: [E2EImportsModule], - declarations: [AmendmentListComponent] + declarations: [AmendmentListComponent, MotionMultiselectActionsComponent] }).compileComponents(); })); diff --git a/client/src/app/site/motions/modules/amendment-list/amendment-list.component.ts b/client/src/app/site/motions/modules/amendment-list/amendment-list.component.ts index 2f1eb10e4..16b390510 100644 --- a/client/src/app/site/motions/modules/amendment-list/amendment-list.component.ts +++ b/client/src/app/site/motions/modules/amendment-list/amendment-list.component.ts @@ -13,11 +13,13 @@ import { AmendmentSortListService } from '../../services/amendment-sort-list.ser import { StorageService } from 'app/core/core-services/storage.service'; import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service'; import { LinenumberingService } from 'app/core/ui-services/linenumbering.service'; +import { OverlayService } from 'app/core/ui-services/overlay.service'; import { ItemVisibilityChoices } from 'app/shared/models/agenda/item'; import { largeDialogSettings } from 'app/shared/utils/dialog-settings'; import { BaseListViewComponent } from 'app/site/base/base-list-view'; import { MotionExportDialogComponent } from '../shared-motion/motion-export-dialog/motion-export-dialog.component'; import { MotionExportInfo, MotionExportService } from '../../services/motion-export.service'; +import { MotionMultiselectService } from '../../services/motion-multiselect.service'; import { MotionPdfExportService } from '../../services/motion-pdf-export.service'; import { MotionSortListService } from '../../services/motion-sort-list.service'; import { ViewMotion } from '../../models/view-motion'; @@ -92,12 +94,14 @@ export class AmendmentListComponent extends BaseListViewComponent im private route: ActivatedRoute, public motionRepo: MotionRepositoryService, public motionSortService: MotionSortListService, + public motionMultiSelectService: MotionMultiselectService, public amendmentSortService: AmendmentSortListService, public amendmentFilterService: AmendmentFilterListService, private dialog: MatDialog, private motionExport: MotionExportService, private linenumberingService: LinenumberingService, - private pdfExport: MotionPdfExportService + private pdfExport: MotionPdfExportService, + private overlayService: OverlayService ) { super(titleService, translate, matSnackBar, storage); super.setTitle('Amendments'); @@ -155,6 +159,15 @@ export class AmendmentListComponent extends BaseListViewComponent im ); } + /** + * Function to await the promises. Afterwards it will hide the spinner. + * + * @param action The promise to await. + */ + public async multiselectWrapper(action: Promise): Promise { + action.then(() => this.overlayService.hideSpinner(), this.raiseError); + } + /** * Export the given motion ist as special PDF */ diff --git a/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.html b/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.html index 8d2d50520..e37f37690 100644 --- a/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.html +++ b/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.html @@ -325,107 +325,27 @@ clear Deselect all -
+ - - - - - - - - - - -
-
- - - -
+ + + + + diff --git a/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.spec.ts b/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.spec.ts index 7c1583633..1160586ee 100644 --- a/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.spec.ts +++ b/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.spec.ts @@ -3,6 +3,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { E2EImportsModule } from 'e2e-imports.module'; import { MotionListComponent } from './motion-list.component'; +import { MotionMultiselectActionsComponent } from '../../../shared-motion/motion-multiselect-actions/motion-multiselect-actions.component'; describe('MotionListComponent', () => { let component: MotionListComponent; @@ -11,7 +12,7 @@ describe('MotionListComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ imports: [E2EImportsModule], - declarations: [MotionListComponent] + declarations: [MotionListComponent, MotionMultiselectActionsComponent] }).compileComponents(); })); diff --git a/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.ts b/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.ts index f4c8cd2a8..c6817484a 100644 --- a/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.ts +++ b/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.ts @@ -362,13 +362,7 @@ export class MotionListComponent extends BaseListViewComponent imple * @param multiselectPromise The promise returned by multiselect actions. */ public async multiselectWrapper(multiselectPromise: Promise): Promise { - try { - await multiselectPromise; - } catch (e) { - this.raiseError(e); - } finally { - this.overlayService.hideSpinner(); - } + multiselectPromise.then(() => this.overlayService.hideSpinner(), this.raiseError); } /** diff --git a/client/src/app/site/motions/modules/shared-motion/motion-multiselect-actions/motion-multiselect-actions.component.html b/client/src/app/site/motions/modules/shared-motion/motion-multiselect-actions/motion-multiselect-actions.component.html new file mode 100644 index 000000000..71ffa4e65 --- /dev/null +++ b/client/src/app/site/motions/modules/shared-motion/motion-multiselect-actions/motion-multiselect-actions.component.html @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + diff --git a/client/src/app/site/motions/modules/shared-motion/motion-multiselect-actions/motion-multiselect-actions.component.scss b/client/src/app/site/motions/modules/shared-motion/motion-multiselect-actions/motion-multiselect-actions.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/client/src/app/site/motions/modules/shared-motion/motion-multiselect-actions/motion-multiselect-actions.component.spec.ts b/client/src/app/site/motions/modules/shared-motion/motion-multiselect-actions/motion-multiselect-actions.component.spec.ts new file mode 100644 index 000000000..572a7c19a --- /dev/null +++ b/client/src/app/site/motions/modules/shared-motion/motion-multiselect-actions/motion-multiselect-actions.component.spec.ts @@ -0,0 +1,27 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { E2EImportsModule } from 'e2e-imports.module'; + +import { MotionMultiselectActionsComponent } from './motion-multiselect-actions.component'; + +describe('MotionMultiselectActionsComponent', () => { + let component: MotionMultiselectActionsComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [E2EImportsModule], + declarations: [MotionMultiselectActionsComponent] + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(MotionMultiselectActionsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/client/src/app/site/motions/modules/shared-motion/motion-multiselect-actions/motion-multiselect-actions.component.ts b/client/src/app/site/motions/modules/shared-motion/motion-multiselect-actions/motion-multiselect-actions.component.ts new file mode 100644 index 000000000..aed5c29d7 --- /dev/null +++ b/client/src/app/site/motions/modules/shared-motion/motion-multiselect-actions/motion-multiselect-actions.component.ts @@ -0,0 +1,111 @@ +import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; +import { MatDialog, MatSnackBar } from '@angular/material'; +import { Title } from '@angular/platform-browser'; + +import { TranslateService } from '@ngx-translate/core'; + +import { CategoryRepositoryService } from 'app/core/repositories/motions/category-repository.service'; +import { MotionBlockRepositoryService } from 'app/core/repositories/motions/motion-block-repository.service'; +import { TagRepositoryService } from 'app/core/repositories/tags/tag-repository.service'; +import { ConfigService } from 'app/core/ui-services/config.service'; +import { largeDialogSettings } from 'app/shared/utils/dialog-settings'; +import { BaseViewComponent } from 'app/site/base/base-view'; +import { ViewCategory } from 'app/site/motions/models/view-category'; +import { ViewMotion } from 'app/site/motions/models/view-motion'; +import { ViewMotionBlock } from 'app/site/motions/models/view-motion-block'; +import { MotionExportInfo, MotionExportService } from 'app/site/motions/services/motion-export.service'; +import { MotionMultiselectService } from 'app/site/motions/services/motion-multiselect.service'; +import { ViewTag } from 'app/site/tags/models/view-tag'; +import { MotionExportDialogComponent } from '../motion-export-dialog/motion-export-dialog.component'; + +@Component({ + selector: 'os-motion-multiselect-actions', + templateUrl: './motion-multiselect-actions.component.html', + styleUrls: ['./motion-multiselect-actions.component.scss'] +}) +export class MotionMultiselectActionsComponent extends BaseViewComponent implements OnInit { + /** + * The list of the selected motions. + */ + @Input() + public selectedMotions: ViewMotion[] = []; + + /** + * An EventEmitter to send the selected actions. + */ + @Output() + public action = new EventEmitter>(); + + /** + * Boolean, if the recommendation is enabled. + */ + public recommendationEnabled = false; + + /** + * The list of all categories. + */ + public categories: ViewCategory[] = []; + + /** + * The list of all tags. + */ + public tags: ViewTag[] = []; + + /** + * The list of all motion-blocks. + */ + public motionBlocks: ViewMotionBlock[] = []; + + /** + * The default constructor. + * + * @param multiselectService + * @param categoryRepo + * @param motionBlockRepo + * @param tagRepo + * @param configService + */ + public constructor( + title: Title, + protected translate: TranslateService, + matSnackbar: MatSnackBar, + public multiselectService: MotionMultiselectService, + private categoryRepo: CategoryRepositoryService, + private motionBlockRepo: MotionBlockRepositoryService, + private tagRepo: TagRepositoryService, + private configService: ConfigService, + private dialog: MatDialog, + private motionExport: MotionExportService + ) { + super(title, translate, matSnackbar); + } + + /** + * OnInit-method. + * + * Subscribe to all view-model-lists. + */ + public ngOnInit(): void { + this.subscriptions.push( + this.categoryRepo.getViewModelListObservable().subscribe(categories => (this.categories = categories)), + this.motionBlockRepo.getViewModelListObservable().subscribe(blocks => (this.motionBlocks = blocks)), + this.tagRepo.getViewModelListObservable().subscribe(tags => (this.tags = tags)), + this.configService.get('motions_recommendations_by').subscribe(recommender => { + this.recommendationEnabled = !!recommender; + }) + ); + } + + /** + * Opens the dialog to choose options for exporting selected motions. + */ + public openExportDialog(): void { + const exportDialogRef = this.dialog.open(MotionExportDialogComponent, largeDialogSettings); + + exportDialogRef + .afterClosed() + .subscribe((exportInfo: MotionExportInfo) => + this.motionExport.evaluateExportRequest(exportInfo, this.selectedMotions) + ); + } +} diff --git a/client/src/app/site/motions/modules/shared-motion/shared-motion.module.ts b/client/src/app/site/motions/modules/shared-motion/shared-motion.module.ts index c16921d70..b13ba9021 100644 --- a/client/src/app/site/motions/modules/shared-motion/shared-motion.module.ts +++ b/client/src/app/site/motions/modules/shared-motion/shared-motion.module.ts @@ -3,10 +3,12 @@ import { NgModule } from '@angular/core'; import { SharedModule } from 'app/shared/shared.module'; import { MotionExportDialogComponent } from './motion-export-dialog/motion-export-dialog.component'; +import { MotionMultiselectActionsComponent } from './motion-multiselect-actions/motion-multiselect-actions.component'; @NgModule({ imports: [CommonModule, SharedModule], - declarations: [MotionExportDialogComponent], + exports: [MotionMultiselectActionsComponent], + declarations: [MotionExportDialogComponent, MotionMultiselectActionsComponent], entryComponents: [MotionExportDialogComponent] }) export class SharedMotionModule {}