Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a page with jobs #4258

Merged
merged 9 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added core functionality
  • Loading branch information
bsekachev committed Jan 26, 2022
commit 0c600e7e65893c31a3496f802e3806f785d35944
22 changes: 12 additions & 10 deletions cvat-core/src/api-implementation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2021 Intel Corporation
// Copyright (C) 2019-2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -152,16 +152,13 @@ const config = require('./config');

cvat.jobs.get.implementation = async (filter) => {
checkFilter(filter, {
page: isInteger,
taskID: isInteger,
jobID: isInteger,
});

if ('taskID' in filter && 'jobID' in filter) {
throw new ArgumentError('Only one of fields "taskID" and "jobID" allowed simultaneously');
}

if (!Object.keys(filter).length) {
throw new ArgumentError('Job filter must not be empty');
throw new ArgumentError('Filter fields "taskID" and "jobID" are not permitted to be used at the same time');
}

if ('taskID' in filter) {
Expand All @@ -173,12 +170,17 @@ const config = require('./config');
return [];
}

const job = await serverProxy.jobs.get(filter.jobID);
if (job) {
return [new Job(job)];
if ('jobID' in filter) {
const job = await serverProxy.jobs.get(filter.jobID);
if (job) {
return [new Job(job)];
}
}

return [];
const jobsData = await serverProxy.jobs.get(filter.jobID);
const jobs = jobsData.results.map((jobData) => new Job(jobData));
jobs.count = jobsData.count;
return jobs;
};

cvat.tasks.get.implementation = async (filter) => {
Expand Down
4 changes: 2 additions & 2 deletions cvat-core/src/frames.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,11 +637,11 @@
return frameDataCache[taskID].frameBuffer.getContextImage(frame);
}

async function getPreview(taskID) {
async function getPreview(taskID = null, jobID = null) {
return new Promise((resolve, reject) => {
// Just go to server and get preview (no any cache)
serverProxy.frames
.getPreview(taskID)
.getPreview(taskID, jobID)
.then((result) => {
if (isNode) {
// eslint-disable-next-line no-undef
Expand Down
23 changes: 15 additions & 8 deletions cvat-core/src/server-proxy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2021 Intel Corporation
// Copyright (C) 2019-2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -924,14 +924,20 @@
return createdTask[0];
}

async function getJob(jobID) {
async function getJobs(jobID = null) {
const { backendAPI } = config;

let response = null;
try {
response = await Axios.get(`${backendAPI}/jobs/${jobID}`, {
proxy: config.proxy,
});
if (jobID !== null) {
response = await Axios.get(`${backendAPI}/jobs/${jobID}`, {
proxy: config.proxy,
});
} else {
response = await Axios.get(`${backendAPI}/jobs`, {
proxy: config.proxy,
});
}
} catch (errorData) {
throw generateError(errorData);
}
Expand Down Expand Up @@ -1069,12 +1075,13 @@
return response.data;
}

async function getPreview(tid) {
async function getPreview(tid, jid) {
const { backendAPI } = config;

let response = null;
try {
response = await Axios.get(`${backendAPI}/tasks/${tid}/data`, {
const url = `${backendAPI}/${jid !== null ? 'jobs' : 'tasks'}/${jid || tid}/data`;
response = await Axios.get(url, {
params: {
type: 'preview',
},
Expand Down Expand Up @@ -1800,7 +1807,7 @@

jobs: {
value: Object.freeze({
get: getJob,
get: getJobs,
save: saveJob,
}),
writable: false,
Expand Down
10 changes: 9 additions & 1 deletion cvat-core/src/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,11 @@
};

Job.prototype.frames.preview.implementation = async function () {
const frameData = await getPreview(this.taskId);
if (!this.jobID || !this.taskId) {
return '';
}

const frameData = await getPreview(this.taskId, this.jobID);
return frameData;
};

Expand Down Expand Up @@ -2220,6 +2224,10 @@
};

Task.prototype.frames.preview.implementation = async function () {
if (!this.id) {
return '';
}

const frameData = await getPreview(this.id);
return frameData;
};
Expand Down
44 changes: 44 additions & 0 deletions cvat-ui/src/actions/jobs-actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (C) 2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

import { ActionUnion, createAction, ThunkAction } from 'utils/redux';
import getCore from 'cvat-core-wrapper';
import { JobsQuery } from 'reducers/interfaces';

const cvat = getCore();

export enum JobsActionTypes {
GET_JOBS = 'GET_JOBS',
GET_JOBS_SUCCESS = 'GET_JOBS_SUCCESS',
GET_JOBS_FAILED = 'GET_JOBS_FAILED',
}

const jobsActions = {
getJobs: (query: Partial<JobsQuery>) => createAction(JobsActionTypes.GET_JOBS, { query }),
getJobsSuccess: (jobs: any[], previews: string[]) => (
createAction(JobsActionTypes.GET_JOBS_SUCCESS, { jobs, previews })
),
getJobsFailed: (error: any) => createAction(JobsActionTypes.GET_JOBS_FAILED, { error }),
};

export type JobsActions = ActionUnion<typeof jobsActions>;

export const getJobsAsync = (query: JobsQuery): ThunkAction => async (dispatch) => {
try {
// Remove all keys with null values from the query
const filteredQuery: Partial<JobsQuery> = { ...query };
for (const [key, value] of Object.entries(filteredQuery)) {
if (value === null) {
delete filteredQuery[key];
}
}

dispatch(jobsActions.getJobs(filteredQuery));
const jobs = cvat.jobs.get(filteredQuery);
const previewPromises = jobs.map((job: any) => (job as any).frames.preview().catch(() => ''));
dispatch(jobsActions.getJobsSuccess(jobs, await Promise.all(previewPromises)));
} catch (error) {
dispatch(jobsActions.getJobsFailed(error));
}
};
5 changes: 4 additions & 1 deletion cvat-ui/src/components/cvat-app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2020-2021 Intel Corporation
// Copyright (C) 2020-2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -26,6 +26,8 @@ import ShortcutsDialog from 'components/shortcuts-dialog/shortcuts-dialog';
import ExportDatasetModal from 'components/export-dataset/export-dataset-modal';
import ModelsPageContainer from 'containers/models-page/models-page';

import JobsPageComponent from 'components/jobs-page/jobs-page';

import TasksPageContainer from 'containers/tasks-page/tasks-page';
import CreateTaskPageContainer from 'containers/create-task-page/create-task-page';
import TaskPageContainer from 'containers/task-page/task-page';
Expand Down Expand Up @@ -360,6 +362,7 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
<Route exact path='/tasks/create' component={CreateTaskPageContainer} />
<Route exact path='/tasks/:id' component={TaskPageContainer} />
<Route exact path='/tasks/:tid/jobs/:jid' component={AnnotationPageContainer} />
<Route exact path='/jobs' component={JobsPageComponent} />
<Route exact path='/cloudstorages' component={CloudStoragesPageComponent} />
<Route
exact
Expand Down
14 changes: 13 additions & 1 deletion cvat-ui/src/components/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ function HeaderContainer(props: Props): JSX.Element {
className='cvat-header-button'
type='link'
value='projects'
href='/projects'
href='/projects?page=1'
onClick={(event: React.MouseEvent): void => {
event.preventDefault();
history.push('/projects');
Expand All @@ -398,6 +398,18 @@ function HeaderContainer(props: Props): JSX.Element {
>
Tasks
</Button>
<Button
className='cvat-header-button'
type='link'
value='jobs'
href='/jobs?page=1'
onClick={(event: React.MouseEvent): void => {
event.preventDefault();
history.push('/jobs');
}}
>
Jobs
</Button>
<Button
className='cvat-header-button'
type='link'
Expand Down
3 changes: 3 additions & 0 deletions cvat-ui/src/components/jobs-page/job-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright (C) 2022 Intel Corporation
//
// SPDX-License-Identifier: MIT
3 changes: 3 additions & 0 deletions cvat-ui/src/components/jobs-page/jobs-content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright (C) 2022 Intel Corporation
//
// SPDX-License-Identifier: MIT
11 changes: 11 additions & 0 deletions cvat-ui/src/components/jobs-page/jobs-page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

import React from 'react';

function JobsPageComponent(): JSX.Element {
return (<div>Test</div>);
}

export default React.memo(JobsPageComponent);
3 changes: 3 additions & 0 deletions cvat-ui/src/components/jobs-page/top-bar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright (C) 2022 Intel Corporation
//
// SPDX-License-Identifier: MIT
21 changes: 20 additions & 1 deletion cvat-ui/src/reducers/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2020-2021 Intel Corporation
// Copyright (C) 2020-2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -78,6 +78,24 @@ export interface Task {
preview: string;
}

export interface JobsQuery {
page: number;
id: number | null;
assignee: string | null;
stage: 'annotation' | 'validation' | 'acceptance' | null;
state: 'new' | 'in progress' | 'rejected' | 'completed' | null;
[index: string]: number | null | string | undefined;
}

export interface JobsState {
initialized: boolean;
query: JobsQuery;
fetching: boolean;
count: number;
current: any[];
previews: string[];
}

export interface TasksState {
importing: boolean;
initialized: boolean;
Expand Down Expand Up @@ -747,6 +765,7 @@ export interface OrganizationState {
export interface CombinedState {
auth: AuthState;
projects: ProjectsState;
jobs: JobsState;
tasks: TasksState;
about: AboutState;
share: ShareState;
Expand Down
55 changes: 55 additions & 0 deletions cvat-ui/src/reducers/jobs-reducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (C) 2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

import { JobsActions, JobsActionTypes } from 'actions/jobs-actions';
import { JobsState } from './interfaces';

const defaultState: JobsState = {
initialized: false,
fetching: false,
count: 0,
query: {
page: 1,
id: null,
state: null,
stage: null,
assignee: null,
},
current: [],
previews: [],
};

export default (state: JobsState = defaultState, action: JobsActions): JobsState => {
switch (action.type) {
case JobsActionTypes.GET_JOBS: {
return {
...state,
fetching: true,
query: {
...defaultState.query,
...action.payload.query,
},
};
}
case JobsActionTypes.GET_JOBS_SUCCESS: {
return {
...state,
fetching: false,
initialized: true,
current: action.payload.jobs,
previews: action.payload.previews,
};
}
case JobsActionTypes.GET_JOBS_FAILED: {
return {
...state,
fetching: false,
initialized: true,
};
}
default: {
return state;
}
}
};
4 changes: 3 additions & 1 deletion cvat-ui/src/reducers/root-reducer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (C) 2020-2021 Intel Corporation
// Copyright (C) 2020-2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

import { combineReducers, Reducer } from 'redux';
import authReducer from './auth-reducer';
import projectsReducer from './projects-reducer';
import tasksReducer from './tasks-reducer';
import jobsReducer from './jobs-reducer';
import aboutReducer from './about-reducer';
import shareReducer from './share-reducer';
import formatsReducer from './formats-reducer';
Expand All @@ -27,6 +28,7 @@ export default function createRootReducer(): Reducer {
auth: authReducer,
projects: projectsReducer,
tasks: tasksReducer,
jobs: jobsReducer,
about: aboutReducer,
share: shareReducer,
formats: formatsReducer,
Expand Down