ep_stats 0.0.62 → 0.0.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ep.json CHANGED
@@ -1,19 +1,22 @@
1
1
  {
2
- "parts":[
2
+ "parts": [
3
3
  {
4
4
  "name": "stats",
5
- "hooks":{
5
+ "hooks": {
6
6
  "expressCreateServer": "ep_stats/express",
7
+ "loadSettings": "ep_stats/index",
8
+ "clientVars": "ep_stats/index",
7
9
  "eejsBlock_exportColumn": "ep_stats/index",
8
10
  "eejsBlock_scripts": "ep_stats/index",
9
11
  "eejsBlock_mySettings": "ep_stats/index",
10
- "eejsBlock_styles":"ep_stats/index",
11
- "eejsBlock_body":"ep_stats/index",
12
- "eejsBlock_dd_view":"ep_stats/index"
12
+ "eejsBlock_padSettings": "ep_stats/index",
13
+ "eejsBlock_styles": "ep_stats/index",
14
+ "eejsBlock_body": "ep_stats/index"
13
15
  },
14
16
  "client_hooks": {
15
17
  "postAceInit": "ep_stats/static/js/stats",
16
- "aceEditEvent": "ep_stats/static/js/stats"
18
+ "aceEditEvent": "ep_stats/static/js/stats",
19
+ "handleClientMessage_CLIENT_MESSAGE": "ep_stats/static/js/stats:handleClientMessage_CLIENT_MESSAGE"
17
20
  }
18
21
  }
19
22
  ]
package/index.js CHANGED
@@ -1,9 +1,36 @@
1
1
  'use strict';
2
2
 
3
3
  const {template} = require('ep_plugin_helpers');
4
+ const {padToggle} = require('ep_plugin_helpers/pad-toggle-server');
5
+
6
+ // Parallel User Settings + Pad Wide Settings checkboxes for "Show Pad and
7
+ // Author stats". Helper owns markup, storage, broadcast, enforce, and i18n.
8
+ const statsToggle = padToggle({
9
+ pluginName: 'ep_stats',
10
+ settingId: 'stats',
11
+ l10nId: 'ep_stats.stats_entry.show_pad_and_author_stats',
12
+ defaultLabel: 'Show Pad and Author stats',
13
+ defaultEnabled: true,
14
+ });
15
+
16
+ // Older settings.json used a top-level `ep_stats_default` key. Translate it
17
+ // to the helper's nested `ep_stats.defaultEnabled` so an admin who set it
18
+ // to `false` keeps a default-off pad.
19
+ exports.loadSettings = async (hookName, args) => {
20
+ const root = args && args.settings;
21
+ if (root) {
22
+ const ps = (root.ep_stats = root.ep_stats || {});
23
+ if (typeof ps.defaultEnabled !== 'boolean' &&
24
+ typeof root.ep_stats_default === 'boolean') {
25
+ ps.defaultEnabled = root.ep_stats_default;
26
+ }
27
+ }
28
+ return statsToggle.loadSettings(hookName, args);
29
+ };
4
30
 
5
- const eejs = require('ep_etherpad-lite/node/eejs');
6
- const settings = require('ep_etherpad-lite/node/utils/Settings');
31
+ exports.clientVars = statsToggle.clientVars;
32
+ exports.eejsBlock_mySettings = statsToggle.eejsBlock_mySettings;
33
+ exports.eejsBlock_padSettings = statsToggle.eejsBlock_padSettings;
7
34
 
8
35
  exports.eejsBlock_exportColumn =
9
36
  template('ep_stats/templates/exportcolumn.html');
@@ -18,21 +45,3 @@ exports.eejsBlock_styles = (hookName, args, cb) => {
18
45
 
19
46
  exports.eejsBlock_body =
20
47
  template('ep_stats/templates/stats.html');
21
-
22
- exports.eejsBlock_mySettings = (hookName, args, cb) => {
23
- let checkedState;
24
- if (!settings.ep_stats_default) {
25
- checkedState = 'unchecked';
26
- } else if (settings.ep_stats_default === true) {
27
- checkedState = 'checked';
28
- }
29
- args.content += eejs.require('ep_stats/templates/stats_entry.ejs', {checked: checkedState});
30
- return cb();
31
- };
32
-
33
-
34
- exports.eejsBlock_dd_view = (hookName, args, cb) => {
35
- args.content +=
36
- "<li><a href='#' onClick='$(\"#options-stats\").click();'>Pad Statistics</a></li>";
37
- return cb();
38
- };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ep_stats",
3
3
  "description": "See pad Stats in Etherpad",
4
- "version": "0.0.62",
4
+ "version": "0.0.63",
5
5
  "author": {
6
6
  "name": "John McLear",
7
7
  "email": "john@mclear.co.uk",
@@ -39,6 +39,6 @@
39
39
  "node": ">=18.0.0"
40
40
  },
41
41
  "dependencies": {
42
- "ep_plugin_helpers": "^0.5.0"
42
+ "ep_plugin_helpers": "^0.5.2"
43
43
  }
44
44
  }
@@ -31,3 +31,11 @@
31
31
  .statsAuthorColor{
32
32
  width:4px;
33
33
  }
34
+
35
+ /* Hide the stats panel in core's in-pad history mode (Etherpad #7659).
36
+ Stats reflect the live pad; they have no meaning when the pad is showing
37
+ a historical revision, and the panel's bottom-right position overlaps
38
+ core's history banner (the "Return to live" button in particular). The
39
+ class is added to <body> by core when entering history and removed when
40
+ the user returns to live. */
41
+ body.history-mode #stats { display: none !important; }
@@ -1,5 +1,23 @@
1
1
  'use strict';
2
2
 
3
+ // Sub-path import keeps the client bundle clean — the top-level
4
+ // `ep_plugin_helpers` index pulls in server-only modules.
5
+ const {padToggle} = require('ep_plugin_helpers/pad-toggle');
6
+
7
+ // Same config as the server-side instance — must agree on pluginName,
8
+ // settingId, l10nId, and defaultLabel so checkbox ids and clientVars line up.
9
+ const statsToggle = padToggle({
10
+ pluginName: 'ep_stats',
11
+ settingId: 'stats',
12
+ l10nId: 'ep_stats.stats_entry.show_pad_and_author_stats',
13
+ defaultLabel: 'Show Pad and Author stats',
14
+ defaultEnabled: true,
15
+ });
16
+
17
+ // Re-export so the helper sees pad-wide broadcasts and refreshes our state
18
+ // when another user toggles the pad-wide checkbox.
19
+ exports.handleClientMessage_CLIENT_MESSAGE = statsToggle.handleClientMessage_CLIENT_MESSAGE;
20
+
3
21
  const stats = {
4
22
  init: () => {
5
23
  stats.update();
@@ -198,19 +216,18 @@ stats.authors = {
198
216
  };
199
217
 
200
218
  exports.postAceInit = (hook, context) => {
201
- stats.show();
202
- /* on click */
203
- $('#options-stats').on('click', () => {
204
- if ($('#options-stats').is(':checked')) {
205
- stats.show();
206
- } else {
207
- stats.hide();
208
- }
219
+ statsToggle.init({
220
+ onChange: (enabled) => {
221
+ if (enabled) stats.show();
222
+ else stats.hide();
223
+ },
209
224
  });
210
225
  };
211
226
 
212
227
  exports.aceEditEvent = (hookName, event) => {
213
- if ($('#options-stats').is(':checked')) { // if stats are enabled
228
+ // The helper keeps #options-stats in sync with the live toggle state,
229
+ // so a DOM check is still the simplest read path on the hot path.
230
+ if ($('#options-stats').is(':checked')) {
214
231
  if (event.callstack.docTextChanged && event.callstack.domClean) {
215
232
  stats.update();
216
233
  }
@@ -1,4 +0,0 @@
1
- <p>
2
- <input type="checkbox" id="options-stats" checked></input>
3
- <label for="options-stats" data-l10n-id="ep_stats.stats_entry.show_pad_and_author_stats">Show Pad and Author stats</label>
4
- </p>