-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Az/import export tasks #3056
Az/import export tasks #3056
Changes from 8 commits
8dd68f4
9554bf3
24cb227
cdf2e12
c44faec
b156ff2
c2801bf
b11ed87
e1cabf8
859271b
958cfd3
b4b0564
11a8bc9
b57c939
55999d3
32266f7
ff80d8a
8669ed6
60df6a9
d972726
c956914
4151d42
e7438e3
1aae8f9
1dc1942
3a1bd56
78eef66
32aacc4
57d1fb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,12 @@ export enum TasksActionTypes { | |
UPDATE_TASK_SUCCESS = 'UPDATE_TASK_SUCCESS', | ||
UPDATE_TASK_FAILED = 'UPDATE_TASK_FAILED', | ||
HIDE_EMPTY_TASKS = 'HIDE_EMPTY_TASKS', | ||
EXPORT_TASK = 'EXPORT_TASK', | ||
EXPORT_TASK_SUCCESS = 'EXPORT_TASK_SUCCESS', | ||
EXPORT_TASK_FAILED = 'EXPORT_TASK_FAILED', | ||
IMPORT_TASK = 'IMPORT_TASK', | ||
IMPORT_TASK_SUCCESS = 'IMPORT_TASK_SUCCESS', | ||
IMPORT_TASK_FAILED = 'IMPORT_TASK_FAILED', | ||
} | ||
|
||
function getTasks(): AnyAction { | ||
|
@@ -213,6 +219,49 @@ export function loadAnnotationsAsync( | |
}; | ||
} | ||
|
||
function importTask(): AnyAction { | ||
const action = { | ||
type: TasksActionTypes.IMPORT_TASK, | ||
payload: {}, | ||
}; | ||
|
||
return action; | ||
} | ||
|
||
function importTaskSuccess(task: any): AnyAction { | ||
const action = { | ||
type: TasksActionTypes.IMPORT_TASK_SUCCESS, | ||
payload: { | ||
task, | ||
}, | ||
}; | ||
|
||
return action; | ||
} | ||
|
||
function importTaskFailed(error: any): AnyAction { | ||
const action = { | ||
type: TasksActionTypes.IMPORT_TASK_FAILED, | ||
payload: { | ||
error, | ||
}, | ||
}; | ||
|
||
return action; | ||
} | ||
|
||
export function importTaskAsync(file: File): ThunkAction<Promise<void>, {}, {}, AnyAction> { | ||
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => { | ||
try { | ||
dispatch(importTask()); | ||
const taskInstance = await cvat.classes.Task.import(file); | ||
dispatch(importTaskSuccess(taskInstance)); | ||
} catch (error) { | ||
dispatch(importTaskFailed(error)); | ||
} | ||
}; | ||
} | ||
|
||
function exportDataset(task: any, exporter: any): AnyAction { | ||
const action = { | ||
type: TasksActionTypes.EXPORT_DATASET, | ||
|
@@ -267,6 +316,57 @@ export function exportDatasetAsync(task: any, exporter: any): ThunkAction<Promis | |
}; | ||
} | ||
|
||
function exportTask(taskID: number): AnyAction { | ||
const action = { | ||
type: TasksActionTypes.EXPORT_TASK, | ||
payload: { | ||
taskID, | ||
}, | ||
}; | ||
|
||
return action; | ||
} | ||
|
||
function exportTaskSuccess(taskID: number): AnyAction { | ||
const action = { | ||
type: TasksActionTypes.EXPORT_TASK_SUCCESS, | ||
payload: { | ||
taskID, | ||
}, | ||
}; | ||
|
||
return action; | ||
} | ||
|
||
function exportTaskFailed(taskID: number, error: Error): AnyAction { | ||
const action = { | ||
type: TasksActionTypes.EXPORT_TASK_FAILED, | ||
payload: { | ||
taskID, | ||
error, | ||
}, | ||
}; | ||
|
||
return action; | ||
} | ||
|
||
export function exportTaskAsync(taskInstance: any): ThunkAction<Promise<void>, {}, {}, AnyAction> { | ||
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => { | ||
dispatch(exportTask(taskInstance.id)); | ||
|
||
try { | ||
const url = await taskInstance.export(); | ||
const downloadAnchor = window.document.getElementById('downloadAnchor') as HTMLAnchorElement; | ||
downloadAnchor.href = url; | ||
downloadAnchor.click(); | ||
} catch (error) { | ||
dispatch(exportTaskFailed(taskInstance.id, error)); | ||
} | ||
|
||
dispatch(exportTaskSuccess(taskInstance.id)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably you can put the line under try. It looks more naturally. |
||
}; | ||
} | ||
|
||
function deleteTask(taskID: number): AnyAction { | ||
const action = { | ||
type: TasksActionTypes.DELETE_TASK, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason behind
annotationData
name? Should it be payload or something like that?