Merge pull request #3849 from FinnStutzenstein/constructors

less constructors
This commit is contained in:
Finn Stutzenstein 2018-09-04 14:58:32 +02:00 committed by GitHub
commit 32c7959b1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 205 additions and 491 deletions

1
.gitignore vendored
View File

@ -63,6 +63,7 @@ client/node_modules
# misc # misc
Compodoc Compodoc
Compodocmodules
client/.sass-cache client/.sass-cache
client/connect.lock client/connect.lock
client/coverage client/coverage

View File

@ -56,7 +56,7 @@ export class AuthService extends OpenSlidesComponent {
}; };
return this.http.post<LoginResponse>(environment.urlPrefix + '/users/login/', user).pipe( return this.http.post<LoginResponse>(environment.urlPrefix + '/users/login/', user).pipe(
tap((response: LoginResponse) => { tap((response: LoginResponse) => {
this.operator.user = new User().deserialize(response.user); this.operator.user = new User(response.user);
}), }),
catchError(this.handleError()) catchError(this.handleError())
) as Observable<LoginResponse>; ) as Observable<LoginResponse>;

View File

@ -66,7 +66,7 @@ export class AutoupdateService extends OpenSlidesComponent {
/*throw new Error*/ console.log(`Unregistered resource ${collection}`); /*throw new Error*/ console.log(`Unregistered resource ${collection}`);
return; 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)));
}); });
} }

View File

@ -129,7 +129,7 @@ export class DataStoreService {
if (target) { if (target) {
Object.keys(serializedStore[collectionString]).forEach(id => { Object.keys(serializedStore[collectionString]).forEach(id => {
const data = JSON.parse(serializedStore[collectionString][id]); const data = JSON.parse(serializedStore[collectionString][id]);
storage[collectionString][id] = new target().deserialize(data); storage[collectionString][id] = new target(data);
}); });
} }
}); });

View File

@ -107,7 +107,7 @@ export class OperatorService extends OpenSlidesComponent {
return this.http.get<WhoAmIResponse>(environment.urlPrefix + '/users/whoami/').pipe( return this.http.get<WhoAmIResponse>(environment.urlPrefix + '/users/whoami/').pipe(
tap((response: WhoAmIResponse) => { tap((response: WhoAmIResponse) => {
if (response && response.user_id) { if (response && response.user_id) {
this.user = new User().deserialize(response.user); this.user = new User(response.user);
} }
}), }),
catchError(this.handleError()) catchError(this.handleError())

View File

@ -28,38 +28,12 @@ export class Item extends BaseModel {
public weight: number; public weight: number;
public parent_id: number; public parent_id: number;
public constructor( public constructor(input?: any) {
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
) {
super(); super();
this._collectionString = 'agenda/item'; this._collectionString = 'agenda/item';
this.id = id; if (input) {
this.item_number = item_number; this.deserialize(input);
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;
} }
public getSpeakers(): User[] { 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); 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); Object.assign(this, input);
if (input.speakers instanceof Array) { if (input.speakers instanceof Array) {
this.speakers = input.speakers.map(speakerData => { this.speakers = input.speakers.map(speakerData => {
return new Speaker().deserialize(speakerData); return new Speaker(speakerData);
}); });
} }
return this;
} }
} }

View File

