PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / assets / src / js / admin / statistics / kpi.js

kpi.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.8, at assets/src/js/admin/statistics/kpi.js

48 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * KPI card renderer — pure DOM fill, no fetch.
3 *
4 * Payload shape comes from PeriodHelper::kpi_payload() on the server:
5 * { value, prev_value, change_pct } plus optional client extras
6 * { formatted, subline }. change_pct null → delta hidden (no wrong deltas).
7 *
8 * @since 4.4.2
9 * @version 1.0.0
10 */
11
12 /**
13 * @param {Element} elCard The .lp-kpi-card root.
14 * @param {Object} payload KPI payload.
15 */
16 export const renderKpi = ( elCard, payload = {} ) => {
17 if ( ! elCard ) {
18 return;
19 }
20
21 const elValue = elCard.querySelector( '.lp-kpi-value' );
22 const elDelta = elCard.querySelector( '.lp-kpi-delta' );
23 const elSubline = elCard.querySelector( '.lp-kpi-subline' );
24
25 if ( elValue ) {
26 const value = payload.formatted ?? payload.value;
27 elValue.textContent = null == value || '' === value ? '' : String( value );
28 }
29
30 if ( elDelta ) {
31 elDelta.classList.remove( 'is-up', 'is-down' );
32
33 if ( 'number' === typeof payload.change_pct ) {
34 const isUp = payload.change_pct >= 0;
35 elDelta.classList.add( isUp ? 'is-up' : 'is-down' );
36 elDelta.textContent = `${ isUp ? '' : '' } ${ Math.abs(
37 payload.change_pct
38 ) }%`;
39 } else {
40 elDelta.textContent = '';
41 }
42 }
43
44 if ( elSubline ) {
45 elSubline.textContent = payload.subline ?? '';
46 }
47 };
48