diff --git a/modules/gitcontent.js b/modules/gitcontent.js index 384bba0..1406b51 100644 --- a/modules/gitcontent.js +++ b/modules/gitcontent.js @@ -34,12 +34,12 @@ module.exports = class GitContent { } //SELECT ALL GIT CONTENT - async allg() { + async all() { try{ console.log('ALL answers') const sql = 'SELECT id, title_of_content, block_of_content FROM git_content' console.log(sql) - const gitselected = await this.db.allg(sql) + const gitselected = await this.db.all(sql) console.log(gitselected) return gitselected } catch(err){ @@ -48,4 +48,19 @@ module.exports = class GitContent { } } + //GETS THE ID + async getById(id){ + try{ + console.log('BY ID') + console.log(id) + const sql =`SELECT * FROM git_content WHERE id=${id}` + console.log(sql) + const contentdb = await this.db.get(sql) + return contentdb + } catch(err) { + console.log(err.message) + throw err + } + } + } \ No newline at end of file diff --git a/modules/questions.js b/modules/questions.js index 9120619..304da20 100644 --- a/modules/questions.js +++ b/modules/questions.js @@ -31,7 +31,7 @@ module.exports = class Question { } } - //SELECT ALL QUESTIONS IN DB + //SELECT MOST QUESTIONS IN DB async all(){ try { console.log('ALL questions') diff --git a/public/style.css b/public/style.css index a703f2f..c4d8712 100644 --- a/public/style.css +++ b/public/style.css @@ -276,6 +276,49 @@ td:last-child { border-top: 5px solid grey; } +/*CCS for individual content*/ + +* { + box-sizing: border-box; + } + + /* Style the header */ + .header { + background-color: #f1f1f1; + padding: 30px; + text-align: center; + font-size: 35px; + } + + /* Create three equal columns that floats next to each other */ + .column { + float: left; + width: 33.33%; + padding: 10px; + height: 300px; /* Should be removed. Only for demonstration */ + } + + /* Clear floats after the columns */ + .row:after { + content: ""; + display: table; + clear: both; + } + + /* Style the footer */ + .footer { + background-color: #f1f1f1; + padding: 120px; + text-align: center; + } + + /* Responsive layout - makes the three columns stack on top of each other instead of next to each other */ + @media (max-width: 600px) { + .column { + width: 100%; + } + } + /*FOOTER*/ footer{ position: absolute; diff --git a/routes/secure.js b/routes/secure.js index 9816aef..24ff9c9 100644 --- a/routes/secure.js +++ b/routes/secure.js @@ -1,23 +1,24 @@ - +//router and body requirements const Router = require('koa-router') const koaBody = require('koa-body')({multipart: true, uploadDir: '.'}) +//all connections to to modules (js) const GitContent = require('../modules/gitcontent') const Answer = require('../modules/answers') const Question = require('../modules/questions') const dbName = 'website.db' +//prefix to make every page /secure const router = new Router({ prefix: '/secure' }) +//----------------ROUTER.GET-------------------// + //renders the menu for the git content and quiz router.get('/', async ctx => { try { if(ctx.hbs.authorised !== true) return ctx.redirect('/login?msg=you need to log in&referrer=/secure') - //const answers = await new Answer(dbName) - //ctx.hbs.answert = await answers.all() console.log(ctx.hbs) await ctx.render('menu.handlebars', ctx.hbs) - //this renders the MENU page } catch(err) { console.log(err.message) ctx.hbs.error = err.message @@ -40,12 +41,40 @@ router.get('/backoffice', async ctx =>{ } }) +//Render for the QUIZ PAGE handlebar +router.get('/quiz', async ctx => { + try { + if(ctx.hbs.authorised !== true) return ctx.redirect('/login?msg=you need to log in&referrer=/secure/quiz') + const questions = await new Question(dbName) + ctx.hbs.questiont = await questions.all() + console.log(ctx.hbs) + await ctx.render('quizpage', ctx.hbs) + } catch(err) { + ctx.hbs.error = err.message + await ctx.render('error', ctx.hbs) + } +}) + +//Render for the INDIVIDUAL QUIZ (loop each id) +router.get('/quizf/:id', async ctx => { + try { + if(ctx.hbs.authorised !== true) return ctx.redirect('/login?msg=you need to log in&referrer=/secure/quizf') + const questions = await new Question(dbName) + ctx.hbs.questiont = await questions.getById(ctx.params.id) + console.log(ctx.hbs) + await ctx.render('quizfinal', ctx.hbs) + } catch(err) { + ctx.hbs.error = err.message + await ctx.render('error', ctx.hbs ) + } +}) + //Render the TEACHING CONTENT page router.get('/learnGit', async ctx =>{ try{ if(ctx.hbs.authorised !== true) return ctx.redirect('/login?msg=you need to log in&referrer=/secure/learnGit') - //const gitcontent = await new GitContent(dbName) - //ctx.hbs.gitselected = await gitcontent.allgt() + const gitselected = await new GitContent(dbName) + ctx.hbs.contentdb = await gitselected.all() console.log(ctx.hbs) await ctx.render('teachingcontent', ctx.hbs) } catch(err){ @@ -55,20 +84,22 @@ router.get('/learnGit', async ctx =>{ } }) -//Render for the QUIZ PAGE handlebar -router.get('/quiz', async ctx => { +//Render for the INDIVIDUAL CONTENT (loop each id) +router.get('/learnIndividual/:id', async ctx => { try { - if(ctx.hbs.authorised !== true) return ctx.redirect('/login?msg=you need to log in&referrer=/secure/quiz') - const questions = await new Question(dbName) - ctx.hbs.questiont = await questions.all() + if(ctx.hbs.authorised !== true) return ctx.redirect('/login?msg=you need to log in&referrer=/secure/quizf') + const gitselected = await new GitContent(dbName) + ctx.hbs.contentdb = await gitselected.getById(ctx.params.id) console.log(ctx.hbs) - await ctx.render('quizpage', ctx.hbs) + await ctx.render('contentindividual', ctx.hbs) } catch(err) { ctx.hbs.error = err.message - await ctx.render('error', ctx.hbs) + await ctx.render('error', ctx.hbs ) } }) +//----------------ROUTER.POST-------------------// + //Gets the ANSWER input from the quizpage router.post('/quiz', koaBody, async ctx => { try{ @@ -115,21 +146,5 @@ router.post('/gitcontentz', koaBody, async ctx => { } }) -//Render for the SECOND QUIZ PAGE handlebar -router.get('/quizpage2/:id', async ctx => { - try { - if(ctx.hbs.authorised !== true) return ctx.redirect('/login?msg=you need to log in&referrer=/secure/quizpage2') - console.log(ctx.hbs) - const questions = await new Question(dbName) - ctx.hbs.questiont = await questions.getById(ctx.params.id) - console.log(ctx.hbs) - await ctx.render('quizpage2', ctx.hbs) - } catch(err) { - ctx.hbs.error = err.message - await ctx.render('error', ctx.hbs) - } -}) - - - +//Export the router to be imported somewhere module.exports = router diff --git a/views/backoffice.handlebars b/views/backoffice.handlebars index f527237..d196431 100644 --- a/views/backoffice.handlebars +++ b/views/backoffice.handlebars @@ -11,7 +11,7 @@
-

