2018-09-04 14:55:07 +02:00
|
|
|
import { Motion } from '../../../shared/models/motions/motion';
|
|
|
|
import { Category } from '../../../shared/models/motions/category';
|
|
|
|
import { User } from '../../../shared/models/users/user';
|
|
|
|
import { Workflow } from '../../../shared/models/motions/workflow';
|
|
|
|
import { WorkflowState } from '../../../shared/models/motions/workflow-state';
|
2018-09-13 09:23:57 +02:00
|
|
|
import { BaseModel } from '../../../shared/models/base/base-model';
|
2018-09-11 16:38:23 +02:00
|
|
|
import { BaseViewModel } from '../../base/base-view-model';
|
2018-10-16 12:41:46 +02:00
|
|
|
import { ViewMotionCommentSection } from './view-motion-comment-section';
|
|
|
|
import { MotionComment } from '../../../shared/models/motions/motion-comment';
|
2018-11-12 15:24:23 +01:00
|
|
|
import { Item } from 'app/shared/models/agenda/item';
|
2018-09-28 15:10:48 +02:00
|
|
|
|
2018-09-30 18:43:20 +02:00
|
|
|
export enum LineNumberingMode {
|
2018-09-28 15:10:48 +02:00
|
|
|
None,
|
|
|
|
Inside,
|
|
|
|
Outside
|
|
|
|
}
|
|
|
|
|
2018-09-30 18:43:20 +02:00
|
|
|
export enum ChangeRecoMode {
|
2018-09-28 15:10:48 +02:00
|
|
|
Original,
|
2018-09-30 18:43:20 +02:00
|
|
|
Changed,
|
2018-09-28 15:10:48 +02:00
|
|
|
Diff,
|
|
|
|
Final
|
|
|
|
}
|
|
|
|
|
2018-09-04 14:55:07 +02:00
|
|
|
/**
|
|
|
|
* Motion class for the View
|
|
|
|
*
|
|
|
|
* Stores a motion including all (implicit) references
|
|
|
|
* Provides "safe" access to variables and functions in {@link Motion}
|
|
|
|
* @ignore
|
|
|
|
*/
|
2018-09-10 15:53:11 +02:00
|
|
|
export class ViewMotion extends BaseViewModel {
|
2018-09-04 14:55:07 +02:00
|
|
|
private _motion: Motion;
|
|
|
|
private _category: Category;
|
|
|
|
private _submitters: User[];
|
|
|
|
private _supporters: User[];
|
|
|
|
private _workflow: Workflow;
|
|
|
|
private _state: WorkflowState;
|
2018-11-12 15:24:23 +01:00
|
|
|
private _item: Item;
|
2018-09-04 14:55:07 +02:00
|
|
|
|
2018-09-28 15:10:48 +02:00
|
|
|
/**
|
2018-09-30 18:43:20 +02:00
|
|
|
* Indicates the LineNumberingMode Mode.
|
2018-09-28 15:10:48 +02:00
|
|
|
* Needs to be accessed from outside
|
|
|
|
*/
|
2018-09-30 18:43:20 +02:00
|
|
|
public lnMode: LineNumberingMode;
|
2018-09-28 15:10:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates the Change reco Mode.
|
|
|
|
* Needs to be accessed from outside
|
|
|
|
*/
|
2018-09-30 18:43:20 +02:00
|
|
|
public crMode: ChangeRecoMode;
|
2018-09-28 15:10:48 +02:00
|
|
|
|
2018-09-09 18:52:47 +02:00
|
|
|
/**
|
|
|
|
* Indicates the maximum line length as defined in the configuration.
|
|
|
|
* Needs to be accessed from outside
|
|
|
|
*/
|
|
|
|
public lineLength: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates the currently highlighted line, if any.
|
|
|
|
* Needs to be accessed from outside
|
|
|
|
*/
|
|
|
|
public highlightedLine: number;
|
|
|
|
|
2018-09-04 14:55:07 +02:00
|
|
|
public get motion(): Motion {
|
|
|
|
return this._motion;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get id(): number {
|
2018-09-11 16:38:23 +02:00
|
|
|
return this.motion ? this.motion.id : null;
|
2018-09-04 14:55:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public get identifier(): string {
|
2018-09-11 16:38:23 +02:00
|
|
|
return this.motion ? this.motion.identifier : null;
|
2018-09-04 14:55:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public get title(): string {
|
2018-09-11 16:38:23 +02:00
|
|
|
return this.motion ? this.motion.title : null;
|
2018-09-04 14:55:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public get text(): string {
|
2018-09-11 16:38:23 +02:00
|
|
|
return this.motion ? this.motion.text : null;
|
2018-09-04 14:55:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public get reason(): string {
|
2018-09-11 16:38:23 +02:00
|
|
|
return this.motion ? this.motion.reason : null;
|
2018-09-04 14:55:07 +02:00
|
|
|
}
|
|
|
|
|
2018-11-08 17:38:44 +01:00
|
|
|
public get weight(): number {
|
|
|
|
return this.motion ? this.motion.weight : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get sort_parent_id(): number {
|
|
|
|
return this.motion ? this.motion.sort_parent_id : null;
|
|
|
|
}
|
|
|
|
|
2018-09-04 14:55:07 +02:00
|
|
|
public get category(): Category {
|
|
|
|
return this._category;
|
|
|
|
}
|
|
|
|
|
2018-10-23 14:20:29 +02:00
|
|
|
public get agenda_item_id(): number {
|
|
|
|
return this.motion ? this.motion.agenda_item_id : null;
|
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
public get category_id(): number {
|
2018-09-11 16:38:23 +02:00
|
|
|
return this.motion && this.category ? this.motion.category_id : null;
|
2018-09-04 14:55:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public get submitters(): User[] {
|
|
|
|
return this._submitters;
|
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
public get submitters_id(): number[] {
|
2018-09-20 12:25:37 +02:00
|
|
|
return this.motion ? this.motion.submitters_id : null;
|
|
|
|
}
|
|
|
|
|
2018-09-04 14:55:07 +02:00
|
|
|
public get supporters(): User[] {
|
|
|
|
return this._supporters;
|
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
public get supporters_id(): number[] {
|
2018-09-20 12:25:37 +02:00
|
|
|
return this.motion ? this.motion.supporters_id : null;
|
|
|
|
}
|
|
|
|
|
2018-09-04 14:55:07 +02:00
|
|
|
public get workflow(): Workflow {
|
|
|
|
return this._workflow;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get state(): WorkflowState {
|
|
|
|
return this._state;
|
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
public get state_id(): number {
|
2018-09-11 16:38:23 +02:00
|
|
|
return this.motion && this.motion.state_id ? this.motion.state_id : null;
|
2018-09-04 14:55:07 +02:00
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
public get recommendation_id(): number {
|
2018-09-11 16:38:23 +02:00
|
|
|
return this.motion && this.motion.recommendation_id ? this.motion.recommendation_id : null;
|
2018-09-04 14:55:07 +02:00
|
|
|
}
|
|
|
|
|
2018-10-28 11:06:36 +01:00
|
|
|
public get statute_paragraph_id(): number {
|
|
|
|
return this.motion && this.motion.statute_paragraph_id ? this.motion.statute_paragraph_id : null;
|
|
|
|
}
|
|
|
|
|
2018-09-04 14:55:07 +02:00
|
|
|
public get recommendation(): WorkflowState {
|
2018-10-05 16:34:08 +02:00
|
|
|
return this.recommendation_id && this.workflow ? this.workflow.getStateById(this.recommendation_id) : null;
|
2018-09-04 14:55:07 +02:00
|
|
|
}
|
|
|
|
|
2018-11-05 17:43:44 +01:00
|
|
|
public get possibleRecommendations(): WorkflowState[] {
|
2018-11-08 17:38:44 +01:00
|
|
|
return this.workflow
|
|
|
|
? this.workflow.states.filter(recommendation => recommendation.recommendation_label !== undefined)
|
|
|
|
: null;
|
2018-11-05 17:43:44 +01:00
|
|
|
}
|
|
|
|
|
2018-09-04 14:55:07 +02:00
|
|
|
public get origin(): string {
|
2018-09-11 16:38:23 +02:00
|
|
|
return this.motion ? this.motion.origin : null;
|
2018-09-04 14:55:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public get nextStates(): WorkflowState[] {
|
2018-09-11 16:38:23 +02:00
|
|
|
return this.state && this.workflow ? this.state.getNextStates(this.workflow) : null;
|
2018-09-04 14:55:07 +02:00
|
|
|
}
|
|
|
|
|
2018-09-20 12:25:37 +02:00
|
|
|
public set supporters(users: User[]) {
|
|
|
|
this._supporters = users;
|
2018-10-16 12:41:46 +02:00
|
|
|
this._motion.supporters_id = users.map(user => user.id);
|
2018-09-20 12:25:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public set submitters(users: User[]) {
|
|
|
|
this._submitters = users;
|
2018-10-16 12:41:46 +02:00
|
|
|
this._motion.submitters_id = users.map(user => user.id);
|
2018-09-20 12:25:37 +02:00
|
|
|
}
|
|
|
|
|
2018-11-12 15:24:23 +01:00
|
|
|
public get item(): Item {
|
|
|
|
return this._item;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get agendaSpeakerAmount(): number {
|
|
|
|
return this.item ? this.item.speakerAmount : null
|
|
|
|
}
|
|
|
|
|
2018-09-04 14:55:07 +02:00
|
|
|
public constructor(
|
|
|
|
motion?: Motion,
|
|
|
|
category?: Category,
|
|
|
|
submitters?: User[],
|
|
|
|
supporters?: User[],
|
|
|
|
workflow?: Workflow,
|
2018-11-12 15:24:23 +01:00
|
|
|
state?: WorkflowState,
|
|
|
|
item?: Item,
|
2018-09-04 14:55:07 +02:00
|
|
|
) {
|
2018-09-10 15:53:11 +02:00
|
|
|
super();
|
|
|
|
|
2018-09-04 14:55:07 +02:00
|
|
|
this._motion = motion;
|
|
|
|
this._category = category;
|
|
|
|
this._submitters = submitters;
|
|
|
|
this._supporters = supporters;
|
|
|
|
this._workflow = workflow;
|
|
|
|
this._state = state;
|
2018-11-12 15:24:23 +01:00
|
|
|
this._item = item;
|
2018-09-28 15:10:48 +02:00
|
|
|
|
|
|
|
// TODO: Should be set using a a config variable
|
2018-09-30 18:43:20 +02:00
|
|
|
this.lnMode = LineNumberingMode.Outside;
|
|
|
|
this.crMode = ChangeRecoMode.Original;
|
2018-09-09 18:52:47 +02:00
|
|
|
this.lineLength = 80;
|
|
|
|
|
|
|
|
this.highlightedLine = null;
|
2018-09-04 14:55:07 +02:00
|
|
|
}
|
|
|
|
|
2018-10-12 11:05:24 +02:00
|
|
|
public getTitle(): string {
|
2018-11-08 17:38:44 +01:00
|
|
|
if (this.identifier) {
|
|
|
|
return this.identifier + ' - ' + this.title;
|
2018-10-15 11:52:57 +02:00
|
|
|
}
|
2018-09-10 15:53:11 +02:00
|
|
|
return this.title;
|
|
|
|
}
|
|
|
|
|
2018-10-16 12:41:46 +02:00
|
|
|
/**
|
|
|
|
* Returns the motion comment for the given section. Null, if no comment exist.
|
|
|
|
* @param section The section to search the comment for.
|
|
|
|
*/
|
|
|
|
public getCommentForSection(section: ViewMotionCommentSection): MotionComment {
|
|
|
|
if (!this.motion) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return this.motion.comments.find(comment => comment.section_id === section.id);
|
|
|
|
}
|
|
|
|
|
2018-09-04 14:55:07 +02:00
|
|
|
/**
|
|
|
|
* Updates the local objects if required
|
|
|
|
* @param update
|
|
|
|
*/
|
|
|
|
public updateValues(update: BaseModel): void {
|
|
|
|
if (update instanceof Workflow) {
|
2018-09-20 12:25:37 +02:00
|
|
|
this.updateWorkflow(update as Workflow);
|
2018-09-04 14:55:07 +02:00
|
|
|
} else if (update instanceof Category) {
|
2018-09-20 12:25:37 +02:00
|
|
|
this.updateCategory(update as Category);
|
2018-11-12 15:24:23 +01:00
|
|
|
} else if (update instanceof Item) {
|
|
|
|
this.updateItem(update as Item);
|
2018-09-04 14:55:07 +02:00
|
|
|
}
|
|
|
|
// TODO: There is no way (yet) to add Submitters to a motion
|
|
|
|
// Thus, this feature could not be tested
|
|
|
|
}
|
|
|
|
|
2018-09-20 12:25:37 +02:00
|
|
|
/**
|
2018-11-12 15:24:23 +01:00
|
|
|
* Update routine for the category
|
|
|
|
* @param update potentially the changed category. Needs manual verification
|
2018-09-20 12:25:37 +02:00
|
|
|
*/
|
|
|
|
public updateCategory(update: Category): void {
|
|
|
|
if (this.motion && update.id === this.motion.category_id) {
|
|
|
|
this._category = update as Category;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-11-12 15:24:23 +01:00
|
|
|
* Update routine for the workflow
|
|
|
|
* @param update potentially the changed workflow (state). Needs manual verification
|
2018-09-20 12:25:37 +02:00
|
|
|
*/
|
|
|
|
public updateWorkflow(update: Workflow): void {
|
|
|
|
if (this.motion && update.id === this.motion.workflow_id) {
|
|
|
|
this._workflow = update as Workflow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-12 15:24:23 +01:00
|
|
|
/**
|
|
|
|
* Update routine for the agenda Item
|
|
|
|
* @param update potentially the changed agenda Item. Needs manual verification
|
|
|
|
*/
|
|
|
|
public updateItem(update: Item): void {
|
|
|
|
if (this.motion && update.id === this.motion.agenda_item_id) {
|
|
|
|
this._item = update as Item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-04 14:55:07 +02:00
|
|
|
public hasSupporters(): boolean {
|
|
|
|
return !!(this.supporters && this.supporters.length > 0);
|
|
|
|
}
|
|
|
|
|
2018-10-28 11:06:36 +01:00
|
|
|
public isStatuteAmendment(): boolean {
|
|
|
|
return !!this.statute_paragraph_id;
|
|
|
|
}
|
|
|
|
|
2018-09-04 14:55:07 +02:00
|
|
|
/**
|
|
|
|
* Duplicate this motion into a copy of itself
|
|
|
|
*/
|
|
|
|
public copy(): ViewMotion {
|
|
|
|
return new ViewMotion(
|
|
|
|
this._motion,
|
|
|
|
this._category,
|
|
|
|
this._submitters,
|
|
|
|
this._supporters,
|
|
|
|
this._workflow,
|
|
|
|
this._state
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|