Merge pull request #5163 from tsiegleauq/no-order-in-comments

Fix order of comments in motion detail
This commit is contained in:
Emanuel Schütze 2019-12-13 09:22:47 +01:00 committed by GitHub
commit cc4d867e06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
import { Component, Input } from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Title } from '@angular/platform-browser';
@ -21,7 +21,7 @@ import { MotionPdfExportService } from 'app/site/motions/services/motion-pdf-exp
templateUrl: './motion-comments.component.html',
styleUrls: ['./motion-comments.component.scss']
})
export class MotionCommentsComponent extends BaseViewComponent {
export class MotionCommentsComponent extends BaseViewComponent implements OnInit {
/**
* An array of all sections the operator can see.
*/
@ -79,20 +79,28 @@ export class MotionCommentsComponent extends BaseViewComponent {
matSnackBar: MatSnackBar
) {
super(titleService, translate, matSnackBar);
}
this.commentRepo.getViewModelListObservable().subscribe(sections => this.setSections(sections));
this.operator.getUserObservable().subscribe(() => this.setSections(this.commentRepo.getViewModelList()));
public ngOnInit(): void {
this.subscriptions.push(
this.commentRepo.getViewModelListObservable().subscribe(sections => {
if (sections && sections.length) {
this.sections = sections;
this.filterSections();
}
})
);
}
/**
* sets the `sections` member with sections, if the operator has reading permissions.
*
* @param allSections A list of all sections available
*/
private setSections(allSections: ViewMotionCommentSection[]): void {
this.sections = allSections.filter(section => this.operator.isInGroupIds(...section.read_groups_id));
private filterSections(): void {
if (this.sections && this.sections.length) {
this.sections = this.sections.filter(section => this.operator.isInGroupIds(...section.read_groups_id));
this.updateComments();
}
}
/**
* Returns true if the operator has write permissions for the given section, so he can edit the comment.