Skip to content
Permalink
Browse files

Merge pull request #252 from ReproNim/refactor-code

reformat code
  • Loading branch information...
sanuann committed Feb 7, 2019
2 parents 8207761 + 4f091a4 commit 2f4cd52623a27afff699c315206a2accf49a06d2
Showing with 15,486 additions and 15,639 deletions.
  1. +3 −3 .travis.yml
  2. +172 −169 eapp/app.js
  3. +62 −61 eapp/modules/data-collection/html/dc-export.html
  4. +57 −56 eapp/modules/data-collection/html/dc-form-2.html
  5. +66 −63 eapp/modules/data-collection/html/dc-form.html
  6. +67 −66 eapp/modules/data-collection/html/dc-list.html
  7. +59 −57 eapp/modules/data-collection/html/dc-mgm.html
  8. +75 −73 eapp/modules/data-collection/html/dc.html
  9. +38 −33 eapp/modules/experiment-planner/css/plan-board.css
  10. +121 −53 eapp/modules/experiment-planner/css/plan.css
  11. +44 −43 eapp/modules/experiment-planner/html/plan-board.html
  12. +53 −52 eapp/modules/experiment-planner/html/plan-mgm.html
  13. +407 −423 eapp/modules/experiment-planner/js/plan-board.js
  14. +95 −99 eapp/modules/experiment-planner/js/plan-mgm.js
  15. +614 −628 eapp/modules/experiment-planner/js/plan-utils.js
  16. +124 −120 eapp/modules/nda-editor/html/nda-editor.html
  17. +350 −421 eapp/modules/nda-editor/js/form-builder.js
  18. +491 −504 eapp/modules/nda-editor/js/nda-editor.js
  19. +55 −54 eapp/public/js/addProject.js
  20. +332 −329 eapp/public/js/form-gen.js
  21. +118 −119 eapp/public/js/form-gen1.js
  22. +5 −5 eapp/public/js/userAccount.js
  23. +91 −130 eapp/routes/acquisition.js
  24. +364 −386 eapp/routes/controllers.js
  25. +55 −64 eapp/routes/dataDictionary.js
  26. +248 −271 eapp/routes/instruments.js
  27. +402 −412 eapp/routes/nda.js
  28. +465 −467 eapp/routes/query.js
  29. +227 −231 eapp/util/graph.js
  30. +495 −506 eapp/util/nidme-graph.js
  31. +91 −90 eapp/views/addProject.pug
  32. +2 −2 eapp/views/formUpload.pug
  33. +17 −17 eapp/views/index.pug
  34. +62 −61 eapp/views/main-layout.pug
  35. +20 −39 eapp/views/main.pug
  36. +9 −9 eapp/views/mixins.pug
  37. +13 −13 eapp/views/sampleUpload.pug
  38. +61 −54 main.js
  39. +9,375 −9,375 package-lock.json
  40. +81 −81 package.json
@@ -25,9 +25,9 @@ matrix:
cache:
yarn: true
directories:
- node_modules
- $HOME/.cache/electron
- $HOME/.cache/electron-builder
- node_modules
- $HOME/.cache/electron
- $HOME/.cache/electron-builder

before_script:
# Replace clientId and clientSecret values in app-config.js with environment
@@ -2,182 +2,185 @@

