Skip to content

Commit

Permalink
feat: campaign form
Browse files Browse the repository at this point in the history
  • Loading branch information
ymarcon committed Oct 18, 2024
1 parent e0d3c31 commit b65f9f4
Show file tree
Hide file tree
Showing 23 changed files with 1,127 additions and 218 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-ui-container-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v4

- name: Build image
run: docker build frontend --build-arg API_URL=https://icebreaker-dev.epfl.ch --build-arg API_PATH=/api --build-arg CDN_PATH=icebreaker-dev --build-arg AUTH_CLIENT_ID=icebreaker-dev-ui --tag $IMAGE_NAME
run: docker build frontend --build-arg API_URL=https://icebreaker-dev.epfl.ch --build-arg API_PATH=/api --build-arg AUTH_CLIENT_ID=icebreaker-dev-ui --tag $IMAGE_NAME

- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-ui-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v4

- name: Build image
run: docker build frontend --build-arg API_URL=https://icebreaker.epfl.ch --build-arg API_PATH=/api --build-arg CDN_PATH=icebreaker --build-arg AUTH_CLIENT_ID=icebreaker-ui --tag $IMAGE_NAME
run: docker build frontend --build-arg API_URL=https://icebreaker.epfl.ch --build-arg API_PATH=/api --build-arg AUTH_CLIENT_ID=icebreaker-ui --tag $IMAGE_NAME

- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
Expand Down
12 changes: 9 additions & 3 deletions backend/api/models/campaigns.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import List, Optional, Tuple
from pydantic import BaseModel
from api.models.files import FileRef

class Reference(BaseModel):
citation: str
Expand All @@ -23,12 +24,17 @@ class TrackColumns(BaseModel):
timestamp: Optional[str] = None

class Track(BaseModel):
file: str
file: FileRef
columns: TrackColumns
color: Optional[str] = None
timestamp_format: Optional[str]


class Funding(BaseModel):
name: str
grant: Optional[str] = None
website: Optional[str] = None

class Campaign(BaseModel):
id: Optional[int] = None
name: str
Expand All @@ -43,9 +49,9 @@ class Campaign(BaseModel):
platform: Optional[str] = None
start_location: Tuple[float, float]
end_location: Optional[Tuple[float, float]] = None
images: Optional[List[str]] = None
images: Optional[List[FileRef]] = None
track: Optional[Track] = None
fundings: Optional[List[str]] = None
fundings: Optional[List[Funding]] = None
references: Optional[List[Reference]] = None
instruments: Optional[List[Instrument]] = None

Expand Down
10 changes: 10 additions & 0 deletions backend/api/models/files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import Optional
from pydantic import BaseModel

