@adaptabletools/adaptable-plugin-ipushpull-cjs 22.0.1 → 22.0.2

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.
@@ -1,305 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PushPullService = exports.ServiceStatus = void 0;
4
- const tslib_1 = require("tslib");
5
- const StringExtensions_1 = tslib_1.__importDefault(require("@adaptabletools/adaptable-cjs/src/Utilities/Extensions/StringExtensions"));
6
- const tinycolor2_1 = tslib_1.__importDefault(require("tinycolor2"));
7
- var ServiceStatus;
8
- (function (ServiceStatus) {
9
- ServiceStatus["Unknown"] = "Unknown";
10
- ServiceStatus["Disconnected"] = "Disconnected";
11
- ServiceStatus["Connected"] = "Connected";
12
- ServiceStatus["Error"] = "Error";
13
- })(ServiceStatus || (exports.ServiceStatus = ServiceStatus = {}));
14
- class PushPullService {
15
- adaptable;
16
- ppInstance = null;
17
- pages = new Map();
18
- constructor(adaptable) {
19
- this.adaptable = adaptable;
20
- this.adaptable = adaptable;
21
- this.adaptable.api.eventApi.on('AdaptableReady', async () => {
22
- // turn off and clear everything
23
- this.getIPPApi().clearIPushPullInternalState();
24
- this.getIPPApi().setIPushPullAvailableOff();
25
- if (!this.ppInstance) {
26
- let instance = this.getIPPApi().getIPushPullInstance();
27
- if (instance) {
28
- this.ppInstance = instance;
29
- // set that it is available
30
- this.getIPPApi().setIPushPullAvailableOn();
31
- let autoLogin = this.getIPPApi().getAutoLogin();
32
- if (autoLogin) {
33
- // get the username and passwrord from the options
34
- let userName = this.getIPPApi().getIPushPullUsername();
35
- let password = this.getIPPApi().getIPushPullPassword();
36
- if (StringExtensions_1.default.IsNotNullOrEmpty(userName) &&
37
- StringExtensions_1.default.IsNotNullOrEmpty(password)) {
38
- try {
39
- // slightly circular but it means tht we do the logic in one go..
40
- this.getIPPApi().loginToIPushPull(userName, password);
41
- }
42
- catch (err) {
43
- // set that it is not running (but still available)
44
- this.getIPPApi().setIPushPullRunningOff();
45
- }
46
- }
47
- }
48
- }
49
- }
50
- });
51
- }
52
- getIPushPullStatus() {
53
- if (!this.ppInstance) {
54
- return ServiceStatus.Error;
55
- }
56
- return this.ppInstance.__status;
57
- }
58
- getIPPApi() {
59
- return this.adaptable.api.pluginsApi.getipushpullPluginApi();
60
- }
61
- // Logs in to ipushpull
62
- login(login, password) {
63
- if (!this.ppInstance) {
64
- return Promise.reject('No ipushpull instance found!');
65
- }
66
- return this.ppInstance.auth
67
- .login(login, password)
68
- .then((result) => {
69
- this.ppInstance.__status = ServiceStatus.Connected;
70
- this.adaptable.logger.success('Logged in to ipushpull.');
71
- return result;
72
- })
73
- .catch((err) => {
74
- this.ppInstance.__status = ServiceStatus.Error;
75
- this.getIPPApi().setIPushPullLoginErrorMessage(err.data ? err.data.error_description || err.message : err.message);
76
- // prefer a more descriptive error, which IPP generally provides
77
- throw err.data ? err.data.error_description || err.message : err.message;
78
- });
79
- }
80
- // Retrieves domain pages from ipushpull
81
- getDomainPages() {
82
- if (!this.ppInstance) {
83
- return Promise.reject('No ipushpull instance found.');
84
- }
85
- return this.ppInstance.api
86
- .getDomainsAndPages(this.ppInstance.config.api_key)
87
- .then((response) => {
88
- this.adaptable.logger.success('Retrieved ipushpull folder and page info.');
89
- return response.data.domains.map((domain) => ({
90
- Name: domain.name,
91
- FolderId: domain.id,
92
- Pages: domain.current_user_domain_page_access.pages
93
- .filter((page) => page.special_page_type == 0 && page.write_access)
94
- .map((page) => page.name),
95
- }));
96
- })
97
- .catch((error) => {
98
- this.adaptable.logger.error('Failed to retrieve folders and pages from ipushpull.', error);
99
- throw error.message;
100
- });
101
- }
102
- loadPage(folderIPP, pageIPP) {
103
- if (!this.ppInstance) {
104
- return Promise.reject('No ipushpull instance found.');
105
- }
106
- return new Promise((resolve, reject) => {
107
- const page = new this.ppInstance.Page(pageIPP, folderIPP);
108
- page.on(page.EVENT_NEW_CONTENT, () => {
109
- this.adaptable.logger.info(`Page ready: "${pageIPP}".`);
110
- this.pages.set(pageIPP, page);
111
- resolve(page);
112
- // we return true so it removes the listener for new content.
113
- // IPP should add that line to their wiki
114
- return true;
115
- });
116
- });
117
- }
118
- unloadPage(page) {
119
- const pageIPP = this.pages.get(page);
120
- if (pageIPP) {
121
- pageIPP.destroy();
122
- this.pages.delete(page);
123
- this.adaptable.logger.info(`Page unloaded: "${page}".`);
124
- }
125
- }
126
- addNewPage(folderId, page) {
127
- if (!this.ppInstance) {
128
- return Promise.reject('No ipushpull instance found.');
129
- }
130
- return this.ppInstance.Page.create(folderId, page)
131
- .then((createdPage) => {
132
- let message = `Page "${page}" created successfully.`;
133
- this.adaptable.api.alertApi.showAlertSuccess('ipushpull', message);
134
- this.adaptable.api.internalApi.hidePopupScreen();
135
- return this.getIPPApi().retrieveIPushPullDomainsFromIPushPull();
136
- })
137
- .catch((err) => {
138
- this.adaptable.logger.error(`Failed to create page "${page}": ${err}`);
139
- });
140
- }
141
- pushData(page, data) {
142
- return new Promise((resolve, reject) => {
143
- let newData = [];
144
- const style = data && data.length > 1 ? this.getCurrentIPPStyle() : this.getDefaultIPPStyle();
145
- newData = data.map((row, i) => row.map((cell, y) => {
146
- const col = i == 0
147
- ? style.Header.Columns.find((x) => x.columnFriendlyName == data[0][y])
148
- : style.Row.Columns.find((x) => x.columnFriendlyName == data[0][y]);
149
- let styleIPP;
150
- if (i == 0) {
151
- styleIPP = {
152
- 'background-color': style.Header.headerBackColor,
153
- bbc: '000000',
154
- bbs: 'none',
155
- bbw: 'none',
156
- lbc: '000000',
157
- lbs: 'none',
158
- lbw: 'none',
159
- rbc: '000000',
160
- rbs: 'none',
161
- rbw: 'none',
162
- tbc: '000000',
163
- tbs: 'none',
164
- tbw: 'none',
165
- color: style.Header.headerColor,
166
- 'font-family': style.Header.headerFontFamily,
167
- 'font-size': style.Header.headerFontSize,
168
- 'font-style': style.Header.headerFontStyle,
169
- 'font-weight': style.Header.headerFontWeight,
170
- height: `${String(style.Header.height / 3)}px`,
171
- 'text-align': col.textAlign,
172
- 'vertical-align': 'middle',
173
- 'white-space': 'nowrap',
174
- width: `${String(col.width)}px`,
175
- 'text-wrap': 'normal',
176
- 'word-wrap': 'normal',
177
- };
178
- }
179
- else if (i == 1) {
180
- styleIPP = {
181
- 'background-color': i % 2 ? style.Row.backColor : style.Row.altBackColor,
182
- color: style.Row.color,
183
- 'font-family': style.Row.fontFamily,
184
- 'font-size': style.Row.fontSize,
185
- 'font-style': style.Row.fontStyle,
186
- 'font-weight': style.Row.fontWeight,
187
- 'text-align': col.textAlign,
188
- };
189
- }
190
- else {
191
- styleIPP = {
192
- 'background-color': i % 2 ? style.Row.backColor : style.Row.altBackColor,
193
- };
194
- }
195
- return {
196
- value: cell,
197
- formatted_value: cell,
198
- style: styleIPP,
199
- };
200
- }));
201
- const pageIPP = this.pages.get(page);
202
- pageIPP.Content.canDoDelta = false;
203
- pageIPP.Content.update(newData, true);
204
- pageIPP.push().then(() => {
205
- this.adaptable.logger.success(`Data pushed for ipushpull page "${page}".`);
206
- resolve();
207
- }, (err) => {
208
- this.adaptable.logger.error(`Failed to push data for ipushpull page "${page}".`);
209
- reject();
210
- });
211
- });
212
- }
213
- getCurrentIPPStyle() {
214
- const headerFirstCol = document
215
- .querySelectorAll('.ag-header-cell')
216
- .item(0);
217
- const header = document.querySelector('.ag-header');
218
- const headerColStyle = header ? window.getComputedStyle(header, null) : null;
219
- const firstRow = document.querySelector('.ag-row-even');
220
- const firstRowStyle = firstRow ? window.getComputedStyle(firstRow, null) : null;
221
- const secondRow = document.querySelector('.ag-row-odd');
222
- const secondRowStyle = secondRow
223
- ? window.getComputedStyle(secondRow, null)
224
- : {
225
- backgroundColor: '#fff',
226
- };
227
- return {
228
- Header: {
229
- headerColor: (0, tinycolor2_1.default)(headerColStyle.color).toHexString(),
230
- headerBackColor: (0, tinycolor2_1.default)(headerColStyle.backgroundColor).toHexString(),
231
- headerFontFamily: headerColStyle.fontFamily,
232
- headerFontSize: headerColStyle.fontSize,
233
- headerFontStyle: headerColStyle.fontStyle,
234
- headerFontWeight: headerColStyle.fontWeight,
235
- height: Number(headerColStyle.height.replace('px', '')),
236
- Columns: this.adaptable.api.columnApi.getUIAvailableColumns().map((col) => {
237
- const headerColumn = document.querySelector(`.ag-header-cell[col-id='${col.columnId}']`);
238
- const headerColumnStyle = window.getComputedStyle(headerColumn || headerFirstCol, null);
239
- return {
240
- columnFriendlyName: col.friendlyName,
241
- width: Number(headerColumnStyle.width.replace('px', '')),
242
- textAlign: headerColumnStyle.textAlign,
243
- };
244
- }),
245
- },
246
- Row: {
247
- color: (0, tinycolor2_1.default)(firstRowStyle.color).toHexString(),
248
- backColor: (0, tinycolor2_1.default)(firstRowStyle.backgroundColor).toHexString(),
249
- altBackColor: (0, tinycolor2_1.default)(secondRowStyle.backgroundColor).toHexString(),
250
- fontFamily: firstRowStyle.fontFamily,
251
- fontSize: firstRowStyle.fontSize,
252
- fontStyle: firstRowStyle.fontStyle,
253
- fontWeight: firstRowStyle.fontWeight,
254
- height: Number(firstRowStyle.height.replace('px', '')),
255
- Columns: this.adaptable.api.columnApi.getUIAvailableColumns().map((col) => {
256
- const cellElement = document.querySelector(`.ag-cell[col-id='${col.columnId}']`);
257
- const headerColumnStyle = window.getComputedStyle(cellElement || firstRow, null);
258
- return {
259
- columnFriendlyName: col.friendlyName,
260
- width: Number(headerColumnStyle.width.replace('px', '')),
261
- textAlign: headerColumnStyle.textAlign,
262
- };
263
- }),
264
- },
265
- };
266
- }
267
- getDefaultIPPStyle() {
268
- return {
269
- Header: {
270
- headerColor: '#000000',
271
- headerBackColor: '#f5f7f7',
272
- headerFontFamily: 'sans-serif',
273
- headerFontSize: '12px',
274
- headerFontStyle: 'normal',
275
- headerFontWeight: '400',
276
- height: 65,
277
- Columns: this.adaptable.api.columnApi.getUIAvailableColumns().map((col) => {
278
- return {
279
- columnFriendlyName: col.friendlyName,
280
- width: 200,
281
- textAlign: 'start',
282
- };
283
- }),
284
- },
285
- Row: {
286
- color: '#000000',
287
- backColor: '#ffffff',
288
- altBackColor: '#fcfdfe',
289
- fontFamily: 'sans-serif',
290
- fontSize: '12px',
291
- fontStyle: 'normal',
292
- fontWeight: '400',
293
- height: 30,
294
- Columns: this.adaptable.api.columnApi.getUIAvailableColumns().map((col) => {
295
- return {
296
- columnFriendlyName: col.friendlyName,
297
- width: 200,
298
- textAlign: 'start',
299
- };
300
- }),
301
- },
302
- };
303
- }
304
- }
305
- exports.PushPullService = PushPullService;