From 67cc41fccec24403fca67114fdc097b45cd0a107 Mon Sep 17 00:00:00 2001 From: Findeton Date: Sat, 22 Jun 2024 10:49:04 -0500 Subject: [PATCH] wip --- app.js | 9 +++++ avBooth/booth-directive/booth-directive.js | 41 +++++++++++++++------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/app.js b/app.js index c69ac889..acfb0a31 100755 --- a/app.js +++ b/app.js @@ -214,6 +214,15 @@ angular.module('voting-booth').config( isPreview: true } }) + .state('election.booth-preview', { + url: '/:id/uuid-preview-vote', + templateUrl: 'avBooth/booth.html', + controller: "BoothController", + params: { + isPreview: true, + isUuidPreview: true + } + }) .state('election.public.show.home.simple', { template: '
' }) diff --git a/avBooth/booth-directive/booth-directive.js b/avBooth/booth-directive/booth-directive.js index 77b4384b..c5de8f65 100644 --- a/avBooth/booth-directive/booth-directive.js +++ b/avBooth/booth-directive/booth-directive.js @@ -24,6 +24,7 @@ angular.module('avBooth') $rootScope, $timeout, $window, + $location, Authmethod, ConfigService, HmacService, @@ -44,6 +45,7 @@ angular.module('avBooth') // demo booth scope.isDemo = (attrs.isDemo === "true"); scope.isPreview = (attrs.isPreview === "true"); + scope.isUuidPreview = (attrs.isUuidPreview === "true"); scope.documentation = ConfigService.documentation; scope.hasSeenStartScreenInThisSession = false; @@ -888,21 +890,34 @@ angular.module('avBooth') var futureResult = $q.defer(); try { if (scope.isPreview) { - var previewElection = JSON.parse(scope.previewElection || sessionStorage.getItem(parseInt(attrs.electionId))); - var foundElection = previewElection.find( - function (element) {return element.id === parseInt(electionId); - }); - - if (foundElection) { - var ballotBoxData = ElectionCreation.generateBallotBoxResponse(foundElection); - futureResult.resolve({ - data: { - payload: ballotBoxData - } - }); + var previewResult = $q.defer(); + if (scope.isUuidPreview) { + var uuid = $location.search().uuid; + Authmethod.getLivePreview(uuid) + .then(function onSuccess(response) { + previewResult.resolve(JSON.parse(response.data)); + }, previewResult.reject) } else { - futureResult.reject("election not found"); + previewResult.resolve(JSON.parse(scope.previewElection || sessionStorage.getItem(parseInt(attrs.electionId)))); } + + futureResult + .then(function onSuccess(previewElection) { + var foundElection = previewElection.find( + function (element) {return element.id === parseInt(electionId); + }); + + if (foundElection) { + var ballotBoxData = ElectionCreation.generateBallotBoxResponse(foundElection); + futureResult.resolve({ + data: { + payload: ballotBoxData + } + }); + } else { + futureResult.reject("election not found"); + } + }, futureResult.reject); } else { var electionPromise = $http.get( scope.baseUrl + "election/" + electionId,