node-red-contrib-alice 2.1.4 → 2.1.5

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,6 +1,5 @@
1
1
  const axios = require('axios');
2
2
 
3
-
4
3
  module.exports = function(RED) {
5
4
  // ***************************** Alice DEVICE ****************************
6
5
  function AliceDevice(config){
package/nodes/alice.html CHANGED
@@ -56,6 +56,7 @@
56
56
  });
57
57
  };
58
58
  function GetToken(code){
59
+ console.log(this.id);
59
60
  RED.notify("Request has been sent. Please, wait",{type:"compact"});
60
61
  $('#verification_code').prop('disabled', true);
61
62
  $('#submit_button').prop('disabled', true);
@@ -84,8 +85,19 @@
84
85
  $('#submit_button').prop('disabled', false);
85
86
  });
86
87
  }
87
- function ClearDataOnGateway(jToken) {
88
-
88
+ function ClearDevicesConfigOnGateway(email) {
89
+ RED.notify("Request has been sent. Please, wait",{type:"compact"});
90
+ const suburl = btoa(email);
91
+ $.ajax({
92
+ url: "/noderedhome/"+suburl+"/clearalldevice",
93
+ type:"GET"
94
+ })
95
+ .done(result=>{
96
+ RED.notify("All configs have been successfully cleared", {type:"success"});
97
+ })
98
+ .fail(error=>{
99
+ RED.notify("Error when deleting configs on the gateway", {type:"error"});
100
+ })
89
101
  };
90
102
  function pay(id, email) {
91
103
  console.log("Start pay");
@@ -203,11 +215,6 @@
203
215
  <span> - By purchasing a subscription, you agree to the terms of the <a href="https://nodered-home.ru/public_offer.pdf" target="_blank">public offer</a></span><br>
204
216
  <span> - View and manage your subscriptions <a href="https://my.cloudpayments.ru/ru/unsubscribe" target="_blank">here</a></span>
205
217
  <div style="text-align: end">
206
- <!-- <label for="node-input-subList" style="text-align: start">Period:</label>
207
- <select id="node-input-subList" style="width:70%; margin-top:10px; margin-bottom:10px;">
208
- <option value=1>1 month - 199 rubles</option>
209
- <option value=12>12 month - 2 300 rubles</option>
210
- </select> -->
211
218
  <button id="subscribe-button"
212
219
  onclick="pay($('#node-config-input-id').val(), $('#node-config-input-email').val())"
213
220
  class="ui-button">Buy a subscription
@@ -217,21 +224,18 @@
217
224
  </div>
218
225
  </div>
219
226
  <hr>
220
- <div name="Clearing" style="display: none;">
221
- <div class="form-row"><b>Сlear all data on the gateway</b></div>
222
- <div class="form-row">
223
- <p>1. Click the clear button</p>
224
- <p>2. Wait for the success message</p>
225
- <p>3. Сlose the window and do a full deploy</p>
226
- <button
227
- style="margin-left: 150px; margin-top: 10px;"
228
- onclick="ClearDataOnGateway($('#node-config-input-token').val())"
229
- class="ui-button">
230
- Сlear data on the gateway
231
- </button>
232
- </div>
227
+ <div name="Clearing">
228
+ <div class="form-row"><b>Сlear all data and configs on the gateway</b></div>
233
229
  <div class="form-tips" id="node-tip">
234
- <span>Tip: Сlear all data on the gateway may take up to 15 seconds, please wait for success or error message.</span>
230
+ <span>Tip: Сlear all data on the gateway may take up to 15 seconds, please wait for success or error message. When finished, make a full deployment to update the settings on the gateway.</span>
231
+ <div style="text-align: end">
232
+ <button
233
+ style="margin-left: 150px; margin-top: 10px;"
234
+ onclick="ClearDevicesConfigOnGateway($('#node-config-input-email').val())"
235
+ class="ui-button">
236
+ Сlear data on the gateway
237
+ </button>
238
+ </div>
235
239
  </div>
236
240
  </div>
237
241
  </script>
package/nodes/alice.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const mqtt = require('mqtt');
2
+ const axios = require('axios');
2
3
 
3
4
  module.exports = function(RED) {
4
5
  //Sevice node, Alice-Service (credential)
@@ -11,6 +12,29 @@ module.exports = function(RED) {
11
12
  const password = this.credentials.password;
12
13
  const token = this.credentials.token;
13
14
 
15
+ const suburl = Buffer.from(email).toString('base64');
16
+ RED.httpAdmin.get("/noderedhome/"+suburl+"/clearalldevice",(req,res)=>{
17
+ const option = {
18
+ method: 'POST',
19
+ url: 'https://api.nodered-home.ru/gtw/device/clearallconfigs',
20
+ headers: {
21
+ 'content-type': 'application/json',
22
+ 'Authorization': "Bearer "+this.getToken()
23
+ },
24
+ data: {}
25
+ };
26
+ axios.request(option)
27
+ .then(result=>{
28
+ this.trace("All devices configs deleted on gateway successfully");
29
+ // console.log(result)
30
+ res.sendStatus(200);
31
+ })
32
+ .catch(error=>{
33
+ this.debug("Error when delete All devices configs deleted on gateway: "+error.message);
34
+ res.sendStatus(500);
35
+ });
36
+ });
37
+
14
38
  this.isOnline = false;
15
39
  if (!token){
16
40
  this.error("Authentication is required!!!");
@@ -97,3 +121,5 @@ module.exports = function(RED) {
97
121
  });
98
122
  };
99
123
 
124
+
125
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-alice",
3
- "version": "2.1.4",
3
+ "version": "2.1.5",
4
4
  "description": "",
5
5
  "main": "alice.js",
6
6
  "scripts": {