Skip to content

Commit

Permalink
Harmonized data/time handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Harald Wilhelmi committed May 28, 2024
1 parent dd93ac1 commit 3e9c2dd
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 16 deletions.
9 changes: 7 additions & 2 deletions client/src/components/dataset/ProjectDetailsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import DataTable from 'primevue/datatable'
import { ref, onMounted } from 'vue'
import { splitStr } from '@/utils/index.js'
import { loadProjects } from '@/services/project'
import LocalTime from '@/components/ui/LocalTime.vue'
const props = defineProps({
projectId: {
Expand Down Expand Up @@ -31,8 +32,12 @@ onMounted(() => {
<Column field="project_id" header="SMID" />
<Column field="project_title" header="Title" />
<Column field="project_summary" header="Summary" />
<Column field="date_added" header="Added" />
<Column field="date_published" header="Published" />
<Column header="Added" #body="{ data }">
<LocalTime :epoch="data.date_added" />
</Column>
<Column header="Published" #body="{ data }">
<LocalTime :epoch="data.date_published" :show-time="false" />
</Column>
<Column field="doi" header="DOI">
<template #body="{ data }">
<div class="list-none" v-for="doi in splitStr(data.doi)">
Expand Down
5 changes: 4 additions & 1 deletion client/src/components/project/ProjectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { ref, inject, onMounted } from 'vue'
import { splitStr } from '@/utils/index.js'
import { loadProjects } from '@/services/project'
import LocalTime from '@/components/ui/LocalTime.vue'
const dialogRef = inject('dialogRef')
const records = ref()
Expand Down Expand Up @@ -32,7 +33,9 @@ function selectProject(data) {
<Column field="project_id" header="SMID"></Column>
<Column field="project_title" header="Title"></Column>
<Column field="project_summary" header="Summary"></Column>
<Column field="date_added" header="Added"></Column>
<Column header="Added" #body="{ data }">
<LocalTime :epoch="data.date_added" />
</Column>
<Column field="contact_name" header="Contact"></Column>
<Column field="contact_institution" header="Institution"></Column>
<Column field="doi" header="DOI">
Expand Down
18 changes: 14 additions & 4 deletions client/src/components/ui/LocalTime.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const props = defineProps({
epoch: {
type: Number,
required: true
},
showTime: {
type: Boolean,
required: false,
default: true
}
})
Expand All @@ -21,10 +26,15 @@ const mm = pad(d.getMonth() + 1)
const dd = pad(
d.getDate()
) /* Really getDate? not getDay or getDayofMonath? Yes - really getDate! */
const HH = pad(d.getHours())
const MM = pad(d.getMinutes())
const SS = pad(d.getSeconds())
const formattedDate = `${yyyy}-${mm}-${dd} ${HH}:${MM}:${SS}`
let time = ''
if (props.showTime) {
const HH = pad(d.getHours())
const MM = pad(d.getMinutes())
const SS = pad(d.getSeconds())
time = ` ${HH}:${MM}:${SS}`
}
const formattedDate = `${yyyy}-${mm}-${dd}${time}`
</script>
<template>
{{ formattedDate }}
Expand Down
4 changes: 2 additions & 2 deletions client/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import HomeRoadmap from '@/components/home/HomeRoadmap.vue'
import PageMaintenance from '@/components/default/PageMaintenance.vue'
import PageNotFound from '@/components/default/PageNotFound.vue'

import AccessView from '@/views/AccessView.vue'
import UserAccountView from '@/views/UserAccountView.vue'
import ProjectView from '@/views/ProjectView.vue'
import UploadView from '@/views/UploadView.vue'

Expand Down Expand Up @@ -60,7 +60,7 @@ const router = createRouter({
{
path: '/',
name: 'access',
component: AccessView,
component: UserAccountView,
meta: { requiresAuth: true }
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import StyledHeadline from '@/components/ui/StyledHeadline.vue'
import SubTitle from '@/components/ui/SubTitle.vue'
import LabeledItem from '@/components/ui/LabeledItem.vue'
import ItemBox from '@/components/ui/ItemBox.vue'
import LocalTime from '@/components/ui/LocalTime.vue'
const accessToken = useAccessToken()
const dialogState = useDialogState()
Expand Down Expand Up @@ -52,7 +53,9 @@ onMounted(() => {
<DataTable :value="records" tableStyle="min-width: 50rem">
<Column field="project_id" header="SMID" />
<Column field="project_title" header="Title" />
<Column field="date_added" header="Added" />
<Column header="Added" #body="{ data }">
<LocalTime :epoch="data.date_added" />
</Column>
</DataTable>
</SectionLayout>
</DefaultLayout>
Expand Down
13 changes: 10 additions & 3 deletions server/src/scimodom/api/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@

@project_api.route("/list_all", methods=["GET"])
def list_all():
return _get_projects_for_network()


def _get_projects_for_network(user=None):
project_service = get_project_service()
return project_service.get_projects()
projects = project_service.get_projects(user)
for project in projects:
for field in ["date_added", "date_published"]:
project[field] = project[field].timestamp()
return projects


@project_api.route("/list_mine", methods=["GET"])
@jwt_required()
def list_mine():
user_service = get_user_service()
project_service = get_project_service()
email = get_jwt_identity()
user = user_service.get_user_by_email(email)
return project_service.get_projects(user)
return _get_projects_for_network(user)
5 changes: 2 additions & 3 deletions server/src/scimodom/services/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import logging
from pathlib import Path
from typing import ClassVar, Optional
from typing import ClassVar, Optional, List, Dict

from sqlalchemy.orm import Session
from sqlalchemy import select, func
Expand Down Expand Up @@ -208,7 +208,7 @@ def get_by_id(self, smid: str) -> Project:
"""
return self._session.scalars(select(Project).where(Project.id == smid)).one()

def get_projects(self, user: Optional[User] = None) -> list[dict[str, str]]:
def get_projects(self, user: Optional[User] = None) -> List[Dict[str, any]]:
"""Retrieve all projects.
:param user: Optionally restricts the
Expand Down Expand Up @@ -247,7 +247,6 @@ def get_projects(self, user: Optional[User] = None) -> list[dict[str, str]]:

def _validate_keys(self) -> None:
"""Validate keys from project description (dictionary)."""
from itertools import chain

cols = utils.get_table_columns(
"Project", remove=["id", "date_added", "contact_id"]
Expand Down

0 comments on commit 3e9c2dd

Please sign in to comment.