Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
227 commits
Select commit Hold shift + click to select a range
25b603a
fix bootstrap style overrides
sjgllghr Sep 29, 2018
78cf511
add basic landing page
sjgllghr Sep 29, 2018
b5bd83c
fix signin redirects
sjgllghr Sep 30, 2018
26c7cf4
fix cross browser appearance
sjgllghr Sep 30, 2018
c4f89bb
update dependencies
sjgllghr Oct 6, 2018
e0dd992
set up cms for survey modules
sjgllghr Oct 6, 2018
d89eb60
add start of team choosing
sjgllghr Oct 7, 2018
0032b3d
add basic account creation
sjgllghr Oct 7, 2018
c207d11
Merge pull request #1 from msarthak90/master
will-saunders Oct 14, 2018
70e4e22
Merge pull request #2 from sjgllghr/WIP_LandingPage
will-saunders Oct 14, 2018
d6b6cde
fix application start error
sjgllghr Oct 14, 2018
be18e22
Merge pull request #3 from sjgllghr/WIP_LandingPage
will-saunders Oct 14, 2018
8e4683f
put survey modules on seperate pages
sjgllghr Nov 5, 2018
24ded0c
add resouce area
sjgllghr Nov 5, 2018
35c8493
try to add some styling
sjgllghr Nov 7, 2018
38b220a
adjust logged in navbar and footer
sjgllghr Nov 8, 2018
3e557b5
fix more spacing
sjgllghr Nov 8, 2018
c4931e4
fix invalid requests
sjgllghr Nov 8, 2018
7937ec8
secondary nav for modules
sjgllghr Nov 8, 2018
33ad929
start of pills
sjgllghr Nov 10, 2018
f8ca265
nav pills working
sjgllghr Nov 10, 2018
947634d
add basic development/contributing documentation
sjgllghr Nov 10, 2018
9c43021
add team label and fix spacing
sjgllghr Nov 11, 2018
e9f6ea0
Merge pull request #4 from sjgllghr/docs
will-saunders Nov 11, 2018
5257722
Merge pull request #6 from sjgllghr/surveyModulePages
will-saunders Nov 11, 2018
990b8a4
fix favicon scaling
sjgllghr Nov 11, 2018
9c6eab0
Merge pull request #5 from sjgllghr/fixIcons
will-saunders Nov 11, 2018
8882e7c
fix new user startup
sjgllghr Nov 11, 2018
b914600
remove team code, fix password confirm
sjgllghr Nov 11, 2018
6f50cbe
Merge pull request #7 from sjgllghr/hack3.0
will-saunders Nov 12, 2018
382401d
add landing page sign in
sjgllghr Nov 13, 2018
09782d8
Merge pull request #8 from sjgllghr/hack3.0
will-saunders Nov 17, 2018
c281e8e
fix readme and no team on assessments bug...
sjgllghr Nov 17, 2018
0875767
Update README.md
Nov 17, 2018
6564a1f
Move wireframes and design guide to new subfolder design
Nov 17, 2018
2fd30c6
adding in backup scripts for mongo
Nov 18, 2018
a3ebf72
Merge branch 'master' of github.com:shankj3/BCAT
Nov 18, 2018
ef78117
removing google apis from package.json
Nov 18, 2018
01d91cf
removing google apis from package.json, also package-lock
Nov 18, 2018
014a3ec
woops
Nov 18, 2018
9fa05c4
add user roles
sjgllghr Nov 18, 2018
96bcc15
Merge pull request #10 from shankj3/master
will-saunders Nov 18, 2018
d87a45d
Merge pull request #11 from sjgllghr/hack3.0
will-saunders Nov 18, 2018
1a31d3e
signin on account creation
sjgllghr Nov 25, 2018
386db5c
rework/fill out signup
sjgllghr Nov 26, 2018
07f6eca
remove unecessary dot files, edit gitignore
sjgllghr Nov 26, 2018
e92a150
update javascript syntax
sjgllghr Nov 27, 2018
7ff0b99
code cleanup
sjgllghr Nov 27, 2018
e46f642
update readme
sjgllghr Dec 16, 2018
f8bc801
update readme
sjgllghr Jan 12, 2019
09da802
add initial team
sjgllghr Jan 12, 2019
43ad9d7
add basic example of using keystone for surveys
sjgllghr Nov 29, 2018
0f9a6e5
the about page will now store answers every 5 seconds, and on page lo…
mariannefeng Dec 17, 2018
adda303
add saving users answers to module
sjgllghr Dec 17, 2018
dd88424
get rid of google forms
sjgllghr Dec 18, 2018
d212712
add updating answers in db
sjgllghr Dec 31, 2018
80fd519
fix questions update after model rename
sjgllghr Jan 12, 2019
ec05e4c
add editable scale end text
sjgllghr Jan 12, 2019
e8f4af7
Get answers from db and localstorage
sjgllghr Jan 12, 2019
63b94f0
added todos list
mariannefeng Feb 24, 2019
e7cf281
Update TODOs.md
kperry150 Feb 24, 2019
689760b
Merge pull request #12 from will-saunders/surveyPoC
sjgllghr Feb 24, 2019
c8a9424
added jquery to conditionally show teams based on state
shankj3 Feb 24, 2019
0f10c56
adding comment
shankj3 Feb 24, 2019
5fe8e9e
removed accidental back tick
shankj3 Feb 24, 2019
a88baec
Merge pull request #13 from shankj3/join-team-state-filter
sjgllghr Feb 24, 2019
0af2f5a
fixed key collision for localstorage, added regular pushes to server …
mariannefeng Feb 25, 2019
eb0feb8
Merge branch 'master' of github.com:will-saunders/BCAT into quiz-changes
mariannefeng Feb 25, 2019
1fed349
changed server push interval back to 1 minute
mariannefeng Feb 25, 2019
622e3a1
Update 0.0.4-questions.js
AliaAnor Feb 25, 2019
7ef46d6
add requested features and fix quiz formatting
sjgllghr Mar 3, 2019
1faadb2
allow adding questions from json files instead of update files
sjgllghr Mar 3, 2019
4f1904f
make actually make file reading async
sjgllghr Mar 3, 2019
59e98ee
update packages, add server reloading
sjgllghr Mar 3, 2019
1b37bd3
added checkmark to mark as complete button in survey form
mariannefeng Mar 24, 2019
a4f197a
cross off participants
shankj3 Apr 14, 2019
dc6a82c
Merge pull request #15 from will-saunders/quiz-changes
sjgllghr Apr 14, 2019
df2947f
Merge branch 'master' into fixQuestions
sjgllghr Apr 14, 2019
585e2f4
Merge pull request #16 from will-saunders/fixQuestions
sjgllghr Apr 14, 2019
e1d78ae
Merge branch 'master' of https://github.com/will-saunders/bcat
shankj3 Apr 14, 2019
a90e733
uppercase L to lowercase for the logo
shankj3 Apr 14, 2019
c8adb18
Merge pull request #23 from shankj3/logo-fix-maybe
sjgllghr Apr 14, 2019
1119201
implement module progress save
shankj3 Apr 14, 2019
4b62310
removing commented out line
shankj3 Apr 14, 2019
c7824d0
making code comment more clear
shankj3 Apr 14, 2019
f8a520a
adding back in save button
shankj3 Apr 14, 2019
e28f702
added question
shankj3 Apr 14, 2019
ef9830f
Merge pull request #36 from will-saunders/finish-progress
sjgllghr Apr 14, 2019
c4d0e1c
Added and changed the modules
AliaAnor Apr 14, 2019
1fb06ff
Merge branch 'fixQuestions' of https://github.com/will-saunders/BCAT …
AliaAnor Apr 14, 2019
2f5198b
Merge pull request #38 from will-saunders/fixQuestions
AliaAnor Apr 15, 2019
5e30678
add basic team lead functionality
sjgllghr Feb 24, 2019
511ed45
fix typo
sjgllghr Apr 14, 2019
cadd5d6
fix appearance and query the right table...
sjgllghr Apr 14, 2019
df64a5a
show assigned modules as checked in modal
sjgllghr Apr 20, 2019
36b7b2c
fix #37 - list modules in order to be completed
sjgllghr May 5, 2019
02c7e9d
Merge pull request #39 from will-saunders/teamLead
sjgllghr May 5, 2019
ffc391a
added export button to team dashboard
mariannefeng May 5, 2019
c954e76
made team table a table, starting switching up modal for modifying us…
shankj3 May 5, 2019
f9bd0d8
add team member completed/assigned counts
sjgllghr May 5, 2019
d766d6a
fix #37 - list modules in order to be completed
sjgllghr May 5, 2019
2904ad8
role displays in the table, can be updated w/ update user modal
shankj3 May 5, 2019
700e10f
made team table a table, starting switching up modal for modifying us…
shankj3 May 5, 2019
784e54c
already saved role show up in modal when opened
shankj3 May 5, 2019
1341af1
first go at exporting answers by csv
mariannefeng May 5, 2019
e851551
add module progress to table
sjgllghr May 5, 2019
0044d38
removed console logs, updated assigner jquery on modal form
shankj3 May 5, 2019
6fd45ed
Merge branch 'team-lead-table' of https://github.com/will-saunders/BC…
sjgllghr May 5, 2019
3ca6aa4
whoops
sjgllghr May 5, 2019
8403190
Merge branch 'team-lead-table' of https://github.com/will-saunders/BC…
sjgllghr May 5, 2019
346b91a
grabbed the wrong change merging
sjgllghr May 5, 2019
df8e1ed
clearer option in role assignment soo ppl know they can un-assign roles
shankj3 May 5, 2019
da5d54d
semi colon
sjgllghr May 5, 2019
a99e4d1
renamed update user function
shankj3 May 5, 2019
32b7f3f
Merge branch 'team-lead-table' of https://github.com/will-saunders/BC…
sjgllghr May 5, 2019
53f432c
formatting modules
shankj3 May 5, 2019
88c93bd
merge conflict
shankj3 May 5, 2019
efbba2b
removing console log
shankj3 May 5, 2019
38651ef
Merge pull request #41 from will-saunders/team-lead-table
shankj3 May 5, 2019
7545031
fixed bug with null user ids and added error handling
mariannefeng May 5, 2019
9b2eebd
comment
mariannefeng May 5, 2019
ccc4362
url list of resources for each survey
sjgllghr May 5, 2019
43cc0ab
moved csv parsing to server side, changed button to be a tag w/ href …
mariannefeng May 6, 2019
ba02913
Merge pull request #40 from will-saunders/csv_export
mariannefeng May 6, 2019
4f9a527
added datatables sorting for team lead view table
shankj3 May 6, 2019
ffaae64
Merge branch 'master' of https://github.com/will-saunders/bcat into s…
shankj3 May 6, 2019
dfdd039
get resource open graph info and format nice-ish
sjgllghr May 6, 2019
37ba047
trying to get rid of dumb git spacing issues
shankj3 May 6, 2019
2fcb723
url list of resources for each survey
sjgllghr May 5, 2019
f28f1a0
get resource open graph info and format nice-ish
sjgllghr May 6, 2019
7445e5e
adding if check, also an onerror for chrome
shankj3 May 6, 2019
abd62df
merge conflict
shankj3 May 6, 2019
3c80b7b
updating datatable overriding style to get rid of intellij whitespace…
shankj3 May 6, 2019
980bb72
Merge pull request #43 from will-saunders/resources
shankj3 May 6, 2019
44d561f
adding comment for default sorting
shankj3 May 6, 2019
e94c1b9
merge conflict
shankj3 May 6, 2019
c67ab8c
regenerated css
shankj3 May 6, 2019
966f4d4
Merge pull request #44 from will-saunders/sort-teamlead-table
sjgllghr May 6, 2019
acd9aa8
changed checkbox to be radio button for na scale
mariannefeng May 6, 2019
4cbe65a
erge branch 'master' of github.com:will-saunders/BCAT
mariannefeng May 6, 2019
6b89537
bump update file name
sjgllghr May 6, 2019
16a3234
Merge branch 'master' of https://github.com/will-saunders/BCAT
sjgllghr May 6, 2019
79b3dc6
fix update script bug for modules
sjgllghr May 6, 2019
c207cc1
update node modules
sjgllghr May 19, 2019
c8914a8
remove powered by keystone
sjgllghr May 19, 2019
9f95b65
Updates text on landing page
kperry150 May 19, 2019
d992a43
fix whitespace
sjgllghr May 19, 2019
78a959e
Updated the modules for formatting and added 4 more.
AliaAnor May 19, 2019
aef1134
landing page style updates
sjgllghr May 19, 2019
d454bc7
remove user location and phone, add affiliation
sjgllghr May 19, 2019
edd4cd0
rename team folder
sjgllghr May 19, 2019
65832c9
Merge pull request #50 from will-saunders/lessUserInfo
sjgllghr May 19, 2019
90c06f1
Merge pull request #47 from will-saunders/modules
sjgllghr May 19, 2019
8620f6d
Corrected the 1 2 3 to be 01 02 03 in modules
AliaAnor May 19, 2019
b4ead0b
remove path and team on assessment page
sjgllghr May 20, 2019
2043cab
add new modules
sjgllghr May 20, 2019
aa706a7
Merge pull request #52 from will-saunders/modules
sjgllghr May 20, 2019
adcd7d9
remove comments
sjgllghr May 20, 2019
95f8808
Merge pull request #54 from will-saunders/updateScripts
sjgllghr May 20, 2019
82bf417
add team table to home page
sjgllghr Jun 3, 2019
3ff0d24
add team name to navbar
sjgllghr Jun 3, 2019
0980e8b
only show team nav link if a team lead
sjgllghr Jun 3, 2019
c96a39b
add missing fields to team model
sjgllghr Jun 9, 2019
b3a59a2
fix no team/role bugs
sjgllghr Jun 9, 2019
a733a83
allow team lead to create users
sjgllghr Jun 9, 2019
a149368
fix new user form view
sjgllghr Jun 9, 2019
92c01ad
clean up home and team pages
sjgllghr Jun 9, 2019
3159013
remove email and progress from home view
sjgllghr Jun 9, 2019
99f65ad
change roles
sjgllghr Jun 9, 2019
7e75551
fix roles to not be plural
sjgllghr Jun 9, 2019
876fde6
unbreak homepage styling
sjgllghr Jun 9, 2019
c57c0bf
Merge pull request #57 from will-saunders/homePage
sjgllghr Jun 9, 2019
8a8a8cd
add roles to modules
sjgllghr Jun 30, 2019
a240ab3
started work on selecting modules based on role
mariannefeng Jun 30, 2019
719fea6
add error handling
sjgllghr Jun 30, 2019
872cf38
Merge pull request #63 from will-saunders/role_module
sjgllghr Jun 30, 2019
f12a7f9
add last login field
sjgllghr Jun 30, 2019
358c248
fix multiple user logins/table bug
sjgllghr Jun 30, 2019
93f059d
fix wording
sjgllghr Jun 30, 2019
9e6851f
formatted last active date to be beautiful in admin team view
mariannefeng Jun 30, 2019
a8c5c57
making it so that date won't wrap even if modules is super long
mariannefeng Jun 30, 2019
753b39a
Merge pull request #64 from will-saunders/lastLogin
sjgllghr Jun 30, 2019
30ca152
most of home progress works, just fixing kinks in assessment url
mariannefeng Jul 1, 2019
9e3ec37
still working on changes from swapping from survey index => assessmen…
mariannefeng Jul 1, 2019
eb7cb1a
having issues with grabbing module progress, db has correct values, b…
mariannefeng Jul 1, 2019
0232d19
Merge branch 'master' into team-home-progress
sjgllghr Jul 21, 2019
d8f7097
fix progress bug
sjgllghr Jul 21, 2019
27e1db5
clean up
sjgllghr Jul 21, 2019
7c424a3
redo home and team lead pages
sjgllghr Jul 22, 2019
a0f248c
fix home and team tables
sjgllghr Jul 22, 2019
0e8ffc3
less weird modals
sjgllghr Jul 22, 2019
546cabe
tamer assessment page
sjgllghr Jul 22, 2019
278fe44
fix assessment spacing
sjgllghr Jul 22, 2019
537a71d
add community representation mock
sjgllghr Jul 22, 2019
a48c414
finish home page, clean up date formats
sjgllghr Jul 22, 2019
6f2bf74
add back resources page
sjgllghr Jul 22, 2019
972c9bd
navbars and home page
sjgllghr Jul 22, 2019
96c4c11
fix homepage tabs
sjgllghr Jul 23, 2019
8452153
remove no longer used login/create user code
sjgllghr Jul 23, 2019
c760d68
add progress bars
sjgllghr Jul 23, 2019
fa1c373
fix home page tabs and buttons
sjgllghr Jul 24, 2019
59c80a5
handle missing module progress better
sjgllghr Jul 25, 2019
364ab2e
404 for non-existant assessment page
sjgllghr Jul 25, 2019
6481d71
Merge pull request #65 from will-saunders/team-home-progress
sjgllghr Jul 27, 2019
9c6c221
Merge pull request #66 from will-saunders/redesign
sjgllghr Jul 27, 2019
58123b4
fix modal text box font color
sjgllghr Jul 27, 2019
0edc6ad
npm audit
sjgllghr Jul 27, 2019
49b6472
add initial mappings
sjgllghr Jul 27, 2019
8cb5604
fix progress percentage bug
sjgllghr Jul 27, 2019
1ab8921
Added real text to index, about, and resources
AliaAnor Aug 4, 2019
4362c8e
Merge branch 'master' of https://github.com/will-saunders/BCAT
AliaAnor Aug 4, 2019
9e295da
couple of edits to about page
sjgllghr Aug 5, 2019
0838b0a
side navbar for assessment page
sjgllghr Jul 28, 2019
30126e8
fix home page spacing
sjgllghr Jul 28, 2019
2773249
update buttons
sjgllghr Aug 5, 2019
e401ddd
fix mobile navbar and home image
sjgllghr Aug 10, 2019
495f53c
fix tables for mobile
sjgllghr Aug 10, 2019
548e452
more mobile friendly assessment links
sjgllghr Aug 10, 2019
9825931
fix announcment links for small screens
sjgllghr Aug 10, 2019
ec64124
fix accidental bug
sjgllghr Aug 10, 2019
65451d9
fix spacing on assessment page
sjgllghr Aug 11, 2019
f26c66e
fix section titles
sjgllghr Aug 11, 2019
30f9a76
mobile assessment page styling
sjgllghr Aug 11, 2019
8ded45d
fix navbar issues for ~750px range
sjgllghr Aug 11, 2019
0b2cfc5
Merge pull request #68 from will-saunders/re-redesign
sjgllghr Aug 11, 2019
4cf172b
Updated the resources page and surveys
AliaAnor Sep 8, 2019
3470fb4
Update resources.pug
will-saunders Sep 21, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Development Info

