Added async task loading

This commit is contained in:
2016-09-07 15:08:49 +02:00
parent 805f56d6f4
commit 3c09586349
3 changed files with 55 additions and 15 deletions

View File

@@ -24,12 +24,13 @@ def for_project(project):
api = pillar_api() api = pillar_api()
tasks = pillarsdk.Node.all({ tasks = pillarsdk.Node.all({
'project': project['_id'], 'where': {
'node_type': 'attract.task', 'project': project['_id'],
}, api=api) 'node_type': 'attract.task',
}}, api=api)
return render_template('attract/tasks/for_project.html', return render_template('attract/tasks/for_project.html',
tasks=tasks, tasks=tasks['_items'],
project=project) project=project)
@@ -37,15 +38,17 @@ def for_project(project):
@attract_project_view() @attract_project_view()
def view_embed_task(project, task_id): def view_embed_task(project, task_id):
api = pillar_api() api = pillar_api()
task = pillarsdk.Node.find(task_id, api=api)
return 'Not done, come back later.' return render_template('attract/tasks/view_task_embed.html',
task=task,
project=project)
@blueprint.route('/<project_url>/create') @blueprint.route('/<project_url>/create')
@attract_project_view() @attract_project_view()
def create_task(project): def create_task(project):
api = pillar_api() api = pillar_api()
node_type = project.get_node_type('attract.task') node_type = project.get_node_type('attract.task')
node_props = dict( node_props = dict(
@@ -61,6 +64,9 @@ def create_task(project):
task = pillarsdk.Node(node_props) task = pillarsdk.Node(node_props)
task.create(api=api) task.create(api=api)
return flask.redirect(flask.url_for('attract.tasks.view_embed_task', resp = flask.make_response()
project_url=project['url'], resp.headers['Location'] = flask.url_for('attract.tasks.view_embed_task',
task_id=task['_id'])) project_url=project['url'],
task_id=task['_id'])
resp.status_code = 201
return resp

View File

@@ -10,12 +10,38 @@
.page-triplet-container.homepage .page-triplet-container.homepage
.row .row
.col-md-4 .col-md-4
h2 The edit p hey, here's a column too!
p one column
.col-md-4 .col-md-4
h2 Tasks ul
a(href="{{ url_for('attract.tasks.index') }}") Go to task manager | {% for task in tasks %}
li
a(href="javascript:open_task('{{ task._id }}');") {{ task.name }}
| {% endfor %}
.col-md-4 .col-md-4
h2 Other stuff #task-details
p three column | {% endblock %}
| {% block footer_scripts %}
script.
/**
* Shows a task in the #task-details div.
*/
function open_task(task_id) {
if (task_id === undefined) {
if (console) console.log("open_task(undefined) called.");
return;
}
var base_url = "{{ url_for('attract.tasks.view_embed_task', project_url=project.url, task_id='TASKID') }}";
var task_url = base_url.replace("TASKID", task_id);
$.get(task_url, function(task_data) {
$('#task-details').html(task_data);
}).fail(function(xhr) {
if (console) {
console.log('Error fetching task', task_id, 'from', task_url);
console.log('XHR:', xhr);
}
$('#task-details').html(xhr.responseText);
});
}
| {% endblock %} | {% endblock %}

View File

@@ -0,0 +1,8 @@
.task
dl
dt Name
dd {{ task.name }}
dt Description
dd {{ task.description }}
dt Status
dd {{ task.properties.status }}