Skip to content

Commit

Permalink
Refactor/redesign results page.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsegura committed Dec 18, 2018
1 parent e3cf455 commit d246ae5
Show file tree
Hide file tree
Showing 16 changed files with 454 additions and 270 deletions.
109 changes: 82 additions & 27 deletions app/js/directives/droitsEligiblesList.js
@@ -1,23 +1,76 @@
'use strict';

var SmoothScroll = require('smooth-scroll');
var scroll = new SmoothScroll();

var mergeDroits = function(prestationsNationales, partenairesLocaux) {

var droits = _.values(prestationsNationales);
_.forEach(partenairesLocaux, function(partenaireLocal) {
droits = droits.concat(_.values(partenaireLocal.prestations));
});

droits.sort(function(a, b) {
return a.label < b.label ? -1 : 1;
});

return droits;
};

angular.module('ddsApp').controller('droitsEligiblesListCtrl', function($scope, TrampolineService) {

$scope.isNumber = _.isNumber;
$scope.isString = _.isString;
$scope.isBoolean = _.isBoolean;

$scope.$watch('droits', function(value) {
if (value) {
var list = mergeDroits(value.prestationsNationales, value.partenairesLocaux);
if ($scope.filter) {
list = _.filter(list, function(value) {

return _.includes($scope.filter, value.id);
});
}
$scope.list = list;
}
});

$scope.trampoline = TrampolineService;
$scope.isNumber = _.isNumber;
$scope.isString = _.isString;
$scope.list = [];

$scope.scrollTo = function(droit, $event) {
$event.preventDefault();
scroll.animateScroll(document.querySelector('#' + droit.id), $event.target, {
updateURL: false,
offset: function () {
return document.querySelector('header').offsetHeight;
}
});
};

$scope.scrollToTop = function($event) {
$event.preventDefault();
scroll.animateScroll(document.querySelector('body'), $event.target, {
updateURL: false
});
};

});

var controllerOptions = function(templateUrl) {
return function() {
return {
restrict: 'E',
templateUrl: templateUrl,
scope: true,
scope: {
droits: '=',
yearMoins2: '=',
filter: '=',
},
controller: 'droitsEligiblesListCtrl',
// Inject list into scope, filtered by benefits specified via the "filter" attribute
link: function ($scope, $element, $attributes) {
if ($attributes.hasOwnProperty('filter')) {
var filter = $scope.$eval($attributes.filter);
$scope.list = _.pickBy($scope.$eval($attributes.list), function(value, key) {
return _.includes(filter, key);
});
} else {
$scope.list = $scope.$eval($attributes.list);
}
}
};
};
};
Expand All @@ -26,20 +79,22 @@ angular.module('ddsApp')
.directive('droitEligiblesList', controllerOptions('/partials/droits-eligibles-list.html'));

angular.module('ddsApp')
.directive('droitNonEligiblesList', controllerOptions('/partials/droits-non-eligibles-list.html'));

angular.module('ddsApp').controller('droitsEligiblesListCtrl', function($scope, TrampolineService) {
$scope.isNumber = _.isNumber;
$scope.isString = _.isString;
$scope.shouldDisplayYM2Warning = function(droit) {
return droit.isBaseRessourcesYearMoins2 && ! $scope.ressourcesYearMoins2Captured && ! _.isString(droit.montant);
};
.directive('droitEligiblesDetails', controllerOptions('/partials/droits-eligibles-details.html'));

$scope.trampoline = TrampolineService;
angular.module('ddsApp')
.directive('droitNonEligiblesList', controllerOptions('/partials/droits-non-eligibles-list.html'));

// ng-class and uib-accordion don't work well together, hence this extra function.
// See https://github.com/angular-ui/bootstrap/issues/4172
$scope.getAccordionClass = function(droit) {
return [$scope.shouldDisplayYM2Warning(droit) ? 'needs-n-2' : '', droit.open ? 'panel-opened': ''].join(' ');
};
});
angular.module('ddsApp')
.directive('droitMontant', function() {
return {
restrict: 'E',
templateUrl: '/partials/droit-montant.html',
scope: {
droit: '=',
},
link: function(scope) {
scope.isNumber = _.isNumber;
scope.isString = _.isString;
}
};
});
2 changes: 1 addition & 1 deletion app/scripts.js
Expand Up @@ -29,7 +29,7 @@ require('./styles/enfants.css');
require('./styles/foyer/capture-montant-ressource.css');
require('./styles/foyer/capture-continuation-ressource.css');
require('./styles/recap-situation.css');
require('./styles/droits-eligibles-list.css');
require('./styles/droits-eligibles-list.scss');
require('./styles/breadcrumb.css');

require('./js/common.js');
Expand Down
62 changes: 0 additions & 62 deletions app/styles/droits-eligibles-list.css

This file was deleted.

0 comments on commit d246ae5

Please sign in to comment.