2018-08-16 17:03:39 +02:00
|
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
2018-08-22 11:26:53 +02:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
2018-09-09 18:52:47 +02:00
|
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
2018-11-02 11:41:03 +01:00
|
|
|
import { MatDialog, MatExpansionPanel, MatSnackBar, MatSelectChange } from '@angular/material';
|
2018-09-03 14:23:54 +02:00
|
|
|
|
2018-09-04 14:55:07 +02:00
|
|
|
import { Category } from '../../../../shared/models/motions/category';
|
|
|
|
import { ViewportService } from '../../../../core/services/viewport.service';
|
|
|
|
import { MotionRepositoryService } from '../../services/motion-repository.service';
|
2018-09-30 18:43:20 +02:00
|
|
|
import { ChangeRecoMode, LineNumberingMode, ViewMotion } from '../../models/view-motion';
|
2018-09-13 07:57:38 +02:00
|
|
|
import { User } from '../../../../shared/models/users/user';
|
2018-09-13 14:40:04 +02:00
|
|
|
import { DataStoreService } from '../../../../core/services/data-store.service';
|
2018-09-19 15:18:57 +02:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2018-09-20 12:25:37 +02:00
|
|
|
import { Motion } from '../../../../shared/models/motions/motion';
|
|
|
|
import { BehaviorSubject } from 'rxjs';
|
2018-09-30 18:43:20 +02:00
|
|
|
import { LineRange } from '../../services/diff.service';
|
|
|
|
import {
|
|
|
|
MotionChangeRecommendationComponent,
|
|
|
|
MotionChangeRecommendationComponentData
|
|
|
|
} from '../motion-change-recommendation/motion-change-recommendation.component';
|
|
|
|
import { ChangeRecommendationRepositoryService } from '../../services/change-recommendation-repository.service';
|
|
|
|
import { ViewChangeReco } from '../../models/view-change-reco';
|
2018-11-02 11:41:03 +01:00
|
|
|
import { DomSanitizer, SafeHtml, Title } from '@angular/platform-browser';
|
2018-09-30 18:43:20 +02:00
|
|
|
import { ViewUnifiedChange } from '../../models/view-unified-change';
|
2018-10-05 16:34:08 +02:00
|
|
|
import { OperatorService } from '../../../../core/services/operator.service';
|
2018-11-02 11:41:03 +01:00
|
|
|
import { BaseViewComponent } from '../../../base/base-view';
|
2018-08-09 16:03:24 +02:00
|
|
|
|
2018-08-22 11:26:53 +02:00
|
|
|
/**
|
|
|
|
* Component for the motion detail view
|
|
|
|
*/
|
2018-08-09 16:03:24 +02:00
|
|
|
@Component({
|
2018-09-03 17:57:20 +02:00
|
|
|
selector: 'os-motion-detail',
|
2018-08-09 16:03:24 +02:00
|
|
|
templateUrl: './motion-detail.component.html',
|
|
|
|
styleUrls: ['./motion-detail.component.scss']
|
|
|
|
})
|
2018-11-02 11:41:03 +01:00
|
|
|
export class MotionDetailComponent extends BaseViewComponent implements OnInit {
|
2018-08-22 11:26:53 +02:00
|
|
|
/**
|
|
|
|
* MatExpansionPanel for the meta info
|
2018-09-04 14:55:07 +02:00
|
|
|
* Only relevant in mobile view
|
2018-08-22 11:26:53 +02:00
|
|
|
*/
|
2018-09-13 07:57:38 +02:00
|
|
|
@ViewChild('metaInfoPanel')
|
|
|
|
public metaInfoPanel: MatExpansionPanel;
|
2018-08-22 11:26:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* MatExpansionPanel for the content panel
|
2018-09-04 14:55:07 +02:00
|
|
|
* Only relevant in mobile view
|
2018-08-22 11:26:53 +02:00
|
|
|
*/
|
2018-09-13 07:57:38 +02:00
|
|
|
@ViewChild('contentPanel')
|
|
|
|
public contentPanel: MatExpansionPanel;
|
2018-08-16 17:03:39 +02:00
|
|
|
|
2018-08-22 11:26:53 +02:00
|
|
|
/**
|
|
|
|
* Motions meta-info
|
|
|
|
*/
|
2018-08-29 13:21:25 +02:00
|
|
|
public metaInfoForm: FormGroup;
|
2018-08-22 11:26:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Motion content. Can be a new version
|
|
|
|
*/
|
2018-08-29 13:21:25 +02:00
|
|
|
public contentForm: FormGroup;
|
2018-08-22 11:26:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if the motion is edited
|
|
|
|
*/
|
2018-08-29 13:21:25 +02:00
|
|
|
public editMotion = false;
|
2018-08-22 11:26:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if the motion is new
|
|
|
|
*/
|
2018-08-29 13:21:25 +02:00
|
|
|
public newMotion = false;
|
2018-08-16 17:03:39 +02:00
|
|
|
|
2018-09-04 14:55:07 +02:00
|
|
|
/**
|
|
|
|
* Target motion. Might be new or old
|
|
|
|
*/
|
|
|
|
public motion: ViewMotion;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy of the motion that the user might edit
|
|
|
|
*/
|
|
|
|
public motionCopy: ViewMotion;
|
|
|
|
|
2018-09-30 18:43:20 +02:00
|
|
|
/**
|
|
|
|
* All change recommendations to this motion
|
|
|
|
*/
|
|
|
|
public changeRecommendations: ViewChangeReco[];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All change recommendations AND amendments, sorted by line number.
|
|
|
|
*/
|
|
|
|
public allChangingObjects: ViewUnifiedChange[];
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
/**
|
|
|
|
* Holds all motions. Required to navigate back and forth
|
|
|
|
*/
|
|
|
|
public allMotions: ViewMotion[];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* preload the next motion for direct navigation
|
|
|
|
*/
|
|
|
|
public nextMotion: ViewMotion;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* preload the previous motion for direct navigation
|
|
|
|
*/
|
|
|
|
public previousMotion: ViewMotion;
|
|
|
|
|
2018-09-19 15:18:57 +02:00
|
|
|
/**
|
|
|
|
* Subject for the Categories
|
|
|
|
*/
|
|
|
|
public categoryObserver: BehaviorSubject<Array<Category>>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subject for the Submitters
|
|
|
|
*/
|
|
|
|
public submitterObserver: BehaviorSubject<Array<User>>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subject for the Supporters
|
|
|
|
*/
|
|
|
|
public supporterObserver: BehaviorSubject<Array<User>>;
|
|
|
|
|
2018-09-30 18:43:20 +02:00
|
|
|
/**
|
|
|
|
* Value for os-motion-detail-diff: when this is set, that component scrolls to the given change
|
|
|
|
*/
|
|
|
|
public scrollToChange: ViewUnifiedChange = null;
|
|
|
|
|
2018-11-05 17:43:44 +01:00
|
|
|
/**
|
|
|
|
* Custom recommender as set in the settings
|
|
|
|
*/
|
|
|
|
public recommender: string;
|
|
|
|
|
2018-08-21 14:56:26 +02:00
|
|
|
/**
|
2018-08-22 11:26:53 +02:00
|
|
|
* Constuct the detail view.
|
|
|
|
*
|
2018-11-02 11:41:03 +01:00
|
|
|
* @param title
|
|
|
|
* @param translate
|
|
|
|
* @param matSnackBar
|
2018-09-03 14:23:54 +02:00
|
|
|
* @param vp the viewport service
|
2018-11-02 11:41:03 +01:00
|
|
|
* @param op
|
2018-09-03 14:23:54 +02:00
|
|
|
* @param router to navigate back to the motion list and to an existing motion
|
2018-08-21 14:56:26 +02:00
|
|
|
* @param route determine if this is a new or an existing motion
|
|
|
|
* @param formBuilder For reactive forms. Form Group and Form Control
|
2018-09-30 18:43:20 +02:00
|
|
|
* @param dialogService For opening dialogs
|
2018-11-02 11:41:03 +01:00
|
|
|
* @param repo Motion Repository
|
|
|
|
* @param changeRecoRepo Change Recommendation Repository
|
|
|
|
* @param DS The DataStoreService
|
|
|
|
* @param sanitizer For making HTML SafeHTML
|
2018-08-21 14:56:26 +02:00
|
|
|
*/
|
2018-08-29 13:21:25 +02:00
|
|
|
public constructor(
|
2018-11-02 11:41:03 +01:00
|
|
|
title: Title,
|
|
|
|
translate: TranslateService,
|
|
|
|
matSnackBar: MatSnackBar,
|
2018-09-03 14:23:54 +02:00
|
|
|
public vp: ViewportService,
|
2018-10-05 16:34:08 +02:00
|
|
|
private op: OperatorService,
|
2018-08-22 11:26:53 +02:00
|
|
|
private router: Router,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private formBuilder: FormBuilder,
|
2018-09-30 18:43:20 +02:00
|
|
|
private dialogService: MatDialog,
|
2018-09-13 14:40:04 +02:00
|
|
|
private repo: MotionRepositoryService,
|
2018-09-30 18:43:20 +02:00
|
|
|
private changeRecoRepo: ChangeRecommendationRepositoryService,
|
2018-09-19 15:18:57 +02:00
|
|
|
private DS: DataStoreService,
|
2018-11-02 11:41:03 +01:00
|
|
|
private sanitizer: DomSanitizer
|
2018-08-22 11:26:53 +02:00
|
|
|
) {
|
2018-11-02 11:41:03 +01:00
|
|
|
super(title, translate, matSnackBar);
|
2018-08-16 17:03:39 +02:00
|
|
|
this.createForm();
|
2018-10-05 16:34:08 +02:00
|
|
|
this.getMotionByUrl();
|
2018-08-21 14:56:26 +02:00
|
|
|
|
2018-09-19 15:18:57 +02:00
|
|
|
// Initial Filling of the Subjects
|
|
|
|
this.submitterObserver = new BehaviorSubject(DS.getAll(User));
|
|
|
|
this.supporterObserver = new BehaviorSubject(DS.getAll(User));
|
2018-09-20 12:25:37 +02:00
|
|
|
this.categoryObserver = new BehaviorSubject(DS.getAll(Category));
|
2018-09-19 15:18:57 +02:00
|
|
|
|
|
|
|
// Make sure the subjects are updated, when a new Model for the type arrives
|
|
|
|
this.DS.changeObservable.subscribe(newModel => {
|
|
|
|
if (newModel instanceof User) {
|
|
|
|
this.submitterObserver.next(DS.getAll(User));
|
|
|
|
this.supporterObserver.next(DS.getAll(User));
|
|
|
|
}
|
|
|
|
if (newModel instanceof Category) {
|
|
|
|
this.categoryObserver.next(DS.getAll(Category));
|
|
|
|
}
|
|
|
|
});
|
2018-08-09 16:03:24 +02:00
|
|
|
}
|
|
|
|
|
2018-09-30 18:43:20 +02:00
|
|
|
/**
|
|
|
|
* Merges amendments and change recommendations and sorts them by the line numbers.
|
|
|
|
* Called each time one of these arrays changes.
|
|
|
|
*/
|
|
|
|
private recalcUnifiedChanges(): void {
|
|
|
|
// @TODO implement amendments
|
|
|
|
this.allChangingObjects = this.changeRecommendations;
|
|
|
|
this.allChangingObjects.sort((a: ViewUnifiedChange, b: ViewUnifiedChange) => {
|
|
|
|
if (a.getLineFrom() < b.getLineFrom()) {
|
|
|
|
return -1;
|
|
|
|
} else if (a.getLineFrom() > b.getLineFrom()) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
/**
|
|
|
|
* determine the motion to display using the URL
|
|
|
|
*/
|
|
|
|
public getMotionByUrl(): void {
|
|
|
|
if (this.route.snapshot.url[0] && this.route.snapshot.url[0].path === 'new') {
|
|
|
|
// creates a new motion
|
|
|
|
this.newMotion = true;
|
|
|
|
this.editMotion = true;
|
|
|
|
this.motion = new ViewMotion();
|
|
|
|
this.motionCopy = new ViewMotion();
|
|
|
|
} else {
|
|
|
|
// load existing motion
|
|
|
|
this.route.params.subscribe(params => {
|
|
|
|
this.repo.getViewModelObservable(params.id).subscribe(newViewMotion => {
|
2018-11-05 17:43:44 +01:00
|
|
|
if (newViewMotion) {
|
|
|
|
this.motion = newViewMotion;
|
|
|
|
this.patchForm(this.motion);
|
|
|
|
}
|
2018-10-05 16:34:08 +02:00
|
|
|
});
|
|
|
|
this.changeRecoRepo
|
|
|
|
.getChangeRecosOfMotionObservable(parseInt(params.id, 10))
|
|
|
|
.subscribe((recos: ViewChangeReco[]) => {
|
|
|
|
this.changeRecommendations = recos;
|
|
|
|
this.recalcUnifiedChanges();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-21 14:56:26 +02:00
|
|
|
/**
|
|
|
|
* Async load the values of the motion in the Form.
|
|
|
|
*/
|
2018-09-04 14:55:07 +02:00
|
|
|
public patchForm(formMotion: ViewMotion): void {
|
2018-10-05 16:34:08 +02:00
|
|
|
const metaInfoPatch = {};
|
|
|
|
Object.keys(this.metaInfoForm.controls).forEach(ctrl => {
|
|
|
|
metaInfoPatch[ctrl] = formMotion[ctrl];
|
2018-08-20 18:13:28 +02:00
|
|
|
});
|
2018-10-05 16:34:08 +02:00
|
|
|
this.metaInfoForm.patchValue(metaInfoPatch);
|
|
|
|
|
|
|
|
const contentPatch = {};
|
|
|
|
Object.keys(this.contentForm.controls).forEach(ctrl => {
|
|
|
|
contentPatch[ctrl] = formMotion[ctrl];
|
2018-08-20 18:13:28 +02:00
|
|
|
});
|
2018-10-05 16:34:08 +02:00
|
|
|
this.contentForm.patchValue(contentPatch);
|
2018-08-16 17:03:39 +02:00
|
|
|
}
|
|
|
|
|
2018-08-21 14:56:26 +02:00
|
|
|
/**
|
|
|
|
* Creates the forms for the Motion and the MotionVersion
|
|
|
|
*
|
|
|
|
* TODO: Build a custom form validator
|
|
|
|
*/
|
2018-09-07 13:12:59 +02:00
|
|
|
public createForm(): void {
|
2018-08-16 17:03:39 +02:00
|
|
|
this.metaInfoForm = this.formBuilder.group({
|
2018-08-20 18:13:28 +02:00
|
|
|
identifier: [''],
|
|
|
|
category_id: [''],
|
|
|
|
state_id: [''],
|
|
|
|
recommendation_id: [''],
|
2018-09-28 15:10:48 +02:00
|
|
|
submitters_id: [],
|
|
|
|
supporters_id: [],
|
2018-08-20 18:13:28 +02:00
|
|
|
origin: ['']
|
|
|
|
});
|
|
|
|
this.contentForm = this.formBuilder.group({
|
2018-08-31 15:33:41 +02:00
|
|
|
title: ['', Validators.required],
|
|
|
|
text: ['', Validators.required],
|
|
|
|
reason: ['']
|
2018-08-16 17:03:39 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-21 14:56:26 +02:00
|
|
|
/**
|
|
|
|
* Save a motion. Calls the "patchValues" function in the MotionObject
|
|
|
|
*
|
|
|
|
* http:post the motion to the server.
|
|
|
|
* The AutoUpdate-Service should see a change once it arrives and show it
|
|
|
|
* in the list view automatically
|
2018-08-23 10:35:05 +02:00
|
|
|
*
|
2018-10-05 16:34:08 +02:00
|
|
|
* TODO: state is not yet saved. Need a special "put" command. Repo should handle this.
|
2018-08-21 14:56:26 +02:00
|
|
|
*/
|
2018-10-26 11:19:05 +02:00
|
|
|
public async saveMotion(): Promise<void> {
|
2018-08-20 18:13:28 +02:00
|
|
|
const newMotionValues = { ...this.metaInfoForm.value, ...this.contentForm.value };
|
2018-10-05 16:34:08 +02:00
|
|
|
|
2018-09-20 12:25:37 +02:00
|
|
|
const fromForm = new Motion();
|
|
|
|
fromForm.deserialize(newMotionValues);
|
|
|
|
|
2018-11-02 11:41:03 +01:00
|
|
|
try {
|
|
|
|
if (this.newMotion) {
|
|
|
|
const response = await this.repo.create(fromForm);
|
|
|
|
this.router.navigate(['./motions/' + response.id]);
|
|
|
|
} else {
|
|
|
|
await this.repo.update(fromForm, this.motionCopy);
|
|
|
|
// if the motion was successfully updated, change the edit mode.
|
|
|
|
this.editMotion = false;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
this.raiseError(e);
|
2018-09-04 14:55:07 +02:00
|
|
|
}
|
2018-08-16 17:03:39 +02:00
|
|
|
}
|
|
|
|
|
2018-09-28 15:10:48 +02:00
|
|
|
/**
|
|
|
|
* get the formated motion text from the repository.
|
|
|
|
*/
|
2018-09-30 18:43:20 +02:00
|
|
|
public getFormattedTextPlain(): string {
|
|
|
|
// Prevent this.allChangingObjects to be reordered from within formatMotion
|
|
|
|
const changes: ViewUnifiedChange[] = Object.assign([], this.allChangingObjects);
|
2018-09-09 18:52:47 +02:00
|
|
|
return this.repo.formatMotion(
|
|
|
|
this.motion.id,
|
|
|
|
this.motion.crMode,
|
2018-09-30 18:43:20 +02:00
|
|
|
changes,
|
2018-09-09 18:52:47 +02:00
|
|
|
this.motion.lineLength,
|
|
|
|
this.motion.highlightedLine
|
|
|
|
);
|
2018-09-28 15:10:48 +02:00
|
|
|
}
|
|
|
|
|
2018-09-30 18:43:20 +02:00
|
|
|
/**
|
|
|
|
* get the formated motion text from the repository, as SafeHTML for [innerHTML]
|
|
|
|
*/
|
|
|
|
public getFormattedText(): SafeHtml {
|
|
|
|
return this.sanitizer.bypassSecurityTrustHtml(this.getFormattedTextPlain());
|
|
|
|
}
|
|
|
|
|
2018-08-21 14:56:26 +02:00
|
|
|
/**
|
2018-08-22 16:03:49 +02:00
|
|
|
* Trigger to delete the motion
|
2018-09-04 14:55:07 +02:00
|
|
|
*
|
|
|
|
* TODO: Repo should handle
|
2018-08-21 14:56:26 +02:00
|
|
|
*/
|
2018-09-07 13:12:59 +02:00
|
|
|
public deleteMotionButton(): void {
|
2018-10-26 11:19:05 +02:00
|
|
|
this.repo.delete(this.motion).then(() => {
|
2018-08-22 16:03:49 +02:00
|
|
|
this.router.navigate(['./motions/']);
|
2018-11-02 11:41:03 +01:00
|
|
|
}, this.raiseError);
|
|
|
|
// TODO: this needs to be in the autoupdate code.
|
|
|
|
/*const motList = this.categoryRepo.getMotionsOfCategory(this.motion.category);
|
2018-10-15 11:52:57 +02:00
|
|
|
const index = motList.indexOf(this.motion.motion, 0);
|
|
|
|
if (index > -1) {
|
|
|
|
motList.splice(index, 1);
|
|
|
|
}
|
2018-11-02 11:41:03 +01:00
|
|
|
this.categoryRepo.updateCategoryNumbering(this.motion.category, motList);*/
|
2018-08-22 16:03:49 +02:00
|
|
|
}
|
2018-08-09 16:03:24 +02:00
|
|
|
|
2018-09-28 15:10:48 +02:00
|
|
|
/**
|
|
|
|
* Sets the motions line numbering mode
|
|
|
|
* @param mode Needs to fot to the enum defined in ViewMotion
|
|
|
|
*/
|
2018-09-30 18:43:20 +02:00
|
|
|
public setLineNumberingMode(mode: LineNumberingMode): void {
|
2018-09-28 15:10:48 +02:00
|
|
|
this.motion.lnMode = mode;
|
|
|
|
}
|
|
|
|
|
2018-09-09 18:52:47 +02:00
|
|
|
/**
|
|
|
|
* Returns true if no line numbers are to be shown.
|
|
|
|
*/
|
|
|
|
public isLineNumberingNone(): boolean {
|
2018-09-30 18:43:20 +02:00
|
|
|
return this.motion.lnMode === LineNumberingMode.None;
|
2018-09-09 18:52:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the line numbers are to be shown within the text with no line breaks.
|
|
|
|
*/
|
|
|
|
public isLineNumberingInline(): boolean {
|
2018-09-30 18:43:20 +02:00
|
|
|
return this.motion.lnMode === LineNumberingMode.Inside;
|
2018-09-09 18:52:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the line numbers are to be shown to the left of the text.
|
|
|
|
*/
|
|
|
|
public isLineNumberingOutside(): boolean {
|
2018-09-30 18:43:20 +02:00
|
|
|
return this.motion.lnMode === LineNumberingMode.Outside;
|
2018-09-09 18:52:47 +02:00
|
|
|
}
|
|
|
|
|
2018-09-28 15:10:48 +02:00
|
|
|
/**
|
|
|
|
* Sets the motions change reco mode
|
|
|
|
* @param mode Needs to fot to the enum defined in ViewMotion
|
|
|
|
*/
|
|
|
|
public setChangeRecoMode(mode: number): void {
|
|
|
|
this.motion.crMode = mode;
|
|
|
|
}
|
|
|
|
|
2018-09-30 18:43:20 +02:00
|
|
|
/**
|
|
|
|
* Returns true if the original version (including change recommendation annotation) is to be shown
|
|
|
|
*/
|
|
|
|
public isRecoModeOriginal(): boolean {
|
|
|
|
return this.motion.crMode === ChangeRecoMode.Original;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the diff version is to be shown
|
|
|
|
*/
|
|
|
|
public isRecoModeDiff(): boolean {
|
|
|
|
return this.motion.crMode === ChangeRecoMode.Diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In the original version, a line number range has been selected in order to create a new change recommendation
|
|
|
|
*
|
|
|
|
* @param lineRange
|
|
|
|
*/
|
|
|
|
public createChangeRecommendation(lineRange: LineRange): void {
|
|
|
|
const data: MotionChangeRecommendationComponentData = {
|
|
|
|
editChangeRecommendation: false,
|
|
|
|
newChangeRecommendation: true,
|
|
|
|
lineRange: lineRange,
|
|
|
|
changeRecommendation: this.repo.createChangeRecommendationTemplate(this.motion.id, lineRange)
|
|
|
|
};
|
|
|
|
this.dialogService.open(MotionChangeRecommendationComponent, {
|
|
|
|
height: '400px',
|
|
|
|
width: '600px',
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In the original version, a change-recommendation-annotation has been clicked
|
|
|
|
* -> Go to the diff view and scroll to the change recommendation
|
|
|
|
*/
|
|
|
|
public gotoChangeRecommendation(changeRecommendation: ViewChangeReco): void {
|
|
|
|
this.scrollToChange = changeRecommendation;
|
|
|
|
this.setChangeRecoMode(ChangeRecoMode.Diff);
|
|
|
|
}
|
|
|
|
|
2018-08-21 14:56:26 +02:00
|
|
|
/**
|
2018-08-22 16:03:49 +02:00
|
|
|
* Init. Does nothing here.
|
2018-10-05 16:34:08 +02:00
|
|
|
* Comes from the head bar
|
|
|
|
* @param mode
|
2018-08-21 14:56:26 +02:00
|
|
|
*/
|
2018-10-05 16:34:08 +02:00
|
|
|
public setEditMode(mode: boolean): void {
|
|
|
|
this.editMotion = mode;
|
|
|
|
if (mode) {
|
|
|
|
this.motionCopy = this.motion.copy();
|
|
|
|
this.patchForm(this.motionCopy);
|
|
|
|
if (this.vp.isMobile) {
|
|
|
|
this.metaInfoPanel.open();
|
|
|
|
this.contentPanel.open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!mode && this.newMotion) {
|
|
|
|
this.router.navigate(['./motions/']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Navigates the user to the given ViewMotion
|
|
|
|
* @param motion target
|
|
|
|
*/
|
|
|
|
public navigateToMotion(motion: ViewMotion): void {
|
|
|
|
this.router.navigate(['../' + motion.id], { relativeTo: this.route });
|
|
|
|
// update the current motion
|
|
|
|
this.motion = motion;
|
|
|
|
this.setSurroundingMotions();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the previous and next motion
|
|
|
|
*/
|
|
|
|
public setSurroundingMotions(): void {
|
|
|
|
const indexOfCurrent = this.allMotions.findIndex(motion => {
|
|
|
|
return motion === this.motion;
|
|
|
|
});
|
|
|
|
if (indexOfCurrent > -1) {
|
|
|
|
if (indexOfCurrent > 0) {
|
|
|
|
this.previousMotion = this.allMotions[indexOfCurrent - 1];
|
|
|
|
} else {
|
|
|
|
this.previousMotion = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (indexOfCurrent < this.allMotions.length - 1) {
|
|
|
|
this.nextMotion = this.allMotions[indexOfCurrent + 1];
|
|
|
|
} else {
|
|
|
|
this.nextMotion = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-05 17:43:44 +01:00
|
|
|
/**
|
|
|
|
* Executed after selecting a state
|
|
|
|
* @param selection MatSelectChange that contains the workflow id
|
|
|
|
*/
|
|
|
|
public onChangeState(selection: MatSelectChange): void {
|
|
|
|
this.repo.setState(this.motion, selection.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executed after selecting the recommenders state
|
|
|
|
* @param selection MatSelectChange that contains the workflow id
|
|
|
|
*/
|
|
|
|
public onChangerRecommenderState(selection: MatSelectChange): void {
|
|
|
|
this.repo.setRecommenderState(this.motion, selection.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Observes the repository for changes in the motion recommender
|
|
|
|
*/
|
|
|
|
public getRecommender(): void {
|
|
|
|
this.repo.getRecommenderObservable().subscribe(newRecommender => {
|
|
|
|
this.recommender = newRecommender;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
/**
|
|
|
|
* Determine if the user has the correct requirements to alter the motion
|
|
|
|
*/
|
|
|
|
public opCanEdit(): boolean {
|
|
|
|
return this.op.hasPerms('motions.can_manage');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init.
|
2018-11-05 17:43:44 +01:00
|
|
|
* Calls getRecommender and sets the surrounding motions to navigate back and forth
|
2018-10-05 16:34:08 +02:00
|
|
|
*/
|
|
|
|
public ngOnInit(): void {
|
2018-11-05 17:43:44 +01:00
|
|
|
this.getRecommender();
|
2018-10-05 16:34:08 +02:00
|
|
|
this.repo.getViewModelListObservable().subscribe(newMotionList => {
|
|
|
|
if (newMotionList) {
|
|
|
|
this.allMotions = newMotionList;
|
|
|
|
this.setSurroundingMotions();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-08-09 16:03:24 +02:00
|
|
|
}
|