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()
tasks = pillarsdk.Node.all({
'where': {
'project': project['_id'],
'node_type': 'attract.task',
}, api=api)
}}, api=api)
return render_template('attract/tasks/for_project.html',
tasks=tasks,
tasks=tasks['_items'],
project=project)
@@ -37,15 +38,17 @@ def for_project(project):
@attract_project_view()
def view_embed_task(project, task_id):
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')
@attract_project_view()
def create_task(project):
api = pillar_api()
node_type = project.get_node_type('attract.task')
node_props = dict(
@@ -61,6 +64,9 @@ def create_task(project):
task = pillarsdk.Node(node_props)
task.create(api=api)
return flask.redirect(flask.url_for('attract.tasks.view_embed_task',
resp = flask.make_response()
resp.headers['Location'] = flask.url_for('attract.tasks.view_embed_task',
project_url=project['url'],
task_id=task['_id']))
task_id=task['_id'])
resp.status_code = 201
return resp

View File

@@ -10,12 +10,38 @@
.page-triplet-container.homepage
.row
.col-md-4
h2 The edit
p one column
p hey, here's a column too!
.col-md-4
h2 Tasks
a(href="{{ url_for('attract.tasks.index') }}") Go to task manager
ul
| {% for task in tasks %}
li
a(href="javascript:open_task('{{ task._id }}');") {{ task.name }}
| {% endfor %}
.col-md-4
h2 Other stuff
p three column
#task-details
| {% 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 %}

View File

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