Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Issue 164: AJAXify the build list and build detail pages

  • Loading branch information...
commit dd470f54c8bd700afb04ab99f145f1d52d3dd5df 1 parent 03d583f
@abrookins abrookins authored
View
BIN  media/images/loader.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
66 media/javascript/rtd.js
@@ -96,3 +96,69 @@ function guessRepo() {
)
}
+
+// Show an animated 'loading' gif while we get the current details of the build
+// with `buildId` from the server.
+//
+// On success, hide the loading gif, populate any <span> nodes that have ids
+// matching the pattern "build-<field name in `data` object>", and if the build
+// state is "finished" clear the client-side polling interval with ID
+// `intervalId`.
+function updateBuildDetails(buildId, intervalId) {
+ $('div#build-' + buildId + ' img.build-loading').removeClass('hide');
+
+ $.get('/api/v1/build/' + buildId, function(data) {
+ for (var prop in data) {
+ if (data.hasOwnProperty(prop)) {
+ var val = data[prop];
+ var el = $('div#build-' + buildId + ' span#build-' + prop);
+
+ if (prop == 'success') {
+ val = val ? "Passed" : "Failed";
+ }
+
+ if (prop == 'state') {
+ val = val.charAt(0).toUpperCase() + val.slice(1);
+
+ if (val == 'Finished') {
+ $('div#build-' + buildId + ' img.build-loading').addClass('hide');
+ clearInterval(intervalId);
+ }
+ }
+
+ if (el) {
+ el.text(val);
+ }
+ }
+ }
+ });
+}
+
+
+// If the the build with ID `buildId` has a state other than finished, poll the
+// server every 5 seconds for the current status. Update the details page with
+// the latest values from the server, to keep the user informed of progress.
+//
+// If we never get a 'finished' state back from the server, stop polling after
+// 10 minutes.
+function pollForBuildDetails(buildId) {
+ var stateSpan = $('div#build-' + buildId + ' span#build-state');
+
+ // If the build is already finished, or it isn't displayed on the page,
+ // ignore it.
+ if (stateSpan.text() == 'Finished' || stateSpan.length == 0) {
+ return;
+ }
+
+ updateBuildDetails(buildId, intervalId);
+
+ var intervalId = setInterval(function() {
+ updateBuildDetails(buildId, intervalId);
+ }, 5000);
+
+ // Stop polling after 10 minutes, in case the build never finishes.
+ setTimeout(function() {
+ updateBuildDetails(buildId, intervalId);
+ }, 600000);
+}
+
View
7 readthedocs/builds/views.py
@@ -21,11 +21,16 @@ def build_list(request, project_slug=None, tag=None):
project = get_object_or_404(Project, slug=project_slug)
queryset = queryset.filter(project=project)
+ active_builds = queryset.exclude(state="finished").values('id')
return object_list(
request,
queryset=queryset,
- extra_context={'project': project, 'tag': tag},
+ extra_context={
+ 'project': project,
+ 'tag': tag,
+ 'active_builds': active_builds
+ },
template_object_name='build',
)
View
1  readthedocs/templates/base.html
@@ -18,6 +18,7 @@
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js"></script>
+ <script type="text/javascript" src="{{ MEDIA_URL }}javascript/instantsearch.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}javascript/rtd.js"></script>
{% block extra_scripts %}{% endblock %}
View
54 readthedocs/templates/builds/build_detail.html
@@ -5,34 +5,46 @@
{% block content-header %}<h1>Build for {{ build.project.name }}</h1>{% endblock %}
{% block content %}
- <p>Built: {{ build.date|date:"N j, Y. P" }}</p>
+ <div id="build-{{ build.id }}">
+ <p>Built: {{ build.date|date:"N j, Y. P" }}</p>
- <p>Outcome: <b>{{ build.success|yesno:"Passed,Failed" }}</b></p>
+ <p>Outcome: <b><span id="build-success">{{ build.success|yesno:"Passed,Failed" }}</span></b></p>
- {% if build.version %}
- <p>Version: <b>{{ build.version.slug }}</b></p>
- {% endif %}
+ {% if build.version %}
+ <p>Version: <b>{{ build.version.slug }}</b></p>
+ {% endif %}
- <p>Type: <b>{{ build.type }}</b></p>
+ <p>Type: <b>{{ build.type }}</b></p>
- <p>State: <b>{{ build.state }}</b></p>
+ <p>State: <b><span id="build-state">{{ build.get_state_display }}</span></b>
+ <img src="/media/images/loader.gif" class="hide build-loading">
+ </p>
- <h3>Sphinx Standard Output</h3>
- <pre class="build-output">{{ build.output }}</pre>
+ <h3>Sphinx Standard Output</h3>
+ <pre class="build-output"><span id="build-output">{{ build.output }}</span></pre>
- {% if build.error %}
- <h3>Sphinx Standard Error</h3>
- <pre class="build-error">{{ build.error }}</pre>
- {% endif %}
+ {% if build.error %}
+ <h3>Sphinx Standard Error</h3>
+ <pre class="build-error"><span id="build-error">{{ build.error }}</span></pre>
+ {% endif %}
- {% if build.setup %}
- <h3>Setup Output</h3>
- <pre class="build-output">{{ build.setup }}</pre>
- {% endif %}
+ {% if build.setup %}
+ <h3>Setup Output</h3>
+ <pre class="build-output"><span id="build-setup">{{ build.setup }}</span></pre>
+ {% endif %}
- {% if build.setup_error %}
- <h3>Environment Standard Error</h3>
- <pre class="build-error">{{ build.setup_error }}</pre>
- {% endif %}
+ {% if build.setup_error %}
+ <h3>Environment Standard Error</h3>
+ <pre class="build-error"><span id="build-setup_error">{{ build.setup_error }}</span></pre>
+ {% endif %}
+ </div>
+{% endblock %}
+{% block extra_scripts %}
+{{ block.super }}
+ <script type="text/javascript">
+ $(function() {
+ pollForBuildDetails({{ build.id }});
+ });
+ </script>
{% endblock %}
View
11 readthedocs/templates/builds/build_list.html
@@ -31,3 +31,14 @@
{% paginate %}
{% endblock %}
+
+{% block extra_scripts %}
+{{ block.super }}
+ <script type="text/javascript">
+ $(function() {
+ {% for build in active_builds %}
+ pollForBuildDetails({{ build.id }});
+ {% endfor %}
+ });
+ </script>
+{% endblock %}
View
7 readthedocs/templates/core/build_list_detailed.html
@@ -1,9 +1,12 @@
{% for build in build_list %}
- <li class="module-item col-span">
- <a href="{{ build.get_absolute_url }}">{% if build.state != 'finished' %}{{ build.get_state_display }} {% else %} {{ build.success|yesno:"Passed,Failed" }} {% endif %}
+ <li class="module-item col-span">
+ <div id="build-{{ build.id }}">
+ <a href="{{ build.get_absolute_url }}"><span id="build-state">{% if build.state != 'finished' %}{{ build.get_state_display }} {% else %} {{ build.success|yesno:"Passed,Failed" }} {% endif %}</span>
+ <img src="/media/images/loader.gif" class="build-loading hide">
<span class="quiet">{% if build.version %}version {{ build.version.slug }} ({{ build.type }}){% endif %}</span><span class="quiet right"> {{ build.date|timesince }} ago</span>
</a>
+ </div>
</li>
{% empty %}
<li class="module-item quiet">No projects found</li>
Please sign in to comment.
Something went wrong with that request. Please try again.