@ -17,34 +17,15 @@ export class Speaker implements Deserializable {
/** /**
* Needs to be completely optional because agenda has (yet) the optional parameter 'speaker' * Needs to be completely optional because agenda has (yet) the optional parameter 'speaker'
* @param id * @param input
* @param user_id
* @param begin_time
* @param end_time
* @param weight
* @param marked
* @param item_id
*/ */
public constructor( public constructor(input?: any) {
id?: number, if (input) {
user_id?: number, this.deserialize(input);
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 deserialize(input: any): this { public deserialize(input: any): void {
Object.assign(this, input); Object.assign(this, input);
return this;
} }
} }

View File

@ -13,22 +13,15 @@ export class AssignmentUser implements Deserializable {
/** /**
* Needs to be completely optional because assignment has (yet) the optional parameter 'assignment_related_users' * Needs to be completely optional because assignment has (yet) the optional parameter 'assignment_related_users'
* @param id * @param input
* @param user_id
* @param elected
* @param assignment_id
* @param weight
*/ */
public constructor(id?: number, user_id?: number, elected?: boolean, assignment_id?: number, weight?: number) { public constructor(input?: any) {
this.id = id; if (input) {
this.user_id = user_id; this.deserialize(input);
this.elected = elected; }
this.assignment_id = assignment_id;
this.weight = weight;
} }
public deserialize(input: any): this { public deserialize(input: any): void {
Object.assign(this, input); Object.assign(this, input);
return this;
} }
} }

View File

@ -21,30 +21,15 @@ export class Assignment extends BaseModel {
public agenda_item_id: number; public agenda_item_id: number;
public tags_id: number[]; public tags_id: number[];
public constructor( public constructor(input?: any) {
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[]
) {
super(); super();
this._collectionString = 'assignments/assignment'; this._collectionString = 'assignments/assignment';
this.id = id; this.assignment_related_users = []; // TODO Array
this.title = title; this.polls = Array(); // TODO Array
this.description = description;
this.open_posts = open_posts; if (input) {
this.phase = phase; this.deserialize(input);
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;
} }
public getAssignmentReleatedUsers(): BaseModel | BaseModel[] { public getAssignmentReleatedUsers(): BaseModel | BaseModel[] {
@ -59,23 +44,22 @@ export class Assignment extends BaseModel {
return this.DS.getMany<Tag>('core/tag', this.tags_id); return this.DS.getMany<Tag>('core/tag', this.tags_id);
} }
public deserialize(input: any): this { public deserialize(input: any): void {
Object.assign(this, input); Object.assign(this, input);
if (input.assignment_related_users instanceof Array) { if (input.assignment_related_users instanceof Array) {
this.assignment_related_users = []; this.assignment_related_users = [];
input.assignment_related_users.forEach(assignmentUserData => { 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) { if (input.polls instanceof Array) {
this.polls = []; this.polls = [];
input.polls.forEach(pollData => { input.polls.forEach(pollData => {
this.polls.push(new Poll().deserialize(pollData)); this.polls.push(new Poll(pollData));
}); });
} }
return this;
} }
} }

View File

@ -16,31 +16,15 @@ export class PollOption implements Deserializable {
/** /**
* Needs to be completely optional because poll has (yet) the optional parameter 'poll-options' * Needs to be completely optional because poll has (yet) the optional parameter 'poll-options'
* @param id * @param input
* @param candidate_id
* @param is_elected
* @param votes
* @param poll_id
* @param weight
*/ */
public constructor( public constructor(input?: any) {
id?: number, if (input) {
candidate_id?: number, this.deserialize(input);
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 deserialize(input: any): this { public deserialize(input: any): void {
Object.assign(this, input); Object.assign(this, input);
return this;
} }
} }

View File

@ -19,50 +19,23 @@ export class Poll implements Deserializable {
/** /**
* Needs to be completely optional because assignment has (yet) the optional parameter 'polls' * Needs to be completely optional because assignment has (yet) the optional parameter 'polls'
* @param id * @param input
* @param pollmethod
* @param description
* @param published
* @param options
* @param votesvalid
* @param votesinvalid
* @param votescast
* @param has_votes
* @param assignment_id
*/ */
public constructor( public constructor(input?: any) {
id?: number, this.options = [new PollOption()];
pollmethod?: string, if (input) {
description?: string, this.deserialize(input);
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 deserialize(input: any): this { public deserialize(input: any): void {
Object.assign(this, input); Object.assign(this, input);
if (input.options instanceof Array) { if (input.options instanceof Array) {
this.options = []; this.options = [];
input.options.forEach(pollOptionData => { input.options.forEach(pollOptionData => {
this.options.push(new PollOption().deserialize(pollOptionData)); this.options.push(new PollOption(pollOptionData));
}); });
} }
return this;
} }
} }

View File

@ -57,8 +57,7 @@ export abstract class BaseModel extends OpenSlidesComponent implements Deseriali
* Inherited to children, can be overwritten for special use cases * Inherited to children, can be overwritten for special use cases
* @param input JSON data for deserialization. * @param input JSON data for deserialization.
*/ */
public deserialize(input: any): this { public deserialize(input: any): void {
Object.assign(this, input); Object.assign(this, input);
return this;
} }
} }

View File

@ -1,4 +1,5 @@
import { BaseModel } from '../base.model'; import { BaseModel } from '../base.model';
import { User } from '../users/user';
/** /**
* Representation of chat messages. * Representation of chat messages.
@ -11,17 +12,16 @@ export class ChatMessage extends BaseModel {
public timestamp: string; // TODO: Type for timestamp public timestamp: string; // TODO: Type for timestamp
public user_id: number; public user_id: number;
public constructor(id?: number, message?: string, timestamp?: string, user_id?: number) { public constructor(input?: any) {
super(); super();
this._collectionString = 'core/chat-message'; this._collectionString = 'core/chat-message';
this.id = id; if (input) {
this.message = message; this.deserialize(input);
this.timestamp = timestamp; }
this.user_id = user_id;
} }
public getUser(): BaseModel | BaseModel[] { public getUser(): User {
return this.DS.get('users/user', this.user_id); return this.DS.get<User>('users/user', this.user_id);
} }
} }

View File

@ -10,12 +10,12 @@ export class Config extends BaseModel {
public key: string; public key: string;
public value: Object; public value: Object;
public constructor(id?: number, key?: string, value?: Object) { public constructor(input?: any) {
super(); super();
this._collectionString = 'core/config'; this._collectionString = 'core/config';
this.id = id; if (input) {
this.key = key; this.deserialize(input);
this.value = value; }
} }
} }

View File

@ -12,20 +12,12 @@ export class Countdown extends BaseModel {
public countdown_time: number; public countdown_time: number;
public running: boolean; public running: boolean;
public constructor( public constructor(input?: any) {
id?: number,
countdown_time?: number,
default_time?: number,
description?: string,
running?: boolean
) {
super(); super();
this._collectionString = 'core/countdown'; this._collectionString = 'core/countdown';
this.id = id; if (input) {
this.description = description; this.deserialize(input);
this.default_time = default_time; }
this.countdown_time = countdown_time;
this.running = running;
} }
} }

View File

@ -9,11 +9,12 @@ export class ProjectorMessage extends BaseModel {
public id: number; public id: number;
public message: string; public message: string;
public constructor(id?: number, message?: string) { public constructor(input?: any) {
super(); super();
this._collectionString = 'core/projector-message'; this._collectionString = 'core/projector-message';
this.id = id; if (input) {
this.message = message; this.deserialize(input);
}
} }
} }

View File

@ -16,28 +16,12 @@ export class Projector extends BaseModel {
public height: number; public height: number;
public projectiondefaults: Object[]; public projectiondefaults: Object[];
public constructor( public constructor(input?: any) {
id?: number,
elements?: Object,
scale?: number,
scroll?: number,
name?: string,
blank?: boolean,
width?: number,
height?: number,
projectiondefaults?: Object[]
) {
super(); super();
this._collectionString = 'core/projector'; this._collectionString = 'core/projector';
this.id = id; if (input) {
this.elements = elements; this.deserialize(input);
this.scale = scale; }
this.scroll = scroll;
this.name = name;
this.blank = blank;
this.width = width;
this.height = height;
this.projectiondefaults = projectiondefaults;
} }
} }

View File

@ -9,11 +9,12 @@ export class Tag extends BaseModel {
public id: number; public id: number;
public name: string; public name: string;
public constructor(id?: number, name?: string) { public constructor(input?: any) {
super(); super();
this._collectionString = 'core/tag'; this._collectionString = 'core/tag';
this.id = id; if (input) {
this.name = name; this.deserialize(input);
}
} }
} }

View File

@ -2,12 +2,16 @@
* Interface tells models to offer a 'deserialize' function * Interface tells models to offer a 'deserialize' function
* *
* Also nested objects and arrays have have to be handled. * 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 { export interface Deserializable {
/** /**
* should be used to assign JSON values to the object itself. * should be used to assign JSON values to the object itself.
* @param input * @param input
*/ */
deserialize(input: any): this; deserialize(input: any): void;
} }

View File

@ -13,13 +13,13 @@ export class File implements Deserializable {
* @param name The name of the file * @param name The name of the file
* @param type The tape (jpg, png, pdf) * @param type The tape (jpg, png, pdf)
*/ */
public constructor(name?: string, type?: string) { public constructor(input?: any) {
this.name = name; if (input) {
this.type = type; this.deserialize(input);
}
} }
public deserialize(input: any): this { public deserialize(input: any): void {
Object.assign(this, input); Object.assign(this, input);
return this;
} }
} }

View File

@ -1,5 +1,6 @@
import { BaseModel } from '../base.model'; import { BaseModel } from '../base.model';
import { File } from './file'; import { File } from './file';
import { User } from '../users/user';
/** /**
* Representation of MediaFile. Has the nested property "File" * Representation of MediaFile. Has the nested property "File"
@ -16,36 +17,21 @@ export class Mediafile extends BaseModel {
public hidden: boolean; public hidden: boolean;
public timestamp: string; public timestamp: string;
public constructor( public constructor(input?: any) {
id?: number,
title?: string,
mediafile?: File,
media_url_prefix?: string,
uploader_id?: number,
filesize?: string,
hidden?: boolean,
timestamp?: string
) {
super(); super();
this._collectionString = 'mediafiles/mediafile'; this._collectionString = 'mediafiles/mediafile';
this.id = id; if (input) {
this.title = title; this.deserialize(input);
this.mediafile = mediafile; }
this.media_url_prefix = media_url_prefix;
this.uploader_id = uploader_id;
this.filesize = filesize;
this.hidden = hidden;
this.timestamp = timestamp;
} }
public deserialize(input: any): this { public deserialize(input: any): void {
Object.assign(this, input); Object.assign(this, input);
this.mediafile = new File().deserialize(input.mediafile); this.mediafile = new File(input.mediafile);
return this;
} }
public getUploader(): BaseModel | BaseModel[] { public getUploader(): User {
return this.DS.get('users/user', this.uploader_id); return this.DS.get<User>('users/user', this.uploader_id);
} }
} }

View File

@ -10,12 +10,12 @@ export class Category extends BaseModel {
public name: string; public name: string;
public prefix: string; public prefix: string;
public constructor(id?: number, name?: string, prefix?: string) { public constructor(input?: any) {
super(); super();
this._collectionString = 'motions/category'; this._collectionString = 'motions/category';
this.id = id; if (input) {
this.name = name; this.deserialize(input);
this.prefix = prefix; }
} }
public toString = (): string => { public toString = (): string => {

View File

@ -10,12 +10,12 @@ export class MotionBlock extends BaseModel {
public title: string; public title: string;
public agenda_item_id: number; public agenda_item_id: number;
public constructor(id?: number, title?: string, agenda_item_id?: number) { public constructor(input?: any) {
super(); super();
this._collectionString = 'motions/motion-block'; this._collectionString = 'motions/motion-block';
this.id = id; if (input) {
this.title = title; this.deserialize(input);
this.agenda_item_id = agenda_item_id; }
} }
public getAgenda(): BaseModel | BaseModel[] { public getAgenda(): BaseModel | BaseModel[] {

View File

@ -16,28 +16,12 @@ export class MotionChangeReco extends BaseModel {
public text: string; public text: string;
public creation_time: string; public creation_time: string;
public constructor( public constructor(input?: any) {
id?: number,
motion_version_id?: number,
rejected?: boolean,
type?: number,
other_description?: string,
line_from?: number,
line_to?: number,
text?: string,
creation_time?: string
) {
super(); super();
this._collectionString = 'motions/motion-change-recommendation'; this._collectionString = 'motions/motion-change-recommendation';
this.id = id; if (input) {
this.motion_version_id = motion_version_id; this.deserialize(input);
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;
} }
} }

View File

@ -11,15 +11,13 @@ export class MotionLog implements Deserializable {
public time: string; public time: string;
public message: string; public message: string;
public constructor(message_list?: string[], person_id?: number, time?: string, message?: string) { public constructor(input?: any) {
this.message_list = message_list; if (input) {
this.person_id = person_id; this.deserialize(input);
this.time = time; }
this.message = message;
} }
public deserialize(input: any): this { public deserialize(input: any): void {
Object.assign(this, input); Object.assign(this, input);
return this;
} }
} }

View File

@ -11,15 +11,13 @@ export class MotionSubmitter implements Deserializable {
public motion_id: number; public motion_id: number;
public weight: number; public weight: number;
public constructor(id?: number, user_id?: number, motion_id?: number, weight?: number) { public constructor(input?: any) {
this.id = id; if (input) {
this.user_id = user_id; this.deserialize(input);
this.motion_id = motion_id; }
this.weight = weight;
} }
public deserialize(input: any): this { public deserialize(input: any): void {
Object.assign(this, input); Object.assign(this, input);
return this;
} }
} }

View File

@ -14,26 +14,17 @@ export class MotionVersion implements Deserializable {
public amendment_paragraphs: string; public amendment_paragraphs: string;
public reason: string; public reason: string;
public constructor( public constructor(input?: any) {
id?: number, this.title = '';
version_number?: number, this.text = '';
creation_time?: string, this.reason = '';
title?: string,
text?: string, if (input) {
amendment_paragraphs?: string, this.deserialize(input);
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 deserialize(input: any): this { public deserialize(input: any): void {
Object.assign(this, input); Object.assign(this, input);
return this;
} }
} }

View File

@ -44,49 +44,20 @@ export class Motion extends BaseModel {
public title: string; public title: string;
public text: string; public text: string;
public constructor( public constructor(input?: any) {
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[]
) {
super(); super();
this._collectionString = 'motions/motion'; this._collectionString = 'motions/motion';
this.id = id; this.identifier = '';
this.identifier = identifier || ''; this.versions = [new MotionVersion()];
this.versions = versions || [new MotionVersion()]; this.origin = '';
this.active_version = active_version; this.submitters = [];
this.parent_id = parent_id; this.supporters_id = [];
this.category_id = category_id; this.state_required_permission_to_see = '';
this.motion_block_id = motion_block_id; this.log_messages = [];
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 || [];
if (input) {
this.deserialize(input);
}
this.initDataStoreValues(); this.initDataStoreValues();
} }
@ -124,7 +95,8 @@ export class Motion extends BaseModel {
* @param user the user * @param user the user
*/ */
public addSubmitter(user: 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); this.submitters.push(newSubmitter);
console.log('did addSubmitter. this.submitters: ', this.submitters); 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); Object.assign(this, input);
if (input.versions instanceof Array) { if (input.versions instanceof Array) {
this.versions = []; this.versions = [];
input.versions.forEach(motionVersionData => { input.versions.forEach(motionVersionData => {
this.versions.push(new MotionVersion().deserialize(motionVersionData)); this.versions.push(new MotionVersion(motionVersionData));
}); });
} }
if (input.submitters instanceof Array) { if (input.submitters instanceof Array) {
this.submitters = []; this.submitters = [];
input.submitters.forEach(SubmitterData => { input.submitters.forEach(SubmitterData => {
this.submitters.push(new MotionSubmitter().deserialize(SubmitterData)); this.submitters.push(new MotionSubmitter(SubmitterData));
}); });
} }
if (input.log_messages instanceof Array) { if (input.log_messages instanceof Array) {
this.log_messages = []; this.log_messages = [];
input.log_messages.forEach(logData => { input.log_messages.forEach(logData => {
this.log_messages.push(new MotionLog().deserialize(logData)); this.log_messages.push(new MotionLog(logData));
}); });
} }
return this;
} }
} }