All of the code for the project is current in the `survey-app` folder. This project is built using [KeystoneJS](https://keystonejs.com/). More specifically it uses [Node.js](https://nodejs.org/en/), [MongoDB](https://www.mongodb.com/what-is-mongodb), [Express](https://expressjs.com/), [Pug](https://pugjs.org/api/getting-started.html), [Stylus](http://stylus-lang.com/) and [Bootstrap](https://getbootstrap.com/).

## Dependencies
* Node.js / npm
* https://nodejs.org/en/download/
* MongoDB
* Mac: `brew install mongodb`
* [Windows](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/)
* If this is your first time using MongoDB, you will also need to set up a `/data/db` directory with the correct permissions.
* [Mac and Windows Examples](https://stackoverflow.com/questions/41420466/mongodb-shuts-down-with-code-100)

## Set up
* Clone the repository

```
git clone https://github.com/will-saunders/BCAT.git
cd BCAT/survey-app
npm install
```
* Create a `.env` file with a cookie secret:

```
echo "COOKIE_SECRET=<a_bunch_of_characters>" > .env
```
For now, `<a_bunch_of_characters>` can be whatever you'd like.

* In a separate terminal start mongodb: `mongod`
* Run `npm start`
* Check `localhost:3000`
* Login to the admin page with username: `user@keystonejs.com` and password: `pass`
* Debugging should work out of the box with VSCode

## Structure
```
BCAT/survey-app
|-- models
|-- public
|-- styles
|-- site
|-- _layout.styl
|-- _variables.styl
|-- routes
|-- index.js
|-- middleware.js
|-- views
|-- templates
|-- views
```
* models
* this is where MongoDB models are defined, using [keystone field types](https://keystonejs.netlify.com/api/field/)
* public/styles/site
* `_layout.styl` and `_variables.styl` are the stylus files to override bootstrap defaults.
* `site.css` and `site.styl` are generated, so any changes you make to them will be overwritten
* routes
* this is the folder for express routing
* new routes are added to `routes/index.js`
* code for handling each new route should go under `routes/views/<your_view>.js`
* to create a variable that's accessible by a pug template, save it as `locals.varname`, which will be `varname` in the pug template
* templates
* this is the folder for pug templates
* code for new pages go under `templates/views/<your_view>.pug`

## Resources
[Keystone Demo](http://demo.keystonejs.com/)
[Keystone Demo Repo](https://github.com/keystonejs/keystone-demo)
[Keystone DB Documentation](https://keystonejs.netlify.com/documentation/database/)
[Throttling Network w/Chrome DevTools](https://developers.google.com/web/tools/chrome-devtools/network-performance/network-conditions)
31 changes: 0 additions & 31 deletions ReadMe

This file was deleted.

Binary file added assets/favicon.xcf
Binary file not shown.
Binary file added assets/favicon__.ico
Binary file not shown.
Binary file added assets/favicon___.ico
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
3 changes: 3 additions & 0 deletions survey-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ node_modules

# Ignore .DS_Store files on OS X
.DS_Store

# Ignore editor specific files
.vscode
39 changes: 39 additions & 0 deletions survey-app/TODOs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# TODO's for BCAT

### Team lead functionality:
* Create users
* Assign modules to individual users
* See module completion from their team (through the dashboard, Alia has designs)
* Add messages to bulletin board that will be visible to everybody on their team

### Answering Quizzes:
* Participants should be able to mark their quiz as complete
* Make it more obvious to participants that they need to **SEND** their quiz
* Assign localstorage bcat responses by bcat + userID

### Allow participants to join teams
~~* Participants should be able to filter down teams to their own state, and then choose their specific team~~

### Dashboard
* Dashboard for participant - see progress of their own modules/quizzes, and bulletin board that's updated by team lead
* Dashboard for team lead - see progress of their team for assigned modules/quizzes, and set messages to be shown on the team bulletin board

### Assessment
* KAP to finalized assessment questions
* Alia to convert to JSON

### Reports
* KAP and Alia to create set of dummy responses
* Mock up Report
* Develop set of Recommended Actions
-- If you want to correct data
-- If you want to identify funding sources
-- If you want to do a more detailed engineering study
-- If you want to evaluate technology/business options
-- If you want to engage partners

### Other
* Consider developing case studies

### Outreach/Testing

131 changes: 131 additions & 0 deletions survey-app/bin/backupMongo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/usr/bin/env node

const backup = require('mongodb-backup');
const fs = require('fs');

const BoxSDK = require('box-node-sdk');

// Create new Box SDK instance
const sdk = new BoxSDK({
clientID: process.env.BOX_CLIENT_ID,
clientSecret: process.env.BOX_CLIENT_SECRET,

});

// Create new basic client with developer token
const client = sdk.getBasicClient(process.env.BOX_DEV_TOKEN);
const folderId = '58640691930';

async function runBackup() {
await backup({

uri: process.env.MONGODB_URI,
root: __dirname + "/", // write files into this dir
tar: 'dump-me.tar',
callback: function(err) {
if (err) {
throw err
} else {
console.log('successfully backed up to ' + __dirname + 'dump-me.tar');
}
}
});
}

function uploadBackup() {
// Set upload values
let filePath = __dirname + '/dump-me.tar';
let fileName = 'mongo-backup.tar';

// Create file upload stream
const stream = fs.createReadStream(filePath);

// Upload file
return client.files.uploadFile(
folderId,
fileName,
stream,
function(err, res) {
if (err) {
throw err
} else {
console.log("successful upload");
}
}
);
}


async function getBackupIds() {
let ids = {};
await client.folders.getItems(folderId, {}, function(err, res){
if (err) {
console.log("error", err);
ids.error = err
} else {
// console.log("response", res);
res.entries.forEach(function(file){
console.log("ENTRIES!!!!!", file.id);
if (file.name === "mongo-backup.tar") {
ids.currentBackup = file.id;
} else if (file.name === "mongo-backup-backup.tar") {
ids.previousBackup = file.id;
} else {
console.log("inconsequential: ", file.name)
}
});
// console.log("IDS", ids);
}
});
// console.log("IDS!!!!!!!!!!!!!!!!!!!", ids);
return ids
}

async function moveAroundOldData() {
let hope = await getBackupIds();
if (hope.error) {
console.log("there was an error getting ids", hope.error);
throw hope.error
}
// if everything went swimmingly, delete old backup
// console.log("backup", hope);
if (hope.previousBackup) {
console.log("deleting previous backup");
await client.files.delete(hope.previousBackup, function(err){
if (err) {
console.log("oh newwwwww", err);
throw err;
}
});
}
// move "current" backup to previous backup
if (hope.currentBackup) {
console.log("moving mongo-backup to mongo-backup-backup");
await client.files.update(hope.currentBackup, {name: "mongo-backup-backup.tar"}
).then((resp) => {
console.log("updated", resp.id, resp.name)
}).catch(err => {
console.log("error occurred!", err);
throw err;
})
}
}

if (module === require.main) {
// create new mongo backup tar
runBackup().then(() => {
// copy mongo-backup.tar to mongo-backup-backup.tar, delete old mongo-backup-backup
moveAroundOldData().then(() => {
// upload new mongo-backup.tar
uploadBackup().catch(err => {
console.error("unable to upload new backup", err)
})
}).catch(err => {
console.error("unable to remove old backup: ", err)
});
}).catch(err => {
console.error("unable to create backup: ", err)
})

}

9 changes: 9 additions & 0 deletions survey-app/bin/restoreMongo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node

const restore = require('mongodb-restore');

restore({
uri: process.env.MONGODB_URI,
root: __dirname,
tar: 'mongo-backup.tar',
});
12 changes: 7 additions & 5 deletions survey-app/keystone.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('dotenv').config();

// Require keystone
var keystone = require('keystone');
const keystone = require('keystone');

// Initialise Keystone with your project's configuration.
// See http://keystonejs.com/guide/config for available options
Expand Down Expand Up @@ -41,14 +41,16 @@ keystone.set('locals', {
// Load your project's Routes
keystone.set('routes', require('./routes'));

// Set login image
keystone.set('signin logo', '../images/BCATlogo.svg');
keystone.set('signin redirect', '/home');
keystone.set('signout redirect', '/');

// Configure the navigation bar in Keystone's Admin UI
keystone.set('nav', {
users: 'users',
users: ['users', 'teams', 'roles'],
modules: ['modules', 'questions']
});

// Start Keystone to connect to your database and initialise the web server



keystone.start();
13 changes: 13 additions & 0 deletions survey-app/models/Answer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const keystone = require('keystone');
const Types = keystone.Field.Types;

const Answer = new keystone.List('Answer', {track: {updatedAt: true}});

Answer.add({
userId: { type: Types.Relationship, ref: 'User', initial: true, required: true },
moduleId: { type: Types.Relationship, ref: 'Module',initial: true, required: true },
questionId: { type: Types.Relationship, ref: 'Question', initial: true, required: true },
answer: { type: Types.TextArray }
});

Answer.register();
21 changes: 21 additions & 0 deletions survey-app/models/Module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const keystone = require('keystone');
const Types = keystone.Field.Types;

const Module = new keystone.List('Module', {
autokey: { from: 'name', path: 'key', unique: true },
label: 'Modules',
});

Module.add({
name: { type: String, required: true },
rank: { type: Number, required: true, initial: true},
resources: {type: Types.TextArray}
});

Module.relationship({ ref: 'Question', refPath: 'module' });
Module.relationship({ ref: 'Answer', refPath: 'moduleId'});
Module.relationship({ ref: 'ModuleProgress', refPath: 'moduleId'});
Module.relationship({ ref: 'User', refPath: 'assignedModules'});
Module.relationship({ ref: 'Role', refPath: 'modules'});

Module.register();
13 changes: 13 additions & 0 deletions survey-app/models/ModuleProgress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const keystone = require('keystone');
const Types = keystone.Field.Types;

const ModuleProgress = new keystone.List('ModuleProgress', {track: {updatedAt: true}});

ModuleProgress.add({
userId: { type: Types.Relationship, ref: 'User', initial: true, required: true },
moduleId: { type: Types.Relationship, ref: 'Module',initial: true, required: true },
progress: { type: Types.Select, options: [{value: 'IN_PROGRESS', label: 'In Progress'}, {value: 'COMPLETE', label: 'Complete'}, {value: 'NOT_STARTED', label: 'Not Started'}]},
percentage: { type: Types.Number }
});

ModuleProgress.register();
20 changes: 20 additions & 0 deletions survey-app/models/Question.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const keystone = require('keystone');
const Types = keystone.Field.Types;

/**
* Question Model
* ==========
*/
const Question = new keystone.List('Question');

Question.add({
name: { type: Types.Text, initial: true, required: true},
question: { type: Types.Text, initial: true, required: true },
type: { type: Types.Select, options:['Checkboxes', 'Radio', 'Textarea', 'Scale', 'Info'], default:'Radio', intial: true, required: true },
module: { type: Types.Relationship, ref: 'Module'},
answers: { type: Types.TextArray }
});

Question.relationship({ ref: 'Answer', refPath: 'questionId'});

Question.register();
Loading