Skip to content

Commit

Permalink
wip use isarInspectionId instead of isarTaskId in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
tsundvoll committed Dec 19, 2024
1 parent 84ccdb5 commit 90abced
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 2 additions & 0 deletions backend/api/Database/Models/MissionTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public MissionTask(MissionTask copy, TaskStatus? status = null)
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Local
public string? IsarTaskId { get; set; } = Guid.NewGuid().ToString();

// TODO: Add the IsarInspectionId here

[Required]
public int TaskOrder { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/api/ApiCaller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ export class BackendAPICaller {
return result.content
}

static async getInspection(installationCode: string, taskId: string): Promise<Blob> {
const path: string = 'inspection/' + installationCode + '/' + taskId + '/taskId'
static async getInspection(isarInspectionId: string): Promise<Blob> {
const path: string = 'inspection/' + isarInspectionId

return BackendAPICaller.GET<Blob>(path, 'image/png')
.then((response) => response.content)
Expand Down
13 changes: 5 additions & 8 deletions frontend/src/components/Contexts/InpectionsContext.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { createContext, FC, useContext, useState, useEffect, useRef } from 'react'
import { BackendAPICaller } from 'api/ApiCaller'
import { Task } from 'models/Task'
import { useInstallationContext } from './InstallationContext'

interface IInspectionsContext {
selectedInspectionTask: Task | undefined
selectedInspectionTasks: Task[]
switchSelectedInspectionTask: (selectedInspectionTask: Task | undefined) => void
switchSelectedInspectionTasks: (selectedInspectionTask: Task[]) => void
mappingInspectionTasksObjectURL: { [taskIsarId: string]: string }
mappingInspectionTasksObjectURL: { [isarInspectionId: string]: string }
}

interface Props {
Expand All @@ -26,8 +25,6 @@ const defaultInspectionsContext = {
const InspectionsContext = createContext<IInspectionsContext>(defaultInspectionsContext)

export const InspectionsProvider: FC<Props> = ({ children }) => {
const { installationCode } = useInstallationContext()

const [selectedInspectionTask, setSelectedInspectionTask] = useState<Task>()
const [selectedInspectionTasks, setSelectedInspectionTasks] = useState<Task[]>([])
const [selectedInspectionTasksToFetch, setSelectedInspectionTasksToFetch] = useState<Task[]>([])
Expand All @@ -51,14 +48,14 @@ export const InspectionsProvider: FC<Props> = ({ children }) => {

useEffect(() => {
Object.values(selectedInspectionTasksToFetch).forEach((task, index) => {
if (task.isarTaskId) {
BackendAPICaller.getInspection(installationCode, task.isarTaskId!)
if (task.isarInspectionId) {
BackendAPICaller.getInspection(task.isarInspectionId!)
.then((imageBlob) => {
imageObjectURL.current = URL.createObjectURL(imageBlob)
})
.then(() => {
setMappingInspectionTasksObjectURL((oldMappingInspectionTasksObjectURL) => {
return { ...oldMappingInspectionTasksObjectURL, [task.isarTaskId!]: imageObjectURL.current }
return { ...oldMappingInspectionTasksObjectURL, [task.isarInspectionId!]: imageObjectURL.current }
})
setSelectedInspectionTasksToFetch((oldSelectedInspectionTasksToFetch) => {
let newInspectionTaksToFetch = { ...oldSelectedInspectionTasksToFetch }
Expand All @@ -72,7 +69,7 @@ export const InspectionsProvider: FC<Props> = ({ children }) => {
}
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [installationCode, selectedInspectionTasksToFetch, triggerFetch])
}, [selectedInspectionTasksToFetch, triggerFetch])

const switchSelectedInspectionTask = (selectedName: Task | undefined) => {
setSelectedInspectionTask(selectedName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export const InspectionDialogView = ({ task, tasks }: InspectionDialogViewProps)
const { switchSelectedInspectionTask, mappingInspectionTasksObjectURL } = useInspectionsContext()

const updateImage = useCallback(() => {
if (task.isarTaskId && mappingInspectionTasksObjectURL[task.isarTaskId]) {
imageObjectURL.current = mappingInspectionTasksObjectURL[task.isarTaskId]
if (task.isarInspectionId && mappingInspectionTasksObjectURL[task.isarInspectionId]) {
imageObjectURL.current = mappingInspectionTasksObjectURL[task.isarInspectionId]

getMeta(imageObjectURL.current).then((img) => {
const inspectionCanvas = document.getElementById('inspectionCanvas') as HTMLCanvasElement
Expand Down Expand Up @@ -201,11 +201,11 @@ const GetInspectionImage = ({ task, tasks }: GetInspectionImageProps) => {
}, [tasks])

const updateImage = useCallback(() => {
if (task.isarTaskId && mappingInspectionTasksObjectURL[task.isarTaskId]) {
imageObjectURL.current = mappingInspectionTasksObjectURL[task.isarTaskId]
if (task.isarInspectionId && mappingInspectionTasksObjectURL[task.isarInspectionId]) {
imageObjectURL.current = mappingInspectionTasksObjectURL[task.isarInspectionId]

getMeta(imageObjectURL.current).then((img) => {
const inspectionCanvas = document.getElementById(task.isarTaskId!) as HTMLCanvasElement
const inspectionCanvas = document.getElementById(task.isarInspectionId!) as HTMLCanvasElement
if (inspectionCanvas) {
inspectionCanvas.width = img.width
inspectionCanvas.height = img.height
Expand All @@ -225,5 +225,5 @@ const GetInspectionImage = ({ task, tasks }: GetInspectionImageProps) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [mappingInspectionTasksObjectURL, inspectionImage])

return <StyledInspectionImage id={task.isarTaskId} />
return <StyledInspectionImage id={task.isarInspectionId} />
}
1 change: 1 addition & 0 deletions frontend/src/models/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Pose } from './Pose'
export interface Task {
id: string
isarTaskId?: string
isarInspectionId?: string
taskOrder: number
type: TaskType
tagId?: string
Expand Down

0 comments on commit 90abced

Please sign in to comment.