From 9581f563b77bcd9ad466a3260d161c87aab19fe2 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Tue, 25 Oct 2016 10:47:49 -0400 Subject: [PATCH] Added task list mockup --- app/scheduler.py | 6 ++-- .../app/js/components/ProjectListItem.jsx | 32 ++++++++++++------- .../js/components/ProjectListItemPanel.jsx | 25 --------------- app/static/app/js/components/TaskList.jsx | 26 +++++++++++++++ app/static/app/js/css/Dashboard.scss | 4 --- app/static/app/js/css/ProjectListItem.scss | 11 +++++++ app/static/app/js/css/TaskList.scss | 5 +++ nodeodm/api_client.py | 10 +++++- nodeodm/models.py | 24 +++++++++----- 9 files changed, 90 insertions(+), 53 deletions(-) delete mode 100644 app/static/app/js/components/ProjectListItemPanel.jsx create mode 100644 app/static/app/js/components/TaskList.jsx create mode 100644 app/static/app/js/css/TaskList.scss diff --git a/app/scheduler.py b/app/scheduler.py index 5b213ab2..94274dff 100644 --- a/app/scheduler.py +++ b/app/scheduler.py @@ -14,9 +14,9 @@ scheduler = None def job(func): def wrapper(*args,**kwargs): if (kwargs.get('background', False)): - thread = (threading.Thread(target=func)) - thread.start() - return thread + t = (threading.Thread(target=func)) + t.start() + return t else: return func(*args, **kwargs) return wrapper diff --git a/app/static/app/js/components/ProjectListItem.jsx b/app/static/app/js/components/ProjectListItem.jsx index e354f85b..c602fe5e 100644 --- a/app/static/app/js/components/ProjectListItem.jsx +++ b/app/static/app/js/components/ProjectListItem.jsx @@ -1,7 +1,7 @@ import '../css/ProjectListItem.scss'; import React from 'react'; import update from 'react-addons-update'; -import ProjectListItemPanel from './ProjectListItemPanel'; +import TaskList from './TaskList'; import EditTaskPanel from './EditTaskPanel'; import UploadProgressBar from './UploadProgressBar'; import Dropzone from '../vendor/dropzone'; @@ -13,12 +13,12 @@ class ProjectListItem extends React.Component { super(props); this.state = { - showPanel: false, + showTaskList: false, updatingTask: false, upload: this.getDefaultUploadState() }; - this.togglePanel = this.togglePanel.bind(this); + this.toggleTaskList = this.toggleTaskList.bind(this); this.handleUpload = this.handleUpload.bind(this); this.closeUploadError = this.closeUploadError.bind(this); this.cancelUpload = this.cancelUpload.bind(this); @@ -145,10 +145,10 @@ class ProjectListItem extends React.Component { dataType: 'json', type: 'PATCH' }).done(() => { - if (this.state.showPanel){ - this.projectListItemPanel.refresh(); + if (this.state.showTaskList){ + this.taskList.refresh(); }else{ - this.setState({showPanel: true}); + this.setState({showTaskList: true}); } }).fail(() => { this.setUploadState({error: "Could not update task information. Plese try again."}); @@ -163,9 +163,9 @@ class ProjectListItem extends React.Component { } } - togglePanel(){ + toggleTaskList(){ this.setState({ - showPanel: !this.state.showPanel + showTaskList: !this.state.showTaskList }); } @@ -223,10 +223,18 @@ class ProjectListItem extends React.Component { - - + {this.props.data.name} - + +
+ {this.props.data.description} +
+
+ + + {(this.state.showTaskList ? 'Hide' : 'Show')} Tasks + +
@@ -234,7 +242,7 @@ class ProjectListItem extends React.Component {
- {this.state.showPanel ? : ""} + {this.state.showTaskList ? : ""} {this.state.upload.showEditTask ? : ""} diff --git a/app/static/app/js/components/ProjectListItemPanel.jsx b/app/static/app/js/components/ProjectListItemPanel.jsx deleted file mode 100644 index 42d611f1..00000000 --- a/app/static/app/js/components/ProjectListItemPanel.jsx +++ /dev/null @@ -1,25 +0,0 @@ -import React from 'react'; - -class ProjectListItemPanel extends React.Component { - constructor(){ - super(); - } - - componentDidMount(){ - console.log("DISPLAY"); - } - - refresh(){ - console.log("REFRESH"); - } - - render() { - return ( -
- TODO -
- ); - } -} - -export default ProjectListItemPanel; diff --git a/app/static/app/js/components/TaskList.jsx b/app/static/app/js/components/TaskList.jsx new file mode 100644 index 00000000..6cae4e70 --- /dev/null +++ b/app/static/app/js/components/TaskList.jsx @@ -0,0 +1,26 @@ +import React from 'react'; +import '../css/TaskList.scss'; + +class TaskList extends React.Component { + constructor(){ + super(); + } + + componentDidMount(){ + console.log("DISPLAY"); + } + + refresh(){ + console.log("REFRESH"); + } + + render() { + return ( +
+ Updating task list... +
+ ); + } +} + +export default TaskList; diff --git a/app/static/app/js/css/Dashboard.scss b/app/static/app/js/css/Dashboard.scss index b4797e4a..8aa2d3a0 100644 --- a/app/static/app/js/css/Dashboard.scss +++ b/app/static/app/js/css/Dashboard.scss @@ -1,8 +1,4 @@ #dashboard-app{ - .project-list-item-panel{ - min-height: 100px; - } - .row{ &.no-margin{ margin: 0; diff --git a/app/static/app/js/css/ProjectListItem.scss b/app/static/app/js/css/ProjectListItem.scss index d9eb7b35..848abf56 100644 --- a/app/static/app/js/css/ProjectListItem.scss +++ b/app/static/app/js/css/ProjectListItem.scss @@ -1,5 +1,16 @@ .project-list-item{ min-height: 60px; + + .project-name{ + font-weight: bold; + } + + .project-links{ + font-size: 90%; + i{ + margin-right: 4px; + } + } .dz-preview{ display: none; diff --git a/app/static/app/js/css/TaskList.scss b/app/static/app/js/css/TaskList.scss new file mode 100644 index 00000000..e8bc078a --- /dev/null +++ b/app/static/app/js/css/TaskList.scss @@ -0,0 +1,5 @@ +.task-list{ + background-color: #ecf0f1; + padding: 10px; + min-height: 100px; +} \ No newline at end of file diff --git a/nodeodm/api_client.py b/nodeodm/api_client.py index 983443f5..d992d9e3 100644 --- a/nodeodm/api_client.py +++ b/nodeodm/api_client.py @@ -32,4 +32,12 @@ class ApiClient: @check_client def options(self): - return self.client.server.get_options().result() \ No newline at end of file + return self.client.server.get_options().result() + + @check_client + def new_task(self): + print(dir(self.client.task.post_task_new)) + return self.client.task.post_task_new(images=[]) + +a = ApiClient("localhost", 3000) +a.new_task() \ No newline at end of file diff --git a/nodeodm/models.py b/nodeodm/models.py index d48f91a1..34165645 100644 --- a/nodeodm/models.py +++ b/nodeodm/models.py @@ -16,12 +16,6 @@ class ProcessingNode(models.Model): queue_count = models.PositiveIntegerField(default=0, help_text="Number of tasks currently being processed by this node (as reported by the node itself)") available_options = fields.JSONField(default=dict(), help_text="Description of the options that can be used for processing") - def __init__(self, *args, **kwargs): - super(ProcessingNode, self).__init__(*args, **kwargs) - - # Initialize api client - self.api_client = ApiClient(self.hostname, self.port) - def __str__(self): return '{}:{}'.format(self.hostname, self.port) @@ -32,12 +26,13 @@ class ProcessingNode(models.Model): :returns: True if information could be updated, False otherwise """ - info = self.api_client.info() + api_client = self.api_client() + info = api_client.info() if info != None: self.api_version = info['version'] self.queue_count = info['taskQueueCount'] - options = self.api_client.options() + options = api_client.options() if options != None: self.available_options = options self.last_refreshed = timezone.now() @@ -46,12 +41,25 @@ class ProcessingNode(models.Model): return True return False + def api_client(self): + return ApiClient(self.hostname, self.port) + def get_available_options_json(self): """ :returns available options in JSON string format """ return json.dumps(self.available_options) + def process_new_task(self): + """ + Sends a set of images (and optional GCP file) via the API + to start processing. + + :returns UUID of the newly created task or ... ? + """ + api_client = self.api_client() + + # First time a processing node is created, automatically try to update @receiver(signals.post_save, sender=ProcessingNode, dispatch_uid="update_processing_node_info") def auto_update_node_info(sender, instance, created, **kwargs):