<div ng-if="copy.fine_level() == 3">[% l('High') %]</div>
</div>
- <div class="flex-cell">[% l('Total Circs') %]</div>
+ <div class="flex-cell">
+ [% l('Total Circs') %]
+ <script type="text/ng-template" id="circ-popover.html">
+ <div ng-repeat="circ_count in circ_counts | orderBy:'year'">
+ {{circ_count.year}}: {{circ_count.count}}
+ </div>
+ </script>
+ <button type="button"
+ class="no-border glyphicon glyphicon-info-sign"
+ uib-popover-template="'circ-popover.html'"
+ popover-title="[% l('Annual Circ History') %]"
+ popover-trigger="'outsideClick'"
+ popover-placement="{{circ_popover_placement}}"
+ aria-label="[% l('Annual Circ History') %]"
+ ng-if="circ_counts && circ_counts.length">
+ </button>
+ </div>
<div class="flex-cell well">{{total_circs}}</div>
<div class="flex-cell">[% l('Duration Rule') %]</div>
$scope.total_circs = 0;
$scope.total_circs_this_year = 0;
$scope.total_circs_prev_year = 0;
+ $scope.circ_popover_placement = 'top';
if (!copyId) return;
egCore.pcrud.search('circbyyr',
{copy : copyId}, null, {atomic : true})
.then(function(counts) {
- $scope.circ_counts = counts;
+ var this_year = new Date().getFullYear();
+ var prev_year = this_year - 1;
- angular.forEach(counts, function(count) {
- $scope.total_circs += Number(count.count());
- });
+ $scope.circ_counts = counts.reduce(function(circ_counts, circbyyr) {
+ var count = Number(circbyyr.count());
+ var year = circbyyr.year();
- var this_year = counts.filter(function(c) {
- return c.year() == new Date().getFullYear();
- });
+ var index = circ_counts.findIndex(function(existing_count) {
+ return existing_count.year === year;
+ });
- $scope.total_circs_this_year = (function() {
- total = 0;
- if (this_year.length == 2) {
- total = (Number(this_year[0].count()) + Number(this_year[1].count()));
- } else if (this_year.length == 1) {
- total = Number(this_year[0].count());
+ if (index === -1) {
+ circ_counts.push({count: count, year: year});
+ } else {
+ circ_counts[index].count += count;
}
- return total;
- })();
- var prev_year = counts.filter(function(c) {
- return c.year() == new Date().getFullYear() - 1;
- });
-
- $scope.total_circs_prev_year = (function() {
- total = 0;
- if (prev_year.length == 2) {
- total = (Number(prev_year[0].count()) + Number(prev_year[1].count()));
- } else if (prev_year.length == 1) {
- total = Number(prev_year[0].count());
+ $scope.total_circs += count;
+ if (this_year === year) {
+ $scope.total_circs_this_year += count;
+ }
+ if (prev_year === year) {
+ $scope.total_circs_prev_year += count;
}
- return total;
- })();
+ return circ_counts;
+ }, []);
+
+ if ($scope.circ_counts.length > 15) {
+ $scope.circ_popover_placement = 'right';
+ }
});
}