Skip to content

Commit

Permalink
feat: campaigns management, measures edition
Browse files Browse the repository at this point in the history
  • Loading branch information
ymarcon committed Oct 18, 2024
1 parent e830b52 commit a47f86c
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 10 deletions.
4 changes: 2 additions & 2 deletions backend/api/services/campaigns.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ async def createOrUpdate(self, campaign: Campaign) -> Campaign:
if campaign.images is not None:
for i, file in enumerate(campaign.images):
if "/tmp/" in file.path:
new_name = f"{i}-{file.name}"
new_name = f"{i + 1}-{file.name}"
file_path = f"{s3_folder}/{new_name}"
new_key = await s3_client.move_file(file.path, file_path)
file.name = new_name
file.path = urllib.parse.quote(new_key)
if file.alt_path is not None:
new_name = f"{i}-{file.alt_name}"
new_name = f"{i + 1}-{file.alt_name}"
new_key = await s3_client.move_file(file.alt_path, f"{s3_folder}/{new_name}")
file.alt_name = new_name
file.alt_path = urllib.parse.quote(new_key)
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/components/CampaignView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@
<div>
<dl>
<template v-for="measure in instrument.measures" :key="measure.name">
<dd
class="q-ma-none text-caption text-bold">{{ measure.name }}</dd>
<dd class="q-ma-none">
<div class="text-caption text-bold">{{ measure.name }}</div>
<div v-if="measure.description" class="text-hint">{{ measure.description }}</div>
</dd>
<dt
v-for="link in measure.datasets"
:key="link"
Expand Down
92 changes: 88 additions & 4 deletions frontend/src/components/admin/CampaignForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
:label="$t('add_image_file')"
:hint="$t('upload_file_hint')"
accept=".jpg, .jpeg, .png, .webp"
:disable="uploading"
@update:model-value="onImageFileSelected"
/>
</div>
Expand Down Expand Up @@ -257,6 +258,7 @@
:label="$t('add_track_file')"
:hint="$t('upload_file_hint')"
accept=".csv, .tsv"
:disable="uploading"
@update:model-value="onTrackFileSelected"
/>
</div>
Expand Down Expand Up @@ -423,8 +425,10 @@
<div>
<dl>
<template v-for="measure in instrument.measures" :key="measure.name">
<dd
class="q-ma-none text-caption text-bold">{{ measure.name }}</dd>
<dd class="q-ma-none">
<div class="text-caption text-bold">{{ measure.name }}</div>
<div v-if="measure.description" class="text-hint">{{ measure.description }}</div>
</dd>
<dt
v-for="link in measure.datasets"
:key="link"
Expand Down Expand Up @@ -576,7 +580,7 @@
</q-dialog>

