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

Fixed issue with deleting Kolloqs

parent 94bd3406
Branches
No related tags found
No related merge requests found
......@@ -6,9 +6,15 @@ var fs = require("fs")
const kolloquiumDirectory = 'Kolloquiums'
function getDirectories(path) {
return fs.readdirSync(path).filter(function (file) {
return fs.statSync(path+'/'+file).isDirectory();
});
// check if directory exists
if (fs.existsSync(path)) {
return fs.readdirSync(path).filter(function (file) {
return fs.statSync(path+'/'+file).isDirectory();
});
} else {
console.log('Directory not found.');
return []
}
}
function isEmpty(checkString) {
......@@ -54,6 +60,7 @@ fs.mkdir(kolloquiumDirectory,function(err) {
router.use('/getKolloquiums', (req, res) => {
console.log('/getKolloquiums')
var directories = getDirectories(kolloquiumDirectory)
console.log('Kolloquiums: ' + directories)
return res.json({
kolloquiums: directories
});
......@@ -96,19 +103,40 @@ router.use('/deleteKolloquium', (req, res) => {
})
}
fs.rmdir(kolloquiumDirectory + '/' + safeTitle, function(err) {
let dirname = kolloquiumDirectory + '/' + safeTitle
fs.readdir(dirname, function(err, files) {
if (err) {
console.error(err);
return res.json({
success: false,
message: err
})
console.error(err);
return res.json({
success: false,
message: err
})
} else {
if (!files.length) {
// directory appears to be empty
fs.rmdir(dirname, function(err) {
if (err) {
console.error(err);
return res.json({
success: false,
message: err
})
}
return res.json({
success: true,
message: 'removed Kolloquium ' + safeTitle
})
});
} else {
// TODO: ask for confirmation to delete anyway
console.log('Directory is not empty. TODO: Ask for confirmation to delete anyway')
return res.json({
success: false,
message: 'Kolloquium ' + safeTitle + ' was not empty'
})
}
}
});
return res.json({
success: true,
message: 'removed Kolloquium ' + safeTitle
})
});
})
// Create Kolloquium
......
......@@ -3,10 +3,19 @@
:selected="selected"
>
<div class="flex flex-row w-full">
<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"
@click="selectMe()"
>
{{ title }}
</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
v-if="inEdit"
......@@ -65,6 +74,9 @@ export default {
},
deleteMe() {
this.$emit("deleteKolloquium")
},
selectMe() {
this.$emit("selectKolloquium")
}
}
}
......
......@@ -16,12 +16,12 @@
<KolloquiumItem
v-for="kolloquium in kolloquiums"
:key="kolloquium.title"
@click.native="selectKolloquium(kolloquium)"
:selected="selectedKolloquium===kolloquium.title"
:title="kolloquium.title"
@update:title="kolloquium.title=$event"
:inEdit="kolloquium.inEdit"
@update:title="kolloquium.title=$event"
@update:inEdit="toggleEdit(kolloquium, $event)"
@selectKolloquium="selectKolloquium(kolloquium.title)"
@deleteKolloquium="deleteKolloquium(kolloquium.title)"
/>
<ListItem
......@@ -37,23 +37,33 @@
</div>
</template>
<template slot="content">
<p class="text-xl"><span class="font-semibold">Titel:</span> {{ selectedKolloquium }}</p>
<p class="font-semibold mt-4 mb-1">Abgaben:</p>
<AbgabeItem
v-for="abgabe in abgaben"
:key="abgabe"
@click.native="selectAbgabe(abgabe)"
:title="abgabe"
/>
<div class="flex flex-row justify-between">
<button class="border rounded mt-4 p-2 font-semibold text-white bg-green-500 hover:bg-green-600 focus:bg-green-700">
Aktivieren
</button>
<n-link :to="'/abgabe/' + selectedKolloquium">
<button class="border rounded mt-4 p-2 font-semibold text-white bg-blue-500 hover:bg-blue-600 focus:bg-blue-700">
Link Teilen
<div v-if="selectedKolloquium">
<p class="text-xl"><span class="font-semibold">Titel:</span> {{ selectedKolloquium }}</p>
<p class="font-semibold mt-4 mb-1">Abgaben:</p>
<div v-if="abgaben.length > 0">
<AbgabeItem
v-for="abgabe in abgaben"
:key="abgabe"
@click.native="selectAbgabe(abgabe)"
:title="abgabe"
/>
</div>
<div v-else>
Keine Abgaben
</div>
<div class="flex flex-row justify-between">
<button class="border rounded mt-4 p-2 font-semibold text-white bg-green-500 hover:bg-green-600 focus:bg-green-700">
Aktivieren
</button>
</n-link>
<n-link :to="'/abgabe/' + selectedKolloquium">
<button class="border rounded mt-4 p-2 font-semibold text-white bg-blue-500 hover:bg-blue-600 focus:bg-blue-700">
Link Teilen
</button>
</n-link>
</div>
</div>
<div v-else class="font-semibold">
Kein Kolloquium ausgewählt
</div>
</template>
</box>
......@@ -80,11 +90,11 @@ export default {
}
},
methods: {
async selectKolloquium(kolloquium) {
this.selectedKolloquium = kolloquium.title
async selectKolloquium(kolloquiumTitle) {
this.selectedKolloquium = kolloquiumTitle
this.selectedAbgabe = ''
this.abgaben = []
const data = await this.$axios.$post('/api/getAbgaben/', { kolloquium: kolloquium.title })
const data = await this.$axios.$post('/api/getAbgaben/', { kolloquium: kolloquiumTitle })
this.abgaben = data.abgaben
},
selectAbgabe(abgabe) {
......@@ -98,7 +108,7 @@ export default {
this.kolloquiums = this.kolloquiums.filter(kolloquium => kolloquium.title.length > 0);
this.kolloquiums = [...this.kolloquiums, {title: '', inEdit: true, isNew: true}];
},
toggleEdit(kolloquium, {inEdit, title}) {
async toggleEdit(kolloquium, {inEdit, title}) {
let createNew = kolloquium.inEdit && kolloquium.isNew;
let changeName = kolloquium.inEdit && !kolloquium.isNew;
......@@ -115,34 +125,55 @@ export default {
return
}
this.$axios.post('api/createKolloquium', { title: title })
this.refreshKolloquiumList()
}
else if (changeName) {
// TODO: Request confirmation before changing name so the link does not break
// TODO: Or make sure the link stays the same if the folder is renamed?
if (!title || title.trim().length == 0) {
return
}
kolloquium.title = title
this.$axios.post('api/renameKolloquium', { oldTitle: kolloquium.title, newTitle: title})
this.refreshKolloquiumList()
}
},
deleteKolloquium(kolloquiumToDelete) {
this.kolloquiums = this.kolloquiums.filter(kolloquium => kolloquium.title != kolloquiumToDelete);
this.selectedKolloquium = ""
if(kolloquiumToDelete != ''){
this.$axios.post('api/deleteKolloquium', { title: kolloquiumToDelete })
async deleteKolloquium(kolloquiumTitle) {
this.selectedKolloquium = ''
if(kolloquiumTitle != ''){
this.$axios.post('api/deleteKolloquium', { title: kolloquiumTitle })
}
this.refreshKolloquiumList()
},
async refreshKolloquiumList() {
this.abgaben = []
this.kolloquiums = []
this.selectedKolloquium = ''
this.selectedAbgabe = ''
const dataKolloquiums = await this.$axios.$get('/api/getKolloquiums/')
dataKolloquiums.kolloquiums.forEach(title => {
this.kolloquiums.push({
title: title,
inEdit: false
})
})
}
},
async asyncData ({ $axios }) {
const dataKolloquiums = await $axios.$get('/api/getKolloquiums/')
let kolloquiumList = []
let abgaben = []
const dataKolloquiums = await $axios.$get('/api/getKolloquiums/')
dataKolloquiums.kolloquiums.forEach(title => {
kolloquiumList.push({
title: title,
inEdit: false
})
})
const dataAbgaben = await $axios.$post('/api/getAbgaben/', { kolloquium: kolloquiumList[0].title })
return { kolloquiums: kolloquiumList, abgaben: dataAbgaben.abgaben, selectedKolloquium: kolloquiumList[0].title }
if (kolloquiumList.length !== 0){
const dataAbgaben = await $axios.$post('/api/getAbgaben/', { kolloquium: kolloquiumList[0].title })
abgaben = dataAbgaben.abgaben
}
return { kolloquiums: kolloquiumList, abgaben: abgaben }
},
}
</script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment