mirror of
https://github.com/abdellahaski/AngularFirebaseVotingApp.git
synced 2025-12-08 11:19:56 +00:00
Compare commits
3 Commits
335bbf6387
...
d95afba826
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d95afba826 | ||
|
|
37706f2716 | ||
|
|
1314b9a822 |
@@ -13,7 +13,7 @@ export class LocalStorageService {
|
||||
}
|
||||
|
||||
public getData(key: string) {
|
||||
let data = localStorage.getItem(key)|| "";
|
||||
let data = localStorage.getItem(key) || "";
|
||||
return this.decrypt(data);
|
||||
}
|
||||
public removeData(key: string) {
|
||||
|
||||
@@ -21,18 +21,18 @@ export class VotesService {
|
||||
return this.voteRef;
|
||||
}
|
||||
getVotesCount(): Observable<number> {
|
||||
return this.voteRef.snapshotChanges().pipe(map(c=>{return c.length}));
|
||||
return this.voteRef.snapshotChanges().pipe(map(c => { return c.length }));
|
||||
|
||||
}
|
||||
|
||||
addVote(vote: Vote): void {
|
||||
this.voteRef.add({...vote});
|
||||
this.voteRef.add({ ...vote });
|
||||
}
|
||||
vote(candidateID: number): void {
|
||||
|
||||
vote(candidateID: number): void {
|
||||
try {
|
||||
this.ipGeoLocationService.getIP().subscribe((IPData: any) => {
|
||||
const vote:Vote = {
|
||||
const vote: Vote = {
|
||||
candidate: candidateID,
|
||||
timestamp: new Date(),
|
||||
ip: IPData.ip_address,
|
||||
@@ -42,7 +42,7 @@ export class VotesService {
|
||||
this.addVote(vote);
|
||||
});
|
||||
} catch (e) {
|
||||
const vote:Vote = {
|
||||
const vote: Vote = {
|
||||
candidate: candidateID,
|
||||
timestamp: new Date(),
|
||||
city: 'unknown',
|
||||
@@ -51,9 +51,6 @@ export class VotesService {
|
||||
};
|
||||
this.addVote(vote);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { map, Observable } from 'rxjs';
|
||||
import { map } from 'rxjs';
|
||||
import { CandidatesService } from '../services/candidates.service';
|
||||
import { Candidate } from '../models/candidate.model';
|
||||
import { VotesService } from '../services/votes.service';
|
||||
@@ -17,15 +17,7 @@ export class VotingComponent implements OnInit {
|
||||
candidates!: any[];
|
||||
groupedCandidates: Candidate[][] = [];
|
||||
groupedVotedCandidates: number[] = [];;
|
||||
votedGroups: number[] = [];
|
||||
votesCount: number=0;
|
||||
public candidatestoshow: any;
|
||||
public rows!: Observable<any[]>;
|
||||
private currentVoteID: any;
|
||||
primes!: number[];
|
||||
items: any;
|
||||
totalVoteData: any;
|
||||
downloadJsonHref: any;
|
||||
candidatesCount: number = 0;
|
||||
|
||||
|
||||
@@ -74,13 +66,11 @@ export class VotingComponent implements OnInit {
|
||||
if(this.groupedVotedCandidates[candidate.group] == undefined)
|
||||
{
|
||||
this.groupedVotedCandidates[candidate.group] = candidate.candidateID;
|
||||
//candidate.votes++;
|
||||
//candidate.votes++;//not needed since the votes are updated in realtime once changed on the firestore DB
|
||||
this.candidatesService.addVote(candidate);
|
||||
this.voteService.vote(candidate.candidateID);
|
||||
}
|
||||
|
||||
this.localStorageService.saveData('groupedVotedCandidates',JSON.stringify(this.groupedVotedCandidates));
|
||||
|
||||
}
|
||||
|
||||
getCandidateClass(group: number, id: number) {
|
||||
|
||||
Reference in New Issue
Block a user