<q-dialog v-model="showInstrument">
<q-card style="width: 500px; max-width: 90hw;">
<q-card style="width: 800px; max-width: 90hw;">
<q-card-section>
<q-input
v-model="editedInstrument.name"
Expand All @@ -588,9 +592,81 @@
v-model="editedInstrument.description"
:label="$t('description')"
filled
autogrow
type="textarea"
class="q-mb-md"
/>
<div class="text-bold q-mb-md">{{ $t('measures') }}</div>
<q-list bordered separator v-if="editedInstrument.measures && editedInstrument.measures.length" class="q-mb-md">
<q-item v-for="(measure, i) in editedInstrument.measures" :key="i">
<q-item-section>
<q-input
v-model="measure.name"
:label="$t('name')"
filled
class="q-mb-md"
/>
<q-input
v-model="measure.description"
:label="$t('description')"
filled
autogrow
type="textarea"
class="q-mb-md"
/>
<div class="text-bold q-mb-md">{{ $t('published_datasets') }}</div>
<div v-for="(dataset, j) in measure.datasets" :key="j" class="q-mb-sm">
<table class="full-width">
<tr>
<td>
<q-input
v-model="measure.datasets[j]"
filled
/>
</td>
<td>
<q-btn
color="secondary"
icon="delete"
dense
flat
size="sm"
class="q-ml-sm"
@click="measure.datasets.splice(j, 1)" />
</td>
</tr>
</table>
</div>
<div>
<q-btn
color="secondary"
icon="add"
dense
size="sm"
@click="measure.datasets.push('')"
class="q-mb-sm"
/>
</div>
</q-item-section>
<q-item-section avatar>
<q-btn
icon="delete"
rounded
dense
flat
color="negative"
size="sm"
@click="editedInstrument.measures.splice(i, 1)"
/>
</q-item-section>
</q-item>
</q-list>
<q-btn
color="primary"
icon="add"
size="sm"
@click="editedInstrument.measures.push({ name: '', description: '', datasets: [] })"
/>
</q-card-section>
<q-card-actions align="right">
<q-btn
Expand Down Expand Up @@ -637,6 +713,7 @@ const end_location_lat = ref(props.modelValue.end_location ? props.modelValue.en
const end_location_lon = ref(props.modelValue.end_location ? props.modelValue.end_location[1] : undefined);
const localFile = ref<FileObject>();
const showFundingDialog = ref(false);
const uploading = ref(false);
const selectedFunding = ref<Funding | undefined>();
const editedFunding = ref<Funding | undefined>();
const showReferenceDialog = ref(false);
Expand Down Expand Up @@ -686,12 +763,15 @@ function onImageFileSelected() {
if (!localFile.value) {
return;
}
uploading.value = true;
adminStore.uploadTmpFile(localFile.value).then((image) => {
if (!campaign.value.images) {
campaign.value.images = [];
}
campaign.value.images.push(image);
localFile.value = undefined;
}).finally(() => {
uploading.value = false;
});
}
Expand All @@ -705,6 +785,7 @@ function onTrackFileSelected() {
if (!localFile.value) {
return;
}
uploading.value = true;
adminStore.uploadTmpFile(localFile.value).then((file) => {
if (!campaign.value.track) {
campaign.value.track = {
Expand All @@ -722,6 +803,8 @@ function onTrackFileSelected() {
campaign.value.track.file = file;
}
localFile.value = undefined;
}).finally(() => {
uploading.value = false;
});
}
Expand Down Expand Up @@ -830,7 +913,8 @@ function onReferenceDown(reference: Reference) {
function onShowInstrument(instrument: Instrument | undefined) {
showInstrument.value = true;
selectedInstrument.value = instrument;
editedInstrument.value = { ...instrument} || {
// deep copy
editedInstrument.value = instrument ? JSON.parse(JSON.stringify(instrument)) : {
name: '',
description: '',
measures: [],
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/i18n/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default {
references: 'References',
upload_file_hint: 'Drag and drop a file here or click to upload a file.',
add_image_file: 'Add image file',
add_track_file: 'Track file (csv or tsv)',
add_track_file: 'Track coordinates file (csv or tsv)',
columns: 'Columns',
track_columns_info: 'The track file must contain at least columns about latitude and longitude. A timestamp column is optional.',
latitude_col_name: 'Latitude column name',
Expand All @@ -59,4 +59,6 @@ export default {
doi: 'DOI',
description: 'Description',
reload_confirmation: 'You have pending changes. Are you sure you want to reload the page? All unsaved changes will be lost.',
measures: 'Measures',
published_datasets: 'Published datasets',
};
6 changes: 5 additions & 1 deletion frontend/src/pages/AdminPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ function onLoad() {
mapStore.loadCampaigns().then(() => {
adminStore.initCampaigns(mapStore.campaigns);
if (campaigns.value.length > 0) {
selected.value = 0;
if (selected.value === null) {
selected.value = 0;
} else if (selected.value >= campaigns.value.length) {
selected.value = campaigns.value.length - 1;
}
}
}).finally(() => {
loading.value = false;
Expand Down

0 comments on commit a47f86c

Please sign in to comment.