Skip to content

Commit

Permalink
feat(server): Add last update field
Browse files Browse the repository at this point in the history
  • Loading branch information
pando85 committed Jan 21, 2024
1 parent 20a1419 commit 53fcbfc
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
11 changes: 6 additions & 5 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ type Identity interface {
getUUID() uuid.UUID
}
type Video struct {
SourcePath string `json:"sourcePath"`
DestinationPath string `json:"destinationPath"`
SourcePath string `json:"sourcePath,omitempty"`
DestinationPath string `json:"destinationPath,omitempty"`
Id uuid.UUID `json:"id"`
Events TaskEvents `json:"events"`
Status string `json:"status"`
StatusMessage string `json:"status_message"`
Events TaskEvents `json:"events,omitempty"`
Status string `json:"status,omitempty"`
StatusMessage string `json:"status_message,omitempty"`
LastUpdate *time.Time `json:"last_update,omitempty"`
}

type JobEventQueue struct {
Expand Down
16 changes: 10 additions & 6 deletions server/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,11 @@ func (S *SQLRepository) getJob(ctx context.Context, tx Transaction, uuid string)
return nil, err
}
video.Events = taskEvents
status, statusMessage, _ := S.getVideoStatus(ctx, tx, video.Id.String())
last_update, status, statusMessage, _ := S.getVideoStatus(ctx, tx, video.Id.String())

if last_update != nil {
video.LastUpdate = last_update
}
video.Status = status
video.StatusMessage = statusMessage

Expand Down Expand Up @@ -268,20 +271,21 @@ func (S *SQLRepository) getTaskEvents(ctx context.Context, tx Transaction, uuid
return taskEvents, nil
}

func (S *SQLRepository) getVideoStatus(ctx context.Context, tx Transaction, uuid string) (string, string, error) {
func (S *SQLRepository) getVideoStatus(ctx context.Context, tx Transaction, uuid string) (*time.Time, string, string, error) {
var last_update time.Time
var status string
var message string

rows, err := tx.QueryContext(ctx, "SELECT status, message FROM video_status WHERE video_id=$1", uuid)
rows, err := tx.QueryContext(ctx, "SELECT event_time, status, message FROM video_status WHERE video_id=$1", uuid)
if err != nil {
return status, message, err
return &last_update, status, message, err
}
defer rows.Close()

for rows.Next() {
rows.Scan(&status, &message)
rows.Scan(&last_update, &status, &message)
}
return status, message, nil
return &last_update, status, message, nil
}

func (S *SQLRepository) getJobByPath(ctx context.Context, tx Transaction, path string) (*model.Video, error) {
Expand Down
41 changes: 36 additions & 5 deletions server/web/ui/src/JobTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import { Table, TableBody, TableCell, TableHead, TableRow, CircularProgress, Typography, Button } from '@mui/material';
import { Info, QuestionMark, Task, VideoSettings } from '@mui/icons-material';
import { CalendarMonth, Info, QuestionMark, Task, VideoSettings } from '@mui/icons-material';

import './JobTable.css';

Expand All @@ -12,13 +12,41 @@ interface Job {
destinationPath: string;
status: string;
status_message: string;
last_update: Date;
}

interface JobTableProps {
token: string;
setShowJobTable: React.Dispatch<React.SetStateAction<boolean>>;
}

const formatDate = (date: Date, options: Intl.DateTimeFormatOptions): string => {
if (date == null) {
return '';
}

try {
return new Intl.DateTimeFormat(navigator.language, options).format(date);
} catch (error) {
console.error('Error formatting date:', error);
return '';
}
};

const formatDateDetailed = (date: Date): string => {
const options: Intl.DateTimeFormatOptions = {
timeStyle: "long",
};
return formatDate(date, options)
}

const formatDateShort = (date: Date): string => {
const options: Intl.DateTimeFormatOptions = {
dateStyle: "short",
};
return formatDate(date, options)
}

const JobTable: React.FC<JobTableProps> = ({ token, setShowJobTable }) => {
const [jobs, setJobs] = useState<Job[]>([]);
const [selectedJob, setSelectedJob] = useState<Job | null>(null);
Expand Down Expand Up @@ -77,6 +105,7 @@ const JobTable: React.FC<JobTableProps> = ({ token, setShowJobTable }) => {
destinationPath: response.data.destinationPath,
status: response.data.status,
status_message: response.data.status_message,
last_update: new Date(response.data.last_update),
};

setJobs((prevJobs) =>
Expand Down Expand Up @@ -116,10 +145,11 @@ const JobTable: React.FC<JobTableProps> = ({ token, setShowJobTable }) => {
<Table className="jobTable">
<TableHead>
<TableRow>
<TableCell className=""> <span title="Source"><Task /></span></TableCell>
<TableCell > <span title="Source"><Task /></span></TableCell>
<TableCell className="d-none d-sm-table-cell"><span title="Destionation"><VideoSettings /></span></TableCell>
<TableCell className=""><span title="Status"><QuestionMark /></span></TableCell>
<TableCell ><span title="Status"><QuestionMark /></span></TableCell>
<TableCell className="d-none d-sm-table-cell"><span title="Message"><Info /></span></TableCell>
<TableCell ><span title="LastUpdate"><CalendarMonth /></span></TableCell>
</TableRow>
</TableHead>
<TableBody>
Expand All @@ -129,9 +159,9 @@ const JobTable: React.FC<JobTableProps> = ({ token, setShowJobTable }) => {
onClick={() => handleRowClick(job.id)}
className="tableRow"
>
<TableCell className="">{job.sourcePath}</TableCell>
<TableCell >{job.sourcePath}</TableCell>
<TableCell className="d-none d-sm-table-cell">{job.destinationPath}</TableCell>
<TableCell className="">
<TableCell >
<Button
variant="contained"
style={{
Expand All @@ -142,6 +172,7 @@ const JobTable: React.FC<JobTableProps> = ({ token, setShowJobTable }) => {
</Button>
</TableCell>
<TableCell className="d-none d-sm-table-cell">{job.status_message}</TableCell>
<TableCell title={formatDateDetailed(job.last_update)}>{formatDateShort(job.last_update)}</TableCell>
</TableRow>
))}
</TableBody>
Expand Down

0 comments on commit 53fcbfc

Please sign in to comment.