module.exports = () => {

const express = require('express')
const session = require('express-session')
const cookieParser = require('cookie-parser')
const bodyParser = require('body-parser')
const flash = require('express-flash')
const path = require('path')
const fs = require('fs')
const rdfstore = require('rdfstore')
const passport = require('passport')
const methodOverride = require('method-override')
const GitHubStrategy = require('passport-github2').Strategy
const partials = require('express-partials')
const config = require('./config/app-config.js')
const rdfHelper = require('./util/nidme-graph.js')



global.uid = {}
global.github_token = ""

const GITHUB_CLIENT_ID = config.clientId
const GITHUB_CLIENT_SECRET = config.clientSecret

passport.serializeUser(function(user, done) {
//console.log("user:",user)
done(null, user);
});

passport.deserializeUser(function(obj, done) {
//console.log("obj",obj)
done(null, obj);
});
passport.use(new GitHubStrategy({
clientID: GITHUB_CLIENT_ID,
clientSecret: GITHUB_CLIENT_SECRET,
callbackURL: "http://127.0.0.1:3000/auth/github/callback"
},
function(accessToken, refreshToken, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function () {

// To keep the example simple, the user's GitHub profile is returned to
// represent the logged-in user. In a typical application, you would want
// to associate the GitHub account with a user record in your database,
// and return that user instead.
// console.log("accessToken: ", accessToken)
github_token = accessToken
// console.log("profile: ", profile)
return done(null, profile)
})
}
))

app = express()

//app.use(cookieParser('secret'))
//app.use(session({cookie: { maxAge: 60000 }}))
app.use(session({ secret: 'keyboard cat', resave: false, saveUninitialized: false }))
app.use(flash())


app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'pug')

app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.use(partials())
app.use(methodOverride())

//app.use(express.static(__dirname + '/public'));

// Passport initialization
app.use(passport.initialize());
app.use(passport.session());

app.get('/', function(req, res){
// console.log("user from request:",req.user)
res.render('index',{user:req.user})
})
app.get('/main', ensureAuthenticated, function(req, res){
//console.log("user from request:",req.user)
res.render('main',{user:req.user})
})
/*app.get('/account', ensureAuthenticated, function(req, res){
console.log("Authenticate account: ", req.user)
res.render('account', { user: req.user });
})*/
app.get('/login', function(req, res){
console.log("Trying to login: ", req.user)
res.render('login', { user: req.user });
})

app.get('/auth/github',
passport.authenticate('github', { scope: [ 'user:email','repo'] }),
function(req, res){
// The request will be redirected to GitHub for authentication, so this
// function will not be called.
})
const express = require('express')
const session = require('express-session')
const cookieParser = require('cookie-parser')
const bodyParser = require('body-parser')
const flash = require('express-flash')
const path = require('path')
const fs = require('fs')
const rdfstore = require('rdfstore')
const passport = require('passport')
const methodOverride = require('method-override')
const GitHubStrategy = require('passport-github2').Strategy
const partials = require('express-partials')
const config = require('./config/app-config.js')
const rdfHelper = require('./util/nidme-graph.js')


global.uid = {}
global.github_token = ""

const GITHUB_CLIENT_ID = config.clientId
const GITHUB_CLIENT_SECRET = config.clientSecret

passport.serializeUser(function (user, done) {
//console.log("user:",user)
done(null, user);
});

passport.deserializeUser(function (obj, done) {
//console.log("obj",obj)
done(null, obj);
});
passport.use(new GitHubStrategy({
clientID: GITHUB_CLIENT_ID,
clientSecret: GITHUB_CLIENT_SECRET,
callbackURL: "http://127.0.0.1:3000/auth/github/callback"
},
function (accessToken, refreshToken, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function () {

// To keep the example simple, the user's GitHub profile is returned to
// represent the logged-in user. In a typical application, you would want
// to associate the GitHub account with a user record in your database,
// and return that user instead.
// console.log("accessToken: ", accessToken)
github_token = accessToken
// console.log("profile: ", profile)
return done(null, profile)
})
}
))

app = express()

//app.use(cookieParser('secret'))
//app.use(session({cookie: { maxAge: 60000 }}))
app.use(session({secret: 'keyboard cat', resave: false, saveUninitialized: false}))
app.use(flash())


app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'pug')

app.use(bodyParser.urlencoded({extended: true}))
app.use(bodyParser.json())
app.use(partials())
app.use(methodOverride())

//app.use(express.static(__dirname + '/public'));

// Passport initialization
app.use(passport.initialize());
app.use(passport.session());

