From 9e4c97e45b6e367842d21d2c0c5392f765a3ebee Mon Sep 17 00:00:00 2001
From: Andreas <6977712+AndreasK79@users.noreply.github.com>
Date: Sun, 14 Nov 2021 17:33:24 +0100
Subject: [PATCH] [Accumulated Statistics] Fixed when no QSOs found.
---
application/models/Accumulate_model.php | 4 +
assets/js/sections/accumulatedstatistics.js | 194 ++++++++++----------
2 files changed, 105 insertions(+), 93 deletions(-)
diff --git a/application/models/Accumulate_model.php b/application/models/Accumulate_model.php
index bf959cf6..914abb8e 100644
--- a/application/models/Accumulate_model.php
+++ b/application/models/Accumulate_model.php
@@ -8,6 +8,10 @@ class Accumulate_model extends CI_Model
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
+ if (!$logbooks_locations_array) {
+ return array();
+ }
+
$location_list = "'".implode("','",$logbooks_locations_array)."'";
switch ($award) {
diff --git a/assets/js/sections/accumulatedstatistics.js b/assets/js/sections/accumulatedstatistics.js
index 349a471a..aced301e 100644
--- a/assets/js/sections/accumulatedstatistics.js
+++ b/assets/js/sections/accumulatedstatistics.js
@@ -9,117 +9,125 @@ function accumulatePlot(form) {
var mode = form.mode.value;
var period = form.periodradio.value;
$.ajax({
- url: base_url+'index.php/accumulated/get_accumulated_data',
+ url: base_url + 'index.php/accumulated/get_accumulated_data',
type: 'post',
- data: {'Band': form.band.value, 'Award': award, 'Mode': mode, 'Period': period},
- success: function(data) {
- // used for switching award text in the table and the chart
- switch(award) {
- case 'dxcc': var awardtext = "DXCC\'s"; break;
- case 'was': var awardtext = "states";break;
- case 'iota': var awardtext = "IOTA\'s";break;
- case 'waz': var awardtext = "CQ zones"; break;
+ data: { 'Band': form.band.value, 'Award': award, 'Mode': mode, 'Period': period },
+ success: function (data) {
+ if (!$.trim(data)) {
+ $("#accumulateContainer").empty();
+ $("#accumulateContainer").append('
');
+ $(".ld-ext-right").removeClass('running');
+ $(".ld-ext-right").prop('disabled', false);
}
+ else {
+ // used for switching award text in the table and the chart
+ switch (award) {
+ case 'dxcc': var awardtext = "DXCC\'s"; break;
+ case 'was': var awardtext = "states"; break;
+ case 'iota': var awardtext = "IOTA\'s"; break;
+ case 'waz': var awardtext = "CQ zones"; break;
+ }
- var periodtext = 'Year';
- if (period == 'month') {
- periodtext += ' + month';
- }
- // removing the old chart so that it will not interfere when loading chart again
- $("#accumulateContainer").empty();
- $("#accumulateContainer").append("");
+ var periodtext = 'Year';
+ if (period == 'month') {
+ periodtext += ' + month';
+ }
+ // removing the old chart so that it will not interfere when loading chart again
+ $("#accumulateContainer").empty();
+ $("#accumulateContainer").append("");
- // appending table to hold the data
- $("#accumulateTable").append('' +
- '' +
- '| # | ' +
- '' + periodtext + ' | ' +
- 'Accumulated # of ' + awardtext + ' worked | '+
- '
' +
- '' +
- '
');
- var labels = [];
- var dataDxcc = [];
+ // appending table to hold the data
+ $("#accumulateTable").append('' +
+ '' +
+ '| # | ' +
+ '' + periodtext + ' | ' +
+ 'Accumulated # of ' + awardtext + ' worked | ' +
+ '
' +
+ '' +
+ '
');
+ var labels = [];
+ var dataDxcc = [];
- var $myTable = $('.accutable');
- var i = 1;
+ var $myTable = $('.accutable');
+ var i = 1;
- // building the rows in the table
- var rowElements = data.map(function ( row ) {
+ // building the rows in the table
+ var rowElements = data.map(function (row) {
- var $row = $('
');
+ var $row = $('
');
- var $iterator = $(' | ').html(i++);
- var $type = $(' | ').html(row.year);
- var $content = $(' | ').html(row.total);
+ var $iterator = $(' | ').html(i++);
+ var $type = $(' | ').html(row.year);
+ var $content = $(' | ').html(row.total);
- $row.append($iterator, $type, $content);
+ $row.append($iterator, $type, $content);
- return $row;
- });
+ return $row;
+ });
- // finally inserting the rows
- $myTable.append(rowElements);
+ // finally inserting the rows
+ $myTable.append(rowElements);
- $.each(data, function(){
- labels.push(this.year);
- dataDxcc.push(this.total);
- });
+ $.each(data, function () {
+ labels.push(this.year);
+ dataDxcc.push(this.total);
+ });
- var ctx = document.getElementById("myChartAccumulate").getContext('2d');
- var myChart = new Chart(ctx, {
- type: 'bar',
- data: {
- labels: labels,
- datasets: [{
- label: 'Accumulated number of ' + awardtext + ' worked each ' + period,
- data: dataDxcc,
- backgroundColor: 'rgba(54, 162, 235, 0.2)',
- borderColor: 'rgba(54, 162, 235, 1)',
- borderWidth: 2,
- }]
- },
- options: {
- scales: {
- yAxes: [{
- ticks: {
- beginAtZero:true,
- fontColor: color
- }
- }],
- xAxes: [{
- ticks: {
- fontColor: color
- }
+ var ctx = document.getElementById("myChartAccumulate").getContext('2d');
+ var myChart = new Chart(ctx, {
+ type: 'bar',
+ data: {
+ labels: labels,
+ datasets: [{
+ label: 'Accumulated number of ' + awardtext + ' worked each ' + period,
+ data: dataDxcc,
+ backgroundColor: 'rgba(54, 162, 235, 0.2)',
+ borderColor: 'rgba(54, 162, 235, 1)',
+ borderWidth: 2,
}]
},
- legend: {
- labels: {
- fontColor: color
+ options: {
+ scales: {
+ yAxes: [{
+ ticks: {
+ beginAtZero: true,
+ fontColor: color
+ }
+ }],
+ xAxes: [{
+ ticks: {
+ fontColor: color
+ }
+ }]
+ },
+ legend: {
+ labels: {
+ fontColor: color
+ }
}
}
+ });
+ $(".ld-ext-right").removeClass('running');
+ $(".ld-ext-right").prop('disabled', false);
+ $('.accutable').DataTable({
+ responsive: false,
+ ordering: false,
+ "scrollY": "400px",
+ "scrollCollapse": true,
+ "paging": false,
+ "scrollX": true,
+ dom: 'Bfrtip',
+ buttons: [
+ 'csv'
+ ]
+ });
+
+ // using this to change color of csv-button if dark mode is chosen
+ var background = $('body').css("background-color");
+
+ if (background != ('rgb(255, 255, 255)')) {
+ $(".buttons-csv").css("color", "white");
}
- });
- $(".ld-ext-right").removeClass('running');
- $(".ld-ext-right").prop('disabled', false);
- $('.accutable').DataTable({
- responsive: false,
- ordering: false,
- "scrollY": "400px",
- "scrollCollapse": true,
- "paging": false,
- "scrollX": true,
- dom: 'Bfrtip',
- buttons: [
- 'csv'
- ]
- });
-
- // using this to change color of csv-button if dark mode is chosen
- var background = $('body').css( "background-color");
-
- if (background != ('rgb(255, 255, 255)')) {
- $(".buttons-csv").css("color", "white");
}
}
});