From 4a24da12dad3ddb86fff531c98c3b11b4f24a695 Mon Sep 17 00:00:00 2001 From: GabrielMeyer Date: Fri, 3 Apr 2020 16:10:56 +0200 Subject: [PATCH] Changes workflow for sorting speakers --- .../list-of-speakers-repository.service.ts | 2 +- .../list-of-speakers.component.html | 14 ++-- .../list-of-speakers.component.ts | 68 ++++++++++++++++--- 3 files changed, 68 insertions(+), 16 deletions(-) diff --git a/client/src/app/core/repositories/agenda/list-of-speakers-repository.service.ts b/client/src/app/core/repositories/agenda/list-of-speakers-repository.service.ts index 942ee9ae7..3f4e6e456 100644 --- a/client/src/app/core/repositories/agenda/list-of-speakers-repository.service.ts +++ b/client/src/app/core/repositories/agenda/list-of-speakers-repository.service.ts @@ -169,8 +169,8 @@ export class ListOfSpeakersRepositoryService extends BaseHasContentObjectReposit /** * Posts an (manually) sorted speaker list to the server * + * @param listOfSpeakers the target list of speakers, which speaker-list is changed. * @param speakerIds array of speaker id numbers - * @param Item the target agenda item */ public async sortSpeakers(listOfSpeakers: ViewListOfSpeakers, speakerIds: number[]): Promise { const restUrl = this.getRestUrl(listOfSpeakers.id, 'sort_speakers'); diff --git a/client/src/app/site/agenda/components/list-of-speakers/list-of-speakers.component.html b/client/src/app/site/agenda/components/list-of-speakers/list-of-speakers.component.html index 648fc234a..d2e856559 100644 --- a/client/src/app/site/agenda/components/list-of-speakers/list-of-speakers.component.html +++ b/client/src/app/site/agenda/components/list-of-speakers/list-of-speakers.component.html @@ -1,9 +1,9 @@
@@ -91,7 +91,13 @@
- + @@ -172,7 +178,7 @@ - diff --git a/client/src/app/site/agenda/components/list-of-speakers/list-of-speakers.component.ts b/client/src/app/site/agenda/components/list-of-speakers/list-of-speakers.component.ts index a00961eb2..37987a3b1 100644 --- a/client/src/app/site/agenda/components/list-of-speakers/list-of-speakers.component.ts +++ b/client/src/app/site/agenda/components/list-of-speakers/list-of-speakers.component.ts @@ -15,6 +15,8 @@ import { UserRepositoryService } from 'app/core/repositories/users/user-reposito import { ConfigService } from 'app/core/ui-services/config.service'; import { DurationService } from 'app/core/ui-services/duration.service'; import { PromptService } from 'app/core/ui-services/prompt.service'; +import { ViewportService } from 'app/core/ui-services/viewport.service'; +import { Selectable } from 'app/shared/components/selectable'; import { SortingListComponent } from 'app/shared/components/sorting-list/sorting-list.component'; import { BaseViewComponent } from 'app/site/base/base-view'; import { ProjectorElementBuildDeskriptor } from 'app/site/base/projectable'; @@ -92,6 +94,11 @@ export class ListOfSpeakersComponent extends BaseViewComponent implements OnInit */ public addSpeakerForm: FormGroup; + /** + * Check, if list-view is seen on mobile-device. + */ + public isMobile = false; + /** * @returns true if the list of speakers list is currently closed */ @@ -122,6 +129,11 @@ export class ListOfSpeakersComponent extends BaseViewComponent implements OnInit private closSubscription: Subscription | null; + /** + * List of speakers to save temporarily changes made by sorting-list. + */ + private speakerListAsSelectable: Selectable[] = []; + /** * Constructor for speaker list component. Generates the forms. * @@ -151,7 +163,8 @@ export class ListOfSpeakersComponent extends BaseViewComponent implements OnInit private userRepository: UserRepositoryService, private collectionStringMapper: CollectionStringMapperService, private currentListOfSpeakersSlideService: CurrentListOfSpeakersSlideService, - private config: ConfigService + private config: ConfigService, + private viewport: ViewportService ) { super(title, translate, snackBar); this.addSpeakerForm = new FormGroup({ user_id: new FormControl() }); @@ -202,6 +215,8 @@ export class ListOfSpeakersComponent extends BaseViewComponent implements OnInit }) ); + this.subscriptions.push(this.viewport.isMobileSubject.subscribe(isMobile => this.checkSortMode(isMobile))); + this.subscriptions.push( this.config.get('agenda_present_speakers_only').subscribe(() => { this.filterUsers(); @@ -307,17 +322,22 @@ export class ListOfSpeakersComponent extends BaseViewComponent implements OnInit } /** - * send the current order of the sorting list to the server + * Saves sorting on mobile devices. */ - public onSaveSorting(): void { - if (this.isSortMode) { - this.isSortMode = false; - this.listOfSpeakersRepo - .sortSpeakers( - this.viewListOfSpeakers, - this.listElement.sortedItems.map(el => el.id) - ) - .catch(this.raiseError); + public onMobileSaveSorting(): void { + this.onSaveSorting(this.speakerListAsSelectable); + this.isSortMode = false; + } + + /** + * Receives an updated list from sorting-event. + * + * @param sortedSpeakerList The updated list. + */ + public onSortingChanged(sortedSpeakerList: Selectable[]): void { + this.speakerListAsSelectable = sortedSpeakerList; + if (!this.isMobile) { + this.onSaveSorting(sortedSpeakerList); } } @@ -493,4 +513,30 @@ export class ListOfSpeakersComponent extends BaseViewComponent implements OnInit this.filteredUsers.next(users.filter(u => !this.speakers.some(speaker => speaker.user_id === u.id))); } } + + /** + * send the current order of the sorting list to the server + * + * @param sortedSpeakerList The list to save. + */ + private onSaveSorting(sortedSpeakerList: Selectable[]): void { + if (this.isSortMode) { + this.listOfSpeakersRepo + .sortSpeakers( + this.viewListOfSpeakers, + sortedSpeakerList.map(el => el.id) + ) + .catch(this.raiseError); + } + } + + /** + * Check, that the sorting mode is immediately active, if not in mobile-view. + * + * @param isMobile If currently a mobile device is used. + */ + private checkSortMode(isMobile: boolean): void { + this.isMobile = isMobile; + this.isSortMode = !isMobile; + } }