Skip to content

Commit

Permalink
Splits the payload table into local an plugin ones
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaptperez committed Jul 2, 2024
1 parent bc23056 commit 84deb7f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/components/payloads/UploadModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function updateFileName($event) {
async function submitFile($event) {
const file = input.value.files[0];
await abilityStore.savePayload($api, file);
await abilityStore.savePayload($api, file, true, true);
fileName.value = fileUploadPlaceholder;
isFileSelected.value = false;
Expand Down
99 changes: 74 additions & 25 deletions src/views/PayloadsView.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { inject, onMounted } from "vue";
import { inject, onMounted, computed } from "vue";
import { storeToRefs } from "pinia";
import { useCoreDisplayStore } from "@/stores/coreDisplayStore";
Expand All @@ -13,14 +13,39 @@ const coreDisplayStore = useCoreDisplayStore();
const { payloads } = storeToRefs(abilityStore);
const { modals } = storeToRefs(coreDisplayStore);
const structuredPayloads = computed(() => {
const regex = /^(?:plugins\/([^/]+)|data)?\/payloads\/(.+)$/;
return payloads.value.map(payload => {
const match = payload.match(regex);
if (!match) {
console.error(`Payload path "${payload}" does not match the expected format.`);
return null;
}
let belongsToAPlugin = match[1] !== undefined;
return {
fullPath: payload,
belongsToAPlugin: match[1] !== undefined,
pluginName: match[1] || null,
fileName: match[2],
};
}).filter(Boolean); // Remove null values
});
const pluginStructuredPayloads = computed(() => {
return structuredPayloads.value.filter(payload => payload.belongsToAPlugin);
});
const nonPluginStructuredPayloads = computed(() => {
return structuredPayloads.value.filter(payload => !payload.belongsToAPlugin);
});
onMounted(async () => {
await abilityStore.getPayloads($api, true, true, false);
await abilityStore.getPayloads($api, true, false, true);
});
</script>

<template lang="pug">
//- Header
.content
h2 Payloads
p
Expand All @@ -29,29 +54,53 @@ onMounted(async () => {
| You can only add or delete local payloads, not plugin ones.
hr

//- Button row
.columns.mb-4
.column.is-one-quarter.is-flex.buttons.mb-0
button.button.is-primary.level-item(@click="modals.payloads.showUpload = true")
span.icon
font-awesome-icon(icon="fas fa-plus")
span Upload a payload
.column.is-half.is-flex.is-justify-content-center
span.tag.is-medium.m-0
span.has-text-success
strong {{ payloads.length }} payload{{ payloads.length === 0 || payloads.length > 1 ? 's' : '' }}
table.table.is-striped.is-fullwidth.is-narrow
thead
tr
th name
th
tbody
tr.pointer(v-for="(payload, index) in payloads")
td.is-four-fifths {{ payload }}
td.has-text-centered
button.delete.is-white(@click.stop="abilityStore.deletePayload($api, payload, false)")
.content
h2 Local Payloads
.columns.mb-4
.column.is-one-quarter.is-flex.buttons.mb-0
button.button.is-primary.level-item(@click="modals.payloads.showUpload = true")
span.icon
font-awesome-icon(icon="fas fa-plus")
span Upload a payload
.column.is-half.is-flex.is-justify-content-center
span.tag.is-medium.m-0
span.has-text-success
strong
| {{ nonPluginStructuredPayloads.length }}
| payload{{ nonPluginStructuredPayloads.length === 0 || nonPluginStructuredPayloads.length > 1 ? 's' : '' }}
table.table.is-striped.is-fullwidth.is-narrow
thead
tr
th File name
th File path
th
tbody
tr.pointer(v-for="(payload, index) in nonPluginStructuredPayloads")
td {{ payload.fileName }}
td.is-four-fifths {{ payload.fullPath }}
td.has-text-centered
button.delete.is-white(@click.stop="abilityStore.deletePayload($api, payload.fileName, true)")

//- Modals
.content
h2 Plugin Payloads
.columns.mb-4
.column.is-full.is-flex.is-justify-content-center
span.tag.is-medium.m-0
span.has-text-success
strong
| {{ pluginStructuredPayloads.length }}
| payload{{ pluginStructuredPayloads.length === 0 || pluginStructuredPayloads.length > 1 ? 's' : '' }}
table.table.is-striped.is-fullwidth.is-narrow
thead
tr
th File name
th File path
th Plugin Name
tbody
tr.pointer(v-for="payload in pluginStructuredPayloads")
td {{ payload.fileName }}
td.is-four-fifths {{ payload.fullPath }}
td {{ payload.pluginName }}
UploadModal
</template>

Expand Down

0 comments on commit 84deb7f

Please sign in to comment.