Skip to content
Snippets Groups Projects
Commit a52ffaf8 authored by Nick Anton Christoph Kleine-Tebbe's avatar Nick Anton Christoph Kleine-Tebbe
Browse files

Kolloquiums titles are loaded from folders

parent d4854176
No related branches found
No related tags found
No related merge requests found
Showing with 5948 additions and 3537 deletions
const express = require('express')
// Create express instance
const app = express()
// Require API routes
const users = require('./routes/users')
const test = require('./routes/kolloquiums')
// Import API Routes
app.use(users)
app.use(kolloquiums)
// Export express app
module.exports = app
// Start standalone server if directly running
if (require.main === module) {
const port = process.env.PORT || 3001
app.listen(port, () => {
// eslint-disable-next-line no-console
console.log(`API server listening on port ${port}`)
})
}
const { Router } = require('express')
const router = Router()
var fs = require("fs")
function getDirectories(path) {
return fs.readdirSync(path).filter(function (file) {
return fs.statSync(path+'/'+file).isDirectory();
});
}
fs.mkdir('Kolloquiums',function(err) {
if (err.code === "EEXIST") {
console.log('Kolloquiums Directory already existed')
}
else if (err.code != "EEXIST") {
return console.error(err);
}
else {
console.log("Directory created successfully!");
}
});
// Get Kolloquiums
router.use('/getKolloquiums', (req, res) => {
var directories = getDirectories('Kolloquiums')
res.json({
kolloquiums: directories
});
})
// Delete Kolloquium
router.use('/deleteKolloquiums', (req, res) => {
console.log(req)
res.json({
status: 'success'
})
})
module.exports = router
const { Router } = require('express')
const router = Router()
// Mock Users
const users = [
{ name: 'Alexandre' },
{ name: 'Pooya' },
{ name: 'Sébastien' }
]
/* GET users listing. */
router.get('/users', function (req, res, next) {
res.json(users)
})
/* GET user by ID. */
router.get('/users/:id', function (req, res, next) {
const id = parseInt(req.params.id)
if (id >= 0 && id < users.length) {
res.json(users[id])
} else {
res.sendStatus(404)
}
})
module.exports = router
# ASSETS
**This directory is not required, you can delete it if you don't want to use it.**
This directory contains your un-compiled assets such as LESS, SASS, or JavaScript.
More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#webpacked).
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<div class="w-full select-none text-left mr-1"> <div class="w-full select-none text-left mr-1">
{{ title }} {{ title }}
</div> </div>
<button <div
class="text-center text-white rounded-md select-none w-9 h-8 ml-1 bg-red-500 hover:bg-red-700 active:bg-red-900"></button> class="text-center text-white rounded-md select-none w-9 h-8 ml-1 bg-red-500 hover:bg-red-700 active:bg-red-900"></div>
</div> </div>
</ListItem> </ListItem>
</template> </template>
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
<h2 class="text-xl leading-4"> <h2 class="text-xl leading-4">
<slot name="title"></slot> <slot name="title"></slot>
</h2> </h2>
<p class="mt-3 text-gray-600"> <div class="mt-3 text-gray-600">
<slot name="content"></slot> <slot name="content"></slot>
</p> </div>
</div> </div>
</div> </div>
</template> </template>
\ No newline at end of file
...@@ -6,19 +6,29 @@ ...@@ -6,19 +6,29 @@
<div v-if="!inEdit" class="w-full select-none text-left mr-1"> <div v-if="!inEdit" class="w-full select-none text-left mr-1">
{{ title }} {{ title }}
</div> </div>
<input v-if="inEdit" class="w-full rounded border p-1" v-model="title" placeholder="Neues Kolloquium..."> <input v-if="inEdit" class="w-full rounded border p-1" v-model="title" placeholder="Neues Kolloquium..." />
<client-only>
<button <button
v-if="inEdit" v-if="inEdit"
@click="save()" @click="save()"
class="text-center text-white rounded-md select-none w-9 h-8 ml-1 bg-green-500 hover:bg-green-700 active:bg-green-900"></button> class="text-center text-white rounded-md select-none w-9 h-8 ml-1 bg-green-500 hover:bg-green-700 active:bg-green-900"
>
</button>
<button <button
v-if="!inEdit" v-if="!inEdit"
@click="edit()" @click="edit()"
class="text-center text-white rounded-md select-none w-9 h-8 ml-1 bg-yellow-500 hover:bg-yellow-700 active:bg-yellow-900"></button> class="text-center text-white rounded-md select-none w-9 h-8 ml-1 bg-yellow-500 hover:bg-yellow-700 active:bg-yellow-900"
>
</button>
<button <button
class="text-center text-white rounded-md select-none w-9 h-8 ml-1 bg-red-500 hover:bg-red-700 active:bg-red-900" class="text-center text-white rounded-md select-none w-9 h-8 ml-1 bg-red-500 hover:bg-red-700 active:bg-red-900"
@click="deleteMe()" @click="deleteMe()"
></button> >
</button>
</client-only>
</div> </div>
</ListItem> </ListItem>
</template> </template>
......
<template>
<div>
<slot></slot>
</div>
</template>
\ No newline at end of file
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/*": ["./*"],
"@/*": ["./*"],
"~~/*": ["./*"],
"@@/*": ["./*"]
}
},
"exclude": ["node_modules", ".nuxt", "dist"]
}
# LAYOUTS
**This directory is not required, you can delete it if you don't want to use it.**
This directory contains your Application Layouts.
More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/views#layouts).
<template>
<div>
<Nuxt />
</div>
</template>
<style>
html {
font-family:
'Source Sans Pro',
-apple-system,
BlinkMacSystemFont,
'Segoe UI',
Roboto,
'Helvetica Neue',
Arial,
sans-serif;
font-size: 16px;
word-spacing: 1px;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
}
.button--green {
display: inline-block;
border-radius: 4px;
border: 1px solid #3b8070;
color: #3b8070;
text-decoration: none;
padding: 10px 30px;
}
.button--green:hover {
color: #fff;
background-color: #3b8070;
}
.button--grey {
display: inline-block;
border-radius: 4px;
border: 1px solid #35495e;
color: #35495e;
text-decoration: none;
padding: 10px 30px;
margin-left: 15px;
}
.button--grey:hover {
color: #fff;
background-color: #35495e;
}
</style>
<template>
<section class="container">
<div>
<Logo />
<h1 class="title">
{{ error.statusCode }}
</h1>
<h2 class="info">
{{ error.message }}
</h2>
<nuxt-link v-if="error.statusCode === 404" class="button" to="/">
Homepage
</nuxt-link>
</div>
</section>
</template>
<script>
export default {
props: {
error: {
type: Object,
default: () => ({})
}
}
}
</script>
<style scoped>
.container {
margin: 0 auto;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
.title {
font-family:
'Quicksand',
'Source Sans Pro',
-apple-system,
BlinkMacSystemFont,
'Segoe UI',
Roboto,
'Helvetica Neue',
Arial,
sans-serif;
display: block;
font-weight: 300;
font-size: 100px;
color: #35495e;
letter-spacing: 1px;
}
.info
{
font-weight: 300;
color: #9aabb1;
margin: 0;
}
.button
{
margin-top: 50px;
}
</style>
# MIDDLEWARE
**This directory is not required, you can delete it if you don't want to use it.**
This directory contains your application middleware.
Middleware let you define custom functions that can be run before rendering either a page or a group of pages.
More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/routing#middleware).
export default { export default {
// Nuxt target see https://nuxtjs.org/api/configuration-target
target: 'server',
// Global page headers: https://go.nuxtjs.dev/config-head // Global page headers: https://go.nuxtjs.dev/config-head
head: { head: {
title: 'KolloquiumVR', title: 'KolloquiumVR',
htmlAttrs: {
lang: 'en',
},
meta: [ meta: [
{ charset: 'utf-8' }, { charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' }, { name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: '' }, { hid: 'description', name: 'description', content: '' },
{ name: 'format-detection', content: 'telephone=no' },
], ],
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }], link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
}, },
...@@ -30,8 +30,32 @@ export default { ...@@ -30,8 +30,32 @@ export default {
], ],
// Modules: https://go.nuxtjs.dev/config-modules // Modules: https://go.nuxtjs.dev/config-modules
modules: [], modules: [
// Doc: https://http.nuxtjs.org
'@nuxt/http',
[
"@nuxtjs/axios",
{
baseURL: process.env.BASE_URL || "http://localhost:3000"
}
]
],
/*
** For deployment you might want to edit host and port
*/
// server: {
// port: 8000, // default: 3000
// host: '0.0.0.0' // default: localhost
// },
// Build Configuration: https://go.nuxtjs.dev/config-build // Build Configuration: https://go.nuxtjs.dev/config-build
build: {}, build: {},
// Server Middleware
serverMiddleware: {
'/api': '~/api'
},
} }
\ No newline at end of file
This diff is collapsed.
...@@ -12,12 +12,10 @@ ...@@ -12,12 +12,10 @@
"lintfix": "prettier --write --list-different ." "lintfix": "prettier --write --list-different ."
}, },
"dependencies": { "dependencies": {
"core-js": "^3.19.3", "@nuxt/http": "latest",
"nuxt": "^2.15.8", "@nuxtjs/axios": "^5.13.6",
"vue": "^2.6.14", "express": "latest",
"vue-server-renderer": "^2.6.14", "nuxt": "latest"
"vue-template-compiler": "^2.6.14",
"webpack": "^4.46.0"
}, },
"devDependencies": { "devDependencies": {
"@nuxtjs/tailwindcss": "^4.2.1", "@nuxtjs/tailwindcss": "^4.2.1",
......
# PAGES
This directory contains your Application Views and Routes.
The framework reads all the `*.vue` files inside this directory and creates the router of your application.
More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/routing).
...@@ -62,7 +62,6 @@ ...@@ -62,7 +62,6 @@
<script> <script>
import Box from '~/components/Box' import Box from '~/components/Box'
import List from '~/components/List'
import ListItem from '~/components/ListItem' import ListItem from '~/components/ListItem'
import KolloquiumItem from '~/components/KolloquiumItem' import KolloquiumItem from '~/components/KolloquiumItem'
import AbgabeItem from '~/components/AbgabeItem' import AbgabeItem from '~/components/AbgabeItem'
...@@ -70,7 +69,6 @@ import AbgabeItem from '~/components/AbgabeItem' ...@@ -70,7 +69,6 @@ import AbgabeItem from '~/components/AbgabeItem'
export default { export default {
components: { components: {
Box, Box,
List,
ListItem, ListItem,
KolloquiumItem, KolloquiumItem,
AbgabeItem AbgabeItem
...@@ -79,20 +77,6 @@ export default { ...@@ -79,20 +77,6 @@ export default {
return { return {
selectedKolloquium: "", selectedKolloquium: "",
selectedAbgabe: "", selectedAbgabe: "",
kolloquiums: [
{
title: "Hier ist eine Liste von Kolloquien.",
inEdit: false,
},
{
title: "Man kann eines auswählen um zu sehen, welche Abgaben eingereicht wurden.",
inEdit: false,
},
{
title: "Man kann ein Kolloquium erstellen oder löschen.",
inEdit: false,
},
],
abgaben: [ abgaben: [
"Hier ist eine Liste von Abgaben für das ausgewählte Kolloquium.", "Hier ist eine Liste von Abgaben für das ausgewählte Kolloquium.",
"Man kann einzelne Abgaben löschen.", "Man kann einzelne Abgaben löschen.",
...@@ -125,7 +109,18 @@ export default { ...@@ -125,7 +109,18 @@ export default {
}, },
deleteKolloquium(kolloquiumToDelete) { deleteKolloquium(kolloquiumToDelete) {
this.kolloquiums = this.kolloquiums.filter(kolloquium => kolloquium.title != kolloquiumToDelete.title); this.kolloquiums = this.kolloquiums.filter(kolloquium => kolloquium.title != kolloquiumToDelete.title);
} },
} },
async asyncData ({ $http }) {
const data = await $http.$get('/api/kolloquiums/getKolloquiums')
let kolloquiumList = []
data.kolloquiums.forEach(title => {
kolloquiumList.push({
title: title,
inEdit: false
})
})
return { kolloquiums: kolloquiumList }
},
} }
</script> </script>
# PLUGINS
**This directory is not required, you can delete it if you don't want to use it.**
This directory contains Javascript plugins that you want to run before mounting the root Vue.js application.
More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/plugins).
The moment you start dealing with user session, you'll notice that protected routes will reject nuxt requests when running from the server. This is because when nuxt is ran from the server, the browser cookie is lost. Below is a quick middleware solution to inject the browser's cookie to your ssr axios request.
## install session
`npm install --save express-session`
## create middleware/ssr-cookie.js
```js
import axios from '~plugins/axios'
export default function({isServer, req}) {
if (isServer) {
axios.defaults.headers.common.cookie = req.headers.cookie
}
}
```
## add middleware to nuxt.config.js
```js
router: {
middleware: ['ssr-cookie']
}
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment