Skip to content

Commit

Permalink
#8 add dialog to generate link and mail for PatchSet
Browse files Browse the repository at this point in the history
  • Loading branch information
Max.-F.Helm committed Apr 9, 2024
1 parent ca78d97 commit 63b2b57
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 2 deletions.
164 changes: 164 additions & 0 deletions src/ui/dialogs/MailPatchSetDlg.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<template>
<Dialog
v-model:visible="show"
:closable="true"
:modal="false"
header="Send Patchset via E-Mail"
>
<div>
<Panel header="Authors to send to" toggleable>
<template #icons>
<Button icon="pi pi-check-square" text aria-label="select all authors" @click="checkAllAuthors" />
<Button icon="pi pi-stop" text aria-label="select no authors" @click="uncheckAllAuthors" />
</template>

<DataTable :value="availableAuthors" responsive-layout="scroll">
<Column field="selected">
<template #body="{ data }">
<Checkbox v-model="data.selected" :binary="true" />
</template>
</Column>
<Column field="author.name" header="Username"/>
<Column field="author.mail" header="E-Mail"/>
</DataTable>
</Panel>

<div class="mt-3 mb-3" v-show="link != ''">
Other Authors can use this <a :href="link">link</a> to apply the Patchset.
</div>

<div class="flex flex-row align-items-end">
<Button @click="showLink">Generate Link</Button>
<div class="w-1rem"></div>
<Button @click="sendMail">Send Mail</Button>
</div>
</div>
</Dialog>
</template>

<script setup lang="ts">
import {reactive, ref, watch} from "vue";
import Dialog from "primevue/dialog";
import Panel from "primevue/panel";
import Button from "primevue/button";
import type Author from "@/processing/model/Author";
import DataTable from "primevue/datatable";
import Column from "primevue/column";
import Checkbox from "primevue/checkbox";
import FileProcessorWrapper from "@/FileProcessorWrapper";
import {useToast} from "primevue/usetoast";
import libsodium from "libsodium-wrappers-sumo";
import {basePath} from "@/ui/utils";
interface SelectableAuthor {
author: Author,
selected: boolean
}
const toast = useToast();
const fileProcessor = FileProcessorWrapper.INSTANCE;
const show = defineModel<boolean>();
const emit = defineEmits<{
(e: 'done'): void
}>();
const availableAuthors = ref<SelectableAuthor[]>([]);
const link = ref("");
let emitDone = false;
function loadAuthors() {
availableAuthors.value = fileProcessor.getProposal().authors
.map(a => reactive(<SelectableAuthor>{ author: a, selected: false }));
}
function checkAllAuthors() {
availableAuthors.value.forEach(a => a.selected = true);
}
function uncheckAllAuthors() {
availableAuthors.value.forEach(a => a.selected = false);
}
async function showLink() {
try {
await generateLink();
emitDone = true;
} catch (e) {
console.error("unable to save PatchSet: generateLink() failed", e);
showErrToast("Error while processing patches", e);
}
}
async function sendMail(){
try {
await generateLink()
const recipients = availableAuthors.value.filter(a => a.selected).map(a => a.author.mail);
if(recipients.length < 1) {
toast.add({
severity: "warn",
summary: "no recipients were selected",
life: 3000
});
return;
}
let cc: string;
if(recipients.length > 1)
cc = "cc=" + recipients.slice(1).join(", ");
else
cc = "";
const subject = "Update for Proposal";
const body = `The Proposal <enter name> was updated. Use the following link to import the Patchset:\n${link.value}`;
const mailto = `mailto:${recipients[0]}?${cc}&subject=${subject}&body=${encodeURIComponent(body)}`;
const trigger = document.createElement("a");
trigger.href = mailto;
//trigger.click();
console.log(mailto);
emitDone = true;
} catch (e) {
console.error("unable to save PatchSet: generateLink() failed", e);
showErrToast("Error while processing patches", e);
}
}
async function generateLink() {
const data = await fileProcessor.exportChanges();
const dataStr = libsodium.to_base64(data, libsodium.base64_variants.URLSAFE);
const url = `${location.origin}${basePath()}/importPatchset#${dataStr}`;
link.value = url;
}
function showErrToast(summary: string, e: any) {
toast.add({
severity: "error",
summary: summary,
detail: e != null ? e.toString() : "unknown reason",
life: 5000
});
}
watch(show, (showing) => {
if(showing) {
emitDone = false;
link.value = "";
loadAuthors();
} else {
if(emitDone) {
emit("done");
}
}
});
</script>

<style scoped lang="scss">
</style>
15 changes: 13 additions & 2 deletions src/ui/dialogs/SaveChangesDlg.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
<div class="flex flex-row mt-1">
<PButton @click="onSavePatches" :disabled="!unsavedPatch" class="w-12rem justify-content-center">Save Patchset</PButton>
<div class="flex-grow-1 mx-1"></div>
<PButton @click="onMailPatches" :disabled="!unsavedPatch" class="w-12rem justify-content-center">Mail Patchset</PButton>
</div>
<div class="flex flex-row mt-1">
<PButton @click="onSaveProposal" class="w-12rem justify-content-center">Save Proposal</PButton>
<template v-if="fileProcessor.storageName !== null">
<div class="flex-grow-1 mx-1"></div>
<PButton @click="onSaveProposalToStorage" class="w-12rem justify-content-center">Update in Storage</PButton>
</template>
</div>

<MailPatchSetDlg v-model="showMailDlg"></MailPatchSetDlg>
</Dialog>
</template>

Expand All @@ -26,6 +31,7 @@
import {download} from "@/ui/utils/utils";
import {useToast} from "primevue/usetoast";
import BrowserStorage from "@/BrowserStorage";
import MailPatchSetDlg from "@/ui/dialogs/MailPatchSetDlg.vue";
const props = defineProps({
modelValue: {
Expand All @@ -41,6 +47,7 @@
const patchExported = ref<boolean>(false);
const unsavedPatch = ref(false);
const showMailDlg = ref(false);
const show = computed({
get() {
Expand Down Expand Up @@ -107,11 +114,15 @@
patchExported.value = true;
} catch (e) {
console.error("unable to save proposal: saveFile failed", e);
showErrToast("Error while saving file", e);
console.error("unable to save PatchSet: exportChanges() failed", e);
showErrToast("Error while saving patches", e);
}
}
function onMailPatches() {
showMailDlg.value = true;
}
function showErrToast(summary: string, e: any) {
toast.add({
severity: "error",
Expand Down

0 comments on commit 63b2b57

Please sign in to comment.