89 lines
2.4 KiB
TypeScript
89 lines
2.4 KiB
TypeScript
import { environment } from 'src/environments/environment';
|
|
|
|
import { Choice } from './choice.model';
|
|
import { Comment } from './comment.model';
|
|
import { PollConfiguration } from './configuration.model';
|
|
import { Owner } from './owner.model';
|
|
|
|
export class Poll {
|
|
public id = 0;
|
|
|
|
public default_expiracy_days_from_now = 60;
|
|
|
|
public title = 'mon titre';
|
|
|
|
public kind: string;
|
|
|
|
public description?: string;
|
|
|
|
public custom_url?: string;
|
|
|
|
public expiracy_date?: string;
|
|
|
|
public creation_date?: string;
|
|
|
|
public creatorPseudo?: string;
|
|
|
|
public creatorEmail?: string;
|
|
|
|
public is_archived?: boolean;
|
|
public allowSeveralHours?: boolean;
|
|
|
|
public archiveNumberOfDays?: number;
|
|
public max_score?: number;
|
|
|
|
public configuration: PollConfiguration = new PollConfiguration();
|
|
|
|
public comments: Comment[] = [];
|
|
|
|
public choices: Choice[] = [];
|
|
|
|
public votes = [];
|
|
|
|
public stacks = [];
|
|
|
|
public allowed_answers = [];
|
|
|
|
public modification_policy = 'everybody';
|
|
|
|
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
|
|
constructor(public owner: Owner = new Owner(), public urlPublic: string = '', public slug: string = '') {}
|
|
|
|
public static adaptFromLocalJsonServer(
|
|
item: Pick<Poll, 'owner' | 'title' | 'description' | 'slug' | 'configuration' | 'comments' | 'choices'>
|
|
): Poll {
|
|
return new Poll(
|
|
new Owner(item.owner.pseudo, item.owner.email, undefined),
|
|
''
|
|
// item.slug,
|
|
// item.title,
|
|
// 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' | 'url' | 'participants' | 'counts'>) => {
|
|
// const choice = new Choice(c.label, c.url, new Map(c.participants));
|
|
// choice.participants.forEach((value, key) => {
|
|
// choice.participants.set(key, new Set(value));
|
|
// });
|
|
// choice.updateCounts();
|
|
// return choice;
|
|
// })
|
|
);
|
|
}
|
|
|
|
public getAdministrationUrl(): string {
|
|
return `${environment.api.baseHref}/administration/polls/${this.slug}`;
|
|
}
|
|
|
|
public getParticipationUrl(): string {
|
|
return `${environment.api.baseHref}/participation/polls/${this.slug}`;
|
|
}
|
|
}
|