File browser on admin page
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { Request, Response, NextFunction, Router } from 'express'
|
import { Request, Response, NextFunction, Router } from 'express'
|
||||||
import { deleteAllTables, deleteExerciseProgressTables, prepopulateDatabase, prepopulateExerciseDatabase } from '../scripts/databaseHelper'
|
import { deleteAllTables, deleteExerciseProgressTables, prepopulateDatabase, prepopulateExerciseDatabase } from '../scripts/databaseHelper'
|
||||||
|
import fs from "fs"
|
||||||
|
|
||||||
export const api = Router()
|
export const api = Router()
|
||||||
|
|
||||||
@@ -24,4 +25,29 @@ api.get("/resetExerciseProgress", async (req: Request, res: Response, next: Next
|
|||||||
await prepopulateExerciseDatabase()
|
await prepopulateExerciseDatabase()
|
||||||
|
|
||||||
res.status(200).send()
|
res.status(200).send()
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all uploaded file names
|
||||||
|
*/
|
||||||
|
api.get("/files", async (req: Request, res: Response) => {
|
||||||
|
let dirNames = fs.readdirSync("./backend/images")
|
||||||
|
let result = []
|
||||||
|
|
||||||
|
dirNames.forEach(dir => {
|
||||||
|
let fileNames = fs.readdirSync("./backend/images/" + dir)
|
||||||
|
|
||||||
|
result.push({
|
||||||
|
folder: dir,
|
||||||
|
files: fileNames.map(file => {
|
||||||
|
return {
|
||||||
|
name: file,
|
||||||
|
size: fs.statSync("./backend/images/" + dir + "/" + file).size,
|
||||||
|
url: "http://localhost:3000/static/" + dir + "/" + file
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
res.status(200).json(result)
|
||||||
})
|
})
|
||||||
@@ -29,7 +29,7 @@ defineProps({
|
|||||||
<slot name="borderless"></slot>
|
<slot name="borderless"></slot>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #actions>
|
<template #actions v-if="$slots.actions">
|
||||||
<slot name="actions"></slot>
|
<slot name="actions"></slot>
|
||||||
</template>
|
</template>
|
||||||
</card-view>
|
</card-view>
|
||||||
|
|||||||
@@ -12,4 +12,8 @@ export function resetDatabase() {
|
|||||||
|
|
||||||
export function resetExerciseProgress() {
|
export function resetExerciseProgress() {
|
||||||
return axios.get(BASE_URL + "/resetExerciseProgress")
|
return axios.get(BASE_URL + "/resetExerciseProgress")
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fetchFileNames() {
|
||||||
|
return axios.get(BASE_URL + "/files")
|
||||||
}
|
}
|
||||||
@@ -204,6 +204,9 @@
|
|||||||
"tooMuchChars": "Zu viele Zeichen",
|
"tooMuchChars": "Zu viele Zeichen",
|
||||||
"onlyDigitsAllowed": "Nur Zahlen erlaubt",
|
"onlyDigitsAllowed": "Nur Zahlen erlaubt",
|
||||||
"digitsAtStartNeeded": "Muss mit einer Zahl beginnen"
|
"digitsAtStartNeeded": "Muss mit einer Zahl beginnen"
|
||||||
}
|
},
|
||||||
|
"file": "Datei | Dateien",
|
||||||
|
"folder": "Ordner | Ordner",
|
||||||
|
"uploadFile": "Datei hochladen"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -204,6 +204,9 @@
|
|||||||
"tooMuchChars": "Too much characters",
|
"tooMuchChars": "Too much characters",
|
||||||
"onlyDigitsAllowed": "Only numbers are allowed",
|
"onlyDigitsAllowed": "Only numbers are allowed",
|
||||||
"digitsAtStartNeeded": "Must start with a number"
|
"digitsAtStartNeeded": "Must start with a number"
|
||||||
}
|
},
|
||||||
|
"file": "File | Files",
|
||||||
|
"folder": "folder | folders",
|
||||||
|
"uploadFile": "Upload file"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
Categories Admin Page
|
|
||||||
</template>
|
|
||||||
@@ -9,6 +9,7 @@ import { useLocationStore } from '@/stores/location.store';
|
|||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { useExerciseStore } from '@/stores/exercise.store';
|
import { useExerciseStore } from '@/stores/exercise.store';
|
||||||
import { useGenreStore } from '@/stores/genre.store';
|
import { useGenreStore } from '@/stores/genre.store';
|
||||||
|
import { usePreferencesStore } from '@/stores/preferences.store';
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const concertStore = useConcertStore()
|
const concertStore = useConcertStore()
|
||||||
@@ -16,21 +17,17 @@ const bandStore = useBandStore()
|
|||||||
const accountStore = useAccountStore()
|
const accountStore = useAccountStore()
|
||||||
const genreStore = useGenreStore()
|
const genreStore = useGenreStore()
|
||||||
const locationStore = useLocationStore()
|
const locationStore = useLocationStore()
|
||||||
const soldOutConcerts = ref(0)
|
|
||||||
const exerciseStore = useExerciseStore()
|
const exerciseStore = useExerciseStore()
|
||||||
|
const preferencesStore = usePreferencesStore()
|
||||||
|
|
||||||
exerciseStore.solveExercise(2, 1)
|
exerciseStore.solveExercise(2, 1)
|
||||||
|
|
||||||
|
preferencesStore.getStaticFiles()
|
||||||
bandStore.getBands()
|
bandStore.getBands()
|
||||||
locationStore.getLocations()
|
locationStore.getLocations()
|
||||||
genreStore.getGenres()
|
genreStore.getGenres()
|
||||||
accountStore.getAllAccounts()
|
accountStore.getAllAccounts()
|
||||||
concertStore.getConcerts()
|
concertStore.getConcerts()
|
||||||
.then(result => {
|
|
||||||
for(let concert of concertStore.concerts) {
|
|
||||||
concert.inStock == 0 ? soldOutConcerts.value++ : ""
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -64,8 +61,14 @@ concertStore.getConcerts()
|
|||||||
{{ concertStore.concerts.length }} {{ $t('concert.concert', 2) }}
|
{{ concertStore.concerts.length }} {{ $t('concert.concert', 2) }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="text-disabled text-center">
|
<div class="text-h6 text-disabled text-center">
|
||||||
{{ soldOutConcerts }} {{ $t('concert.concertSoldOut') }}
|
{{ concertStore.concerts.reduce((counter, obj) => {
|
||||||
|
if (obj.inStock == 0) {
|
||||||
|
counter += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return counter
|
||||||
|
}, 0) }} {{ $t('concert.concertSoldOut') }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<template #actions>
|
<template #actions>
|
||||||
@@ -88,6 +91,18 @@ concertStore.getConcerts()
|
|||||||
{{ locationStore.locations.length }} {{ $t('location.location', 2) }}
|
{{ locationStore.locations.length }} {{ $t('location.location', 2) }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="text-h6 text-disabled text-center">
|
||||||
|
{{
|
||||||
|
locationStore.locations.reduce((city, obj) => {
|
||||||
|
city[obj.city.name] =
|
||||||
|
city[obj.city.name] === undefined ? city.push(obj.city.name) : city[obj.city.name] += 1
|
||||||
|
|
||||||
|
return city
|
||||||
|
}, []).length
|
||||||
|
}}
|
||||||
|
{{ $t('location.city', 2) }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<template #actions>
|
<template #actions>
|
||||||
<outlined-button
|
<outlined-button
|
||||||
@click="router.push('/admin/locations')"
|
@click="router.push('/admin/locations')"
|
||||||
@@ -139,7 +154,34 @@ concertStore.getConcerts()
|
|||||||
</template>
|
</template>
|
||||||
</card-view>
|
</card-view>
|
||||||
</v-col>
|
</v-col>
|
||||||
|
|
||||||
|
<v-col>
|
||||||
|
<card-view
|
||||||
|
:title="$t('misc.file', 2)"
|
||||||
|
icon="mdi-file"
|
||||||
|
>
|
||||||
|
<div class="text-h4 text-center">
|
||||||
|
{{ preferencesStore.staticFiles.reduce((counter, obj) => {
|
||||||
|
return counter += obj.files.length
|
||||||
|
}, 0) }} {{ $t('misc.file', 2) }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="text-h6 text-center text-disabled">
|
||||||
|
{{ preferencesStore.staticFiles.length }} {{ $t('misc.folder', 2) }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template #actions>
|
||||||
|
<outlined-button
|
||||||
|
@click="router.push('/admin/files')"
|
||||||
|
>
|
||||||
|
{{ $t('misc.actions.more') }}
|
||||||
|
</outlined-button>
|
||||||
|
</template>
|
||||||
|
</card-view>
|
||||||
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
|
|
||||||
|
<!-- todo: Orders -->
|
||||||
|
|
||||||
</v-container>
|
</v-container>
|
||||||
</template>
|
</template>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import actionDialog from '@/components/basics/actionDialog.vue';
|
||||||
|
|
||||||
|
const showDialog = defineModel("showDialog")
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
url: String
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<action-dialog v-model="showDialog" max-width="500">
|
||||||
|
<v-img :src="url" max-height="400" />
|
||||||
|
</action-dialog>
|
||||||
|
</template>
|
||||||
44
software/src/pages/admin/filesAdminPage/index.vue
Normal file
44
software/src/pages/admin/filesAdminPage/index.vue
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import adminDataLayout from '@/layouts/adminDataLayout.vue';
|
||||||
|
import { usePreferencesStore } from '@/stores/preferences.store';
|
||||||
|
import filePreviewDialog from './filePreviewDialog.vue';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
const preferencesStore = usePreferencesStore()
|
||||||
|
const showDialog = ref(false)
|
||||||
|
const previewFile = ref("")
|
||||||
|
|
||||||
|
preferencesStore.getStaticFiles()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<admin-data-layout
|
||||||
|
:add-button-string="$t('misc.uploadFile')"
|
||||||
|
:fetch-in-progress="preferencesStore.fetchInProgress"
|
||||||
|
:on-add-click="() => { /** todo */ }"
|
||||||
|
>
|
||||||
|
<v-row>
|
||||||
|
<v-col
|
||||||
|
v-for="folder of preferencesStore.staticFiles"
|
||||||
|
cols="12"
|
||||||
|
md="3"
|
||||||
|
sm="6"
|
||||||
|
>
|
||||||
|
<v-list>
|
||||||
|
<v-list-subheader>{{ folder.folder }}/</v-list-subheader>
|
||||||
|
<v-list-item
|
||||||
|
v-for="file of folder.files"
|
||||||
|
:title="file.name"
|
||||||
|
:subtitle="Math.round(file.size / 1024) + ' KB'"
|
||||||
|
@click="() => { previewFile = file.url; showDialog = true }"
|
||||||
|
/>
|
||||||
|
</v-list>
|
||||||
|
</v-col>
|
||||||
|
</v-row>
|
||||||
|
</admin-data-layout>
|
||||||
|
|
||||||
|
<file-preview-dialog
|
||||||
|
v-model:show-dialog="showDialog"
|
||||||
|
:url="previewFile"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
@@ -3,8 +3,8 @@ import ConcertsAdminPage from "@/pages/admin/concertsAdminPage/index.vue"
|
|||||||
import BandsAdminPage from "@/pages/admin/bandsAdminPage/index.vue"
|
import BandsAdminPage from "@/pages/admin/bandsAdminPage/index.vue"
|
||||||
import AccountsAdminPage from "@/pages/admin/accountsAdminPage/index.vue"
|
import AccountsAdminPage from "@/pages/admin/accountsAdminPage/index.vue"
|
||||||
import GenresAdminPage from "@/pages/admin/genresAdminPage/index.vue"
|
import GenresAdminPage from "@/pages/admin/genresAdminPage/index.vue"
|
||||||
import CategoriesAdminPage from "@/pages/admin/categoriesAdminPage/index.vue"
|
|
||||||
import LocationsAdminPage from "@/pages/admin/locationsAdminPage/index.vue"
|
import LocationsAdminPage from "@/pages/admin/locationsAdminPage/index.vue"
|
||||||
|
import FilesAdminPage from "@/pages/admin/filesAdminPage/index.vue"
|
||||||
|
|
||||||
export const adminRoutes = [
|
export const adminRoutes = [
|
||||||
{
|
{
|
||||||
@@ -27,12 +27,12 @@ export const adminRoutes = [
|
|||||||
path: '/admin/genres',
|
path: '/admin/genres',
|
||||||
component: GenresAdminPage
|
component: GenresAdminPage
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: '/admin/categories',
|
|
||||||
component: CategoriesAdminPage
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: '/admin/locations',
|
path: '/admin/locations',
|
||||||
component: LocationsAdminPage
|
component: LocationsAdminPage
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/admin/files',
|
||||||
|
component: FilesAdminPage
|
||||||
|
}
|
||||||
]
|
]
|
||||||
@@ -3,7 +3,7 @@ import { useLocalStorage } from "@vueuse/core";
|
|||||||
import { ThemeEnum } from "../data/enums/themeEnums";
|
import { ThemeEnum } from "../data/enums/themeEnums";
|
||||||
import { LanguageEnum } from "../data/enums/languageEnum";
|
import { LanguageEnum } from "../data/enums/languageEnum";
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { fetchServerState, resetDatabase, resetExerciseProgress } from "@/data/api/mainApi";
|
import { fetchFileNames, fetchServerState, resetDatabase, resetExerciseProgress } from "@/data/api/mainApi";
|
||||||
import { ServerStateEnum } from "@/data/enums/serverStateEnum";
|
import { ServerStateEnum } from "@/data/enums/serverStateEnum";
|
||||||
import { BannerStateEnum } from "@/data/enums/bannerStateEnum";
|
import { BannerStateEnum } from "@/data/enums/bannerStateEnum";
|
||||||
import { useFeedbackStore } from "./feedback.store";
|
import { useFeedbackStore } from "./feedback.store";
|
||||||
@@ -26,7 +26,9 @@ export const usePreferencesStore = defineStore('preferencesStore', {
|
|||||||
showDeleteDbDialog: ref(false),
|
showDeleteDbDialog: ref(false),
|
||||||
|
|
||||||
/** Show the "Delete Exercise progress?" confirm dialog */
|
/** Show the "Delete Exercise progress?" confirm dialog */
|
||||||
showDeleteExerciseDialog: ref(false)
|
showDeleteExerciseDialog: ref(false),
|
||||||
|
|
||||||
|
staticFiles: ref([])
|
||||||
}),
|
}),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
@@ -90,6 +92,16 @@ export const usePreferencesStore = defineStore('preferencesStore', {
|
|||||||
this.fetchInProgress = false
|
this.fetchInProgress = false
|
||||||
this.showDeleteExerciseDialog = false
|
this.showDeleteExerciseDialog = false
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
async getStaticFiles() {
|
||||||
|
this.fetchInProgress = true
|
||||||
|
|
||||||
|
fetchFileNames()
|
||||||
|
.then(res => {
|
||||||
|
this.staticFiles = res.data
|
||||||
|
this.fetchInProgress = false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user