app.get('/', function (req, res) {
// console.log("user from request:",req.user)
res.render('index', {user: req.user})
})
app.get('/main', ensureAuthenticated, function (req, res) {
//console.log("user from request:",req.user)
res.render('main', {user: req.user})
})
/*app.get('/account', ensureAuthenticated, function(req, res){
console.log("Authenticate account: ", req.user)
res.render('account', { user: req.user });
})*/
app.get('/login', function (req, res) {
console.log("Trying to login: ", req.user)
res.render('login', {user: req.user});
})

app.get('/auth/github',
passport.authenticate('github', {scope: ['user:email', 'repo']}),
function (req, res) {
// The request will be redirected to GitHub for authentication, so this
// function will not be called.
})

// GET /auth/github/callback
// Use passport.authenticate() as route middleware to authenticate the
// request. If authentication fails, the user will be redirected back to the
// login page. Otherwise, the primary route function will be called,
// which, in this example, will redirect the user to the home page.
app.get('/auth/github/callback',
passport.authenticate('github', { failureRedirect: '/login' }),
function(req, res) {
//res.redirect('/')
res.redirect('/main')
app.get('/auth/github/callback',
passport.authenticate('github', {failureRedirect: '/login'}),
function (req, res) {
//res.redirect('/')
res.redirect('/main')
})
app.get('/logout', function (req, res) {
req.logout()
res.redirect('/')
})
app.get('/logout', function(req, res){
req.logout()
res.redirect('/')
})
app.use('/dist/css',express.static(path.join(__dirname,'/../node_modules/bootstrap/dist/css')))
app.use('/dist/fonts',express.static(path.join(__dirname,'/../node_modules/bootstrap/dist/fonts')))
app.use('/dist/jquery',express.static(path.join(__dirname,'/../node_modules/jquery/dist/')))
app.use('/dist/moment',express.static(path.join(__dirname,'/../node_modules/moment/')))
app.use('/dist/bootstrap',express.static(path.join(__dirname,'/../node_modules/bootstrap/dist/js')))
app.use('/dist/select2',express.static(path.join(__dirname,'/../node_modules/select2/dist')))
app.use('/dist/select2-bootstrap',express.static(path.join(__dirname,'/../node_modules/select2-bootstrap-theme/dist')))
app.use('/dist/slickgrid',express.static(path.join(__dirname,'/../node_modules/slickgrid')))
app.use('/dist/slickgrid-bootstrap',express.static(path.join(__dirname,'/../node_modules/slickgrid-bootstrap-dev/bootstrap')))
app.use('/dist/jqwidgets-framework',express.static(path.join(__dirname,'/../node_modules/jqwidgets-framework')))
app.use('/dist/handlebars',express.static(path.join(__dirname,'/../node_modules/handlebars/dist')))
app.use('/views/js',express.static(path.join(__dirname,'views/js')))
app.use('/dist/alpacalib',express.static(path.join(__dirname,'/../node_modules/alpaca/dist/lib')))
app.use('/dist/alpaca',express.static(path.join(__dirname,'/../node_modules/alpaca/dist/alpaca')))
app.use('/dist/uuid',express.static(path.join(__dirname,'/../node_modules/uuid-random')))
app.use(express.static(path.join(__dirname, 'public/images/')))

app.use(function (req, res, next) {
if (!req.isAuthenticated()) { return res.redirect('/') }
next();
});

app.use(express.static(path.join(__dirname, 'public/')))
app.use(express.static(path.join(__dirname, 'modules/')))

app.locals.setup = {}
app.locals.store = {}
// Setup Globally Included Routes
fs.readdirSync(path.join(__dirname, 'routes')).forEach(function(filename) {
console.log('reading routes file')
if(~filename.indexOf('.js'))
require(path.join(__dirname, 'routes/'+filename))(app)
})

/**
** TODO Create a directory structure specified on a default configuration file
**/
const dirPaths = config.dirPaths
new Promise(function(resolve){
console.log("paths list: ",dirPaths[0])
console.log("userData path: ", userData)
console.log("full path: ", path.join(userData,dirPaths[0]))
fs.stat(path.join(userData,dirPaths[0]), function(err,stat){
if(err){
for(let i=0;i<config.dirPaths.length;i++){
console.log("paths: ",dirPaths[i])
fs.mkdirSync(path.join(userData,dirPaths[i]))
app.use('/dist/css', express.static(path.join(__dirname, '/../node_modules/bootstrap/dist/css')))
app.use('/dist/fonts', express.static(path.join(__dirname, '/../node_modules/bootstrap/dist/fonts')))
app.use('/dist/jquery', express.static(path.join(__dirname, '/../node_modules/jquery/dist/')))
app.use('/dist/moment', express.static(path.join(__dirname, '/../node_modules/moment/')))
app.use('/dist/bootstrap', express.static(path.join(__dirname, '/../node_modules/bootstrap/dist/js')))
app.use('/dist/select2', express.static(path.join(__dirname, '/../node_modules/select2/dist')))
app.use('/dist/select2-bootstrap', express.static(path.join(__dirname, '/../node_modules/select2-bootstrap-theme/dist')))
app.use('/dist/slickgrid', express.static(path.join(__dirname, '/../node_modules/slickgrid')))
app.use('/dist/slickgrid-bootstrap', express.static(path.join(__dirname, '/../node_modules/slickgrid-bootstrap-dev/bootstrap')))
app.use('/dist/jqwidgets-framework', express.static(path.join(__dirname, '/../node_modules/jqwidgets-framework')))
app.use('/dist/handlebars', express.static(path.join(__dirname, '/../node_modules/handlebars/dist')))
app.use('/views/js', express.static(path.join(__dirname, 'views/js')))
app.use('/dist/alpacalib', express.static(path.join(__dirname, '/../node_modules/alpaca/dist/lib')))
app.use('/dist/alpaca', express.static(path.join(__dirname, '/../node_modules/alpaca/dist/alpaca')))
app.use('/dist/uuid', express.static(path.join(__dirname, '/../node_modules/uuid-random')))
app.use(express.static(path.join(__dirname, 'public/images/')))

app.use(function (req, res, next) {
if (!req.isAuthenticated()) {
return res.redirect('/')
}
}
resolve()
next();
});

app.use(express.static(path.join(__dirname, 'public/')))
app.use(express.static(path.join(__dirname, 'modules/')))

app.locals.setup = {}
app.locals.store = {}
// Setup Globally Included Routes
fs.readdirSync(path.join(__dirname, 'routes')).forEach(function (filename) {
console.log('reading routes file')
if (~filename.indexOf('.js'))
require(path.join(__dirname, 'routes/' + filename))(app)
})

/**
** TODO Create a directory structure specified on a default configuration file
**/
const dirPaths = config.dirPaths
new Promise(function (resolve) {
console.log("paths list: ", dirPaths[0])
console.log("userData path: ", userData)
console.log("full path: ", path.join(userData, dirPaths[0]))
fs.stat(path.join(userData, dirPaths[0]), function (err, stat) {
if (err) {
for (let i = 0; i < config.dirPaths.length; i++) {
console.log("paths: ", dirPaths[i])
fs.mkdirSync(path.join(userData, dirPaths[i]))
}
}
resolve()
})
}).then(function () {
setup = rdfHelper.rdfStoreSetup()
store = setup.store
})
}).then(function(){
setup = rdfHelper.rdfStoreSetup()
store = setup.store
})

app.listen(3000, function(){
console.log('Example app listening on port 3000')
})

function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated()) { return next() }
res.redirect('/')
}

app.listen(3000, function () {
console.log('Example app listening on port 3000')
})

function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated()) {
return next()
}
res.redirect('/')
}
}

0 comments on commit 2f4cd52

Please sign in to comment.
You can’t perform that action at this time.