funky-framadate-front/src/app/core/models/poll.model.ts

60 lines
2.0 KiB
TypeScript
Raw Normal View History

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';
import { User } from './user.model';
export class Poll {
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,
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-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),
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
);
}
}