Fix selector with in submitter component

Fixes the too small search value selector in the submitter component

fixed the ad-hoc creation
This commit is contained in:
Sean 2020-08-21 16:33:33 +02:00
parent 216e4f00a3
commit 5070069910
3 changed files with 36 additions and 16 deletions

View File

@ -484,14 +484,14 @@ export class MotionRepositoryService extends BaseIsAgendaItemAndListOfSpeakersCo
* Sets the submitters by sending a request to the server, * Sets the submitters by sending a request to the server,
* *
* @param viewMotion The motion to change the submitters from * @param viewMotion The motion to change the submitters from
* @param submitters The submitters to set * @param submitterUserIds The submitters to set
*/ */
public async setSubmitters(viewMotion: ViewMotion, submitters: ViewUser[]): Promise<void> { public async setSubmitters(viewMotion: ViewMotion, submitterUserIds: number[]): Promise<void> {
const requestData = { const requestData = {
motions: [ motions: [
{ {
id: viewMotion.id, id: viewMotion.id,
submitters: submitters.map(s => s.id) submitters: submitterUserIds
} }
] ]
}; };

View File

@ -33,14 +33,20 @@
</ng-template> </ng-template>
</os-sorting-list> </os-sorting-list>
<form *ngIf="users && users.value.length > 0" [formGroup]="addSubmitterForm"> <form class="search-users" *ngIf="users && users.value.length > 0" [formGroup]="addSubmitterForm">
<mat-form-field> <mat-form-field>
<os-search-value-selector <os-search-value-selector
class="search-users"
formControlName="userId" formControlName="userId"
placeholder="{{ 'Select or search new submitter ...' | translate }}" placeholder="{{ 'Select or search new submitter ...' | translate }}"
[inputListValues]="users" [inputListValues]="users"
></os-search-value-selector> [showNotFoundButton]="true"
(clickNotFound)="createNewSubmitter($event)"
>
<ng-container notFoundDescription>
<mat-icon>add</mat-icon>
{{ 'Create user' | translate }}
</ng-container>
</os-search-value-selector>
</mat-form-field> </mat-form-field>
</form> </form>

View File

@ -9,7 +9,7 @@ import { BehaviorSubject, Observable } from 'rxjs';
import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service';
import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service'; import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service';
import { UserRepositoryService } from 'app/core/repositories/users/user-repository.service'; import { UserRepositoryService } from 'app/core/repositories/users/user-repository.service';
import { User } from 'app/shared/models/users/user'; import { Selectable } from 'app/shared/components/selectable';
import { BaseViewComponent } from 'app/site/base/base-view'; import { BaseViewComponent } from 'app/site/base/base-view';
import { ViewMotion } from 'app/site/motions/models/view-motion'; import { ViewMotion } from 'app/site/motions/models/view-motion';
import { LocalPermissionsService } from 'app/site/motions/services/local-permissions.service'; import { LocalPermissionsService } from 'app/site/motions/services/local-permissions.service';
@ -43,13 +43,13 @@ export class ManageSubmittersComponent extends BaseViewComponent {
/** /**
* The current list of submitters. * The current list of submitters.
*/ */
public readonly editSubmitterSubject: BehaviorSubject<ViewUser[]> = new BehaviorSubject([]); public readonly editSubmitterSubject: BehaviorSubject<Selectable[]> = new BehaviorSubject([]);
/** /**
* The observable from editSubmitterSubject. Fixing this value is a performance boost, because * The observable from editSubmitterSubject. Fixing this value is a performance boost, because
* it is just set one time at loading instead of calling .asObservable() every time. * it is just set one time at loading instead of calling .asObservable() every time.
*/ */
public editSubmitterObservable: Observable<ViewUser[]>; public editSubmitterObservable: Observable<Selectable[]>;
/** /**
* Saves, if the users edits the note. * Saves, if the users edits the note.
@ -83,7 +83,8 @@ export class ManageSubmittersComponent extends BaseViewComponent {
// detect changes in the form // detect changes in the form
this.addSubmitterForm.valueChanges.subscribe(formResult => { this.addSubmitterForm.valueChanges.subscribe(formResult => {
if (formResult && formResult.userId) { if (formResult && formResult.userId) {
this.addNewSubmitter(formResult.userId); const submitter = this.viewModelStore.get(ViewUser, formResult.userId);
this.addNewSubmitter(submitter);
} }
}); });
} }
@ -105,7 +106,10 @@ export class ManageSubmittersComponent extends BaseViewComponent {
*/ */
public onSave(): void { public onSave(): void {
this.motionRepository this.motionRepository
.setSubmitters(this.motion, this.editSubmitterSubject.getValue()) .setSubmitters(
this.motion,
this.editSubmitterSubject.getValue().map(user => user.id)
)
.then(() => (this.isEditMode = false), this.raiseError); .then(() => (this.isEditMode = false), this.raiseError);
} }
@ -116,15 +120,25 @@ export class ManageSubmittersComponent extends BaseViewComponent {
this.isEditMode = false; this.isEditMode = false;
} }
public async createNewSubmitter(username: string): Promise<void> {
const newUserObj = await this.userRepository.createFromString(username);
const selectableUser: Selectable = {
id: newUserObj.id,
getTitle: () => newUserObj.name,
getListTitle: () => newUserObj.name
};
this.addNewSubmitter(selectableUser);
}
/** /**
* Adds the user to the submitters, if he isn't already in there. * Adds the user to the submitters, if he isn't already in there.
* *
* @param userId The user to add * @param userId The user to add
*/ */
public addNewSubmitter(userId: number): void { public addNewSubmitter(user: Selectable): void {
const submitters = this.editSubmitterSubject.getValue(); const submitters = this.editSubmitterSubject.getValue();
if (!submitters.map(u => u.id).includes(userId)) { if (!submitters.map(u => u.id).includes(user.id)) {
submitters.push(this.viewModelStore.get(ViewUser, userId)); submitters.push(user);
this.editSubmitterSubject.next(submitters); this.editSubmitterSubject.next(submitters);
} }
this.addSubmitterForm.reset(); this.addSubmitterForm.reset();
@ -135,7 +149,7 @@ export class ManageSubmittersComponent extends BaseViewComponent {
* *
* @param users The new, sorted users. * @param users The new, sorted users.
*/ */
public onSortingChange(users: ViewUser[]): void { public onSortingChange(users: Selectable[]): void {
this.editSubmitterSubject.next(users); this.editSubmitterSubject.next(users);
} }
@ -144,7 +158,7 @@ export class ManageSubmittersComponent extends BaseViewComponent {
* *
* @param user The user to remove as a submitters * @param user The user to remove as a submitters
*/ */
public onRemove(user: User): void { public onRemove(user: Selectable): void {
const submitters = this.editSubmitterSubject.getValue(); const submitters = this.editSubmitterSubject.getValue();
this.editSubmitterSubject.next(submitters.filter(u => u.id !== user.id)); this.editSubmitterSubject.next(submitters.filter(u => u.id !== user.id));
} }