mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Tidy up pushbullet (no fixes)
remove old migration code)
This commit is contained in:
parent
e5f41880c3
commit
4884550215
@ -1,7 +1,7 @@
|
||||
|
||||
<!-- PUSHBULLET CONFIG -->
|
||||
|
||||
<script type="text/x-red" data-template-name="pushbullet-config">
|
||||
<script type="text/html" data-template-name="pushbullet-config">
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||
<input type="text" id="node-config-input-name" placeholder="Name">
|
||||
@ -30,7 +30,7 @@
|
||||
|
||||
<!-- PUSHBULLET OUT -->
|
||||
|
||||
<script type="text/x-red" data-template-name="pushbullet">
|
||||
<script type="text/html" data-template-name="pushbullet">
|
||||
<div class="form-row">
|
||||
<label for="node-input-config"><i class="fa fa-user"></i> Config</label>
|
||||
<input type="text" id="node-input-config">
|
||||
@ -72,12 +72,9 @@
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-tips" id="pushbullet-migration-info" style="display: none;">
|
||||
<p><i class="fa fa-random"></i> Configuration node has been migrated, please click Ok and then re-deploy flow to save settings.</p>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="pushbullet">
|
||||
<script type="text/html" data-help-name="pushbullet">
|
||||
<p>Uses PushBullet to push <code>msg.payload</code> to a device that has the PushBullet app installed.</p>
|
||||
<p>Optionally uses <code>msg.topic</code> to set the title, if not already set in the properties.</p>
|
||||
<p>Optionally uses <code>msg.pushtype</code> to set the type of the push, if not already set in the properties.</p>
|
||||
@ -122,7 +119,6 @@
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
getName(this.credentials.deviceid);
|
||||
}
|
||||
@ -131,7 +127,6 @@
|
||||
getName(data.deviceid);
|
||||
});
|
||||
}
|
||||
|
||||
return this.name||this.devicename||this.title||"pushbullet";
|
||||
},
|
||||
labelStyle: function() {
|
||||
@ -139,9 +134,6 @@
|
||||
},
|
||||
oneditsave: function() {
|
||||
this.devicename = undefined;
|
||||
if(this.migrationData) {
|
||||
$.ajax('pushbullet/'+this.id+'/migrate?save=true');
|
||||
}
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var node = this, ddConfig = $('#node-input-config'), ddDevice = $('#node-input-deviceid'), ddPushtype = $('#node-input-pushtype');
|
||||
@ -181,7 +173,6 @@
|
||||
addCurrent = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(currentDevice) {
|
||||
if(addCurrent && currentDevice !== "_msg_") {
|
||||
ddDevice.append('<option value="'+currentDevice+'">'+currentDevice+'</option>');
|
||||
@ -191,75 +182,13 @@
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function checkMigration(cb) {
|
||||
$.getJSON('pushbullet/'+node.id+'/migrate', function(data) {
|
||||
var showMigration = false;
|
||||
node.migrationData = data.config;
|
||||
if(data.migrated) {
|
||||
if(data.config) {
|
||||
var configId = data.config;
|
||||
var configType = 'pushbullet-config';
|
||||
var configTypeDef = RED.nodes.getType(configType);
|
||||
RED.nodes.add({
|
||||
type: configType,
|
||||
id: configId,
|
||||
name: "Imported",
|
||||
users: [node.id],
|
||||
label: configTypeDef.label,
|
||||
_def: configTypeDef,
|
||||
});
|
||||
}
|
||||
if(node.credentials) {
|
||||
if(node.credentials.pushkey) {
|
||||
if(ddConfig.find('option[value="'+data.config+'"]').length === 0) {
|
||||
ddConfig.append('<option value="'+data.config+'">Imported</option>');
|
||||
}
|
||||
ddConfig.val(data.config);
|
||||
showMigration = true;
|
||||
}
|
||||
else {
|
||||
ddConfig.val("_ADD_");
|
||||
}
|
||||
|
||||
if(node.credentials.deviceid) {
|
||||
ddDevice.append('<option value="'+node.credentials.deviceid+'">Imported</option>');
|
||||
ddDevice.val(node.credentials.deviceid);
|
||||
showMigration = true;
|
||||
}
|
||||
else {
|
||||
ddDevice.val("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(showMigration) {
|
||||
ddPushtype.val("note");
|
||||
node.dirty = true;
|
||||
$('#pushbullet-migration-info').show();
|
||||
}
|
||||
if(cb) {
|
||||
cb(showMigration);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
checkMigration(function(migrated) {
|
||||
if(!migrated) {
|
||||
ddConfig.change(function() {
|
||||
if(ddConfig.val() && ddConfig.val() !== "_ADD_") {
|
||||
updateDeviceList();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- PUSHBULLET IN -->
|
||||
|
||||
<script type="text/x-red" data-template-name="pushbullet in">
|
||||
<script type="text/html" data-template-name="pushbullet in">
|
||||
<div class="form-row">
|
||||
<label for="node-input-config"><i class="fa fa-user"></i> Config</label>
|
||||
<input type="text" id="node-input-config" placeholder="Node-RED">
|
||||
@ -277,7 +206,7 @@
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="pushbullet in">
|
||||
<script type="text/html" data-help-name="pushbullet in">
|
||||
<p>Receives Pushbullets from all devices. Messages contain the following data:</p>
|
||||
<p><code>msg.pushtype</code>: type of message</p>
|
||||
<p><code>msg.topic</code>: topic information from the push</p>
|
||||
|
@ -34,23 +34,11 @@ module.exports = function(RED) {
|
||||
});
|
||||
|
||||
PushbulletConfig.prototype.initialise = function() {
|
||||
if (this.initialised) {
|
||||
return;
|
||||
}
|
||||
if (this.initialised) { return; }
|
||||
this.emitter = new EventEmitter();
|
||||
|
||||
this.initialised = true;
|
||||
var self = this;
|
||||
|
||||
// sort migration from old node
|
||||
var apikey;
|
||||
if (this.n._migrate) {
|
||||
apikey = this.n._apikey;
|
||||
this.credentials = {apikey:apikey};
|
||||
}
|
||||
else if (this.credentials) {
|
||||
apikey = this.credentials.apikey;
|
||||
}
|
||||
var apikey = this.credentials.apikey;
|
||||
|
||||
if (apikey) {
|
||||
try {
|
||||
@ -254,84 +242,23 @@ module.exports = function(RED) {
|
||||
this._inputNodes.push(handler);
|
||||
};
|
||||
|
||||
function migrateOldSettings(n) {
|
||||
if (n.config === undefined) {
|
||||
var newid, config, apikey, deviceid, pushkeys;
|
||||
|
||||
try {
|
||||
pushkeys = RED.settings.pushbullet || require(process.env.NODE_RED_HOME+"/../pushkey.js");
|
||||
}
|
||||
catch(err) { }
|
||||
|
||||
var cred = RED.nodes.getCredentials(n.id);
|
||||
// get old apikey
|
||||
if (cred && cred.hasOwnProperty("pushkey")) {
|
||||
apikey = cred.pushkey;
|
||||
}
|
||||
else if (pushkeys) {
|
||||
apikey = pushkeys.pushbullet;
|
||||
}
|
||||
// get old device
|
||||
if (cred && cred.hasOwnProperty("deviceid")) {
|
||||
deviceid = cred.deviceid;
|
||||
}
|
||||
else if (pushkeys) {
|
||||
deviceid = pushkeys.deviceid;
|
||||
}
|
||||
|
||||
if (apikey) {
|
||||
newid = (1+Math.random()*4294967295).toString(16);
|
||||
config = new PushbulletConfig({
|
||||
id: newid,
|
||||
type: 'pushbullet-config',
|
||||
name: n.name,
|
||||
_migrate: true,
|
||||
_apikey: apikey,
|
||||
});
|
||||
}
|
||||
|
||||
if (!(apikey || deviceid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// override configuration properties to compatible migrated ones
|
||||
n.pushtype = "note";
|
||||
n.deviceid = deviceid;
|
||||
return {
|
||||
deviceid: deviceid,
|
||||
apikey: apikey,
|
||||
config: config,
|
||||
id: newid
|
||||
};
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function PushbulletOut(n) {
|
||||
RED.nodes.createNode(this, n);
|
||||
var self = this;
|
||||
|
||||
this.migrated = migrateOldSettings(n);
|
||||
this.title = n.title;
|
||||
this.chan = n.chan;
|
||||
this.pushtype = n.pushtype;
|
||||
this.pusher = null;
|
||||
|
||||
var configNode;
|
||||
if (this.migrated) {
|
||||
this.warn('Settings migrated from previous version of Pushbullet Node, please edit node to update settings.');
|
||||
this.status({fill: 'yellow', shape: 'ring', text: 'Node migrated'});
|
||||
this.deviceid = this.migrated.deviceid;
|
||||
configNode = this.migrated.config;
|
||||
}
|
||||
else {
|
||||
this.status({});
|
||||
configNode = RED.nodes.getNode(n.config);
|
||||
try {
|
||||
this.deviceid = this.credentials.deviceid;
|
||||
}
|
||||
catch(err) { }
|
||||
|
||||
this.status({});
|
||||
configNode = RED.nodes.getNode(n.config);
|
||||
try {
|
||||
this.deviceid = this.credentials.deviceid;
|
||||
}
|
||||
catch(err) { }
|
||||
|
||||
if (configNode) {
|
||||
configNode.initialise();
|
||||
@ -462,27 +389,6 @@ module.exports = function(RED) {
|
||||
}
|
||||
};
|
||||
|
||||
RED.httpAdmin.get('/pushbullet/:id/migrate', RED.auth.needsPermission('pushbullet.read'), function(req, res) {
|
||||
var node = RED.nodes.getNode(req.params.id);
|
||||
if (node && node.migrated) {
|
||||
if (req.query.save) {
|
||||
var promise;
|
||||
if (node.migrated.apikey) {
|
||||
promise = RED.nodes.addCredentials(node.migrated.id, {apikey: node.migrated.apikey});
|
||||
}
|
||||
if (node.migrated.deviceid) {
|
||||
when(promise).then(function() {
|
||||
RED.nodes.addCredentials(req.params.id, {deviceid: node.migrated.deviceid});
|
||||
});
|
||||
}
|
||||
}
|
||||
res.send(JSON.stringify({migrated: true, config: node.migrated.id}));
|
||||
}
|
||||
else {
|
||||
res.send("{}");
|
||||
}
|
||||
});
|
||||
|
||||
RED.httpAdmin.get('/pushbullet/:id/devices', RED.auth.needsPermission('pushbullet.read'), function(req, res) {
|
||||
var config = RED.nodes.getNode(req.params.id);
|
||||
var cred = RED.nodes.getCredentials(req.params.id);
|
||||
|
Loading…
Reference in New Issue
Block a user