@reveldigital/player-client 2.0.5 → 2.2.0

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.
@@ -11,8 +11,203 @@ import { RouterModule } from '@angular/router';
11
11
  import { APP_BASE_HREF } from '@angular/common';
12
12
  import * as i1$1 from '@angular/platform-browser';
13
13
 
14
+ /**
15
+ * Angular-friendly wrapper around the global `gadgets.reveldigital.datatable` library.
16
+ *
17
+ * Provides typed Promise-based methods and RxJS Observables for real-time events.
18
+ *
19
+ * ```typescript
20
+ * const dt = this.client.createDataTable('tbl_menu_items');
21
+ *
22
+ * // Fetch rows
23
+ * const result = await dt.getRows({ sort: 'price', sortDir: 'asc' });
24
+ *
25
+ * // Real-time updates
26
+ * dt.rowUpdated$.subscribe(change => console.log('Updated:', change));
27
+ *
28
+ * // Cleanup
29
+ * dt.dispose();
30
+ * ```
31
+ */
32
+ class DataTableRef {
33
+ /**
34
+ * Creates a new DataTableRef.
35
+ *
36
+ * @param tableId - The data table ID (e.g. 'tbl_menu_items')
37
+ * @param options - Optional configuration overrides
38
+ * @throws Error if the global datatable library is not loaded
39
+ */
40
+ constructor(tableId, options) {
41
+ /** Emits when an existing row is modified. */
42
+ this.rowUpdated$ = new Subject();
43
+ /** Emits when a new row is added. */
44
+ this.rowCreated$ = new Subject();
45
+ /** Emits when a row is removed. */
46
+ this.rowDeleted$ = new Subject();
47
+ const lib = window.gadgets?.['reveldigital.datatable'];
48
+ if (!lib || typeof lib.create !== 'function') {
49
+ throw new Error('RevelDigital DataTable library is not available. ' +
50
+ 'Ensure the datatable feature is enabled for this gadget.');
51
+ }
52
+ this._instance = lib.create(tableId, options);
53
+ this._wireEvents();
54
+ }
55
+ /**
56
+ * Fetches rows from the data table.
57
+ *
58
+ * @param params - Optional query parameters (filter, sort, pagination)
59
+ * @returns Promise resolving to the result set
60
+ *
61
+ * ```typescript
62
+ * const result = await dt.getRows({
63
+ * filter: { category: 'Entree', price: { op: 'lte', value: 25 } },
64
+ * sort: 'itemName',
65
+ * sortDir: 'asc',
66
+ * pageSize: 20
67
+ * });
68
+ * ```
69
+ */
70
+ getRows(params) {
71
+ return this._instance.getRows(params);
72
+ }
73
+ /**
74
+ * Fetches the table schema (column definitions and metadata).
75
+ *
76
+ * @returns Promise resolving to the table schema
77
+ */
78
+ getSchema() {
79
+ return this._instance.getSchema();
80
+ }
81
+ /**
82
+ * Gets visible (non-hidden) columns from the table schema.
83
+ *
84
+ * @returns Promise resolving to an array of visible column definitions
85
+ */
86
+ getVisibleColumns() {
87
+ return this._instance.getVisibleColumns();
88
+ }
89
+ /**
90
+ * Fetches rows with hidden column data stripped.
91
+ *
92
+ * @param params - Optional query parameters (same as getRows)
93
+ * @returns Promise resolving to the result set with hidden fields removed
94
+ */
95
+ getVisibleRows(params) {
96
+ return this._instance.getVisibleRows(params);
97
+ }
98
+ /**
99
+ * Starts polling for changes at the given interval.
100
+ * Emits on `rowUpdated$` when new data is detected.
101
+ *
102
+ * @param intervalMs - Polling interval in milliseconds (default 30000)
103
+ */
104
+ startPolling(intervalMs) {
105
+ this._instance.startPolling(intervalMs);
106
+ }
107
+ /**
108
+ * Stops polling for changes.
109
+ */
110
+ stopPolling() {
111
+ this._instance.stopPolling();
112
+ }
113
+ /**
114
+ * Releases all resources: stops polling, closes the real-time connection,
115
+ * removes event listeners, and completes all RxJS observables.
116
+ */
117
+ dispose() {
118
+ this._instance.off('rowUpdated', this._onRowUpdated);
119
+ this._instance.off('rowCreated', this._onRowCreated);
120
+ this._instance.off('rowDeleted', this._onRowDeleted);
121
+ this._instance.dispose();
122
+ this.rowUpdated$.complete();
123
+ this.rowCreated$.complete();
124
+ this.rowDeleted$.complete();
125
+ }
126
+ /** @ignore */
127
+ static _fromInstance(instance) {
128
+ const ref = Object.create(DataTableRef.prototype);
129
+ ref.rowUpdated$ = new Subject();
130
+ ref.rowCreated$ = new Subject();
131
+ ref.rowDeleted$ = new Subject();
132
+ ref._instance = instance;
133
+ ref._wireEvents();
134
+ return ref;
135
+ }
136
+ /** @ignore */
137
+ _wireEvents() {
138
+ this._onRowUpdated = (change) => this.rowUpdated$.next(change);
139
+ this._onRowCreated = (change) => this.rowCreated$.next(change);
140
+ this._onRowDeleted = (change) => this.rowDeleted$.next(change);
141
+ this._instance.on('rowUpdated', this._onRowUpdated);
142
+ this._instance.on('rowCreated', this._onRowCreated);
143
+ this._instance.on('rowDeleted', this._onRowDeleted);
144
+ }
145
+ }
146
+ /**
147
+ * Wrapper around a data table created from a gadget preference value.
148
+ *
149
+ * Automatically configures filter and sort settings from the preference,
150
+ * and provides a `getFilteredRows()` convenience method that applies them.
151
+ *
152
+ * ```typescript
153
+ * const cfg = this.client.createDataTableFromPref(prefs.getString('rdDataTable'));
154
+ *
155
+ * // Fetch rows with auto-wired filter + sort from the preference
156
+ * const result = await cfg.getFilteredRows();
157
+ *
158
+ * // Access the underlying DataTableRef for schema, events, etc.
159
+ * cfg.dataTable.rowUpdated$.subscribe(change => console.log(change));
160
+ *
161
+ * // Cleanup
162
+ * cfg.dispose();
163
+ * ```
164
+ */
165
+ class DataTablePrefRef {
166
+ /**
167
+ * Creates a new DataTablePrefRef from a gadget preference JSON string.
168
+ *
169
+ * @param prefValue - The raw gadget preference string (JSON)
170
+ * @param options - Optional configuration overrides
171
+ * @throws Error if the global datatable library is not loaded
172
+ */
173
+ constructor(prefValue, options) {
174
+ const lib = window.gadgets?.['reveldigital.datatable'];
175
+ if (!lib || typeof lib.createFromPref !== 'function') {
176
+ throw new Error('RevelDigital DataTable library is not available. ' +
177
+ 'Ensure the datatable feature is enabled for this gadget.');
178
+ }
179
+ this._config = lib.createFromPref(prefValue, options);
180
+ this.pref = this._config.pref;
181
+ this.dataTable = DataTableRef._fromInstance(this._config.dt);
182
+ }
183
+ /**
184
+ * Fetches rows with the filter and sort settings from the preference automatically applied.
185
+ * Additional query parameters can override or supplement the preference settings.
186
+ *
187
+ * @param params - Optional additional query parameters
188
+ * @returns Promise resolving to the result set
189
+ *
190
+ * ```typescript
191
+ * // Use preference defaults
192
+ * const result = await cfg.getFilteredRows();
193
+ *
194
+ * // Override page size
195
+ * const page = await cfg.getFilteredRows({ pageSize: 10 });
196
+ * ```
197
+ */
198
+ getFilteredRows(params) {
199
+ return this._config.getFilteredRows(params);
200
+ }
201
+ /**
202
+ * Releases all resources held by the underlying DataTableRef.
203
+ */
204
+ dispose() {
205
+ this.dataTable.dispose();
206
+ }
207
+ }
208
+
14
209
  // Generated by genversion.
