Skip to content

Commit

Permalink
new button for export content field with unencrypted data
Browse files Browse the repository at this point in the history
  • Loading branch information
scammo committed Apr 3, 2024
1 parent e495370 commit 042bb1b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
12 changes: 11 additions & 1 deletion frontend/src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,14 @@ const getProposalById = async (id) => {
});
};

export { createProposal, getProposalById, client, user, isLoggedIn, setLogin, setLogout, i18n };
const downLoadJson = (data, filename) => {
const jsonData = JSON.stringify({ data })
const a = document.createElement('a');
const type = filename.split(".").pop();
a.href = URL.createObjectURL(new Blob([jsonData], { type: `text/${type === "txt" ? "plain" : type}` }));
a.download = filename;
a.click();
}

export { createProposal, getProposalById, client, user, isLoggedIn, setLogin, setLogout, i18n, downLoadJson };

34 changes: 27 additions & 7 deletions frontend/src/views/orga/ProposalsTrack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { onMounted, ref } from "vue";
import { useRouter, useRoute } from "vue-router";
import { useToast } from "primevue/usetoast";
import { status } from "../../lib/const";
import { client, user } from "../../lib/api";
import { client, createProposal, getProposalById, user, downLoadJson } from "../../lib/api";
import StatusDropdown from "../../components/StatusDropdown.vue";
import ProgressSpinner from "primevue/progressspinner";
import Toast from "primevue/toast";
Expand Down Expand Up @@ -92,13 +92,8 @@ const exportTrackData = async () => {
loading.value = true;
try {
const response = await client.get(`track/export/?slug=${route.params.slug}`)
const data = JSON.stringify({ track: response.data })
const name = `${+new Date()}-${route.params.slug}.json`
const a = document.createElement('a');
const type = name.split(".").pop();
a.href = URL.createObjectURL(new Blob([data], { type: `text/${type === "txt" ? "plain" : type}` }));
a.download = name;
a.click();
downLoadJson(response.data, name)
} catch (error) {
console.error(error);
toast.add({
Expand All @@ -111,6 +106,30 @@ const exportTrackData = async () => {
loading.value = false;
}
};
const exportContentData = async () => {
loading.value = true;
try {
let proposolsContent = []
for (const proposal of proposals.value) {
const { data } = await getProposalById(proposal.id)
const { title, short_description, description, why, type } = data
proposolsContent.push({ title, short_description, description, why, type })
}
const name = `${+new Date()}-${route.params.slug}.json`
downLoadJson(proposolsContent, name)
} catch (error) {
console.error(error);
toast.add({
severity: "warn",
summary: "Error",
detail: error?.message || "Beim laden ist ein Fehler aufgetrente",
life: 5000,
});
} finally {
loading.value = false;
}
}
const onRowSelect = (event) => {
console.log(event);
const { id } = event.data;
Expand Down Expand Up @@ -187,5 +206,6 @@ const rowClass = (data) => {
</section>
<Button label="💾 Alle Track Daten Exportieren" @click="exportTrackData" />
<Button class="ml-2" label="Export Inhaltsfelder (NICHT VERSCHLÜSSELT)" @click="exportContentData" />
</template>
</template>

0 comments on commit 042bb1b

Please sign in to comment.