diff --git a/app/api/tasks.py b/app/api/tasks.py index 5edcff99..7cf2453c 100644 --- a/app/api/tasks.py +++ b/app/api/tasks.py @@ -111,7 +111,7 @@ class TaskViewSet(viewsets.ViewSet): for file in filesList] task = models.Task.create_from_images(files, project) - if not task is None: + if task is not None: return Response({"id": task.id}, status=status.HTTP_201_CREATED) else: raise exceptions.ValidationError(detail="Cannot create task, input provided is not valid.") diff --git a/app/static/app/js/components/ProjectListItem.jsx b/app/static/app/js/components/ProjectListItem.jsx index f2c81266..17518aab 100644 --- a/app/static/app/js/components/ProjectListItem.jsx +++ b/app/static/app/js/components/ProjectListItem.jsx @@ -167,6 +167,7 @@ class ProjectListItem extends React.Component { this.setState({ showTaskList: !this.state.showTaskList }); + console.log(this.props); } closeUploadError(){ @@ -179,9 +180,6 @@ class ProjectListItem extends React.Component { handleUpload(){ this.resetUploadState(); - - // Hide task list - // if (this.state.showTaskList) this.toggleTaskList(); } handleTaskSaved(taskInfo){ diff --git a/app/static/app/js/components/TaskListItem.jsx b/app/static/app/js/components/TaskListItem.jsx index b7dea4bb..26e62948 100644 --- a/app/static/app/js/components/TaskListItem.jsx +++ b/app/static/app/js/components/TaskListItem.jsx @@ -118,6 +118,33 @@ class TaskListItem extends React.Component { return [pad(h), pad(m), pad(s)].join(':'); } + genActionApiCall(action){ + return () => { + this.setState({actionButtonsDisabled: true}); + + $.post(`/api/projects/${this.state.task.project}/tasks/${this.state.task.id}/${action}/`, + { + uuid: this.state.task.uuid + } + ).done(json => { + if (json.success){ + this.refresh(); + }else{ + this.setState({ + actionError: json.error, + actionButtonsDisabled: false + }); + } + }) + .fail(() => { + this.setState({ + error: url + " is unreachable.", + actionButtonsDisabled: false + }); + }); + }; + } + render() { let name = this.state.task.name !== null ? this.state.task.name : `Task #${this.state.task.id}`; @@ -133,36 +160,9 @@ class TaskListItem extends React.Component { className, icon, label, onClick }); }; - const genActionApiCall = (action) => { - return () => { - this.setState({actionButtonsDisabled: true}); - - $.post(`/api/projects/${this.state.task.project}/tasks/${this.state.task.id}/${action}/`, - { - uuid: this.state.task.uuid - } - ).done(json => { - if (json.success){ - this.refresh(); - }else{ - this.setState({ - actionError: json.error, - actionButtonsDisabled: false - }); - } - }) - .fail(() => { - this.setState({ - error: url + " is unreachable.", - actionButtonsDisabled: false - }); - }); - }; - }; - if ([statusCodes.QUEUED, statusCodes.RUNNING, null].indexOf(this.state.task.status) !== -1){ - addActionButton("Cancel", "btn-primary", "glyphicon glyphicon-remove-circle", genActionApiCall("cancel")); + addActionButton("Cancel", "btn-primary", "glyphicon glyphicon-remove-circle", this.genActionApiCall("cancel")); } // addActionButton("Restart", "btn-primary", "glyphicon glyphicon-play", genActionApiCall("cancel"));