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