Skip to content

Commit

Permalink
Merge branch 'balie-rewrite-poc'
Browse files Browse the repository at this point in the history
  • Loading branch information
hirviid committed Sep 25, 2023
2 parents 8497139 + 6f8e072 commit 6555f97
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 3 deletions.
73 changes: 71 additions & 2 deletions app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ angular
header: {
templateUrl: 'views/header.html'
}
}
},
params: {
forceAngularNavigation: false
},
})
.state('counter.main.error', {
redirectOnScan: true,
Expand Down Expand Up @@ -139,8 +142,74 @@ angular
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
})
.run(function(nfcService, eIDService) {
.run(function($rootScope, $state, $window, $location, nfcService, eIDService, counterService, appConfig) {
nfcService.init();
eIDService.init();

var runningInIframe = window !== window.parent;

$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
// Don't block any state changes if not running inside an iframe
if (!runningInIframe && appConfig.features && appConfig.features.balieV2) {
window.location.href = appConfig.features.balieV2 + toState.url;
return;
}

// Allow the first state change, because the initial page rendering is also a "state change".
if (fromState.name === '') {
return;
}

// Generate to and from paths with actual param values
var to = $state.href(toState.name, toParams, {absolute: false});
var from = $state.href(fromState.name, fromState, {absolute: false});

// Don't block any reloading of the same state.
// For example, after deleting an organizer from the overview list of organizers and the list reloads.
if (to === from) {
return;
}

if (runningInIframe && !toParams.forceAngularNavigation) {
// Block the state change and emit the new path to the parent window for further handling.
event.preventDefault();
window.parent.postMessage({
source: 'BALIE',
type: 'URL_CHANGED',
payload: {
path: to
}
}, '*');
}
});

function activeCounterListener() {
window.addEventListener('message', function(event) {
if (event.data.source === 'BALIE' && event.data.type === 'SET_COUNTER') {
var counterId = event.data.payload.counter.id;

counterService.getActive().then(function (activeCounter){
if (!activeCounter || activeCounter.actorId !== counterId) {
throw new Error('No counter selected');
}
}).catch(function () {
counterService.setActiveByActorId(counterId).then(function() {
$state.go('counter.main', {
forceAngularNavigation: true
});
});
});
}
});

window.parent.postMessage({
source: 'BALIE',
type: 'GET_COUNTER'
}, '*');
}

if (runningInIframe) {
activeCounterListener();
}
})
.constant('isJavaFXBrowser', navigator.userAgent.indexOf('JavaFX') > -1);
15 changes: 15 additions & 0 deletions app/scripts/counter/counter.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ function counterService($q, $http, $rootScope, $cookies, uitid, appConfig, momen
return deferred.promise;
};

service.setActiveByActorId = function (actorId) {
return service.getList().then(() => {
var counterFound = null;
angular.forEach(service.list, function(counter) {
if (counter.actorId === actorId) {
counterFound = counter;
}
});

if (counterFound) {
return service.setActive(counterFound);
}
});
};

/**
* @param {object} activeCounter
*
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/utilities/app.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function appController($rootScope, $location, $state, $stateParams, appConfig, u
app.user = undefined;
app.counter = undefined;
app.buildNumber = appConfig.buildNumber;

app.runningInIframe = window !== window.parent;

function browserEngineIsOlderThan(requiredEngineVersion){
var matches = navigator.userAgent.match(/(.*)\/(.*)$/);
Expand Down
15 changes: 15 additions & 0 deletions app/scripts/utilities/uitid.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function uitidService($q, $window, $http, appConfig) {
*/
uitId.getUser = function() {
var deferredUser = $q.defer();
var runningInIframe = window !== window.parent;

if (uitId.user) {
deferredUser.resolve(uitId.user);
Expand All @@ -37,9 +38,23 @@ function uitidService($q, $window, $http, appConfig) {
uitId.user.displayName = uitId.user.givenName || uitId.user.nick;

deferredUser.resolve(userData);

if (runningInIframe) {
window.parent.postMessage({
source: 'BALIE',
type: 'LOGIN',
}, '*');
}
}))
.error(function () {
deferredUser.reject();

if (runningInIframe) {
window.parent.postMessage({
source: 'BALIE',
type: 'LOGOUT',
}, '*');
}
});
}

Expand Down
3 changes: 3 additions & 0 deletions config.dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"insightsApiUrl": "https://balie-insights-proxy-test-auth-s4vvfnqwhq-ew.a.run.app/v1/",
"uivUrl": "https://test.uitinvlaanderen.be/",
"udbUrl": "https://test.uitdatabank.be/",
"features": {
"balieV2": ""
},
"contacts": [
{
"name": "Dender",
Expand Down

0 comments on commit 6555f97

Please sign in to comment.