Skip to content

Commit

Permalink
#149_adding_temporal_filter_Kundenportal Adding overview filter gesch…
Browse files Browse the repository at this point in the history
…aeftsjahre
  • Loading branch information
mcmpp committed Jan 16, 2024
1 parent b256248 commit c66ad56
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="geschaeftsjahre-dropdown" ng-show="showFilter">
<span ng-if="selectedGJ != 'Alle' && selectedGJ.jahr != 'Alle'" translate>Geschäftsjahr</span>
<span ng-if="selectedGJ === 'Alle' || selectedGJ.jahr === 'Alle'" translate>Geschäftsjahre</span>
<oo-dropdown
dropdown-id="geschaeftsjahre"
display-style="uib-dropdown"
values="geschaeftsjahre"
display-function="displayGeschaeftsjahre"
selected-function="selectGJ"
selected-prop="jahr"
selected-value="selectedGJ"
disabled="disabled">
</oo-dropdown>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
'use strict';

/**
*/
angular.module('openolitor-kundenportal')
.controller('OverviewfilterGeschaeftsjahreController', ['$scope', '$rootScope',
'ProjektModel', 'moment', '$cookies', '$location',
function($scope, $rootScope, ProjektModel, moment, $cookies, $location) {

const ALLE = {jahr:'Alle'};

$scope.showFilter = true;

var gjDisabled = $location.search().gjDisabled;
if (gjDisabled) {
$scope.showFilter = false;
}

var storeSelected = function(selected) {
var expireDate = new Date();
expireDate.setDate(expireDate.getDate() + 3650);
$cookies.put('gjFilterSelected', selected, {'expires' : expireDate});
};

var fetchSelected = function() {
return $cookies.get('gjFilterSelected');
};

ProjektModel.query({}, function(result) {
$scope.projekt = result;
ProjektModel.geschaeftsjahre({id: result.id}, function(gjL) {
$scope.geschaeftsjahre = gjL.reverse();
$scope.geschaeftsjahre.unshift(ALLE);
if(angular.isUndefined($scope.select)) {
//if no preselected value, check if
if(angular.isDefined($scope.selectCurrent) && false && !angular.isDefined(fetchSelected())) {
var thisYearsGJstart = moment().date($scope.projekt.geschaeftsjahrTag).month($scope.projekt.geschaeftsjahrMonat - 1);
if(moment().isBefore(thisYearsGJstart)) {
$scope.select = moment().year() - 1;
} else {
$scope.select = moment().year();
}
} else if(angular.isDefined($scope.selectCurrent)) {
var stored = fetchSelected();
if(angular.isDefined(stored)) {
$scope.select = stored;
}
}
}

if(angular.isDefined($scope.select)) {
$scope.geschaeftsjahre.forEach((item) => {
if($scope.select == item.jahr) {
$scope.selectGJ($scope.select, true);
}
});
} else {
//by default 'ALLE' is selected
$scope.selectGJ(ALLE.jahr, true);
}
});
});

$scope.displayGeschaeftsjahre = function(gj) {
var von = moment(gj.jahr + '-' + gj.monat + '-' + gj.tag);
var bis = moment(von);
bis.add(1, 'year');
bis.add(-1, 'day');
if(angular.isUndefined(gj.tag)) {
return gj.jahr;
} else {
return von.format('L') + ' - ' + bis.format('L');
}
};

$scope.selectGJ = function(gj, init) {
if(!$scope.showFilter) {
$scope.selectedFunct()();
return;
}
if(angular.isUndefined(init)) {
init = false;
}
$scope.selectedGJ = gj;
if(gj && gj != ALLE.jahr && (angular.isUndefined(gj.jahr) || gj.jahr != ALLE.jahr)) {
$scope.selectedFunct()((gj.jahr) ? gj.jahr : gj);
} else {
$scope.selectedFunct()();
}
if(angular.isDefined($scope.selectCurrent) || !init) {
storeSelected(angular.isDefined($scope.selectedGJ.jahr) ? $scope.selectedGJ.jahr : $scope.selectedGJ);
}
};
}
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

angular.module('openolitor-kundenportal').directive('ooOverviewfilterGeschaeftsjahre', [
function() {
return {
restrict: 'E',
replace: true,
scope: {
selectedFunct: '&',
select: '=?',
disabled: '=',
selectCurrent: '=?'
},
transclude: true,
templateUrl: 'scripts/util/overviewfiltergeschaeftsjahre/overviewfiltergeschaeftsjahre.controller.html',
controller: 'OverviewfilterGeschaeftsjahreController'
};
}
]);

0 comments on commit c66ad56

Please sign in to comment.