Skip to content

Commit

Permalink
feat: add csv export
Browse files Browse the repository at this point in the history
  • Loading branch information
bayang committed May 13, 2022
1 parent 84c682b commit efc8d9f
Show file tree
Hide file tree
Showing 30 changed files with 1,241 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/jelu-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/jelu-ui/src/components/AdminBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const items = ref([{ name:t('settings.profile'), tooltip:t('settings.my_profile'
{ name:t('settings.settings'), icon:"bxs-cog", href:"/profile/settings", tooltip: t('settings.profile') },
{ name:t('settings.authors'), icon:"bxs-user-account", href:"/profile/admin/authors", tooltip: t('settings.author_management') },
{ name:t('settings.imports'), icon:"bxs-file-plus", href:"/profile/imports", tooltip: t('settings.csv_import') },
{ name:t('settings.messages'), icon:"bxs-message-alt-detail", href:"/profile/messages" },
])
if (store.getters.isAdmin) {
Expand Down
42 changes: 42 additions & 0 deletions src/jelu-ui/src/components/Imports.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const fetchMetadata = ref(true)
const fetchCovers = ref(true)
const uploadPercentage = ref(0);
const errorMessage = ref("");
const exportErrorMessage = ref("");
const exportMessage = ref("");
const handleFileUpload = (event: any) => {
file.value = event.target.files[0];
Expand All @@ -42,6 +44,16 @@ const importFile = async () => {
})
}
const exportFile =async () => {
console.log("export requested")
try {
await dataService.exportCsv()
exportMessage.value = t('csv_import.export_ok')
} catch (error) {
exportErrorMessage.value = t('csv_import.export_ko')
}
}
</script>

<template>
Expand Down Expand Up @@ -131,6 +143,36 @@ const importFile = async () => {
</p>
</div>
</div>
<h1 class="text-2xl typewriter w-11/12 sm:w-8/12 py-4 capitalize">
{{ t('csv_import.export') }}
</h1>
<div class="w-11/12 sm:w-8/12">
<p class="first-letter:capitalize pb-2">
{{ t('csv_import.export_message') }}
</p>
<div class="field">
<p class="control">
<button
class="btn btn-info"
@click="exportFile"
>
{{ t('csv_import.export_file') }}
</button>
</p>
<p
v-if="exportMessage"
class=""
>
{{ exportMessage }}
</p>
<p
v-if="exportErrorMessage"
class="text-error"
>
{{ exportErrorMessage }}
</p>
</div>
</div>
</div>
</template>

Expand Down
196 changes: 196 additions & 0 deletions src/jelu-ui/src/components/UserMessages.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<script setup lang="ts">
import { useThrottleFn, useTitle } from '@vueuse/core';
import { onMounted, Ref, ref, watch } from "vue";
import { useI18n } from 'vue-i18n';
import usePagination from '../composables/pagination';
import { MessageCategory, UserMessage } from "../model/UserMessage";
import dataService from "../services/DataService";
const { t } = useI18n({
inheritLocale: true,
useScope: 'global'
})
useTitle('Jelu | Messages')
const { total, page, pageAsNumber, perPage, updatePage, getPageIsLoading, updatePageLoading } = usePagination()
perPage.value = 10
const read: Ref<boolean> = ref(false)
const categories: Ref<Array<MessageCategory>> = ref([])
const messages: Ref<Array<UserMessage>> = ref([]);
const getMessagesIsLoading: Ref<boolean> = ref(false)
const getMessages = () => {
getMessagesIsLoading.value = true
dataService.messages(categories.value, read.value, pageAsNumber.value - 1, perPage.value, undefined)
.then(res => {
console.log(res)
total.value = res.totalElements
messages.value = res.content
if (! res.empty) {
page.value = (res.number + 1).toString(10)
}
else {
page.value = "1"
}
getMessagesIsLoading.value = false
updatePageLoading(false)
})
.catch(e => {
getMessagesIsLoading.value = false
updatePageLoading(false)
})
}
const updateMessage = (message: UserMessage, read: boolean) => {
if (message.id !== undefined) {
dataService.updateUserMessage(message.id, {read: read, message: "Message 5 updated"})
.then(res => {
console.log(`message ${message.id} read : ${read}`)
getMessages()
})
.catch(e => {
console.log(`error : message ${message.id} read : ${read}`)
})
}
}
function category(cat: MessageCategory) {
if (cat === MessageCategory.ERROR) {
return 'alert-error'
} else if (cat === MessageCategory.INFO) {
return 'alert-info'
} else if (cat === MessageCategory.SUCCESS) {
return 'alert-success'
} else if (cat === MessageCategory.WARNING) {
return 'alert-warning'
}
}
function icon(cat: MessageCategory) {
if (cat === MessageCategory.ERROR) {
return 'M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z'
} else if (cat === MessageCategory.INFO) {
return 'M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z'
} else if (cat === MessageCategory.SUCCESS) {
return 'M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z'
} else if (cat === MessageCategory.WARNING) {
return 'M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z'
}
}
watch(page, (newVal, oldVal) => {
console.log("all " + newVal + " " + oldVal)
if (newVal !== oldVal) {
throttledGetMessages()
}
})
// watches set above sometimes called twice
const throttledGetMessages = useThrottleFn(() => {
getMessages()
}, 100, false)
onMounted(() => {
console.log("Component is mounted!");
try {
getMessages();
} catch (error) {
console.log("failed get messages : " + error);
}
});
</script>

<template>
<div class="grid grid-cols-1 justify-center justify-items-center justify-self-center">
<h1 class="text-2xl typewriter w-11/12 sm:w-8/12 pb-4 capitalize">
{{ t('settings.messages') }}
</h1>
<div
v-for="message in messages"
:key="message.id"
class="m-1 alert shadow-lg sm:w-9/12"
:class="category(message.category)"
>
<div>
<svg
xmlns="http://www.w3.org/2000/svg"
class="stroke-current flex-shrink-0 h-6 w-6"
fill="none"
viewBox="0 0 24 24"
><path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
:d="icon(message.category)"
/></svg>
<div>
<span>{{ message.message }}</span>
<a
v-if="message.link"
class="link mx-3 uppercase"
:href="message.link"
target="_blank"
>{{ t('user-messages.link') }}
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5 inline"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M12.586 4.586a2 2 0 112.828 2.828l-3 3a2 2 0 01-2.828 0 1 1 0 00-1.414 1.414 4 4 0 005.656 0l3-3a4 4 0 00-5.656-5.656l-1.5 1.5a1 1 0 101.414 1.414l1.5-1.5zm-5 5a2 2 0 012.828 0 1 1 0 101.414-1.414 4 4 0 00-5.656 0l-3 3a4 4 0 105.656 5.656l1.5-1.5a1 1 0 10-1.414-1.414l-1.5 1.5a2 2 0 11-2.828-2.828l3-3z"
clip-rule="evenodd"
/>
</svg>
</a>
</div>
</div>
<div
class="flex-none tooltip"
:data-tip="t('user-messages.mark_read')"
>
<button
class="btn btn-circle btn-xs"
@click="updateMessage(message, !message.read)"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
clip-rule="evenodd"
/>
</svg>
</button>
</div>
</div>
</div>
<o-pagination
v-if="messages.length > 0"
:current="pageAsNumber"
:total="total"
order="centered"
:per-page="perPage"
@change="updatePage"
/>
<o-loading
v-model:active="getPageIsLoading"
:full-page="true"
:can-cancel="true"
/>
</template>

<style scoped>
</style>
16 changes: 13 additions & 3 deletions src/jelu-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"profile" : "Profile",
"my_profile" : "My profile",
"settings" : "Settings",
"imports" : "Imports",
"imports" : "Imports/Exports",
"author_management" : "Authors management",
"csv_import" : "Csv import",
"authors" : "Authors",
Expand All @@ -101,7 +101,8 @@
"users" : "Users",
"users_management" : "Users management",
"shortcuts" : "Shortcuts",
"shortcuts_tooltip" : "Keyboard shortcuts"
"shortcuts_tooltip" : "Keyboard shortcuts",
"messages" : "Messages"
},
"user" : {
"log_first" : "Please log in first"
Expand Down Expand Up @@ -201,7 +202,12 @@
"auto_fetch_online" : "Automatically fetch metadata online",
"fetch_covers" : "Also fetch covers",
"choose_file" : "Choose file to import",
"import_file" : "import file"
"import_file" : "import file",
"export" : "export your data",
"export_file" : "export file",
"export_message" : "clicking the button below will trigger an export request, you will be warned in the messages section when your export is ready.",
"export_ok" : "Your export request has been saved. You can leave this page, the report will be available in the messages section.",
"export_ko" : "An error happened and you export request has probably not been registered."
},
"login" : {
"login" : "login",
Expand Down Expand Up @@ -234,5 +240,9 @@
},
"profile" : {
"edit_user" : "Edit user"
},
"user-messages" : {
"link" : "link",
"mark_read": "mark as read"
}
}
16 changes: 13 additions & 3 deletions src/jelu-ui/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"profile" : "Profil",
"my_profile" : "Mon profil",
"settings" : "Paramètres",
"imports" : "Imports",
"imports" : "Imports/Exports",
"author_management" : "Gestion des auteurs",
"csv_import" : "Import Csv",
"authors" : "Auteurs",
Expand All @@ -102,7 +102,8 @@
"users" : "Utilisateurs",
"users_management" : "gestion des utilisateurs",
"shortcuts" : "Raccourcis",
"shortcuts_tooltip" : "Raccourcis claviers"
"shortcuts_tooltip" : "Raccourcis claviers",
"messages" : "Messages"
},
"user" : {
"log_first" : "Veuillez vous identifier"
Expand Down Expand Up @@ -202,7 +203,12 @@
"auto_fetch_online" : "Récupérer automatiquement les métadonnées depuis le web",
"fetch_covers" : "Récupérer aussi les couvertures",
"choose_file" : "Choisissez le fichier à importer",
"import_file" : "importer le fichier"
"import_file" : "importer le fichier",
"export" : "exportez vos données",
"export_file" : "exporter fichier",
"export_message" : "Cliquer sur le bouton pour déclencher un export, consulter ensuite la section messages pour savoir quand l'export est prêt.",
"export_ok" : "Votre demande d'export a bien été enregistrée. Vous pouvez quitter cette page, l'export sera disponible dans la section messages.",
"export_ko" : "Une erreur est survenue, votre demande d'export n'a probablement pas été prise en compte."
},
"login" : {
"login" : "identifiant",
Expand Down Expand Up @@ -235,5 +241,9 @@
},
"profile" : {
"edit_user" : "Modifier utilisateur"
},
"user-messages" : {
"link" : "lien",
"mark_read": "marquer comme lu"
}
}
23 changes: 23 additions & 0 deletions src/jelu-ui/src/model/UserMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export interface UserMessage {
id?: string,
creationDate?: string,
modificationDate?: Date,
category: MessageCategory,
message?: string,
link?: string,
read?: boolean
}

export interface UpdateUserMessage {
category?: MessageCategory,
message?: string,
link?: string,
read?: boolean
}

export enum MessageCategory {
SUCCESS = 'SUCCESS',
INFO = 'INFO',
WARNING = 'WARNING',
ERROR = 'ERROR'
}
Loading

0 comments on commit efc8d9f

Please sign in to comment.