Commit b2803e65 authored by Leonardo Piccioni de Almeida's avatar Leonardo Piccioni de Almeida
Browse files

Refactor data fetching to child components

parent 0c1e54ba
......@@ -8,27 +8,61 @@
controller: RoleParticipationReportCtrl,
bindings: {
date: '<',
roles: '<',
total: '<',
cities: '<',
networks: '<',
ntes: '<',
redes: '<',
cities: '<'
},
});
RoleParticipationReportCtrl.$inject = ['$scope'];
RoleParticipationReportCtrl.$inject = ['$scope', 'RoleParticipationReport'];
function RoleParticipationReportCtrl ($scope) {
function RoleParticipationReportCtrl ($scope, RoleParticipationReport) {
var ctrl = this;
ctrl.city = '';
ctrl.fetchRoles = fetchRoles;
ctrl.minimized = false;
ctrl.network = '';
ctrl.nte = '';
ctrl.roles = null;
ctrl.toggleDetails = toggleDetails;
ctrl.total = null;
ctrl.$onInit = function() {
ctrl.$onChanges = function() {
fetchRoles();
};
function fetchRoles() {
var params = { date: ctrl.date };
if (ctrl.city) {
}
if (ctrl.network) {
}
if (ctrl.nte) {
}
RoleParticipationReport.get(params, (data) => {
ctrl.roles = data;
ctrl.roles.$promise = undefined;
ctrl.roles.$resolved = undefined;
ctrl.total = { actives: 0, not_actives: 0, not_involved: 0, total: 0 };
Object.values(ctrl.roles).forEach((role) => {
if (role !== undefined) {
ctrl.total.actives += role.actives;
ctrl.total.not_actives += role.not_actives;
ctrl.total.not_involved += role.not_involved;
ctrl.total.total += role.actives + role.not_actives + role.not_involved;
}
});
});
}
function toggleDetails() {
ctrl.minimized = !ctrl.minimized;
}
......
......@@ -18,27 +18,13 @@
var ctrl = this;
ctrl.date = new Date();
ctrl.filters = null;
ctrl.formatDate = formatDate;
ctrl.formattedDate = formatDate(ctrl.date);
ctrl.report_filters = null;
ctrl.$onInit = function() {
GeneralFilterOptions.get({}, (data) =>{
ctrl.report_filters = data;
});
RoleParticipationReport.get({}, (data) => {
ctrl.roles_reports = data;
ctrl.roles_reports.$promise = undefined; ctrl.roles_reports.$resolved = undefined;
ctrl.roles_total = {'actives': 0, 'not_actives': 0, 'not_involved': 0, 'total': 0}
Object.entries(ctrl.roles_reports).forEach(([role, participation]) => {
if (participation !== undefined) {
ctrl.roles_total['actives'] += participation.actives;
ctrl.roles_total['not_actives'] += participation.not_actives;
ctrl.roles_total['not_involved'] += participation.not_involved;
ctrl.roles_total['total'] += participation.actives + participation.not_actives + participation.not_involved;
}
});
ctrl.filters = data;
});
};
......
{% verbatim %}
<section class="widget container-fluid">
<section class="widget container-fluid" ng-if="$ctrl.roles">
<header class="widget-header">
<div class="row">
<div class="col-sm-12 col-md-12">
......@@ -18,15 +18,15 @@
<main class="widget-body" ng-if="!$ctrl.minimized">
<div class="filter-row">
<span>Filtre a lista:</span>
<select name="nte" aria-label="NTE">
<select name="nte" aria-label="NTE" ng-model="$ctrl.nte" ng-blur="$ctrl.fetchRoles()">
<option value="">Selecione o NTE</option>
<option ng-repeat="nte in $ctrl.ntes" ng-value="nte">{{ nte }}</option>
</select>
<select name="network" aria-label="Rede">
<select name="network" aria-label="Rede" ng-model="$ctrl.network" ng-blur="$ctrl.fetchRoles()">
<option value="">Selecione a Rede</option>
<option ng-repeat="rede in $ctrl.redes" ng-value="rede">{{ rede }}</option>
<option ng-repeat="network in $ctrl.networks" ng-value="network">{{ network }}</option>
</select>
<select name="city" aria-label="Município">
<select name="city" aria-label="Município" ng-model="$ctrl.city" ng-blur="$ctrl.fetchRoles()">
<option value="">Selecione o Município</option>
<option ng-repeat="city in $ctrl.cities" ng-value="city">{{ city }}</option>
</select>
......
......@@ -16,11 +16,11 @@
<user-participation-graphics-report date="$ctrl.formattedDate"></user-participation-graphics-report>
<city-participation-report-list ng-if="$ctrl.report_filters" date="$ctrl.formattedDate" roles="$ctrl.report_filters.funcoes"></city-participation-report-list>
<city-participation-report-list ng-if="$ctrl.filters" date="$ctrl.formattedDate" roles="$ctrl.filters.funcoes"></city-participation-report-list>
<classroom-participation-report date="$ctrl.formattedDate"></classroom-participation-report>
<role-participation-report teste="$ctrl.report_filters.ntes" roles="$ctrl.roles_reports" total="$ctrl.roles_total" ntes="$ctrl.report_filters.ntes" redes="$ctrl.report_filters.redes" cities="$ctrl.report_filters.municipios"></role-participation-report>
<role-participation-report ng-if="$ctrl.filters" date="$ctrl.formattedDate" cities="$ctrl.filters.municipios" networks="$ctrl.filters.redes" ntes="$ctrl.filters.ntes"></role-participation-report>
</div>
{% endverbatim %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment