Merge pull request #3849 from FinnStutzenstein/constructors
less constructors
This commit is contained in:
commit
32c7959b1c
1
.gitignore
vendored
1
.gitignore
vendored
@ -63,6 +63,7 @@ client/node_modules
|
||||
|
||||
# misc
|
||||
Compodoc
|
||||
Compodocmodules
|
||||
client/.sass-cache
|
||||
client/connect.lock
|
||||
client/coverage
|
||||
|
@ -56,7 +56,7 @@ export class AuthService extends OpenSlidesComponent {
|
||||
};
|
||||
return this.http.post<LoginResponse>(environment.urlPrefix + '/users/login/', user).pipe(
|
||||
tap((response: LoginResponse) => {
|
||||
this.operator.user = new User().deserialize(response.user);
|
||||
this.operator.user = new User(response.user);
|
||||
}),
|
||||
catchError(this.handleError())
|
||||
) as Observable<LoginResponse>;
|
||||
|
@ -66,7 +66,7 @@ export class AutoupdateService extends OpenSlidesComponent {
|
||||
/*throw new Error*/ console.log(`Unregistered resource ${collection}`);
|
||||
return;
|
||||
}
|
||||
this.DS.add(...autoupdate.changed[collection].map(_obj => new targetClass().deserialize(_obj.data)));
|
||||
this.DS.add(...autoupdate.changed[collection].map(_obj => new targetClass(_obj.data)));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ export class DataStoreService {
|
||||
if (target) {
|
||||
Object.keys(serializedStore[collectionString]).forEach(id => {
|
||||
const data = JSON.parse(serializedStore[collectionString][id]);
|
||||
storage[collectionString][id] = new target().deserialize(data);
|
||||
storage[collectionString][id] = new target(data);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -107,7 +107,7 @@ export class OperatorService extends OpenSlidesComponent {
|
||||
return this.http.get<WhoAmIResponse>(environment.urlPrefix + '/users/whoami/').pipe(
|
||||
tap((response: WhoAmIResponse) => {
|
||||
if (response && response.user_id) {
|
||||
this.user = new User().deserialize(response.user);
|
||||
this.user = new User(response.user);
|
||||
}
|
||||
}),
|
||||
catchError(this.handleError())
|
||||
|
@ -28,38 +28,12 @@ export class Item extends BaseModel {
|
||||
public weight: number;
|
||||
public parent_id: number;
|
||||
|
||||
public constructor(
|
||||
id?: number,
|
||||
item_number?: string,
|
||||
title?: string,
|
||||
list_view_title?: string,
|
||||
comment?: string,
|
||||
closed?: boolean,
|
||||
type?: number,
|
||||
is_hidden?: boolean,
|
||||
duration?: number,
|
||||
speakers?: Speaker[],
|
||||
speaker_list_closed?: boolean,
|
||||
content_object?: ContentObject,
|
||||
weight?: number,
|
||||
parent_id?: number
|
||||
) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'agenda/item';
|
||||
this.id = id;
|
||||
this.item_number = item_number;
|
||||
this.title = title;
|
||||
this.list_view_title = list_view_title;
|
||||
this.comment = comment;
|
||||
this.closed = closed;
|
||||
this.type = type;
|
||||
this.is_hidden = is_hidden;
|
||||
this.duration = duration;
|
||||
this.speakers = speakers;
|
||||
this.speaker_list_closed = speaker_list_closed;
|
||||
this.content_object = content_object;
|
||||
this.weight = weight;
|
||||
this.parent_id = parent_id;
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public getSpeakers(): User[] {
|
||||
@ -75,15 +49,14 @@ export class Item extends BaseModel {
|
||||
return this.DS.get<BaseModel>(this.content_object.collection, this.content_object.id);
|
||||
}
|
||||
|
||||
public deserialize(input: any): this {
|
||||
public deserialize(input: any): void {
|
||||
Object.assign(this, input);
|
||||
|
||||
if (input.speakers instanceof Array) {
|
||||
this.speakers = input.speakers.map(speakerData => {
|
||||
return new Speaker().deserialize(speakerData);
|
||||
return new Speaker(speakerData);
|
||||
});
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,34 +17,15 @@ export class Speaker implements Deserializable {
|
||||
|
||||
/**
|
||||
* Needs to be completely optional because agenda has (yet) the optional parameter 'speaker'
|
||||
* @param id
|
||||
* @param user_id
|
||||
* @param begin_time
|
||||
* @param end_time
|
||||
* @param weight
|
||||
* @param marked
|
||||
* @param item_id
|
||||
* @param input
|
||||
*/
|
||||
public constructor(
|
||||
id?: number,
|
||||
user_id?: number,
|
||||
begin_time?: string,
|
||||
end_time?: string,
|
||||
weight?: number,
|
||||
marked?: boolean,
|
||||
item_id?: number
|
||||
) {
|
||||
this.id = id;
|
||||
this.user_id = user_id;
|
||||
this.begin_time = begin_time;
|
||||
this.end_time = end_time;
|
||||
this.weight = weight;
|
||||
this.marked = marked;
|
||||
this.item_id = item_id;
|
||||
public constructor(input?: any) {
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public deserialize(input: any): this {
|
||||
public deserialize(input: any): void {
|
||||
Object.assign(this, input);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -13,22 +13,15 @@ export class AssignmentUser implements Deserializable {
|
||||
|
||||
/**
|
||||
* Needs to be completely optional because assignment has (yet) the optional parameter 'assignment_related_users'
|
||||
* @param id
|
||||
* @param user_id
|
||||
* @param elected
|
||||
* @param assignment_id
|
||||
* @param weight
|
||||
* @param input
|
||||
*/
|
||||
public constructor(id?: number, user_id?: number, elected?: boolean, assignment_id?: number, weight?: number) {
|
||||
this.id = id;
|
||||
this.user_id = user_id;
|
||||
this.elected = elected;
|
||||
this.assignment_id = assignment_id;
|
||||
this.weight = weight;
|
||||
public constructor(input?: any) {
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public deserialize(input: any): this {
|
||||
public deserialize(input: any): void {
|
||||
Object.assign(this, input);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -21,30 +21,15 @@ export class Assignment extends BaseModel {
|
||||
public agenda_item_id: number;
|
||||
public tags_id: number[];
|
||||
|
||||
public constructor(
|
||||
id?: number,
|
||||
title?: string,
|
||||
description?: string,
|
||||
open_posts?: number,
|
||||
phase?: number,
|
||||
assignment_related_users?: AssignmentUser[],
|
||||
poll_description_default?: number,
|
||||
polls?: Poll[],
|
||||
agenda_item_id?: number,
|
||||
tags_id?: number[]
|
||||
) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'assignments/assignment';
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.open_posts = open_posts;
|
||||
this.phase = phase;
|
||||
this.assignment_related_users = assignment_related_users || []; // TODO Array
|
||||
this.poll_description_default = poll_description_default;
|
||||
this.polls = polls || Array(); // TODO Array
|
||||
this.agenda_item_id = agenda_item_id;
|
||||
this.tags_id = tags_id;
|
||||
this.assignment_related_users = []; // TODO Array
|
||||
this.polls = Array(); // TODO Array
|
||||
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public getAssignmentReleatedUsers(): BaseModel | BaseModel[] {
|
||||
@ -59,23 +44,22 @@ export class Assignment extends BaseModel {
|
||||
return this.DS.getMany<Tag>('core/tag', this.tags_id);
|
||||
}
|
||||
|
||||
public deserialize(input: any): this {
|
||||
public deserialize(input: any): void {
|
||||
Object.assign(this, input);
|
||||
|
||||
if (input.assignment_related_users instanceof Array) {
|
||||
this.assignment_related_users = [];
|
||||
input.assignment_related_users.forEach(assignmentUserData => {
|
||||
this.assignment_related_users.push(new AssignmentUser().deserialize(assignmentUserData));
|
||||
this.assignment_related_users.push(new AssignmentUser(assignmentUserData));
|
||||
});
|
||||
}
|
||||
|
||||
if (input.polls instanceof Array) {
|
||||
this.polls = [];
|
||||
input.polls.forEach(pollData => {
|
||||
this.polls.push(new Poll().deserialize(pollData));
|
||||
this.polls.push(new Poll(pollData));
|
||||
});
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,31 +16,15 @@ export class PollOption implements Deserializable {
|
||||
|
||||
/**
|
||||
* Needs to be completely optional because poll has (yet) the optional parameter 'poll-options'
|
||||
* @param id
|
||||
* @param candidate_id
|
||||
* @param is_elected
|
||||
* @param votes
|
||||
* @param poll_id
|
||||
* @param weight
|
||||
* @param input
|
||||
*/
|
||||
public constructor(
|
||||
id?: number,
|
||||
candidate_id?: number,
|
||||
is_elected?: boolean,
|
||||
votes?: number[],
|
||||
poll_id?: number,
|
||||
weight?: number
|
||||
) {
|
||||
this.id = id;
|
||||
this.candidate_id = candidate_id;
|
||||
this.is_elected = is_elected;
|
||||
this.votes = votes;
|
||||
this.poll_id = poll_id;
|
||||
this.weight = weight;
|
||||
public constructor(input?: any) {
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public deserialize(input: any): this {
|
||||
public deserialize(input: any): void {
|
||||
Object.assign(this, input);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -19,50 +19,23 @@ export class Poll implements Deserializable {
|
||||
|
||||
/**
|
||||
* Needs to be completely optional because assignment has (yet) the optional parameter 'polls'
|
||||
* @param id
|
||||
* @param pollmethod
|
||||
* @param description
|
||||
* @param published
|
||||
* @param options
|
||||
* @param votesvalid
|
||||
* @param votesinvalid
|
||||
* @param votescast
|
||||
* @param has_votes
|
||||
* @param assignment_id
|
||||
* @param input
|
||||
*/
|
||||
public constructor(
|
||||
id?: number,
|
||||
pollmethod?: string,
|
||||
description?: string,
|
||||
published?: boolean,
|
||||
options?: PollOption[],
|
||||
votesvalid?: number,
|
||||
votesinvalid?: number,
|
||||
votescast?: number,
|
||||
has_votes?: boolean,
|
||||
assignment_id?: number
|
||||
) {
|
||||
this.id = id;
|
||||
this.pollmethod = pollmethod;
|
||||
this.description = description;
|
||||
this.published = published;
|
||||
this.options = options || Array(new PollOption()); // TODO Array
|
||||
this.votesvalid = votesvalid;
|
||||
this.votesinvalid = votesinvalid;
|
||||
this.votescast = votescast;
|
||||
this.has_votes = has_votes;
|
||||
this.assignment_id = assignment_id;
|
||||
public constructor(input?: any) {
|
||||
this.options = [new PollOption()];
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public deserialize(input: any): this {
|
||||
public deserialize(input: any): void {
|
||||
Object.assign(this, input);
|
||||
|
||||
if (input.options instanceof Array) {
|
||||
this.options = [];
|
||||
input.options.forEach(pollOptionData => {
|
||||
this.options.push(new PollOption().deserialize(pollOptionData));
|
||||
this.options.push(new PollOption(pollOptionData));
|
||||
});
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -57,8 +57,7 @@ export abstract class BaseModel extends OpenSlidesComponent implements Deseriali
|
||||
* Inherited to children, can be overwritten for special use cases
|
||||
* @param input JSON data for deserialization.
|
||||
*/
|
||||
public deserialize(input: any): this {
|
||||
public deserialize(input: any): void {
|
||||
Object.assign(this, input);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { BaseModel } from '../base.model';
|
||||
import { User } from '../users/user';
|
||||
|
||||
/**
|
||||
* Representation of chat messages.
|
||||
@ -11,17 +12,16 @@ export class ChatMessage extends BaseModel {
|
||||
public timestamp: string; // TODO: Type for timestamp
|
||||
public user_id: number;
|
||||
|
||||
public constructor(id?: number, message?: string, timestamp?: string, user_id?: number) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'core/chat-message';
|
||||
this.id = id;
|
||||
this.message = message;
|
||||
this.timestamp = timestamp;
|
||||
this.user_id = user_id;
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public getUser(): BaseModel | BaseModel[] {
|
||||
return this.DS.get('users/user', this.user_id);
|
||||
public getUser(): User {
|
||||
return this.DS.get<User>('users/user', this.user_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,12 +10,12 @@ export class Config extends BaseModel {
|
||||
public key: string;
|
||||
public value: Object;
|
||||
|
||||
public constructor(id?: number, key?: string, value?: Object) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'core/config';
|
||||
this.id = id;
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,20 +12,12 @@ export class Countdown extends BaseModel {
|
||||
public countdown_time: number;
|
||||
public running: boolean;
|
||||
|
||||
public constructor(
|
||||
id?: number,
|
||||
countdown_time?: number,
|
||||
default_time?: number,
|
||||
description?: string,
|
||||
running?: boolean
|
||||
) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'core/countdown';
|
||||
this.id = id;
|
||||
this.description = description;
|
||||
this.default_time = default_time;
|
||||
this.countdown_time = countdown_time;
|
||||
this.running = running;
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,11 +9,12 @@ export class ProjectorMessage extends BaseModel {
|
||||
public id: number;
|
||||
public message: string;
|
||||
|
||||
public constructor(id?: number, message?: string) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'core/projector-message';
|
||||
this.id = id;
|
||||
this.message = message;
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,28 +16,12 @@ export class Projector extends BaseModel {
|
||||
public height: number;
|
||||
public projectiondefaults: Object[];
|
||||
|
||||
public constructor(
|
||||
id?: number,
|
||||
elements?: Object,
|
||||
scale?: number,
|
||||
scroll?: number,
|
||||
name?: string,
|
||||
blank?: boolean,
|
||||
width?: number,
|
||||
height?: number,
|
||||
projectiondefaults?: Object[]
|
||||
) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'core/projector';
|
||||
this.id = id;
|
||||
this.elements = elements;
|
||||
this.scale = scale;
|
||||
this.scroll = scroll;
|
||||
this.name = name;
|
||||
this.blank = blank;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.projectiondefaults = projectiondefaults;
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,11 +9,12 @@ export class Tag extends BaseModel {
|
||||
public id: number;
|
||||
public name: string;
|
||||
|
||||
public constructor(id?: number, name?: string) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'core/tag';
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,12 +2,16 @@
|
||||
* Interface tells models to offer a 'deserialize' function
|
||||
*
|
||||
* Also nested objects and arrays have have to be handled.
|
||||
* @example const myUser = new User().deserialize(jsonData)
|
||||
* @example
|
||||
* ``` ts
|
||||
* const myUser = new User();
|
||||
* myUser.deserialize(jsonData);
|
||||
* ```
|
||||
*/
|
||||
export interface Deserializable {
|
||||
/**
|
||||
* should be used to assign JSON values to the object itself.
|
||||
* @param input
|
||||
*/
|
||||
deserialize(input: any): this;
|
||||
deserialize(input: any): void;
|
||||
}
|
||||
|
@ -13,13 +13,13 @@ export class File implements Deserializable {
|
||||
* @param name The name of the file
|
||||
* @param type The tape (jpg, png, pdf)
|
||||
*/
|
||||
public constructor(name?: string, type?: string) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
public constructor(input?: any) {
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public deserialize(input: any): this {
|
||||
public deserialize(input: any): void {
|
||||
Object.assign(this, input);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { BaseModel } from '../base.model';
|
||||
import { File } from './file';
|
||||
import { User } from '../users/user';
|
||||
|
||||
/**
|
||||
* Representation of MediaFile. Has the nested property "File"
|
||||
@ -16,36 +17,21 @@ export class Mediafile extends BaseModel {
|
||||
public hidden: boolean;
|
||||
public timestamp: string;
|
||||
|
||||
public constructor(
|
||||
id?: number,
|
||||
title?: string,
|
||||
mediafile?: File,
|
||||
media_url_prefix?: string,
|
||||
uploader_id?: number,
|
||||
filesize?: string,
|
||||
hidden?: boolean,
|
||||
timestamp?: string
|
||||
) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'mediafiles/mediafile';
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.mediafile = mediafile;
|
||||
this.media_url_prefix = media_url_prefix;
|
||||
this.uploader_id = uploader_id;
|
||||
this.filesize = filesize;
|
||||
this.hidden = hidden;
|
||||
this.timestamp = timestamp;
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public deserialize(input: any): this {
|
||||
public deserialize(input: any): void {
|
||||
Object.assign(this, input);
|
||||
this.mediafile = new File().deserialize(input.mediafile);
|
||||
return this;
|
||||
this.mediafile = new File(input.mediafile);
|
||||
}
|
||||
|
||||
public getUploader(): BaseModel | BaseModel[] {
|
||||
return this.DS.get('users/user', this.uploader_id);
|
||||
public getUploader(): User {
|
||||
return this.DS.get<User>('users/user', this.uploader_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,12 +10,12 @@ export class Category extends BaseModel {
|
||||
public name: string;
|
||||
public prefix: string;
|
||||
|
||||
public constructor(id?: number, name?: string, prefix?: string) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'motions/category';
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.prefix = prefix;
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public toString = (): string => {
|
||||
|
@ -10,12 +10,12 @@ export class MotionBlock extends BaseModel {
|
||||
public title: string;
|
||||
public agenda_item_id: number;
|
||||
|
||||
public constructor(id?: number, title?: string, agenda_item_id?: number) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'motions/motion-block';
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.agenda_item_id = agenda_item_id;
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public getAgenda(): BaseModel | BaseModel[] {
|
||||
|
@ -16,28 +16,12 @@ export class MotionChangeReco extends BaseModel {
|
||||
public text: string;
|
||||
public creation_time: string;
|
||||
|
||||
public constructor(
|
||||
id?: number,
|
||||
motion_version_id?: number,
|
||||
rejected?: boolean,
|
||||
type?: number,
|
||||
other_description?: string,
|
||||
line_from?: number,
|
||||
line_to?: number,
|
||||
text?: string,
|
||||
creation_time?: string
|
||||
) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'motions/motion-change-recommendation';
|
||||
this.id = id;
|
||||
this.motion_version_id = motion_version_id;
|
||||
this.rejected = rejected;
|
||||
this.type = type;
|
||||
this.other_description = other_description;
|
||||
this.line_from = line_from;
|
||||
this.line_to = line_to;
|
||||
this.text = text;
|
||||
this.creation_time = creation_time;
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,15 +11,13 @@ export class MotionLog implements Deserializable {
|
||||
public time: string;
|
||||
public message: string;
|
||||
|
||||
public constructor(message_list?: string[], person_id?: number, time?: string, message?: string) {
|
||||
this.message_list = message_list;
|
||||
this.person_id = person_id;
|
||||
this.time = time;
|
||||
this.message = message;
|
||||
public constructor(input?: any) {
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public deserialize(input: any): this {
|
||||
public deserialize(input: any): void {
|
||||
Object.assign(this, input);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -11,15 +11,13 @@ export class MotionSubmitter implements Deserializable {
|
||||
public motion_id: number;
|
||||
public weight: number;
|
||||
|
||||
public constructor(id?: number, user_id?: number, motion_id?: number, weight?: number) {
|
||||
this.id = id;
|
||||
this.user_id = user_id;
|
||||
this.motion_id = motion_id;
|
||||
this.weight = weight;
|
||||
public constructor(input?: any) {
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public deserialize(input: any): this {
|
||||
public deserialize(input: any): void {
|
||||
Object.assign(this, input);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -14,26 +14,17 @@ export class MotionVersion implements Deserializable {
|
||||
public amendment_paragraphs: string;
|
||||
public reason: string;
|
||||
|
||||
public constructor(
|
||||
id?: number,
|
||||
version_number?: number,
|
||||
creation_time?: string,
|
||||
title?: string,
|
||||
text?: string,
|
||||
amendment_paragraphs?: string,
|
||||
reason?: string
|
||||
) {
|
||||
this.id = id;
|
||||
this.version_number = version_number;
|
||||
this.creation_time = creation_time;
|
||||
this.title = title || '';
|
||||
this.text = text || '';
|
||||
this.amendment_paragraphs = amendment_paragraphs || '';
|
||||
this.reason = reason || '';
|
||||
public constructor(input?: any) {
|
||||
this.title = '';
|
||||
this.text = '';
|
||||
this.reason = '';
|
||||
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public deserialize(input: any): this {
|
||||
public deserialize(input: any): void {
|
||||
Object.assign(this, input);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -44,49 +44,20 @@ export class Motion extends BaseModel {
|
||||
public title: string;
|
||||
public text: string;
|
||||
|
||||
public constructor(
|
||||
id?: number,
|
||||
identifier?: string,
|
||||
versions?: MotionVersion[],
|
||||
active_version?: number,
|
||||
parent_id?: number,
|
||||
category_id?: number,
|
||||
motion_block_id?: number,
|
||||
origin?: string,
|
||||
submitters?: MotionSubmitter[],
|
||||
supporters_id?: number[],
|
||||
comments?: Object,
|
||||
state_id?: number,
|
||||
state_required_permission_to_see?: string,
|
||||
recommendation_id?: number,
|
||||
tags_id?: number[],
|
||||
attachments_id?: number[],
|
||||
polls?: BaseModel[],
|
||||
agenda_item_id?: number,
|
||||
log_messages?: MotionLog[]
|
||||
) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'motions/motion';
|
||||
this.id = id;
|
||||
this.identifier = identifier || '';
|
||||
this.versions = versions || [new MotionVersion()];
|
||||
this.active_version = active_version;
|
||||
this.parent_id = parent_id;
|
||||
this.category_id = category_id;
|
||||
this.motion_block_id = motion_block_id;
|
||||
this.origin = origin || '';
|
||||
this.submitters = submitters || [];
|
||||
this.supporters_id = supporters_id;
|
||||
this.comments = comments;
|
||||
this.state_id = state_id;
|
||||
this.state_required_permission_to_see = state_required_permission_to_see || '';
|
||||
this.recommendation_id = recommendation_id;
|
||||
this.tags_id = tags_id;
|
||||
this.attachments_id = attachments_id;
|
||||
this.polls = polls;
|
||||
this.agenda_item_id = agenda_item_id;
|
||||
this.log_messages = log_messages || [];
|
||||
this.identifier = '';
|
||||
this.versions = [new MotionVersion()];
|
||||
this.origin = '';
|
||||
this.submitters = [];
|
||||
this.supporters_id = [];
|
||||
this.state_required_permission_to_see = '';
|
||||
this.log_messages = [];
|
||||
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
this.initDataStoreValues();
|
||||
}
|
||||
|
||||
@ -124,7 +95,8 @@ export class Motion extends BaseModel {
|
||||
* @param user the user
|
||||
*/
|
||||
public addSubmitter(user: User) {
|
||||
const newSubmitter = new MotionSubmitter(null, user.id);
|
||||
const newSubmitter = new MotionSubmitter();
|
||||
newSubmitter.user_id = user.id;
|
||||
this.submitters.push(newSubmitter);
|
||||
console.log('did addSubmitter. this.submitters: ', this.submitters);
|
||||
}
|
||||
@ -264,31 +236,29 @@ export class Motion extends BaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
public deserialize(input: any): this {
|
||||
public deserialize(input: any): void {
|
||||
Object.assign(this, input);
|
||||
|
||||
if (input.versions instanceof Array) {
|
||||
this.versions = [];
|
||||
input.versions.forEach(motionVersionData => {
|
||||
this.versions.push(new MotionVersion().deserialize(motionVersionData));
|
||||
this.versions.push(new MotionVersion(motionVersionData));
|
||||
});
|
||||
}
|
||||
|
||||
if (input.submitters instanceof Array) {
|
||||
this.submitters = [];
|
||||
input.submitters.forEach(SubmitterData => {
|
||||
this.submitters.push(new MotionSubmitter().deserialize(SubmitterData));
|
||||
this.submitters.push(new MotionSubmitter(SubmitterData));
|
||||
});
|
||||
}
|
||||
|
||||
if (input.log_messages instanceof Array) {
|
||||
this.log_messages = [];
|
||||
input.log_messages.forEach(logData => {
|
||||
this.log_messages.push(new MotionLog().deserialize(logData));
|
||||
this.log_messages.push(new MotionLog(logData));
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,57 +27,12 @@ export class WorkflowState implements Deserializable {
|
||||
|
||||
/**
|
||||
* Needs to be completely optional because Workflow has (yet) the optional parameter 'states'
|
||||
* @param id
|
||||
* @param name
|
||||
* @param action_word
|
||||
* @param recommendation_label
|
||||
* @param css_class
|
||||
* @param required_permission_to_see
|
||||
* @param allow_support
|
||||
* @param allow_create_poll
|
||||
* @param allow_submitter_edit
|
||||
* @param versioning
|
||||
* @param leave_old_version_active
|
||||
* @param dont_set_identifier
|
||||
* @param show_state_extension_field
|
||||
* @param show_recommendation_extension_field
|
||||
* @param next_states_id
|
||||
* @param workflow_id
|
||||
* @param input If given, it will be deserialized
|
||||
*/
|
||||
public constructor(
|
||||
id?: number,
|
||||
name?: string,
|
||||
action_word?: string,
|
||||
recommendation_label?: string,
|
||||
css_class?: string,
|
||||
required_permission_to_see?: string,
|
||||
allow_support?: boolean,
|
||||
allow_create_poll?: boolean,
|
||||
allow_submitter_edit?: boolean,
|
||||
versioning?: boolean,
|
||||
leave_old_version_active?: boolean,
|
||||
dont_set_identifier?: boolean,
|
||||
show_state_extension_field?: boolean,
|
||||
show_recommendation_extension_field?: boolean,
|
||||
next_states_id?: number[],
|
||||
workflow_id?: number
|
||||
) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.action_word = action_word;
|
||||
this.recommendation_label = recommendation_label;
|
||||
this.css_class = css_class;
|
||||
this.required_permission_to_see = required_permission_to_see;
|
||||
this.allow_support = allow_support;
|
||||
this.allow_create_poll = allow_create_poll;
|
||||
this.allow_submitter_edit = allow_submitter_edit;
|
||||
this.versioning = versioning;
|
||||
this.leave_old_version_active = leave_old_version_active;
|
||||
this.dont_set_identifier = dont_set_identifier;
|
||||
this.show_state_extension_field = show_state_extension_field;
|
||||
this.show_recommendation_extension_field = show_recommendation_extension_field;
|
||||
this.next_states_id = next_states_id;
|
||||
this.workflow_id = workflow_id;
|
||||
public constructor(input?: any) {
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,9 +49,8 @@ export class WorkflowState implements Deserializable {
|
||||
return nextStates;
|
||||
}
|
||||
|
||||
public deserialize(input: any): this {
|
||||
public deserialize(input: any): void {
|
||||
Object.assign(this, input);
|
||||
return this;
|
||||
}
|
||||
|
||||
public toString = (): string => {
|
||||
|
@ -12,13 +12,12 @@ export class Workflow extends BaseModel {
|
||||
public states: WorkflowState[];
|
||||
public first_state: number;
|
||||
|
||||
public constructor(id?: number, name?: string, states?: WorkflowState[], first_state?: number) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'motions/workflow';
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.states = states;
|
||||
this.first_state = first_state;
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,15 +49,14 @@ export class Workflow extends BaseModel {
|
||||
return targetState as WorkflowState;
|
||||
}
|
||||
|
||||
public deserialize(input: any): this {
|
||||
public deserialize(input: any): void {
|
||||
Object.assign(this, input);
|
||||
if (input.states instanceof Array) {
|
||||
this.states = [];
|
||||
input.states.forEach(workflowStateData => {
|
||||
this.states.push(new WorkflowState().deserialize(workflowStateData));
|
||||
this.states.push(new WorkflowState(workflowStateData));
|
||||
});
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,14 +14,12 @@ export class Topic extends BaseModel {
|
||||
public attachments_id: number[];
|
||||
public agenda_item_id: number;
|
||||
|
||||
public constructor(id?: number, title?: string, text?: string, attachments_id?: number[], agenda_item_id?: number) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'topics/topic';
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.text = text;
|
||||
this.attachments_id = attachments_id;
|
||||
this.agenda_item_id = agenda_item_id;
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public getAttachments(): Mediafile[] {
|
||||
|
@ -11,12 +11,12 @@ export class Group extends BaseModel {
|
||||
public name: string;
|
||||
public permissions: string[];
|
||||
|
||||
public constructor(id?: number, name?: string, permissions?: string[]) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'users/group';
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.permissions = permissions;
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public get users() {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { BaseModel } from '../base.model';
|
||||
import { User } from './user';
|
||||
|
||||
/**
|
||||
* Representation of users personal note.
|
||||
@ -10,16 +11,16 @@ export class PersonalNote extends BaseModel {
|
||||
public user_id: number;
|
||||
public notes: Object;
|
||||
|
||||
public constructor(id?: number, user_id?: number, notes?: Object) {
|
||||
public constructor(input: any) {
|
||||
super();
|
||||
this._collectionString = 'users/personal-note';
|
||||
this.id = id;
|
||||
this.user_id = user_id;
|
||||
this.notes = notes;
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public getUser(): BaseModel | BaseModel[] {
|
||||
return this.DS.get('users/user', this.user_id);
|
||||
public getUser(): User {
|
||||
return this.DS.get<User>('users/user', this.user_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,42 +24,13 @@ export class User extends BaseModel {
|
||||
public is_active: boolean;
|
||||
public default_password: string;
|
||||
|
||||
public constructor(
|
||||
id?: number,
|
||||
username?: string,
|
||||
title?: string,
|
||||
first_name?: string,
|
||||
last_name?: string,
|
||||
structure_level?: string,
|
||||
number?: string,
|
||||
about_me?: string,
|
||||
groups_id?: number[],
|
||||
is_present?: boolean,
|
||||
is_committee?: boolean,
|
||||
email?: string,
|
||||
last_email_send?: string,
|
||||
comment?: string,
|
||||
is_active?: boolean,
|
||||
default_password?: string
|
||||
) {
|
||||
public constructor(input?: any) {
|
||||
super();
|
||||
this._collectionString = 'users/user';
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.title = title;
|
||||
this.first_name = first_name;
|
||||
this.last_name = last_name;
|
||||
this.structure_level = structure_level;
|
||||
this.number = number;
|
||||
this.about_me = about_me;
|
||||
this.groups_id = groups_id;
|
||||
this.is_present = is_present;
|
||||
this.is_committee = is_committee;
|
||||
this.email = email;
|
||||
this.last_email_send = last_email_send;
|
||||
this.comment = comment;
|
||||
this.is_active = is_active;
|
||||
this.default_password = default_password;
|
||||
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
public get groups(): Group[] {
|
||||
|
@ -106,13 +106,10 @@ export class MotionDetailComponent extends BaseComponent implements OnInit {
|
||||
* Async load the values of the motion in the Form.
|
||||
*/
|
||||
public patchForm(formMotion: Motion) {
|
||||
console.log('Motion: ', this.motion);
|
||||
console.log('category_id: ', formMotion);
|
||||
|
||||
this.metaInfoForm.patchValue({
|
||||
category_id: formMotion.category.id,
|
||||
state_id: formMotion.state.id,
|
||||
recommendation_id: formMotion.recommendation.id,
|
||||
category_id: formMotion.category_id,
|
||||
state_id: formMotion.state_id,
|
||||
recommendation_id: formMotion.recommendation_id,
|
||||
identifier: formMotion.identifier,
|
||||
origin: formMotion.origin
|
||||
});
|
||||
|
@ -80,18 +80,18 @@ export class StartComponent extends BaseComponent implements OnInit {
|
||||
*/
|
||||
public DataStoreTest() {
|
||||
console.log('add a user to dataStore');
|
||||
this.DS.add(new User(100));
|
||||
this.DS.add(new User({ id: 100 }));
|
||||
console.log('add three users to dataStore');
|
||||
this.DS.add(new User(200), new User(201), new User(202));
|
||||
this.DS.add(new User({ id: 200 }), new User({ id: 201 }), new User({ id: 202 }));
|
||||
console.log('use the spread operator "..." to add an array');
|
||||
const userArray = [];
|
||||
for (let i = 300; i < 400; i++) {
|
||||
userArray.push(new User(i));
|
||||
userArray.push(new User({ id: i }));
|
||||
}
|
||||
this.DS.add(...userArray);
|
||||
|
||||
console.log('try to get user with ID 1:');
|
||||
const user1fromStore = this.DS.get(User, 1);
|
||||
const user1fromStore = this.DS.get<User>(User, 1);
|
||||
console.log('the user: ', user1fromStore);
|
||||
|
||||
console.log('remove a single user:');
|
||||
@ -102,7 +102,7 @@ export class StartComponent extends BaseComponent implements OnInit {
|
||||
this.DS.remove(User, ...[321, 363, 399]);
|
||||
|
||||
console.log('test filter: ');
|
||||
console.log(this.DS.filter(User, user => user.id === 1));
|
||||
console.log(this.DS.filter<User>(User, user => user.id === 1));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -153,32 +153,30 @@ export class StartComponent extends BaseComponent implements OnInit {
|
||||
|
||||
for (let i = 1; i <= requiredMotions; ++i) {
|
||||
// version
|
||||
const newMotionVersion = new MotionVersion(
|
||||
200 + i,
|
||||
1,
|
||||
'now',
|
||||
'GenMo ' + i,
|
||||
longMotionText,
|
||||
null,
|
||||
longMotionText
|
||||
);
|
||||
const newMotionVersion = new MotionVersion({
|
||||
id: 200 + i,
|
||||
version_number: 1,
|
||||
create_time: 'now',
|
||||
title: 'GenMo ' + i,
|
||||
text: longMotionText,
|
||||
reason: longMotionText
|
||||
});
|
||||
// submitter
|
||||
const newMotionSubmitter = new MotionSubmitter(1, 1, 200 + 1, 0);
|
||||
const newMotionSubmitter = new MotionSubmitter({
|
||||
id: 1,
|
||||
user_id: 1,
|
||||
motion_id: 200 + i,
|
||||
weight: 0
|
||||
});
|
||||
// motion
|
||||
const newMotion = new Motion(
|
||||
200 + i,
|
||||
'GenMo ' + i,
|
||||
[newMotionVersion],
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
'Generated',
|
||||
[newMotionSubmitter],
|
||||
null,
|
||||
null,
|
||||
1
|
||||
);
|
||||
const newMotion = new Motion({
|
||||
id: 200 + i,
|
||||
identifier: 'GenMo ' + i,
|
||||
versions: [newMotionVersion],
|
||||
origin: 'Generated',
|
||||
submitters: [newMotionSubmitter],
|
||||
state_id: 1
|
||||
});
|
||||
newMotionsArray.push(newMotion);
|
||||
}
|
||||
this.DS.add(...newMotionsArray);
|
||||
|
Loading…
Reference in New Issue
Block a user