| 1 |
/******/ (() => { // webpackBootstrap |
| 2 |
var __webpack_exports__ = {}; |
| 3 |
/*!*****************************************************!*\ |
| 4 |
!*** ./assets/src/apps/js/admin/pages/statistic.js ***! |
| 5 |
\*****************************************************/ |
| 6 |
(function ($) { |
| 7 |
$.fn.LP_Chart_Line = function (data, config) { |
| 8 |
return $.each(this, function () { |
| 9 |
const $elem = $(this), |
| 10 |
$canvas = $('<canvas />'); |
| 11 |
$elem.html(''); |
| 12 |
$canvas.appendTo($elem); |
| 13 |
var lineChart = new Chart($canvas, { |
| 14 |
type: 'line', |
| 15 |
data: data, |
| 16 |
options: config |
| 17 |
}); |
| 18 |
}); |
| 19 |
// |
| 20 |
}; |
| 21 |
$.fn.LP_Statistic_Users = function () { |
| 22 |
if (parseInt($(this).length) === 0) { |
| 23 |
return; |
| 24 |
} |
| 25 |
return $.each(this, function () { |
| 26 |
const $buttons = $('.chart-buttons button').on('click', function () { |
| 27 |
const $button = $(this), |
| 28 |
type = $button.data('type'); |
| 29 |
let from = '', |
| 30 |
to = ''; |
| 31 |
$buttons.not(this).not('[data-type="user-custom-time"]').prop('disabled', false); |
| 32 |
if (type == 'user-custom-time') { |
| 33 |
from = $('#user-custom-time input[name="from"]').val(); |
| 34 |
to = $('#user-custom-time input[name="to"]').val(); |
| 35 |
if (from == '' || to == '') { |
| 36 |
return false; |
| 37 |
} |
| 38 |
} else { |
| 39 |
$button.prop('disabled', true); |
| 40 |
} |
| 41 |
const $container = $('#learn-press-chart'); |
| 42 |
$container.addClass('loading'); |
| 43 |
$.ajax({ |
| 44 |
url: 'admin-ajax.php', |
| 45 |
data: { |
| 46 |
action: 'learnpress_load_chart', |
| 47 |
type, |
| 48 |
range: [from, to] |
| 49 |
}, |
| 50 |
dataType: 'text', |
| 51 |
success(response) { |
| 52 |
response = LP.parseJSON(response); |
| 53 |
$container.LP_Chart_Line(response, LP_Chart_Config); |
| 54 |
$container.removeClass('loading'); |
| 55 |
} |
| 56 |
}); |
| 57 |
return false; |
| 58 |
}), |
| 59 |
$inputs = $('.chart-buttons #user-custom-time input[type="text"]').on('change', function () { |
| 60 |
const _valid_date = function () { |
| 61 |
if (new Date($inputs[0].value) < new Date($inputs[1].value)) { |
| 62 |
return true; |
| 63 |
} |
| 64 |
}; |
| 65 |
$buttons.filter('[data-type="user-custom-time"]').prop('disabled', $inputs.filter(function () { |
| 66 |
return this.value == ''; |
| 67 |
}).get().length || !_valid_date()); |
| 68 |
}); |
| 69 |
}); |
| 70 |
}; |
| 71 |
$.fn.LP_Statistic_Courses = function () { |
| 72 |
if (parseInt($(this).length) === 0) { |
| 73 |
return; |
| 74 |
} |
| 75 |
return $.each(this, function () { |
| 76 |
var $buttons = $('.chart-buttons button').on('click', function () { |
| 77 |
let $button = $(this), |
| 78 |
type = $button.data('type'), |
| 79 |
from = '', |
| 80 |
to = '', |
| 81 |
$container = $('#learn-press-chart'); |
| 82 |
$buttons.not(this).not('[data-type="course-custom-time"]').prop('disabled', false); |
| 83 |
if (type == 'course-custom-time') { |
| 84 |
from = $('#course-custom-time input[name="from"]').val(); |
| 85 |
to = $('#course-custom-time input[name="to"]').val(); |
| 86 |
if (from == '' || to == '') { |
| 87 |
return false; |
| 88 |
} |
| 89 |
} else { |
| 90 |
$button.prop('disabled', true); |
| 91 |
} |
| 92 |
$container.addClass('loading'); |
| 93 |
$.ajax({ |
| 94 |
url: 'admin-ajax.php', |
| 95 |
data: { |
| 96 |
action: 'learnpress_load_chart', |
| 97 |
type, |
| 98 |
range: [from, to] |
| 99 |
}, |
| 100 |
dataType: 'text', |
| 101 |
success(response) { |
| 102 |
response = LP.parseJSON(response); |
| 103 |
$container.LP_Chart_Line(response, LP_Chart_Config); |
| 104 |
$container.removeClass('loading'); |
| 105 |
} |
| 106 |
}); |
| 107 |
return false; |
| 108 |
}), |
| 109 |
$inputs = $('.chart-buttons #course-custom-time input[type="text"]').on('change', function () { |
| 110 |
const _valid_date = function () { |
| 111 |
if (new Date($inputs[0].value) < new Date($inputs[1].value)) { |
| 112 |
return true; |
| 113 |
} |
| 114 |
}; |
| 115 |
$buttons.filter('[data-type="course-custom-time"]').prop('disabled', $inputs.filter(function () { |
| 116 |
return this.value == ''; |
| 117 |
}).get().length || !_valid_date()); |
| 118 |
}); |
| 119 |
}); |
| 120 |
}; |
| 121 |
$.fn.LP_Statistic_Orders = function () { |
| 122 |
if (parseInt($(this).length) === 0) { |
| 123 |
return; |
| 124 |
} |
| 125 |
$('.panel_report_option').hide(); |
| 126 |
$('#panel_report_sales_by_' + $('#report_sales_by').val()).show(); |
| 127 |
$('#report_sales_by').on('change', function () { |
| 128 |
$('.panel_report_option').hide(); |
| 129 |
$('#panel_report_sales_by_' + $(this).val()).show(); |
| 130 |
if ('date' == $(this).val()) { |
| 131 |
LP_Statistic_Orders_Upgrade_Chart(); |
| 132 |
} |
| 133 |
}); |
| 134 |
|
| 135 |
/** |
| 136 |
* Upgrade Chart for Order Statistics |
| 137 |
* |
| 138 |
* @return {boolean} |
| 139 |
*/ |
| 140 |
var LP_Statistic_Orders_Upgrade_Chart = function () { |
| 141 |
let type = '', |
| 142 |
from = '', |
| 143 |
to = '', |
| 144 |
report_sales_by = 'date', |
| 145 |
cat_id = 0, |
| 146 |
course_id = 0; |
| 147 |
report_sales_by = $('#report_sales_by').val(); |
| 148 |
$container = $('#learn-press-chart'); |
| 149 |
$container.addClass('loading'); |
| 150 |
// get type |
| 151 |
const $buttons = $('.chart-buttons button:disabled').not('[data-type="order-custom-time"]'); |
| 152 |
if (parseInt($buttons.length) > 0) { |
| 153 |
type = $($buttons[0]).data('type'); |
| 154 |
} else { |
| 155 |
type = 'order-custom-time'; |
| 156 |
from = $('#order-custom-time input[name="from"]').val(); |
| 157 |
to = $('#order-custom-time input[name="to"]').val(); |
| 158 |
if (from == '' || to == '') { |
| 159 |
return false; |
| 160 |
} |
| 161 |
} |
| 162 |
if ('course' === report_sales_by) { |
| 163 |
course_id = $('#report-by-course-id').val(); |
| 164 |
} else if ('category' === report_sales_by) { |
| 165 |
cat_id = $('#report-by-course-category-id').val(); |
| 166 |
} |
| 167 |
$.ajax({ |
| 168 |
url: 'admin-ajax.php', |
| 169 |
data: { |
| 170 |
action: 'learnpress_load_chart', |
| 171 |
type, |
| 172 |
range: [from, to], |
| 173 |
report_sales_by, |
| 174 |
course_id, |
| 175 |
cat_id |
| 176 |
}, |
| 177 |
dataType: 'text', |
| 178 |
success(response) { |
| 179 |
response = LP.parseJSON(response); |
| 180 |
$container.LP_Chart_Line(response, LP_Chart_Config); |
| 181 |
$container.removeClass('loading'); |
| 182 |
} |
| 183 |
}); |
| 184 |
}; |
| 185 |
$('#report-by-course-id').select2({ |
| 186 |
placeholder: 'Select a course', |
| 187 |
minimumInputLength: 1, |
| 188 |
ajax: { |
| 189 |
url: ajaxurl + '?action=learnpress_search_course', |
| 190 |
dataType: 'json', |
| 191 |
quietMillis: 250, |
| 192 |
data(term, page) { |
| 193 |
return { |
| 194 |
q: term // search term |
| 195 |
}; |
| 196 |
}, |
| 197 |
results(data, page) { |
| 198 |
return { |
| 199 |
results: data.items |
| 200 |
}; |
| 201 |
}, |
| 202 |
cache: true |
| 203 |
} |
| 204 |
}); |
| 205 |
$('#report-by-course-id').on('change', function () { |
| 206 |
LP_Statistic_Orders_Upgrade_Chart(); |
| 207 |
}); |
| 208 |
$('#report-by-course-category-id').select2({ |
| 209 |
placeholder: 'Select a course', |
| 210 |
minimumInputLength: 1, |
| 211 |
ajax: { |
| 212 |
url: ajaxurl + '?action=learnpress_search_course_category', |
| 213 |
dataType: 'json', |
| 214 |
quietMillis: 250, |
| 215 |
data(term, page) { |
| 216 |
return { |
| 217 |
q: term // search term |
| 218 |
}; |
| 219 |
}, |
| 220 |
results(data, page) { |
| 221 |
return { |
| 222 |
results: data.items |
| 223 |
}; |
| 224 |
}, |
| 225 |
cache: true |
| 226 |
} |
| 227 |
}); |
| 228 |
$('#report-by-course-category-id').on('change', function () { |
| 229 |
LP_Statistic_Orders_Upgrade_Chart(); |
| 230 |
}); |
| 231 |
var $buttons = $('.chart-buttons button').on('click', function () { |
| 232 |
const $button = $(this), |
| 233 |
type = $button.data('type'), |
| 234 |
from = '', |
| 235 |
to = '', |
| 236 |
$container = $('#learn-press-chart'); |
| 237 |
$buttons.not(this).not('[data-type="order-custom-time"]').prop('disabled', false); |
| 238 |
if (type !== 'order-custom-time') { |
| 239 |
$button.prop('disabled', true); |
| 240 |
$('#order-custom-time input[name="from"]').val(''); |
| 241 |
$('#order-custom-time input[name="to"]').val(''); |
| 242 |
} |
| 243 |
LP_Statistic_Orders_Upgrade_Chart(); |
| 244 |
return false; |
| 245 |
}); |
| 246 |
var $inputs = $('.chart-buttons #order-custom-time input[type="text"]').on('change', function () { |
| 247 |
const _valid_date = function () { |
| 248 |
if (new Date($inputs[0].value) < new Date($inputs[1].value)) { |
| 249 |
return true; |
| 250 |
} |
| 251 |
}; |
| 252 |
$buttons.filter('[data-type="order-custom-time"]').prop('disabled', $inputs.filter(function () { |
| 253 |
return this.value == ''; |
| 254 |
}).get().length || !_valid_date()); |
| 255 |
}); |
| 256 |
}; |
| 257 |
$(function () { |
| 258 |
if (typeof $.fn.datepicker != 'undefined') { |
| 259 |
$('.date-picker').datepicker({ |
| 260 |
dateFormat: 'yy/mm/dd' |
| 261 |
}); |
| 262 |
} |
| 263 |
$('.learn-press-statistic-users').LP_Statistic_Users(); |
| 264 |
$('.learn-press-statistic-courses').LP_Statistic_Courses(); |
| 265 |
$('.learn-press-statistic-orders').LP_Statistic_Orders(); |
| 266 |
}); |
| 267 |
return; |
| 268 |
})(jQuery); |
| 269 |
/******/ })() |
| 270 |
; |
| 271 |
//# sourceMappingURL=statistic.js.map |