15
- const version = '2.0.5';
210
+ const version = '2.2.0';
16
211
 
17
212
  /**
18
213
  * Service for interacting with the Revel Digital player client.
@@ -145,22 +340,21 @@ class PlayerClientService {
145
340
  this.onConfig$.next(null);
146
341
  }
147
342
  }), tap(e => this.onPostMessage$.next(e)));
148
- let self = this;
149
343
  window.RevelDigital = {
150
344
  Controller: {
151
- onCommand: function (name, arg) {
345
+ onCommand: (name, arg) => {
152
346
  zone.run(() => {
153
- self.onCommand$.next({ name: name, arg: arg });
347
+ this.onCommand$.next({ name: name, arg: arg });
154
348
  });
155
349
  },
156
- onStart: function () {
350
+ onStart: () => {
157
351
  zone.run(() => {
158
- self.onStart$.next(null);
352
+ this.onStart$.next(null);
159
353
  });
160
354
  },
161
- onStop: function () {
355
+ onStop: () => {
162
356
  zone.run(() => {
163
- self.onStop$.next(null);
357
+ this.onStop$.next(null);
164
358
  });
165
359
  }
166
360
  }
@@ -649,7 +843,7 @@ class PlayerClientService {
649
843
  */
650
844
  async getDevice() {
651
845
  const client = await this.getClient();
652
- let obj = JSON.parse(await client.getDevice());
846
+ const obj = JSON.parse(await client.getDevice());
653
847
  const device = [obj].map((device) => {
654
848
  return {
655
849
  name: device.name,
@@ -801,6 +995,69 @@ class PlayerClientService {
801
995
  console.log('%capplyConfig() is only available in preview mode.', 'background-color:blue; color:yellow;');
802
996
  }
803
997
  }
998
+ /**
999
+ * Creates a typed wrapper for a Revel Digital data table.
1000
+ *
1001
+ * The data table feature must be enabled for the gadget. The returned
1002
+ * {@link DataTableRef} provides typed Promise-based methods and RxJS
1003
+ * Observables for real-time row change events.
1004
+ *
1005
+ * @param tableId - The data table ID (e.g. 'tbl_menu_items')
1006
+ * @param options - Optional configuration overrides
1007
+ * @returns A {@link DataTableRef} instance
1008
+ * @throws Error if the global datatable library is not loaded
1009
+ *
1010
+ * ```typescript
1011
+ * const dt = this.client.createDataTable('tbl_menu_items');
1012
+ *
1013
+ * // Fetch rows with filtering and sorting
1014
+ * const result = await dt.getRows({
1015
+ * filter: { category: 'Entree', price: { op: 'lte', value: 25 } },
1016
+ * sort: 'price',
1017
+ * sortDir: 'asc'
1018
+ * });
1019
+ *
1020
+ * // Subscribe to real-time updates
1021
+ * dt.rowUpdated$.subscribe(change => console.log('Row updated:', change));
1022
+ * dt.rowCreated$.subscribe(change => console.log('Row created:', change));
1023
+ * dt.rowDeleted$.subscribe(change => console.log('Row deleted:', change));
1024
+ *
1025
+ * // Cleanup when done
1026
+ * dt.dispose();
1027
+ * ```
1028
+ */
1029
+ createDataTable(tableId, options) {
1030
+ return new DataTableRef(tableId, options);
1031
+ }
1032
+ /**
1033
+ * Creates a typed data table wrapper from a gadget preference value.
1034
+ *
1035
+ * The preference JSON string (as serialized by the template editor's datatable
1036
+ * option) is parsed and used to auto-configure filter, sort, and logic settings.
1037
+ * The returned {@link DataTablePrefRef} provides a `getFilteredRows()` convenience
1038
+ * method that applies these settings automatically.
1039
+ *
1040
+ * @param prefValue - The raw gadget preference string (JSON)
1041
+ * @param options - Optional configuration overrides
1042
+ * @returns A {@link DataTablePrefRef} instance
1043
+ * @throws Error if the global datatable library is not loaded
1044
+ *
1045
+ * ```typescript
1046
+ * const cfg = this.client.createDataTableFromPref(prefs.getString('rdDataTable'));
1047
+ *
1048
+ * // Fetch rows with auto-wired filter + sort
1049
+ * const result = await cfg.getFilteredRows();
1050
+ *
1051
+ * // Access the underlying DataTableRef for events, schema, etc.
1052
+ * cfg.dataTable.rowUpdated$.subscribe(change => console.log(change));
1053
+ *
1054
+ * // Cleanup when done
1055
+ * cfg.dispose();
1056
+ * ```
1057
+ */
1058
+ createDataTableFromPref(prefValue, options) {
1059
+ return new DataTablePrefRef(prefValue, options);
1060
+ }
804
1061
  // ---
805
1062
  // PRIVATE METHODS.
806
1063
  // ---
@@ -927,7 +1184,7 @@ class NoopClient {
927
1184
  return Promise.resolve(version);
928
1185
  }
929
1186
  applyConfig(prefs) {
930
- let evt = { type: 'applyConfig', prefs: prefs, isOpener: window.opener !== null };
1187
+ const evt = { type: 'applyConfig', prefs: prefs, isOpener: window.opener !== null };
931
1188
  if (window.opener) {
932
1189
  window.opener.postMessage(JSON.stringify(evt), '*');
933
1190
  }
@@ -947,7 +1204,7 @@ class AppInitService {
947
1204
  this._router = _router;
948
1205
  }
949
1206
  init() {
950
- return new Promise(async (resolve) => {
1207
+ return new Promise((resolve) => {
951
1208
  this.loadFonts();
952
1209
  if (isDevMode()) {
953
1210
  console.log('%cRunning in development mode', 'background-color:blue; color:yellow;');
@@ -965,7 +1222,7 @@ class AppInitService {
965
1222
  getLang() { return this.getParameterByName('lang') === '' ? 'en' : this.getParameterByName('lang'); }
966
1223
  getParameterByName(name, search = window.location.href) {
967
1224
  name = name.replace(/[\[\]]/g, '\\$&');
968
- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), results = regex.exec(search);
1225
+ const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), results = regex.exec(search);
969
1226
  if (!results)
970
1227
  return '';
971
1228
  if (!results[2])
@@ -979,7 +1236,7 @@ class AppInitService {
979
1236
  }).subscribe({
980
1237
  next: (data) => {
981
1238
  const doc = yaml.load(data);
982
- let params = {};
1239
+ const params = {};
983
1240
  for (const val of doc.prefs) {
984
1241
  params[val.name] = val.default_value;
985
1242
  }
@@ -999,9 +1256,9 @@ class AppInitService {
999
1256
  });
1000
1257
  }
1001
1258
  getFamilyName(css) {
1002
- let FONT_FAMILY_REGEX = /font-family:\s*(?:['"])*['"]*(.+?)['"]*(?:['"])*\s*;/i;
1259
+ const FONT_FAMILY_REGEX = /font-family:\s*(?:['"])*['"]*(.+?)['"]*(?:['"])*\s*;/i;
1003
1260
  if (FONT_FAMILY_REGEX.test(css)) {
1004
- var matches = css.match(FONT_FAMILY_REGEX);
1261
+ const matches = css.match(FONT_FAMILY_REGEX);
1005
1262
  return matches[1].split(',')[0];
1006
1263
  }
1007
1264
  else {
@@ -1015,7 +1272,7 @@ class AppInitService {
1015
1272
  const parameters = new URLSearchParams(window.location.search);
1016
1273
  parameters.forEach((val, key) => {
1017
1274
  try {
1018
- let fontFamily = this.getFamilyName(val);
1275
+ const fontFamily = this.getFamilyName(val);
1019
1276
  if (fontFamily !== '') {
1020
1277
  WebFont.load({
1021
1278
  google: {
@@ -1152,5 +1409,5 @@ function initializeApp(appInitService) {
1152
1409
  * Generated bundle index. Do not edit.
1153
1410
  */
1154
1411
 
1155
- export { NgSafeStylePipeModule, PlayerClientModule, PlayerClientService, SafeStylePipe };
1412
+ export { DataTablePrefRef, DataTableRef, NgSafeStylePipeModule, PlayerClientModule, PlayerClientService, SafeStylePipe };
1156
1413
  //# sourceMappingURL=reveldigital-player-client.mjs.map