View File

@ -27,57 +27,12 @@ export class WorkflowState implements Deserializable {
/** /**
* Needs to be completely optional because Workflow has (yet) the optional parameter 'states' * Needs to be completely optional because Workflow has (yet) the optional parameter 'states'
* @param id * @param input If given, it will be deserialized
* @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
*/ */
public constructor( public constructor(input?: any) {
id?: number, if (input) {
name?: string, this.deserialize(input);
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;
} }
/** /**
@ -94,9 +49,8 @@ export class WorkflowState implements Deserializable {
return nextStates; return nextStates;
} }
public deserialize(input: any): this { public deserialize(input: any): void {
Object.assign(this, input); Object.assign(this, input);
return this;
} }
public toString = (): string => { public toString = (): string => {

View File

@ -12,13 +12,12 @@ export class Workflow extends BaseModel {
public states: WorkflowState[]; public states: WorkflowState[];
public first_state: number; public first_state: number;
public constructor(id?: number, name?: string, states?: WorkflowState[], first_state?: number) { public constructor(input?: any) {
super(); super();
this._collectionString = 'motions/workflow'; this._collectionString = 'motions/workflow';
this.id = id; if (input) {
this.name = name; this.deserialize(input);
this.states = states; }
this.first_state = first_state;
} }
/** /**
@ -50,15 +49,14 @@ export class Workflow extends BaseModel {
return targetState as WorkflowState; return targetState as WorkflowState;
} }
public deserialize(input: any): this { public deserialize(input: any): void {
Object.assign(this, input); Object.assign(this, input);
if (input.states instanceof Array) { if (input.states instanceof Array) {
this.states = []; this.states = [];
input.states.forEach(workflowStateData => { input.states.forEach(workflowStateData => {
this.states.push(new WorkflowState().deserialize(workflowStateData)); this.states.push(new WorkflowState(workflowStateData));
}); });
} }
return this;
} }
} }

View File

@ -14,14 +14,12 @@ export class Topic extends BaseModel {
public attachments_id: number[]; public attachments_id: number[];
public agenda_item_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(); super();
this._collectionString = 'topics/topic'; this._collectionString = 'topics/topic';
this.id = id; if (input) {
this.title = title; this.deserialize(input);
this.text = text; }
this.attachments_id = attachments_id;
this.agenda_item_id = agenda_item_id;
} }
public getAttachments(): Mediafile[] { public getAttachments(): Mediafile[] {

View File

@ -11,12 +11,12 @@ export class Group extends BaseModel {
public name: string; public name: string;
public permissions: string[]; public permissions: string[];
public constructor(id?: number, name?: string, permissions?: string[]) { public constructor(input?: any) {
super(); super();
this._collectionString = 'users/group'; this._collectionString = 'users/group';
this.id = id; if (input) {
this.name = name; this.deserialize(input);
this.permissions = permissions; }
} }
public get users() { public get users() {

View File

@ -1,4 +1,5 @@
import { BaseModel } from '../base.model'; import { BaseModel } from '../base.model';
import { User } from './user';
/** /**
* Representation of users personal note. * Representation of users personal note.
@ -10,16 +11,16 @@ export class PersonalNote extends BaseModel {
public user_id: number; public user_id: number;
public notes: Object; public notes: Object;
public constructor(id?: number, user_id?: number, notes?: Object) { public constructor(input: any) {
super(); super();
this._collectionString = 'users/personal-note'; this._collectionString = 'users/personal-note';
this.id = id; if (input) {
this.user_id = user_id; this.deserialize(input);
this.notes = notes; }
} }
public getUser(): BaseModel | BaseModel[] { public getUser(): User {
return this.DS.get('users/user', this.user_id); return this.DS.get<User>('users/user', this.user_id);
} }
} }

View File

@ -24,42 +24,13 @@ export class User extends BaseModel {
public is_active: boolean; public is_active: boolean;
public default_password: string; public default_password: string;
public constructor( public constructor(input?: any) {
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
) {
super(); super();
this._collectionString = 'users/user'; this._collectionString = 'users/user';
this.id = id;
this.username = username; if (input) {
this.title = title; this.deserialize(input);
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;
} }
public get groups(): Group[] { public get groups(): Group[] {

View File

@ -106,13 +106,10 @@ export class MotionDetailComponent extends BaseComponent implements OnInit {
* Async load the values of the motion in the Form. * Async load the values of the motion in the Form.
*/ */
public patchForm(formMotion: Motion) { public patchForm(formMotion: Motion) {
console.log('Motion: ', this.motion);
console.log('category_id: ', formMotion);
this.metaInfoForm.patchValue({ this.metaInfoForm.patchValue({
category_id: formMotion.category.id, category_id: formMotion.category_id,
state_id: formMotion.state.id, state_id: formMotion.state_id,
recommendation_id: formMotion.recommendation.id, recommendation_id: formMotion.recommendation_id,
identifier: formMotion.identifier, identifier: formMotion.identifier,
origin: formMotion.origin origin: formMotion.origin
}); });

View File

@ -80,18 +80,18 @@ export class StartComponent extends BaseComponent implements OnInit {
*/ */
public DataStoreTest() { public DataStoreTest() {
console.log('add a user to dataStore'); 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'); 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'); console.log('use the spread operator "..." to add an array');
const userArray = []; const userArray = [];
for (let i = 300; i < 400; i++) { for (let i = 300; i < 400; i++) {
userArray.push(new User(i)); userArray.push(new User({ id: i }));
} }
this.DS.add(...userArray); this.DS.add(...userArray);
console.log('try to get user with ID 1:'); 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('the user: ', user1fromStore);
console.log('remove a single user:'); console.log('remove a single user:');
@ -102,7 +102,7 @@ export class StartComponent extends BaseComponent implements OnInit {
this.DS.remove(User, ...[321, 363, 399]); this.DS.remove(User, ...[321, 363, 399]);
console.log('test filter: '); 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) { for (let i = 1; i <= requiredMotions; ++i) {
// version // version
const newMotionVersion = new MotionVersion( const newMotionVersion = new MotionVersion({
200 + i, id: 200 + i,
1, version_number: 1,
'now', create_time: 'now',
'GenMo ' + i, title: 'GenMo ' + i,
longMotionText, text: longMotionText,
null, reason: longMotionText
longMotionText });
);
// submitter // 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 // motion
const newMotion = new Motion( const newMotion = new Motion({
200 + i, id: 200 + i,
'GenMo ' + i, identifier: 'GenMo ' + i,
[newMotionVersion], versions: [newMotionVersion],
null, origin: 'Generated',
null, submitters: [newMotionSubmitter],
null, state_id: 1
null, });
'Generated',
[newMotionSubmitter],
null,
null,
1
);
newMotionsArray.push(newMotion); newMotionsArray.push(newMotion);
} }
this.DS.add(...newMotionsArray); this.DS.add(...newMotionsArray);