javascript - Trouble declaring and linking a controller together in my app -
so have 3 files. there source folder contains app.js file , contains folder called sheets_api_quickstart, contains quickstart.js, , folder called project, contains waiting_list.html
i attempted set controller call function test() waiting_list.html using button. unfortunately app won't start after trying implement this. gives console error failed load resource: net::err_connection_refused
is there obvious i'm missing or doing wrong?
app.js
var express = require('express'); var app = express(); var fs = require('fs'); var myapp = angular.module('myapp.controllers', []); //var file = "daycaredb.db"; //var exists = fs.existssync(file); //var db = opendatabase(file); app.use(express.static(__dirname + '/project')); app.use(express.static(__dirname + '/')); app.get('/', function (req, res) { res.sendfile('project/home.html', {root: __dirname }); }); app.listen(3000); console.log("running @ port 3000");
quickstart.js
angular.module('myapp.controllers').controller('quickstartcontroller', ['$scope', '$http', function($scope, $http){ var fs = require('fs'); var updatedb = require('./updatedb.js'); var readline = require('readline'); var google = require('googleapis'); var googleauth = require('google-auth-library'); var splitdata; // if modifying these scopes, delete saved credentials // @ ~/.credentials/sheets.googleapis.com-nodejs-quickstart.json var scopes = ['https://www.googleapis.com/auth/spreadsheets']; var token_dir = (process.env.home || process.env.homepath || process.env.userprofile) + '/.credentials/'; var token_path = token_dir + 'sheets.googleapis.com-nodejs-quickstart.json'; var array = []; var test = function(){ console.log("hello world"); } var run = { runquickstart : function() { // load client secrets local file. fs.readfile('client_secret.json', function processclientsecrets(err, content) { if (err) { console.log('error loading client secret file: ' + err); return; } // authorize client loaded credentials, call // google sheets api. authorize(json.parse(content), listchildren); }); }, test : function(){ console.log("hello world"); } } /** * create oauth2 client given credentials, , execute * given callback function. * * @param {object} credentials authorization client credentials. * @param {function} callback callback call authorized client. */ function authorize(credentials, callback) { var clientsecret = credentials.installed.client_secret; var clientid = credentials.installed.client_id; var redirecturl = credentials.installed.redirect_uris[0]; var auth = new googleauth(); var oauth2client = new auth.oauth2(clientid, clientsecret, redirecturl); // check if have stored token. fs.readfile(token_path, function(err, token) { if (err) { getnewtoken(oauth2client, callback); } else { oauth2client.credentials = json.parse(token); callback(oauth2client); } }); } /** * , store new token after prompting user authorization, , * execute given callback authorized oauth2 client. * * @param {google.auth.oauth2} oauth2client oauth2 client token for. * @param {geteventscallback} callback callback call authorized * client. */ function getnewtoken(oauth2client, callback) { var authurl = oauth2client.generateauthurl({ access_type: 'offline', scope: scopes }); console.log('authorize app visiting url: ', authurl); var rl = readline.createinterface({ input: process.stdin, output: process.stdout }); rl.question('enter code page here: ', function(code) { rl.close(); oauth2client.gettoken(code, function(err, token) { if (err) { console.log('error while trying retrieve access token', err); return; } oauth2client.credentials = token; storetoken(token); callback(oauth2client); }); }); } /** * store token disk used in later program executions. * * @param {object} token token store disk. */ function storetoken(token) { try { fs.mkdirsync(token_dir); } catch (err) { if (err.code != 'eexist') { throw err; } } fs.writefile(token_path, json.stringify(token)); console.log('token stored ' + token_path); } /** * print information children registered, store information in database. */ function listchildren(auth) { var sheets = google.sheets('v4'); sheets.spreadsheets.values.get({ auth: auth, spreadsheetid: '1ev8s8aaamxf3vp0f6rwxkiulvf6ufemsrofwa1onbyi', //this can found in url of our google sheet range: 'form responses 1!a2:x2', }, function(err, response) { if (err) { console.log('the api returned error: ' + err); return; } var rows = response.values; if (!rows) { console.log('no data found.'); return; } else { updatedb.inputformtodb.apply(this, rows); console.log('form responses'); (var = 0; < rows.length; i++) { var row = rows[i]; // print columns through x, correspond indices 0 through 23. console.log('%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s', row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9],row[10], row[11], row[12], row[13], row[14], row[15], row[16], row[17], row[18], row[19], row[20], row[21], row[22], row[23]); } var spreadsheetid = '1ev8s8aaamxf3vp0f6rwxkiulvf6ufemsrofwa1onbyi'; //this can found in url of our google sheet var requests = []; requests.push({ "deletedimension": { "range": { "sheetid": 1484177643, //this can found after string 'gid=' in url of our google sheet "dimension": "rows", "startindex": 1, "endindex": 2 } } }); requests.push({ "insertdimension": { "range": { "sheetid": 1484177643, //this can found after string 'gid=' in url of our google sheet "dimension": "rows", "startindex": 499, "endindex": 500 } } }); var batchupdaterequest = {requests: requests} sheets.spreadsheets.batchupdate({ auth: auth, spreadsheetid: spreadsheetid, //this can found in url of our google sheet resource: batchupdaterequest }, function(err, response) { if(err) { // handle error console.log(err); } else{ sheets.spreadsheets.values.get({ auth: auth, spreadsheetid: '1ev8s8aaamxf3vp0f6rwxkiulvf6ufemsrofwa1onbyi', //this can found in url of our google sheet range: 'form responses 1!a2', }, function(err, response) { if (err) { console.log('the api returned error: ' + err); return; } var cell = response.values; if (!cell) { console.log('sheet empty now.'); return; } else { settimeout(function() { listchildren(auth); },1150); } }); } }); } }); } module.exports = run; }]);
waiting_list.html
<doctype! html> <html> <head> <script type="text/javascript" src="waitinglist.js"></script> <style type="text/css"> .tftable { width:100%; border: 1px solid black; background-color: black; /* border-collapse: collapse; */ padding: 5px; } /* define background color odd background rows */ .tftable tr:nth-child(odd){ background: #b8d1f3; } /* define background color background rows */ .tftable tr:nth-child(even){ background: #dae5f4; } </style> <script type="text/javascript" src="updatedb.js"></script> <script type="text/javascript" src="quickstart.js"></script> <script src="app.js"></script> <script src="quickstart.js"></script> </head> <body ng-app="myapp" ng-controller="quickstartcontroller"> <h1>waiting list testing</h1> <button type="button" onclick="()" ng-submit="test()">refresh list</button> <div id="display"></div> <table class = "tftable"> <tr> <th>child's name</th> <th>d.o.b.</th> <th>phone number</th> <th>primany parent name</th> <th>primanry parent status</th> <th>secondary parent name</th> <th>secondary parent status</th> <th>date of app.</th> <th>desired start date</th> <th>class</th> <th>days</th> <th>view profile</th> <th>accept</th> </tr> <tr> <th>jessica brown</th> <th>06/04/2007</th> <th>(123)456-7890</th> <th>john brown</th> <th>student</th> <th>jane brown</th> <th>comunaty</th> <th>10/31/2016</th> <th>1/1/2017</th> <th>in</th> <th>mwf</th> <!-- make shure button code between <th> , </th> tags --> <th><button type="button" onclick="profile()"> profile</button></th> <th><button type="button" onclick="accept()">accept</button> </th> </table> <p id="accepted"></p> <script> function accept(){ confirm("you clicked accept! \nnothing has happened.\n thank you."); } function profile(){ window.location.href = 'demopage.html'; } </script> </body> </html>
you mixing front-end , back-end. node.js server side language, , angular client side. while work together, don't manage them same script. think you'll want full mean stack tutorial untangle of this.
Comments
Post a Comment