diff --git a/src/app/features/consultation/consultation.component.html b/src/app/features/consultation/consultation.component.html index 0277c06d..236c8e51 100644 --- a/src/app/features/consultation/consultation.component.html +++ b/src/app/features/consultation/consultation.component.html @@ -1,159 +1,28 @@
- - -
-
- {{ 'participation.poll_expired' | translate }} -
-
-
-
- {{ 'participation.you_are_admin' | translate }} -
-
- -
-
- {{ 'participation.edit_only_self' | translate }} -
-
- - - - - - -
-
-
-
-
-
-

{{ poll.title }}

-

{{ poll.description }}

-
- {{ poll.stacks.length }} - {{ 'participation.voters' | translate }} -
-

- {{ 'participation.author' | translate }} {{ poll.owner?.pseudo }} -

-
-
- -
-
-
- -
-
-
-
- -
-
- -
- - -
-
-
- -
- - -
- - -
+
+
+
+
+

+ {{ poll.title }} +

- - -
-
-
- aucun vote pour le moment -
-
-
- -
- - -
- -
-
- -
- Ce sondage ne permet pas d'ajouter de commentaires -
-
-
- - -
- - -
-
- Ce sondage est archivé
+ +

+ {{ poll.description }} +

+
+
+

loading ...

+
+
diff --git a/src/app/features/consultation/consultation.component.ts b/src/app/features/consultation/consultation.component.ts index dbd84ccc..dba37e08 100644 --- a/src/app/features/consultation/consultation.component.ts +++ b/src/app/features/consultation/consultation.component.ts @@ -15,17 +15,14 @@ import { ToastService } from '../../core/services/toast.service'; styleUrls: ['./consultation.component.scss'], }) export class ConsultationComponent implements OnInit, OnDestroy { - // public isCompactMode = false; - public isCompactMode = true; - public poll: Poll; - public pollSlug: string; - public pass_hash: string; public fetching = true; - public isArchived: boolean; - public isAdmin: boolean; private routeSubscription: Subscription; window: any; + private isArchived: boolean; + private poll: Poll; + private pollSlug: string; + private pass_hash: string; constructor( private router: Router, @@ -47,8 +44,6 @@ 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; - this.isAdmin = this.poll.admin_key !== null; this.poll.choices_grouped.map((elem) => (elem.subSetToYes = false)); } }); @@ -83,60 +78,7 @@ export class ConsultationComponent implements OnInit, OnDestroy { } } - /** - * update existing vote stack - * @param Stack - */ - updateVoteStack(): void { - const vote_stack = this.storageService.vote_stack; - vote_stack.poll_custom_url = this.poll.custom_url; - - console.log('updateVoteStack vote_stack.votes', vote_stack.votes.length, vote_stack.votes); - const handlingError = this.api.ousideHandleError; - - this.api - .sendUpdateVoteStack(vote_stack) - .then((resp) => { - console.log('sendUpdateVoteStack updated resp', resp); - this.storeVoteStackAndReloadPoll(resp); - this.toastService.display('vote bien mis à jour', 'success'); - }) - .catch(handlingError); - } - - /** - * create a new vote stack - */ - addVoteStack(): void { - this.storageService.vote_stack.poll_custom_url = this.poll.custom_url; - this.pollService.pass_hash = this.pass_hash; - - this.toastService.display('envoi du vote ....'); - this.api - .sendNewVoteStackOfPoll(this.storageService.vote_stack) - .then((resp: any) => { - console.log('sendNewVoteStackOfPoll resp', resp); - this.storeVoteStackAndReloadPoll(resp); - }) - // eslint-disable-next-line @typescript-eslint/unbound-method - .catch(this.api.ousideHandleError); - } - - /** - * store the updated vote stack - * @param voteStack - */ - storeVoteStackAndReloadPoll(voteStack: any) { - if (voteStack.status == 200) { - this.storageService.mapVotes(voteStack.data); - this.pollService.enrichVoteStackWithCurrentPollChoicesDefaultVotes(this.storageService.vote_stack); - if (this.pass_hash) { - this.pollService.loadPollByCustomUrlWithPasswordHash(this.poll.custom_url, this.pass_hash); - } else { - this.pollService.loadPollByCustomUrl(this.poll.custom_url); - } - } else { - this.toastService.display('erreur à l enregistrement'); - } + displayOptions() { + alert('TODO'); } } diff --git a/src/app/features/consultation/consultation.module.ts b/src/app/features/consultation/consultation.module.ts index 8a5c44d3..ad73ace5 100644 --- a/src/app/features/consultation/consultation.module.ts +++ b/src/app/features/consultation/consultation.module.ts @@ -16,6 +16,7 @@ import { ConsultationUserComponent } from './consultation-user/consultation-user import { SuccessComponent } from './success/success.component'; import { AdministrationModule } from '../administration/administration.module'; import { EditComponent } from './edit/edit.component'; +import { ResultsRoundedComponent } from './results-rounded/results-rounded.component'; @NgModule({ declarations: [ @@ -28,6 +29,7 @@ import { EditComponent } from './edit/edit.component'; ConsultationUserComponent, SuccessComponent, EditComponent, + ResultsRoundedComponent, ], imports: [ CommonModule, diff --git a/src/app/features/consultation/poll-results-compact/poll-results-compact.component.html b/src/app/features/consultation/poll-results-compact/poll-results-compact.component.html index e46a048a..fbe52f18 100644 --- a/src/app/features/consultation/poll-results-compact/poll-results-compact.component.html +++ b/src/app/features/consultation/poll-results-compact/poll-results-compact.component.html @@ -9,7 +9,7 @@ > - {{ showAsDate(group.date_string) | date: 'fullDate':'Europe/Paris':'fr_FR' }} + {{ showAsDate(group.date_string) | date: 'fullDate':'Europe/Paris':'fr' }}
diff --git a/src/app/features/consultation/results-rounded/results-rounded.component.html b/src/app/features/consultation/results-rounded/results-rounded.component.html new file mode 100644 index 00000000..0277c06d --- /dev/null +++ b/src/app/features/consultation/results-rounded/results-rounded.component.html @@ -0,0 +1,159 @@ +
+ + +
+
+ {{ 'participation.poll_expired' | translate }} +
+
+
+
+ {{ 'participation.you_are_admin' | translate }} +
+
+ +
+
+ {{ 'participation.edit_only_self' | translate }} +
+
+ + + + + + +
+
+
+
+
+
+

{{ poll.title }}

+

{{ poll.description }}

+
+ {{ poll.stacks.length }} + {{ 'participation.voters' | translate }} +
+

+ {{ 'participation.author' | translate }} {{ poll.owner?.pseudo }} +

+
+
+ +
+
+
+ +
+
+
+
+ +
+
+ +
+ + +
+
+
+ +
+ + +
+ + +
+
+ + +
+
+
+ aucun vote pour le moment +
+
+
+ +
+ + +
+ +
+
+ +
+ Ce sondage ne permet pas d'ajouter de commentaires +
+
+
+ + +
+ + +
+
+ Ce sondage est archivé +
+
+
+
+
diff --git a/src/app/features/consultation/results-rounded/results-rounded.component.scss b/src/app/features/consultation/results-rounded/results-rounded.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/src/app/features/consultation/results-rounded/results-rounded.component.spec.ts b/src/app/features/consultation/results-rounded/results-rounded.component.spec.ts new file mode 100644 index 00000000..58664e6d --- /dev/null +++ b/src/app/features/consultation/results-rounded/results-rounded.component.spec.ts @@ -0,0 +1,24 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ResultsRoundedComponent } from './results-rounded.component'; + +describe('ResultsRoundedComponent', () => { + let component: ResultsRoundedComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ResultsRoundedComponent], + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ResultsRoundedComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/features/consultation/results-rounded/results-rounded.component.ts b/src/app/features/consultation/results-rounded/results-rounded.component.ts new file mode 100644 index 00000000..0592ffbb --- /dev/null +++ b/src/app/features/consultation/results-rounded/results-rounded.component.ts @@ -0,0 +1,141 @@ +import { Component, OnInit } from '@angular/core'; +import { Poll } from '../../../core/models/poll.model'; +import { Subscription } from 'rxjs'; +import { ActivatedRoute, ParamMap, Router } from '@angular/router'; +import { PollUtilitiesService } from '../../../core/services/poll.utilities.service'; +import { StorageService } from '../../../core/services/storage.service'; +import { ApiService } from '../../../core/services/api.service'; +import { PollService } from '../../../core/services/poll.service'; +import { DateService } from '../../../core/services/date.service'; +import { ToastService } from '../../../core/services/toast.service'; + +@Component({ + selector: 'app-results-rounded', + templateUrl: './results-rounded.component.html', + styleUrls: ['./results-rounded.component.scss'], +}) +export class ResultsRoundedComponent implements OnInit { + // public isCompactMode = false; + public isCompactMode = true; + public poll: Poll; + public pollSlug: string; + public pass_hash: string; + public fetching = true; + public isArchived: boolean; + public isAdmin: boolean; + + private routeSubscription: Subscription; + window: any; + + constructor( + private router: Router, + private utils: PollUtilitiesService, + private _Activatedroute: ActivatedRoute, + public storageService: StorageService, + public api: ApiService, + public pollService: PollService, + public dateService: DateService, + public toastService: ToastService + ) {} + + /** + * fetch poll data on init + */ + ngOnInit(): void { + console.log('constultation de poll'); + this.pollService.poll.subscribe((newpoll: Poll) => { + this.poll = newpoll; + if (newpoll) { + this.isArchived = new Date(newpoll.expiracy_date) < new Date(); + this.poll.is_archived = this.isArchived; + this.isAdmin = this.poll.admin_key !== null; + this.poll.choices_grouped.map((elem) => (elem.subSetToYes = false)); + } + }); + + this._Activatedroute.paramMap.subscribe((params: ParamMap) => { + console.log('params _Activatedroute', params); + this.pollSlug = params.get('custom_url'); + this.pass_hash = params.get('pass_hash'); + + console.log('this.pass_hash ', this.pass_hash); + if (this.pass_hash) { + this.pollService.loadPollByCustomUrlWithPasswordHash(this.pollSlug, this.pass_hash).then((resp) => { + console.log('loadPollByCustomUrlWithPasswordHash resp', resp); + this.fetching = false; + this.storageService.vote_stack.id = null; + this.storageService.setChoicesForVoteStack(this.pollService._poll.getValue().choices); + }); + } else { + this.pollService.loadPollByCustomUrl(this.pollSlug).then((resp) => { + console.log('loadPollByCustomUrl resp', resp); + this.fetching = false; + this.storageService.vote_stack.id = null; + this.storageService.setChoicesForVoteStack(this.pollService._poll.getValue().choices); + }); + } + }); + } + + ngOnDestroy(): void { + if (this.routeSubscription) { + this.routeSubscription.unsubscribe(); + } + } + /** + * update existing vote stack + * @param Stack + */ + updateVoteStack(): void { + const vote_stack = this.storageService.vote_stack; + vote_stack.poll_custom_url = this.poll.custom_url; + + console.log('updateVoteStack vote_stack.votes', vote_stack.votes.length, vote_stack.votes); + const handlingError = this.api.ousideHandleError; + + this.api + .sendUpdateVoteStack(vote_stack) + .then((resp) => { + console.log('sendUpdateVoteStack updated resp', resp); + this.storeVoteStackAndReloadPoll(resp); + this.toastService.display('vote bien mis à jour', 'success'); + }) + .catch(handlingError); + } + + /** + * create a new vote stack + */ + addVoteStack(): void { + this.storageService.vote_stack.poll_custom_url = this.poll.custom_url; + this.pollService.pass_hash = this.pass_hash; + + this.toastService.display('envoi du vote ....'); + this.api + .sendNewVoteStackOfPoll(this.storageService.vote_stack) + .then((resp: any) => { + console.log('sendNewVoteStackOfPoll resp', resp); + this.storeVoteStackAndReloadPoll(resp); + }) + // eslint-disable-next-line @typescript-eslint/unbound-method + .catch(this.api.ousideHandleError); + } + + /** + * store the updated vote stack + * @param voteStack + */ + storeVoteStackAndReloadPoll(voteStack: any) { + if (voteStack.status == 200) { + this.storageService.mapVotes(voteStack.data); + this.pollService.enrichVoteStackWithCurrentPollChoicesDefaultVotes(this.storageService.vote_stack); + if (this.pass_hash) { + this.pollService.loadPollByCustomUrlWithPasswordHash(this.poll.custom_url, this.pass_hash); + } else { + this.pollService.loadPollByCustomUrl(this.poll.custom_url); + } + } else { + this.toastService.display('erreur à l enregistrement'); + } + } +}