From 03c346f5d2ba40a42ab01d016232032b5754d8c8 Mon Sep 17 00:00:00 2001 From: GotPPay Date: Fri, 5 Jan 2018 17:56:24 +0100 Subject: [PATCH] popup info ; token update --- backend/helpers/amazon.js | 2 -- backend/helpers/database.js | 16 +++++++++++----- web/package.json | 2 ++ web/src/App.js | 25 ++++++++++++++++++++++--- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/backend/helpers/amazon.js b/backend/helpers/amazon.js index 2bca863..bae5d87 100644 --- a/backend/helpers/amazon.js +++ b/backend/helpers/amazon.js @@ -95,8 +95,6 @@ var uploadSkill = function(skill){ module.exports = { updateSkill: function(skill, db){ - console.log("update skill function"); - return new Promise((resolve,reject)=>{ if (new Date() / 1000 > config.TOKEN_EXPIRES_IN){ refreshToken(db).then(()=>{ diff --git a/backend/helpers/database.js b/backend/helpers/database.js index ac580b8..fd32459 100644 --- a/backend/helpers/database.js +++ b/backend/helpers/database.js @@ -10,12 +10,18 @@ module.exports = { loadTokens : function(){ db.collection('token_list').findOne().then(tokens=>{ - config.TOKEN = tokens.access_token; - config.REFRESH_TOKEN = tokens.refresh_token; - config.TOKEN_EXPIRES_IN = tokens.expires_in; - console.log("Tokens loaded"); + if (tokens !== null){ + config.TOKEN = tokens.access_token; + config.REFRESH_TOKEN = tokens.refresh_token; + config.TOKEN_EXPIRES_IN = tokens.expires_in; + }else{ + //Cannot continue without tokens + console.log("Cannot continue without tokens in database"); + process.exit(-1); + } }).catch(e=>{ - console.log("Error loading tokens"); + console.log("Error loading tokens ! Cannot continue without tokens in database"); + process.exit(-1); }) } } \ No newline at end of file diff --git a/web/package.json b/web/package.json index 0c49f3b..217a9a8 100644 --- a/web/package.json +++ b/web/package.json @@ -3,9 +3,11 @@ "version": "0.1.0", "private": true, "dependencies": { + "keymaster": "^1.6.2", "react": "^16.2.0", "react-dom": "^16.2.0", "react-md": "^1.2.8", + "react-popup": "^0.9.1", "react-scripts": "1.0.17", "webfontloader": "^1.6.28" }, diff --git a/web/src/App.js b/web/src/App.js index df1c76f..c8944f5 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -1,8 +1,10 @@ import React, { Component } from 'react'; import './css/App.css'; +import './css/popup.css'; import IntentList from './components/IntentList'; import IntentDetails from './components/IntentDetails'; import LaunchRequest from './components/LaunchRequest'; +import Popup from 'react-popup'; import {getSkill, updateSkill} from './lib/api' @@ -42,6 +44,7 @@ class App extends Component { if(this.state.launchRequest){ return (
+

Tell All

@@ -59,6 +62,7 @@ class App extends Component { }else{ return (
+

Tell All

@@ -100,10 +104,15 @@ class App extends Component { console.log("handleSaveLaunchRequest"); updateSkill(this.createSkill(this.state.allIntents,name,answer)).then(l=>l.text()).then(result=>{ let jResult = JSON.parse(result); - console.log(jResult.result); + if (jResult.result !== 0){ + Popup.alert('Model was not saved. Please try again'); + }else{ + Popup.alert('Saved'); + } console.log(jResult.message); }).catch(e=>{ console.log("Error :" + e); + Popup.alert('Model was not saved. Please try again'); }); } @@ -118,10 +127,15 @@ class App extends Component { this.setState({allIntents: newAllIntents, selectedIntent: {intentName:'', questions:[''],answer:''}}); updateSkill(this.createSkill(newAllIntents)).then(l=>l.text()).then(result=>{ let jResult = JSON.parse(result); - console.log(jResult.result); + if (jResult.result !== 0){ + Popup.alert('Model was not saved. Please try again'); + }else{ + Popup.alert('Saved'); + } console.log(jResult.message); }).catch(e=>{ console.log("error : " + e); + Popup.alert('Model was not saved. Please try again'); }); }catch(e){ console.log("error : " + e); @@ -143,9 +157,14 @@ class App extends Component { updateSkill(this.createSkill(newAllIntents)).then(l=>l.text()).then(result=>{ let jResult = JSON.parse(result); - console.log(jResult.result); + if (jResult.result !== 0){ + Popup.alert('Model was not saved. Please try again'); + }else{ + Popup.alert('Saved'); + } console.log(jResult.message); }).catch(e=>{ + Popup.alert('Model was not saved. Please try again'); console.log("error : " + e); });