stack of vote relié au formulaire de commentaire

This commit is contained in:
tykayn 2021-04-28 12:01:09 +02:00 committed by Baptiste Lemoine
parent 7a0061eeb1
commit 620a7b99fa
32 changed files with 132 additions and 109 deletions

View File

@ -2,7 +2,7 @@ import { Component, Input, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { SettingsComponent } from '../../../shared/components/settings/settings.component';
import { User } from '../../models/user.model';
import { Owner } from '../../models/owner.model';
import { ModalService } from '../../services/modal.service';
import { UserService } from '../../services/user.service';
import { environment } from '../../../../environments/environment';
@ -13,7 +13,7 @@ import { environment } from '../../../../environments/environment';
styleUrls: ['./header.component.scss'],
})
export class HeaderComponent implements OnInit {
public _user: Observable<User> = this.userService.user;
public _user: Observable<Owner> = this.userService.user;
public env = environment;
@Input() public appTitle: string = 'FramaDate Funky';
@Input() public appLogo: string;

View File

@ -1,5 +1,5 @@
import { Answer } from '../enums/answer.enum';
import { User } from './user.model';
import { Owner } from './owner.model';
export class Choice {
public id: number;
@ -13,10 +13,10 @@ export class Choice {
public maybe?: any;
constructor(
public participants: Map<Answer, Set<User>> = new Map<Answer, Set<User>>([
[Answer.YES, new Set<User>()],
[Answer.NO, new Set<User>()],
[Answer.MAYBE, new Set<User>()],
public participants: Map<Answer, Set<Owner>> = new Map<Answer, Set<Owner>>([
[Answer.YES, new Set<Owner>()],
[Answer.NO, new Set<Owner>()],
[Answer.MAYBE, new Set<Owner>()],
]),
public counts: Map<Answer, number> = new Map<Answer, number>([
[Answer.YES, 0],
@ -25,13 +25,13 @@ export class Choice {
])
) {}
public updateParticipation(user: User, responseType: Answer): void {
public updateParticipation(user: Owner, responseType: Answer): void {
this.removeParticipant(user);
this.participants.get(responseType).add(user);
this.updateCounts();
}
public removeParticipant(user: User): void {
public removeParticipant(user: Owner): void {
for (const responseType of Object.values(Answer)) {
if (this.participants.get(responseType).has(user)) {
this.participants.get(responseType).delete(user);

View File

@ -1,7 +1,7 @@
import { UserRole } from '../enums/user-role.enum';
import { Poll } from './poll.model';
export class User {
export class Owner {
constructor(
public pseudo: string = 'pseudo',
public email: string = 'example@example.com',

View File

@ -3,7 +3,7 @@ import { environment } from 'src/environments/environment';
import { Choice } from './choice.model';
import { Comment } from './comment.model';
import { PollConfiguration } from './configuration.model';
import { User } from './user.model';
import { Owner } from './owner.model';
export class Poll {
public id = 0;
@ -49,13 +49,13 @@ export class Poll {
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 = '') {}
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 User(item.owner.pseudo, item.owner.email, undefined),
new Owner(item.owner.pseudo, item.owner.email, undefined),
''
// item.slug,
// item.title,

View File

@ -0,0 +1,10 @@
import { Vote } from './vote.model';
import { Owner } from './owner.model';
export class Stack {
public id: number;
public pseudo: string = 'Choque Nourrice';
public comment: string = 'Le beau commentaire de Choque Nourrice';
public owner: Owner = new Owner();
public votes: Vote[];
}

View File

@ -0,0 +1,4 @@
export class Vote {
public choice_id: number;
public value: string; // valeur de réponse
}

View File

@ -5,7 +5,7 @@ import { BehaviorSubject, Observable, Subscription } from 'rxjs';
import { Answer } from '../enums/answer.enum';
import { Choice } from '../models/choice.model';
import { Poll } from '../models/poll.model';
import { User } from '../models/user.model';
import { Owner } from '../models/owner.model';
import { ApiService } from './api.service';
import { ToastService } from './toast.service';
import { UserService } from './user.service';
@ -136,7 +136,7 @@ export class PollService implements Resolve<Poll> {
}
}
public saveParticipation(choice: Choice, user: User, response: Answer): void {
public saveParticipation(choice: Choice, user: Owner, response: Answer): void {
const currentPoll = this._poll.getValue();
currentPoll.choices.find((c) => c.name === choice.name)?.updateParticipation(user, response);
this.updateCurrentPoll(currentPoll);
@ -162,8 +162,8 @@ export class PollService implements Resolve<Poll> {
public buildAnswersByChoiceLabelByPseudo(poll: Poll): Map<string, Map<string, Answer>> {
const pseudos: Set<string> = new Set();
poll.choices.forEach((choice: Choice) => {
// choice.voters.forEach((users: Set<User>) => {
// users.forEach((user: User) => {
// choice.voters.forEach((users: Set<Owner>) => {
// users.forEach((user: Owner) => {
// pseudos.add(user.pseudo);
// });
// });
@ -182,8 +182,8 @@ export class PollService implements Resolve<Poll> {
});
poll.choices.forEach((choice: Choice) => {
choice.participants.forEach((users: Set<User>, answer: Answer) => {
users.forEach((user: User) => {
choice.participants.forEach((users: Set<Owner>, answer: Answer) => {
users.forEach((user: Owner) => {
list.get(user.pseudo).set(choice.name, answer);
});
});

View File

@ -3,6 +3,7 @@ import { LocalStorage } from 'ngx-webstorage';
import { Language } from '../enums/language.enum';
import { Theme } from '../enums/theme.enum';
import { Stack } from '../models/stack.model';
@Injectable({
providedIn: 'root',
@ -18,5 +19,5 @@ export class StorageService {
public userPollsIds: string[];
@LocalStorage()
public pseudo: string;
public vote_stack: Stack = new Stack();
}

View File

@ -2,25 +2,25 @@ import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { UserRole } from '../enums/user-role.enum';
import { User } from '../models/user.model';
import { Owner } from '../models/owner.model';
import { ApiService } from './api.service';
@Injectable({
providedIn: 'root',
})
export class UserService {
public anonymous: User = new User('', '', [], UserRole.ANONYMOUS);
public anonymous: Owner = new Owner('', '', [], UserRole.ANONYMOUS);
private _user: BehaviorSubject<User> = new BehaviorSubject<User>(this.anonymous);
public readonly user: Observable<User> = this._user.asObservable();
private _user: BehaviorSubject<Owner> = new BehaviorSubject<Owner>(this.anonymous);
public readonly user: Observable<Owner> = this._user.asObservable();
constructor(private apiService: ApiService) {}
public updateUser(user: User): void {
public updateUser(user: Owner): void {
this._user.next(user);
}
public getCurrentUser(): User {
public getCurrentUser(): Owner {
return this._user.getValue();
}
@ -29,7 +29,7 @@ export class UserService {
}
public async getUserPolls(): Promise<void> {
const currentUser: User = this._user.getValue();
const currentUser: Owner = this._user.getValue();
currentUser.polls = await this.apiService.getPollsUrlsByUserEmail(currentUser.email);
this.updateUser(currentUser);
}

View File

@ -1,6 +1,10 @@
<section class="loading_poll" *ngIf="fetching"></section>
<section class="poll_loaded padded" *ngIf="!fetching && poll">
<!-- infos locales storage-->
mon pseudo : {{ storageService.vote_stack.pseudo }}
<!-- messages-->
<article class="message is-warning" *ngIf="isArchived">
<div class="message-body">
⚰️ Ce sondage a expiré, il n'est plus possible d'y ajouter de votes ou de commentaires
@ -88,7 +92,7 @@
</div>
<div class="columns">
<div class="column">
<app-comments [poll]="poll"></app-comments>
<app-comments [poll]="poll" [vote_stack]="storageService.vote_stack"></app-comments>
</div>
</div>

View File

@ -7,6 +7,7 @@ import { PollService } from '../../core/services/poll.service';
import { DateService } from '../../core/services/date.service';
import { PollUtilities } from '../old-stuff/config/PollUtilities';
import { Comment } from '../../core/models/comment.model';
import { StorageService } from '../../core/services/storage.service';
@Component({
selector: 'app-consultation',
@ -33,6 +34,7 @@ export class ConsultationComponent implements OnInit, OnDestroy {
private router: Router,
private utils: PollUtilities,
private _Activatedroute: ActivatedRoute,
public storageService: StorageService,
public pollService: PollService,
public dateService: DateService,
private modalService: ModalService

View File

@ -4,7 +4,7 @@ import { Answer } from 'src/app/core/enums/answer.enum';
import { Choice } from '../../../core/models/choice.model';
import { Poll } from '../../../core/models/poll.model';
import { User } from '../../../core/models/user.model';
import { Owner } from '../../../core/models/owner.model';
import { ModalService } from '../../../core/services/modal.service';
import { PollService } from '../../../core/services/poll.service';
import { ChoiceDetailsComponent } from '../../../shared/components/choice-details/choice-details.component';
@ -15,7 +15,7 @@ import { ChoiceDetailsComponent } from '../../../shared/components/choice-detail
styleUrls: ['./add-answer.component.scss'],
})
export class AddAnswerComponent {
@Input() user: User;
@Input() user: Owner;
@Input() poll: Poll;
@Input() choice: Choice;
public answerEnum = Answer;

View File

@ -1,7 +1,7 @@
import { Component, Input, OnInit } from '@angular/core';
import { Poll } from '../../../core/models/poll.model';
import { User } from '../../../core/models/user.model';
import { Owner } from '../../../core/models/owner.model';
@Component({
selector: 'app-answers',
@ -10,7 +10,7 @@ import { User } from '../../../core/models/user.model';
})
export class AnswersComponent implements OnInit {
@Input() poll: Poll;
@Input() user: User;
@Input() user: Owner;
constructor() {}

View File

@ -3,7 +3,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import { Observable, Subscription } from 'rxjs';
import { Poll } from '../../core/models/poll.model';
import { User } from '../../core/models/user.model';
import { Owner } from '../../core/models/owner.model';
import { ModalService } from '../../core/services/modal.service';
import { UserService } from '../../core/services/user.service';
import { SettingsComponent } from '../../shared/components/settings/settings.component';
@ -15,7 +15,7 @@ import { SettingsComponent } from '../../shared/components/settings/settings.com
})
export class ParticipationComponent implements OnInit, OnDestroy {
public poll: Poll;
public _user: Observable<User> = this.userService.user;
public _user: Observable<Owner> = this.userService.user;
private routeSubscription: Subscription;
constructor(

View File

@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { User } from '../../../core/models/user.model';
import { Owner } from '../../../core/models/owner.model';
import { UserService } from '../../../core/services/user.service';
@Component({
@ -10,7 +10,7 @@ import { UserService } from '../../../core/services/user.service';
styleUrls: ['./user-polls.component.scss'],
})
export class UserPollsComponent implements OnInit {
public _user: Observable<User> = this.userService.user;
public _user: Observable<Owner> = this.userService.user;
public isModalOpened = false;
public pollsAreLoaded = false;

View File

@ -1,62 +1,8 @@
<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 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>
</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>
<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>
<section class="comments-part" *ngIf="poll && poll.comments">
<section class="comments-part" *ngIf="!poll.is_archived && poll.comments">
<h2 class="title is-2">
<i class="fa fa-comment"></i>
{{ poll.comments.length }} Commentaires
@ -82,4 +28,57 @@
</div>
</article>
</section>
<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)]="vote_stack.owner.email"
placeholder="chuck@norris.com"
required="required"
/>
<span class="icon is-small is-left">
<i class="fa fa-envelope"></i>
</span>
</span>
<span class="control has-icons-left">
<input
type="text"
class="margin-btm-x3"
name="crname"
[(ngModel)]="vote_stack.pseudo"
id="crname"
placeholder="pseudo"
required="required"
/>
<span class="icon is-small is-left">
<i class="fa fa-user"></i>
</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)]="vote_stack.comment"> </textarea>
<input
type="submit"
name="add-comment"
class="btn btn--primary btn--outline"
value="Ajouter mon commentaire ✉️"
(click)="addComment()"
/>
</div>
</article>
</section>
</div>

View File

@ -1,6 +1,8 @@
import { Component, Input } from '@angular/core';
import { PollService } from '../../../core/services/poll.service';
import * as moment from 'moment';
import { Stack } from '../../../core/models/stack.model';
import { Poll } from '../../../core/models/poll.model';
@Component({
selector: 'app-comments',
@ -8,7 +10,8 @@ import * as moment from 'moment';
styleUrls: ['./comments.component.scss'],
})
export class CommentsComponent {
@Input() public poll: any;
@Input() public vote_stack: Stack;
@Input() public poll: Poll;
public config: any = {
myName: '',

View File

@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { MatDialogRef } from '@angular/material/dialog';
import { Subscription } from 'rxjs';
import { User } from '../../../core/models/user.model';
import { Owner } from '../../../core/models/owner.model';
import { UserService } from '../../../core/services/user.service';
@Component({
@ -11,7 +11,7 @@ import { UserService } from '../../../core/services/user.service';
styleUrls: ['./settings.component.scss'],
})
export class SettingsComponent implements OnInit {
public user: User;
public user: Owner;
private userSubscription: Subscription;
constructor(private userService: UserService, public dialogRef: MatDialogRef<SettingsComponent>) {}

View File

@ -1014,7 +1014,7 @@ msgid "Respond-to mail address"
msgstr "Chomlec'h postel respont"
#: .Installation.User
msgid "User"
msgid "Owner"
msgstr "Arveriad"
#: .Language+selector.Change+language

View File

@ -1031,7 +1031,7 @@ msgid "Respond-to mail address"
msgstr "Respon a l'adreça de correu"
#: .Installation.User
msgid "User"
msgid "Owner"
msgstr "Usuari"
#: .Language+selector.Change+language

View File

@ -1042,7 +1042,7 @@ msgstr ""
"werden)"
#: .Installation.User
msgid "User"
msgid "Owner"
msgstr "Datenbank-Benutzername"
#: .Language+selector.Change+language

View File

@ -1024,7 +1024,7 @@ msgid "Respond-to mail address"
msgstr "Email απάντησης"
#: .Installation.User
msgid "User"
msgid "Owner"
msgstr "Χρήστης"
#: .Language+selector.Change+language

View File

@ -1029,8 +1029,8 @@ msgid "Respond-to mail address"
msgstr "Respond-to mail address"
#: .Installation.User
msgid "User"
msgstr "User"
msgid "Owner"
msgstr "Owner"
#: .Language+selector.Change+language
msgid "Change language"

View File

@ -1043,7 +1043,7 @@ msgid "Respond-to mail address"
msgstr "Correo electrónico para \"responder a\""
#: .Installation.User
msgid "User"
msgid "Owner"
msgstr "Usuario"
#: .Language+selector.Change+language

View File

@ -1047,7 +1047,7 @@ msgid "Respond-to mail address"
msgstr "Mail de réponse"
#: .Installation.User
msgid "User"
msgid "Owner"
msgstr "Utilisateur·rice"
#: .Language+selector.Change+language

View File

@ -959,7 +959,7 @@ msgid "Respond-to mail address"
msgstr ""
#: .Installation.User
msgid "User"
msgid "Owner"
msgstr ""
#: .Language+selector.Change+language

View File

@ -1016,7 +1016,7 @@ msgid "Respond-to mail address"
msgstr "Correo electrónico para as respostas"
#: .Installation.User
msgid "User"
msgid "Owner"
msgstr "Persoa usuaria"
#: .Language+selector.Change+language

View File

@ -1024,7 +1024,7 @@ msgid "Respond-to mail address"
msgstr "Válasz e-mail cím"
#: .Installation.User
msgid "User"
msgid "Owner"
msgstr "Felhasználó"
#: .Language+selector.Change+language

View File

@ -1039,7 +1039,7 @@ msgid "Respond-to mail address"
msgstr "E-mail per le risposte"
#: .Installation.User
msgid "User"
msgid "Owner"
msgstr "Utente"
#: .Language+selector.Change+language

View File

@ -1020,7 +1020,7 @@ msgid "Respond-to mail address"
msgstr "Antwoordmail"
#: .Installation.User
msgid "User"
msgid "Owner"
msgstr "Gebruiker"
#: .Language+selector.Change+language

View File

@ -1040,7 +1040,7 @@ msgid "Respond-to mail address"
msgstr "Adreça de responsa"
#: .Installation.User
msgid "User"
msgid "Owner"
msgstr "Utilizaire"
#: .Language+selector.Change+language

View File

@ -1015,7 +1015,7 @@ msgid "Respond-to mail address"
msgstr "E-postadress för svar"
#: .Installation.User
msgid "User"
msgid "Owner"
msgstr "Användare"
#: .Language+selector.Change+language