transmettre l'information d'expiration du sondage au front

This commit is contained in:
Tykayn 2021-04-26 12:00:20 +02:00 committed by tykayn
parent 1e90d92ab9
commit 163b89b03f
8 changed files with 141 additions and 99 deletions

View File

@ -5,6 +5,7 @@ export class Choice {
constructor(
public id: number,
public name: string,
public enabled: boolean,
public imageUrl?: string,
public participants: Map<Answer, Set<User>> = new Map<Answer, Set<User>>([
[Answer.YES, new Set<User>()],

View File

@ -6,41 +6,59 @@ import { PollConfiguration } from './configuration.model';
import { User } from './user.model';
export class Poll {
constructor(
public owner: User = new User(),
public urlPublic: string = '',
public slug: string = '',
public id: number = 0,
public default_expiracy_days_from_now: number = 60,
public title: string = '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 allowSeveralHours?: boolean,
public archiveNumberOfDays?: number,
public configuration: PollConfiguration = new PollConfiguration(),
public comments: Comment[] = [],
public choices: Choice[] = [],
public votes = [],
public stacks_of_votes = [],
public allowed_answers = [],
public modification_policy = [],
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
) {}
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 configuration: PollConfiguration = new PollConfiguration();
public comments: Comment[] = [];
public choices: Choice[] = [];
public votes = [];
public stacks_of_votes = [];
public allowed_answers = [];
public modification_policy = [];
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: User = new User(), public urlPublic: string = '', public slug: string = '') {}
public static adaptFromLocalJsonServer(
item: Pick<Poll, 'owner' | 'title' | 'description' | 'slug' | 'configuration' | 'comments' | 'choices'>
): Poll {
return new Poll(
new User(item.owner.pseudo, item.owner.email, undefined),
item.slug,
item.title,
item.description
''
// item.slug,
// item.title,
// item.description
// item.configuration,
// item.comments
// .map(

View File

@ -153,14 +153,6 @@ export class ApiService {
const adapterInterceptor: number = this.axiosInstance.interceptors.response.use(
(response: AxiosResponse): AxiosResponse => {
console.log('response', response);
if (response.data['poll']) {
// response from cipherbliss backend, actually used by oldstuffModule
response.data = response.data['poll'];
} else if (response.data[0] && response.data[0]['slug'] && response.data[0]['question']) {
// response from local json-server
response.data = Poll.adaptFromLocalJsonServer(response.data[0]);
}
return response;
}
);

View File

@ -137,9 +137,9 @@ export class PollService implements Resolve<Poll> {
public saveParticipation(choice: Choice, user: User, response: Answer): void {
const currentPoll = this._poll.getValue();
currentPoll.choices.find((c) => c.label === choice.label)?.updateParticipation(user, response);
currentPoll.choices.find((c) => c.name === choice.name)?.updateParticipation(user, response);
this.updateCurrentPoll(currentPoll);
this.apiService.createParticipation(currentPoll.slug, choice.label, user.pseudo, response);
this.apiService.createParticipation(currentPoll.slug, choice.name, user.pseudo, response);
this.toastService.display('Votre participation au sondage a été enregistrée.');
}
@ -174,7 +174,7 @@ export class PollService implements Resolve<Poll> {
pseudo,
new Map<string, Answer>(
poll.choices.map((choice: Choice) => {
return [choice.label, undefined];
return [choice.name, undefined];
})
)
);
@ -183,7 +183,7 @@ export class PollService implements Resolve<Poll> {
poll.choices.forEach((choice: Choice) => {
choice.participants.forEach((users: Set<User>, answer: Answer) => {
users.forEach((user: User) => {
list.get(user.pseudo).set(choice.label, answer);
list.get(user.pseudo).set(choice.name, answer);
});
});
});

View File

@ -11,6 +11,11 @@
aucun vote pour le moment
</div>
</article>
<article class="message is-info" *ngIf="poll.modification_policy == 'self'">
<div class="message-body">
Vous ne pouvez modifier que votre propre vote à ce sondage
</div>
</article>
<!-- actions-->
@ -32,15 +37,19 @@
<h3 class="margin-top-x6 margin-btm-x3">
Exporter/Imprimer
</h3>
<button class="export export-csv" (click)="exportCSV()">
<button class="replicate export-csv btn" (click)="duplicate()">
<i class="fa fa-copy" aria-hidden="true"></i>
Dupliquer
</button>
<button class="export export-csv btn" (click)="exportCSV()">
<i class="fa fa-file-calc-o" aria-hidden="true"></i>
Exporter en .csv
</button>
<button class="btn btn--primary" (click)="exportJson()">
<button class="export export-json btn" (click)="exportJson()">
<i class="fa fa-file-archive-o" aria-hidden="true"></i>
export json
</button>
<button class="export export-print" (click)="print()">
<button class="export export-print btn" (click)="print()">
<i class="fa fa-print"></i>
Imprimer le sondage
</button>
@ -83,7 +92,7 @@
</div>
</div>
<div class="bar-votestack">
<div class="bar-votestack" *ngIf="!isArchived">
<button
class="btn btn-block submit-votestack"
(click)="addVoteStack()"

View File

@ -44,6 +44,7 @@ export class ConsultationComponent implements OnInit, OnDestroy {
this.poll = newpoll;
if (newpoll) {
this.isArchived = new Date(newpoll.expiracy_date) < new Date();
this.poll.is_archived = this.isArchived;
}
});
@ -161,4 +162,12 @@ export class ConsultationComponent implements OnInit, OnDestroy {
document.body.removeChild(element);
}
duplicate() {
alert('TODO');
}
print() {
alert('TODO');
}
}

View File

@ -22,6 +22,10 @@
<img class="image is-24x24" src="../../../assets/img/icon_voter_MAYBE.svg" />
<!-- {{ choice.counts.get(answerEnum.MAYBE) }}-->
</button>
<button class="button is-white" *ngIf="poll.allowed_answers.indexOf('no') !== -1">
<img class="image is-24x24" src="../../../assets/img/icon_voter_NO.svg" />
<!-- {{ choice.counts.get(answerEnum.MAYBE) }}-->
</button>
</div>
</div>
</div>

View File

@ -1,67 +1,76 @@
<div class="comments" id="comments">
<h2 class="margin-top-x7">Laisser un commentaire</h2>
<article class="message">
<div class="message-header">
<div class="field">
<span class="control has-icons-left has-icons-right">
<input
type="email"
name="cremail"
id="email_comment"
[(ngModel)]="config.myEmail"
placeholder="chuck@norris.com"
required="required"
/>
<span class="icon is-small is-left">
<i class="fa fa-envelope"></i>
<div class="comments padded" id="comments">
<section class="add-comment" *ngIf="!poll.is_archived">
<h2 class="margin-top-x7">Laisser un commentaire</h2>
<article class="message">
<div class="message-header">
<div class="field">
<span class="control has-icons-left has-icons-right">
<input
type="email"
name="cremail"
id="email_comment"
[(ngModel)]="config.myEmail"
placeholder="chuck@norris.com"
required="required"
/>
<span class="icon is-small is-left">
<i class="fa fa-envelope"></i>
</span>
</span>
</span>
<span class="control has-icons-left">
<input
type="text"
class="margin-btm-x3"
name="crname"
[(ngModel)]="config.myName"
id="crname"
placeholder="pseudo"
required="required"
/>
<span class="icon is-small is-left">
<i class="fa fa-user"></i>
<span class="control has-icons-left">
<input
type="text"
class="margin-btm-x3"
name="crname"
[(ngModel)]="config.myName"
id="crname"
placeholder="pseudo"
required="required"
/>
<span class="icon is-small is-left">
<i class="fa fa-user"></i>
</span>
</span>
</span>
</div>
<!-- <label for="crname"><i class="fa fa-user" aria-hidden="true"></i> Votre nom / pseudo :</label>-->
<!-- <label for="cremail"><i class="fa fa-envelope" aria-hidden="true"></i> Votre email :</label>-->
</div>
<div class="message-body">
<label for="comment">Votre commentaire :</label>
<br />
<textarea name="comment" id="comment" [(ngModel)]="config.myComment"> </textarea>
<!-- <label for="crname"><i class="fa fa-user" aria-hidden="true"></i> Votre nom / pseudo :</label>-->
<input
type="submit"
name="add-comment"
class="btn btn--primary btn--outline"
value="Ajouter mon commentaire ✉️"
(click)="addComment()"
/>
</div>
</article>
</section>
<div class="message-body" *ngIf="poll.is_archived">
⚰️ Ce sondage a expiré, il n'est plus possible d'y ajouter de votes ou de commentaires
</div>
<!-- <label for="cremail"><i class="fa fa-envelope" aria-hidden="true"></i> Votre email :</label>-->
</div>
<div class="message-body">
<label for="comment">Votre commentaire :</label>
<br />
<textarea name="comment" id="comment" [(ngModel)]="config.myComment"> </textarea>
<input
type="submit"
name="add-comment"
class="btn btn--primary btn--outline"
value="Ajouter mon commentaire ✉️"
(click)="addComment()"
/>
</div>
</article>
<div class="comments-part" *ngIf="poll && poll.comments">
<h2 class="title is-2">{{ poll.comments.length }} Commentaires</h2>
<section class="comments-part" *ngIf="poll && poll.comments">
<h2 class="title is-2">
<i class="fa fa-comment"></i>
{{ poll.comments.length }} Commentaires
</h2>
<article class="message" *ngFor="let comment of poll.comments">
<div class="message-header">
<p>
<em class="cname"> {{ comment.pseudo }} </em>, le
<span class="date-days-ago">
<em class="cname"> {{ comment.pseudo }} </em>,
<span class="date-days-ago is-small">
il y a
{{ calculateDaysAgoOfComment(comment.owner.created_at) }} jours, le </span
><span class="date"> {{ comment.owner.created_at }} </span>
><span class="date is-small"> {{ comment.owner.created_at }} </span>
</p>
</div>
<div class="message-body">
@ -70,5 +79,5 @@
</p>
</div>
</article>
</div>
</section>
</div>