node-red-node-web-nodes
Version:
A collection of Node-RED nodes for popular web services.
262 lines (242 loc) • 12.2 kB
HTML
<!--
Copyright 2014 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/x-red" data-template-name="jawboneup-credentials">
<div id="node-config-jawboneup-app-keys">
<div class="form-row">
<p style="margin-top: 10px;"><b>1.</b> Create an account on <a href="https://jawbone.com/up/developer/auth/login" target="_blank" style="text-decoration:underline;">Jawbone.com</a>,
then sign in via the link under "Account" on the left side of the developer portal
(see <a href="https://jawbone.com/up/developer/faq" target="_blank" style="text-decoration:underline;">Developer FAQ</a>).</p>
</div>
<div class="form-tips" id="node-config-jawboneup-tooltip">
</div>
<div class="form-row">
<p style="margin-top: 10px;"><b>2.</b> Copy the app details here:</p>
</div>
<div class="form-row">
<label style="margin-left: 10px; margin-right: -10px;" for="node-config-input-client_id"><i class="fa fa-user"></i> Client Id</label>
<input type="password" id="node-config-input-client_id">
</div>
<div class="form-row">
<label style="margin-left: 10px; margin-right: -10px;" for="node-config-input-app_secret"><i class="fa fa-key"></i> App Secret</label>
<input type="password" id="node-config-input-app_secret">
</div>
<div class="form-row">
<label> </label>
<a class="btn" id="node-config-start-auth" href="#" target="_blank">Authenticate with Jawbone</a>
</div>
</div>
<div id="node-config-jawboneup-user">
<div class="form-row">
<label><i class="fa fa-user"></i> Jawbone User</label><span id="node-config-jawboneup-displayname" class="input-xlarge uneditable-input"></span>
</div>
<input type="hidden" id="node-config-input-displayname">
</div>
</script>
<script type="text/javascript">
(function() {
RED.nodes.registerType('jawboneup-credentials',{
category: 'config',
defaults: {
displayname: {value:""}
},
credentials: {
displayname: {type:"text", required: true},
clientid: {type:"password",required:true},
appsecret: {type: "password",required:true},
accesstoken: {type: "password", required:true}
},
label: function() {
return this.displayname;
},
exportable: false,
oneditprepare: function() {
var id = this.id;
var pathname = document.location.pathname;
if (pathname.slice(-1) != "/") {
pathname += "/";
}
var callback = location.protocol + "//" +
location.hostname +
(location.port?":"+location.port:"")+
pathname + "jawboneup-credentials";
$("#node-config-jawboneup-tooltip").html("<p>Please configure the authorized <b>OAuth Redirect URIs</b> of your app to include the following url:</p>\n<code>"+callback+"</code>");
function updateJawboneupAuthButton() {
var v1 = $("#node-config-input-client_id").val();
var v2 = $("#node-config-input-app_secret").val();
$("#node-config-start-auth").toggleClass("disabled",(v1.length === 0 || v2.length === 0));
}
$("#node-config-input-client_id").on('change keydown paste input',updateJawboneupAuthButton);
$("#node-config-input-app_secret").on('change keydown paste input',updateJawboneupAuthButton);
function updateJawboneupScreenName(sn) {
$("#node-config-jawboneup-app-keys").hide();
$("#node-config-jawboneup-user").show();
$("#node-config-input-displayname").val(sn);
$("#node-config-jawboneup-displayname").html(sn);
}
function pollJawboneupCredentials(e) {
$.getJSON('credentials/jawboneup-credentials/'+id,function(data) {
if (data.displayname) {
$("#node-config-dialog-ok").button("enable");
updateJawboneupScreenName(data.displayname);
delete window.jawboneupConfigNodeIntervalId;
} else {
window.jawboneupConfigNodeIntervalId = window.setTimeout(pollJawboneupCredentials,2000);
}
});
}
updateJawboneupAuthButton();
if (this.displayname) {
updateJawboneupScreenName(this.displayname);
} else {
$("#node-config-jawboneup-app-keys").show();
$("#node-config-jawboneup-user").hide();
$("#node-config-dialog-ok").button("disable");
}
$("#node-config-start-auth").mousedown(function(e) {
var client_id = $("#node-config-input-client_id").val();
var app_secret = $("#node-config-input-app_secret").val();
var pathname = document.location.pathname;
if (pathname.slice(-1) != "/") {
pathname += "/";
}
var callback = encodeURIComponent(location.protocol+"//"+location.hostname+
(location.port?":"+location.port:"")+
pathname+"jawboneup-credentials/auth/callback");
var url = 'jawboneup-credentials/auth?id='+id+'&callback='+callback+'&clientid='+client_id+"&appsecret="+app_secret;
$(this).attr("href",url);
window.jawboneupConfigNodeIntervalId = window.setTimeout(pollJawboneupCredentials,2000);
});
$("#node-config-start-auth").click(function(e) {
var key = $("#node-config-input-client_id").val();
var secret = $("#node-config-input-app_secret").val();
if (key === "" || secret === "") {
e.preventDefault();
}
});
},
oneditsave: function() {
if (window.jawboneupConfigNodeIntervalId) {
window.clearTimeout(window.jawboneupConfigNodeIntervalId);
delete window.jawboneupConfigNodeIntervalId;
}
},
oneditcancel: function(adding) {
if (window.jawboneupConfigNodeIntervalId) {
window.clearTimeout(window.jawboneupConfigNodeIntervalId);
delete window.jawboneupConfigNodeIntervalId;
}
}
});
})();
</script>
<script type="text/x-red" data-template-name="jawboneup">
<div class="form-row">
<label for="node-input-jawboneup"><i class="fa fa-user"></i> Log in as</label>
<input type="text" id="node-input-jawboneup">
</div>
<div class="form-row">
<label for="node-input-get"> <i class="fa fa-filter"></i> Get</label>
the workouts completed since
</div>
<div class="form-row">
<label> </label>
<input type="text" id="node-input-starttime" style="width:200px"> (epoch)
</div>
<div class="form-row">
<label for="node-input-outputnumber"><i class="fa fa-sign-out"></i> Output</label>
<select id="node-input-outputnumber" style="width:15% !important">
<option value="1">1</option>
<option value="10">10</option>
</select>
result<span id="node-input-outputnumber-plural">s</span>
as <select id="node-input-outputas" style='width:40% !important'>
<option value="multiple">multiple messages</option>
<option value="single">a single message</option>
</select>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name">
</div>
</script>
<script type="text/x-red" data-help-name="jawboneup">
<p>Jawbone Up node.</p>
<p>Can be used to retrieve the workouts completed since the provided time (given as Epoch). This
time can be passed in as settings on the node or as the <b>msg.starttime</b> section of the message input.
The value set on the node will take precedence over the contents of incoming message.
</p>
<p>The number of results to return from the query and how to return them (either as a single message
or as multiple messages) are settings on the node.</p>
<p>The node sets the following properties, if available,
<ul>
<li><b>payload</b> - the JSON of the workout</li>
<li><b>title</b> - the type of workout</li>
<li><b>id</b> - the unique id for the workout</li>
<li><b>location.lat</b> - the latitude of where the workout took place</li>
<li><b>location.lon</b> - the longitude of where the workout took place</li>
<li><b>payload.type</b> - the type of workout</li>
<li><b>payload.starttime</b> - the start time of the workout as a Javascript Date object</li>
<li><b>payload.duration</b> - the duration of the workout in seconds</li>
<li><b>payload.distance</b> - the distance of the workout in meters</li>
<li><b>payload.calories</b> - the total calories burned during the workout</li>
<li><b>data</b> - the JSON of the workout</li>
</ul>
The exact location of these properties depends on the number of results chosen to be returned along
with how to return them:
<ul>
<li>If the node output value is set to one then for both returning as a single message and as multiple
messages, the node returns a msg for the latest workout since the provided start time. The returned msg
has the properties set on it.
</li>
<li>If the node output value is set to more than one to be returned as a single message
the node sets <b>msg.payload</b>
to be an array of <b>msg</b>'s, each one corresponding to a workout. The first element in the array is
the latest workout and the length of the array is the output value set on the node or the
number of workouts found, whichever is smaller. Each element in this array has the properties on them.
</li>
<li>If the node output value is set to more than one but to be returned as a multiple then the node sends
multiple msgs, each one representing a workout found.
</ul>
<p>Jawbone and Up are trademarks of Jawbone.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('jawboneup',{
category: 'fitness',
color:"#C0DEED",
defaults: {
jawboneup: {type:"jawboneup-credentials",required:true},
starttime:{value:""},
outputnumber:{value:"1"},
outputas:{value:"single"},
name: {value:""}
},
inputs:1,
outputs:1,
icon: "up.png",
label: function() {
return this.name||'jawbone up';
},
oneditprepare: function() {
var updateOptions = function() {
var outputnumber = $("#node-input-outputnumber option:selected").val();
if (outputnumber == "1") {
$("#node-input-outputnumber-plural").hide();
} else {
$("#node-input-outputnumber-plural").show();
}
};
updateOptions();
$("#node-input-outputnumber").change(updateOptions);
}
});
</script>