Choose the table and populate

+

Backoffice

Log out
{{#if msg}} @@ -43,6 +43,5 @@ - \ No newline at end of file diff --git a/views/contentindividual.handlebars b/views/contentindividual.handlebars new file mode 100644 index 0000000..15b32f8 --- /dev/null +++ b/views/contentindividual.handlebars @@ -0,0 +1,37 @@ + + + + + + E-Learning + + + + + +
+
Lamp
+ Log out +
+ {{#if msg}} +

{{msg}}

+ {{/if}} + + + +
+

{{contentdb.title_of_content}}

+
+ +
+
{{contentdb.block_of_content}}
+
Image
+
Column
+
+ + + + + \ No newline at end of file diff --git a/views/extracode b/views/extracode deleted file mode 100644 index 27b4d59..0000000 --- a/views/extracode +++ /dev/null @@ -1,26 +0,0 @@ -
- - {{#each answert}} - - - - {{/each}} -
{{this.answer}}
- - {{#each questiont}} - - - - {{/each}} -
{{this.question}}
-
- - DISPLAY DATA !!! - - -
-

- -

-

-

Secure Page

\ No newline at end of file diff --git a/views/quizfinal.handlebars b/views/quizfinal.handlebars new file mode 100644 index 0000000..cd870ab --- /dev/null +++ b/views/quizfinal.handlebars @@ -0,0 +1,34 @@ + + + + + + + Quiz Page + + + + + +
+

Questions

+ Log out +
+ {{#if msg}} +

{{msg}}

+ {{/if}} +
+
+

{{questiont.question}}

+ +
+ + +

Back

+

Home page

+

Add new questions ans answers

+
+ + + + diff --git a/views/quizpage.handlebars b/views/quizpage.handlebars index 569f7de..370b644 100644 --- a/views/quizpage.handlebars +++ b/views/quizpage.handlebars @@ -18,10 +18,23 @@

{{msg}}

{{/if}}
- {{#each questiont}} -

Press the first question at random to start

-

Question:

- {{/each}} +

How to answer the quiz questions?

+

Just read the question and answer when ready ✔

+
+ + {{#each questiont}} + + + + + {{/each}} +
{{this.question}}

Click me

+

The quiz is not time constrained ⏱

+

User score: 0

+ +

Home page

+

Add new questions ans answers

+
diff --git a/views/quizpage2.handlebars b/views/quizpage2.handlebars deleted file mode 100644 index cfa9227..0000000 --- a/views/quizpage2.handlebars +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - Quiz Page - - - - - -
-

Questions

- Log out -
- {{#if msg}} -

{{msg}}

- {{/if}} -
-

Question:

-

-> {{questiont.question}}

- - {{questiont.possible_answer1}}
-
- {{questiont.possible_answer2}}
-
- {{questiont.possible_answer3}} - - -

Next Question

-

Previous Question

-
- - - \ No newline at end of file diff --git a/views/teachingcontent.handlebars b/views/teachingcontent.handlebars index 9c1a696..e666552 100644 --- a/views/teachingcontent.handlebars +++ b/views/teachingcontent.handlebars @@ -17,7 +17,23 @@

{{msg}}

{{/if}}
- +

Welcome to the git content page

+

Choose the most interesting topic and enjoy

+
+ + {{#each contentdb}} + + + + + + + {{/each}} +
{{this.title_of_content}}Learn here
+ +

Home page

+

Add new questions ans answers

+