Fix order of comments in motion detail

Fixes an error where the order of comment section in
the motion comment section component was wrong
This commit is contained in:
Sean Engelhardt 2019-12-12 12:10:56 +01:00
parent bb41125bd1
commit f64a855b50

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 { FormBuilder, FormGroup } from '@angular/forms';
import { MatSnackBar } from '@angular/material/snack-bar'; import { MatSnackBar } from '@angular/material/snack-bar';
import { Title } from '@angular/platform-browser'; 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', templateUrl: './motion-comments.component.html',
styleUrls: ['./motion-comments.component.scss'] 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. * An array of all sections the operator can see.
*/ */
@ -79,19 +79,27 @@ export class MotionCommentsComponent extends BaseViewComponent {
matSnackBar: MatSnackBar matSnackBar: MatSnackBar
) { ) {
super(titleService, translate, matSnackBar); super(titleService, translate, matSnackBar);
}
this.commentRepo.getViewModelListObservable().subscribe(sections => this.setSections(sections)); public ngOnInit(): void {
this.operator.getUserObservable().subscribe(() => this.setSections(this.commentRepo.getViewModelList())); 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. * 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 { private filterSections(): void {
this.sections = allSections.filter(section => this.operator.isInGroupIds(...section.read_groups_id)); if (this.sections && this.sections.length) {
this.updateComments(); this.sections = this.sections.filter(section => this.operator.isInGroupIds(...section.read_groups_id));
this.updateComments();
}
} }
/** /**