Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mykle1 committed Jul 24, 2017
1 parent fc02a0c commit 46f3f1e
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 10 additions & 0 deletions MMM-Launch.css
@@ -0,0 +1,10 @@
/* Copy and paste any or all of these css entries into your custom.css file inside your
* css folder. The functions are annotated to make things as easy as possible for you.
* Use any colors you want! Go to - "http://htmlcolorcodes.com/color-picker/"
* Pick your color, copy and paste the HEX number. Example - #62FF00 = bright green.
*/

.MMM-Launch .header{
color: white; /* Header color. Default is white. */
text-align: left; /* Align header text. (left, center, right) */
}
134 changes: 134 additions & 0 deletions MMM-Launch.js
@@ -0,0 +1,134 @@
/* Magic Mirror
* Module: MMM-Launch
*
* By Mykle1
*
*/
Module.register("MMM-Launch", {

// Module config defaults.
defaults: {
// multipleChoice: "Yes", // No = no multiple choice answers appear
useHeader: true, // false if you don't want a header
header: "We have liftoff!", // Any text you want
maxWidth: "250px",
rotateInterval: 30 * 1000, // 20 secs to think then answer appears for 10 secs
animationSpeed: 3000, // fade in and out speed
initialLoadDelay: 4250,
retryDelay: 2500,
updateInterval: 25 * 60 * 1000, // API limits 50 questions per call

},

getStyles: function() {
return ["MMM-Launch.css"];
},

start: function() {
Log.info("Starting module: " + this.name);

requiresVersion: "2.1.0",

// Set locale.
this.url = "https://launchlibrary.net/1.1/launch?next=60&mode=verbose";
this.Launch = [];
this.activeItem = 0;
this.rotateInterval = null;
this.scheduleUpdate();
},

getDom: function() {

var wrapper = document.createElement("div");
wrapper.className = "wrapper";
wrapper.style.maxWidth = this.config.maxWidth;

if (!this.loaded) {
wrapper.innerHTML = "T - Minus 10 seconds . . .";
wrapper.classList.add("bright", "light", "small");
return wrapper;
}

if (this.config.useHeader != false) {
var header = document.createElement("header");
header.classList.add("xsmall", "bright", "light", "header");
header.innerHTML = this.config.header;
wrapper.appendChild(header);
}


var LaunchKeys = Object.keys(this.Launch);
if (LaunchKeys.length > 0) {
if (this.activeItem >= LaunchKeys.length) {
this.activeItem = 0;
}
var Launch = this.Launch[LaunchKeys[this.activeItem]];


var top = document.createElement("div");
top.classList.add("list-row");


// picture of rocket type
var img = document.createElement("img");
img.classList.add("photo");
img.src = Launch[0].rocket.imageURL;
wrapper.appendChild(img);


// launch date and time
var launchDate = document.createElement("div");
launchDate.classList.add("small", "bright", "launchDate");
launchDate.innerHTML = "Launching " + Launch[0].net;
wrapper.appendChild(launchDate);


// launch site
var launchSite = document.createElement("div");
launchSite.classList.add("small", "bright", "launchSite");
launchSite.innerHTML = "Launch site " + Launch[0].location.name;
wrapper.appendChild(launchSite);

}
return wrapper;
},


processLaunch: function(data) {
this.today = data.Today;
this.Launch = data;
console.log(this.Launch); // checking my data
this.loaded = true;
},

scheduleCarousel: function() {
console.log("Carousel of Launch fucktion!");
this.rotateInterval = setInterval(() => {
this.activeItem++;
this.updateDom(this.config.animationSpeed);
}, this.config.rotateInterval);
},

scheduleUpdate: function() {
setInterval(() => {
this.getLaunch();
}, this.config.updateInterval);
this.getLaunch(this.config.initialLoadDelay);
var self = this;
},

getLaunch: function() {
this.sendSocketNotification('GET_LAUNCH', this.url);
},

socketNotificationReceived: function(notification, payload) {
if (notification === "LAUNCH_RESULT") {
this.processLaunch(payload);
if (this.rotateInterval == null) {
this.scheduleCarousel();
}
this.updateDom(this.config.animationSpeed);
}
this.updateDom(this.config.initialLoadDelay);
},
});
37 changes: 37 additions & 0 deletions node_helper.js
@@ -0,0 +1,37 @@
/* Magic Mirror
* Module: MMM-Launch
*
* By Mykle1
*
*/
const NodeHelper = require('node_helper');
const request = require('request');



module.exports = NodeHelper.create({

start: function() {
console.log("Starting node_helper for: " + this.name);
},

getLaunch: function(url) {
request({
url: url,
method: 'GET'
}, (error, response, body) => {
if (!error && response.statusCode == 200) {
var result = JSON.parse(body).launches; // Parsing an array
console.log(response.statusCode + result);
this.sendSocketNotification('LAUNCH_RESULT', result);

}
});
},

socketNotificationReceived: function(notification, payload) {
if (notification === 'GET_LAUNCH') {
this.getLaunch(payload);
}
}
});

0 comments on commit 46f3f1e

Please sign in to comment.