2020-05-12 19:16:23 +02:00
|
|
|
import { environment } from 'src/environments/environment';
|
|
|
|
|
2020-05-05 18:17:12 +02:00
|
|
|
import { Choice } from './choice.model';
|
|
|
|
import { Comment } from './comment.model';
|
2020-10-29 18:43:19 +01:00
|
|
|
import { PollConfiguration } from './configuration.model';
|
2020-04-19 14:22:10 +02:00
|
|
|
import { User } from './user.model';
|
|
|
|
|
|
|
|
export class Poll {
|
2020-04-21 17:26:25 +02:00
|
|
|
constructor(
|
2020-11-05 19:13:43 +01:00
|
|
|
public owner: User = new User(),
|
2021-02-05 15:34:00 +01:00
|
|
|
public slug: string = '',
|
|
|
|
public title: string = '',
|
2020-05-12 19:16:23 +02:00
|
|
|
public description?: string,
|
2021-02-05 15:34:00 +01:00
|
|
|
public creatorPseudo?: string,
|
|
|
|
public creatorEmail?: string,
|
2021-02-05 23:03:49 +01:00
|
|
|
public allowSeveralHours?: boolean,
|
|
|
|
public archiveNumberOfDays?: number,
|
2020-10-29 18:43:19 +01:00
|
|
|
public configuration: PollConfiguration = new PollConfiguration(),
|
2020-05-12 19:16:23 +02:00
|
|
|
public comments: Comment[] = [],
|
2020-11-11 12:14:01 +01:00
|
|
|
public choices: Choice[] = [],
|
2021-04-24 12:52:51 +02:00
|
|
|
public votes = [],
|
2021-02-08 18:55:31 +01:00
|
|
|
public dateChoices: Choice[] = [], // sets of days as strings, config to set identical time for days in a special days poll
|
|
|
|
public timeChoices: Choice[] = [] // ranges of time expressed as strings
|
2020-04-21 17:26:25 +02:00
|
|
|
) {}
|
2020-05-12 19:16:23 +02:00
|
|
|
|
|
|
|
public getAdministrationUrl(): string {
|
|
|
|
return `${environment.api.baseHref}/administration/polls/${this.slug}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
public getParticipationUrl(): string {
|
|
|
|
return `${environment.api.baseHref}/participation/polls/${this.slug}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static adaptFromLocalJsonServer(
|
2020-10-29 18:43:19 +01:00
|
|
|
item: Pick<Poll, 'owner' | 'title' | 'description' | 'slug' | 'configuration' | 'comments' | 'choices'>
|
2020-05-12 19:16:23 +02:00
|
|
|
): Poll {
|
2020-11-03 15:44:08 +01:00
|
|
|
return new Poll(
|
2020-05-12 19:16:23 +02:00
|
|
|
new User(item.owner.pseudo, item.owner.email, undefined),
|
2020-06-16 18:40:48 +02:00
|
|
|
item.slug,
|
2020-10-29 18:43:19 +01:00
|
|
|
item.title,
|
2021-02-05 17:02:52 +01:00
|
|
|
item.description
|
|
|
|
// item.configuration,
|
|
|
|
// item.comments
|
|
|
|
// .map(
|
|
|
|
// (c: Pick<Comment, 'author' | 'content' | 'dateCreated'>) =>
|
|
|
|
// new Comment(c.author, c.content, new Date(c.dateCreated))
|
|
|
|
// )
|
|
|
|
// .sort(Comment.sortChronologically),
|
|
|
|
// item.choices.map((c: Pick<Choice, 'label' | 'imageUrl' | 'participants' | 'counts'>) => {
|
|
|
|
// const choice = new Choice(c.label, c.imageUrl, new Map(c.participants));
|
|
|
|
// choice.participants.forEach((value, key) => {
|
|
|
|
// choice.participants.set(key, new Set(value));
|
|
|
|
// });
|
|
|
|
// choice.updateCounts();
|
|
|
|
// return choice;
|
|
|
|
// })
|
2020-05-12 19:16:23 +02:00
|
|
|
);
|
|
|
|
}
|
2020-04-19 14:22:10 +02:00
|
|
|
}
|