class FileRef(BaseModel):
name: str
path: str
size: int
alt_name: Optional[str] = None
alt_path: Optional[str] = None
alt_size: Optional[int] = None
28 changes: 9 additions & 19 deletions backend/api/views/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@
Handle / uploads
"""
import datetime

from fastapi.datastructures import UploadFile
from fastapi.param_functions import File
from api.services.s3 import s3_client

from fastapi import Depends, Security, Query, APIRouter, HTTPException
from fastapi.responses import Response

from api.utils.file_size import size_checker

from api.auth import require_admin, User
from pydantic import BaseModel

from api.utils.file_nodes import FileNode
from api.config import config


class FilePath(BaseModel):
Expand All @@ -26,7 +22,7 @@ class FilePath(BaseModel):

@router.get("/{file_path:path}",
status_code=200,
description="-- Download any assets from S3 --")
description="Download any assets from S3")
async def get_file(file_path: str,
download: bool = Query(
False, alias="d", description="Download file instead of inline display")):
Expand All @@ -44,7 +40,7 @@ async def get_file(file_path: str,

@router.post("/tmp",
status_code=200,
description="-- Upload any assets to S3 --",
description="Upload any assets to S3",
dependencies=[Depends(size_checker)])
async def upload_temp_files(
files: list[UploadFile] = File(description="multiple file upload")):
Expand All @@ -53,21 +49,15 @@ async def upload_temp_files(
folder_name = str(current_time.timestamp()).replace('.', '')
folder_path = f"tmp/{folder_name}"
children = [await s3_client.upload_file(file, s3_folder=folder_path) for file in files]
parent_path = s3_client.to_s3_path(folder_path)
return {
"name": folder_name,
"path": parent_path,
"is_file": False,
"children": children
}
return children


@router.delete("/{file_path:path}",
status_code=204,
description="-- Delete asset present in S3 --",
description="Delete asset present in S3",
)
async def delete_temp_files(file_path: str):
async def delete_file(file_path: str, user: User = Depends(require_admin)):
# delete path if it contains /tmp/
if "/tmp/" in file_path:
if file_path.startswith(config.S3_PATH_PREFIX):
await s3_client.delete_file(file_path)
return
return Response(status_code=204)
3 changes: 2 additions & 1 deletion frontend/.eslintrc-auto-import.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"useId": true,
"useModel": true,
"useTemplateRef": true,
"useAuthStore": true
"useAuthStore": true,
"useAdminStore": true
}
}
2 changes: 0 additions & 2 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ ARG API_URL
ENV API_URL $API_URL
ARG API_PATH
ENV API_PATH $API_PATH
ARG CDN_PATH
ENV CDN_PATH $CDN_PATH
ARG AUTH_CLIENT_ID
ENV AUTH_CLIENT_ID $AUTH_CLIENT_ID
RUN npm run build
Expand Down
1 change: 0 additions & 1 deletion frontend/quasar.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ module.exports = configure(function (ctx) {
env: {
API_URL: ctx.dev ? 'http://localhost:8000' : process.env.API_URL,
API_PATH: ctx.dev ? '' : process.env.API_PATH,
CDN_PATH: ctx.dev ? 'icebreaker-local-dev' : process.env.CDN_PATH,
AUTH_CLIENT_ID: ctx.dev ? 'local-ui' : process.env.AUTH_CLIENT_ID,
CESIUM_ACCESS_TOKEN: ctx.dev ? '' : process.env.CESIUM_ACCESS_TOKEN,
},
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ declare global {
const toValue: typeof import('vue')['toValue']
const triggerRef: typeof import('vue')['triggerRef']
const unref: typeof import('vue')['unref']
const useAdminStore: typeof import('./stores/admin')['useAdminStore']
const useAttrs: typeof import('vue')['useAttrs']
const useAuthStore: typeof import('./stores/auth')['useAuthStore']
const useCatalogStore: typeof import('./stores/catalog')['useCatalogStore']
Expand Down Expand Up @@ -176,6 +177,7 @@ declare module 'vue' {
readonly toValue: UnwrapRef<typeof import('vue')['toValue']>
readonly triggerRef: UnwrapRef<typeof import('vue')['triggerRef']>
readonly unref: UnwrapRef<typeof import('vue')['unref']>
readonly useAdminStore: UnwrapRef<typeof import('./stores/admin')['useAdminStore']>
readonly useAttrs: UnwrapRef<typeof import('vue')['useAttrs']>
readonly useAuthStore: UnwrapRef<typeof import('./stores/auth')['useAuthStore']>
readonly useCssModule: UnwrapRef<typeof import('vue')['useCssModule']>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/boot/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ declare module '@vue/runtime-core' {
}
}

const cdnUrl = `https://enacit4r-cdn.epfl.ch/${process.env.CDN_PATH}`;
const cdnUrl = 'https://enacit4r-cdn.epfl.ch';

const baseUrl = `${process.env.API_URL}${process.env.API_PATH}`;

Expand Down
36 changes: 4 additions & 32 deletions frontend/src/components/AppToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
:label="mapStore.showGlobe ? 'Show 2D' : 'Show 3D'"
@click="toggleShowGlobe"
></q-btn>
<q-btn
flat
round
icon="settings"
:title="$t('administration')"
:to="'/admin'"
></q-btn>
<q-btn
flat
round
Expand All @@ -47,26 +40,10 @@
<q-btn
flat
round
:title="$t('profile')"
icon="account_circle"
class="on-left"
>
<q-popup-proxy>
<q-list class="bg-white">
<q-item clickable v-close-popup to="/profile">
<q-item-section>
<q-item-label v-if="authStore.isAuthenticated">{{ $t('profile') }}</q-item-label>
<q-item-label v-else>{{ $t('user.login') }}</q-item-label>
</q-item-section>
</q-item>
<q-item v-if="authStore.isAuthenticated" clickable v-close-popup @click="authStore.logout">
<q-item-section>
<q-item-label>{{ $t('user.logout') }}</q-item-label>
</q-item-section>
</q-item>
</q-list>
</q-popup-proxy>
</q-btn>
icon="settings"
:title="$t('administration')"
:to="'/admin'"
></q-btn>
</span>
<q-btn v-if="$q.screen.lt.md" flat round icon="more_vert">
<q-popup-proxy>
Expand All @@ -86,11 +63,6 @@
<q-item-label>{{ $t('introduction') }}</q-item-label>
</q-item-section>
</q-item>
<q-item clickable v-close-popup :to="'/profile'">
<q-item-section>
<q-item-label>{{ $t('profile') }}</q-item-label>
</q-item-section>
</q-item>
</q-list>
</q-popup-proxy>
</q-btn>
Expand Down
17 changes: 12 additions & 5 deletions frontend/src/components/CampaignView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<q-item-section>
<q-item-label>
<a :href="trackUrl" target="_blank" class="epfl">
{{ campaign.track.file.split('/').pop() }}
{{ campaign.track.file.name }}
<q-icon name="download" />
</a>
</q-item-label>
Expand Down Expand Up @@ -131,9 +131,16 @@
</q-tab-panel>
<q-tab-panel name="fundings">
<q-list separator>
<q-item v-for="funding in campaign.fundings" :key="funding">
<q-item v-for="funding in campaign.fundings" :key="funding.name">
<q-item-section>
<q-item-label overline>{{ funding }}</q-item-label>
<q-item-label overline>{{ funding.name }}</q-item-label>
<q-item-label v-if="funding.grant" class="text-help">{{ funding.grant }}</q-item-label>
</q-item-section>
<q-item-section v-if="funding.website">
<a :href="funding.website" target="_blank" class="epfl">
{{ truncateString(funding.website, 40) }}
<q-icon name="open_in_new" />
</a>
</q-item-section>
</q-item>
</q-list>
Expand Down Expand Up @@ -161,11 +168,11 @@ const tab = ref('info');
const slide = ref(1);
const imageUrls = computed(() => {
return props.campaign.images ? props.campaign.images.map((image) => `${cdnUrl}/campaigns/${props.campaign.id}/${image}`) : [];
return props.campaign.images ? props.campaign.images.map((image) => `${cdnUrl}/${image.path}`) : [];
});
const trackUrl = computed(() => {
return props.campaign.track ? `${cdnUrl}/campaigns/${props.campaign.id}/${props.campaign.track.file}` : '';
return props.campaign.track ? `${cdnUrl}/${props.campaign.track.file.path}` : '';
});
function truncateString(str: string, num: number) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/SimpleDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</div>
<q-space />
<q-btn flat icon="close" color="primary" v-close-popup class="float-right" />
</q-card-actions>
</q-card-actions>
<q-card-section class="q-pt-none">
<div v-if="props.content">
<q-markdown :src="props.content" />
Expand Down
Loading

0 comments on commit b65f9f4

Please sign in to comment.