Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Findeton committed Jun 22, 2024
1 parent 2b9c7aa commit 67cc41f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
9 changes: 9 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<div ave-simple-question></div>'
})
Expand Down
41 changes: 28 additions & 13 deletions avBooth/booth-directive/booth-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ angular.module('avBooth')
$rootScope,
$timeout,
$window,
$location,
Authmethod,
ConfigService,
HmacService,
Expand All @@ -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;

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 67cc41f

Please sign in to comment.