diff options
author | Michael Wood <michael.g.wood@intel.com> | 2015-03-13 14:34:41 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-03-21 00:00:27 +0000 |
commit | 3c5e2917604315775eebe7e62a560a853e5b1c58 (patch) | |
tree | d9312698dba69508bb67ce2df502c149d0bad195 /bitbake | |
parent | 2f684f1bdc188fde5142ee95989994a7990984c5 (diff) | |
download | poky-3c5e2917604315775eebe7e62a560a853e5b1c58.tar.gz |
bitbake: toaster: Add cancel build to latest build section
Add this functionality to the common managed_mrb_section
Make sure we are using the correct version of this template in the
projects template and remove now redundant code.
[YOCTO #7351]
(Bitbake rev: 23f1439a5d3e8f4053826794c6502eca20189054)
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
5 files changed, 53 insertions, 69 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js index 38320667dc..fcf82ac65b 100644 --- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js +++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js | |||
@@ -93,6 +93,33 @@ var libtoaster = (function (){ | |||
93 | } }); | 93 | } }); |
94 | } | 94 | } |
95 | 95 | ||
96 | /* cancelABuild: | ||
97 | * url: xhr_projectbuild | ||
98 | * builds_ids: space separated list of build request ids | ||
99 | * onsuccess: callback for successful execution | ||
100 | * onfail: callback for failed execution | ||
101 | */ | ||
102 | function _cancelABuild(url, build_ids, onsuccess, onfail){ | ||
103 | $.ajax( { | ||
104 | type: "POST", | ||
105 | url: url, | ||
106 | data: { 'buildCancel': build_ids }, | ||
107 | headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, | ||
108 | success: function (_data) { | ||
109 | if (_data.error !== "ok") { | ||
110 | console.warn(_data.error); | ||
111 | } else { | ||
112 | if (onsuccess !== undefined) onsuccess(_data); | ||
113 | } | ||
114 | }, | ||
115 | error: function (_data) { | ||
116 | console.warn("Call failed"); | ||
117 | console.warn(_data); | ||
118 | if (onfail) onfail(data); | ||
119 | } | ||
120 | }); | ||
121 | } | ||
122 | |||
96 | /* Get a project's configuration info */ | 123 | /* Get a project's configuration info */ |
97 | function _getProjectInfo(url, projectId, onsuccess, onfail){ | 124 | function _getProjectInfo(url, projectId, onsuccess, onfail){ |
98 | $.ajax({ | 125 | $.ajax({ |
@@ -197,6 +224,7 @@ var libtoaster = (function (){ | |||
197 | return { | 224 | return { |
198 | reload_params : reload_params, | 225 | reload_params : reload_params, |
199 | startABuild : _startABuild, | 226 | startABuild : _startABuild, |
227 | cancelABuild : _cancelABuild, | ||
200 | makeTypeahead : _makeTypeahead, | 228 | makeTypeahead : _makeTypeahead, |
201 | getProjectInfo: _getProjectInfo, | 229 | getProjectInfo: _getProjectInfo, |
202 | getLayerDepsForProject : _getLayerDepsForProject, | 230 | getLayerDepsForProject : _getLayerDepsForProject, |
diff --git a/bitbake/lib/toaster/toastergui/templates/managed_mrb_section.html b/bitbake/lib/toaster/toastergui/templates/managed_mrb_section.html index 51610e4ab3..a6d4ac66fc 100644 --- a/bitbake/lib/toaster/toastergui/templates/managed_mrb_section.html +++ b/bitbake/lib/toaster/toastergui/templates/managed_mrb_section.html | |||
@@ -3,6 +3,7 @@ | |||
3 | {% load humanize %} | 3 | {% load humanize %} |
4 | 4 | ||
5 | {%if mru|length > 0%} | 5 | {%if mru|length > 0%} |
6 | {# Template provides the latest builds section requires mru in the context which can be added from _managed_get_latest_builds #} | ||
6 | <div class="page-header top-air"> | 7 | <div class="page-header top-air"> |
7 | <h1> | 8 | <h1> |
8 | Latest builds | 9 | Latest builds |
@@ -118,6 +119,7 @@ | |||
118 | <div class="span4 lead">Build queued | 119 | <div class="span4 lead">Build queued |
119 | <i title="This build will start as soon as a build server is available" class="icon-question-sign get-help get-help-blue heading-help" data-toggle="tooltip"></i> | 120 | <i title="This build will start as soon as a build server is available" class="icon-question-sign get-help get-help-blue heading-help" data-toggle="tooltip"></i> |
120 | </div> | 121 | </div> |
122 | <button class="btn btn-info pull-right cancel-build-btn" data-build-id="{{buildrequest.id}}" data-request-url="{% url 'xhr_projectbuild' buildrequest.project.id %}" >Cancel</button> | ||
121 | 123 | ||
122 | {% elif buildrequest.state == buildrequest.REQ_CREATED %} | 124 | {% elif buildrequest.state == buildrequest.REQ_CREATED %} |
123 | 125 | ||
@@ -155,37 +157,25 @@ | |||
155 | 157 | ||
156 | <script> | 158 | <script> |
157 | 159 | ||
158 | /* ensure csrf cookie exists {% csrf_token %} */ | 160 | function scheduleBuild(url, projectName, projectUrl, buildlist) { |
159 | function _makeXHRBuildCall(url, data, onsuccess, onfail) { | 161 | console.log("scheduleBuild"); |
160 | $.ajax( { | 162 | libtoaster.startABuild(url, null, buildlist.join(" "), function(){ |
161 | type: "POST", | 163 | window.location.reload(); |
162 | url: url, | 164 | }, null); |
163 | data: data, | ||
164 | headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, | ||
165 | success: function (_data) { | ||
166 | if (_data.error != "ok") { | ||
167 | alert(_data.error); | ||
168 | } else { | ||
169 | if (onsuccess != undefined) onsuccess(_data); | ||
170 | } | ||
171 | }, | ||
172 | error: function (_data) { | ||
173 | alert("Call failed"); | ||
174 | console.log(_data); | ||
175 | if (onfail) onfail(data); | ||
176 | } }); | ||
177 | } | 165 | } |
178 | 166 | ||
167 | $(document).ready(function(){ | ||
179 | 168 | ||
180 | function scheduleBuild(url, projectName, projectUrl, buildlist) { | 169 | $(".cancel-build-btn").click(function (){ |
181 | console.log("scheduleBuild"); | 170 | var url = $(this).data('request-url'); |
182 | _makeXHRBuildCall(url, {targets: buildlist.join(" ")}, function (_data) { | 171 | var buildIds = $(this).data('build-id'); |
172 | var btn = $(this); | ||
183 | 173 | ||
184 | $('#latest-builds').prepend("<div class=\"alert alert-info project-name\"><span class=\"label label-info\"><a href=\""+projectUrl+"\">"+projectName+"</a></span><div class=\"row-fluid\">" + | 174 | libtoaster.cancelABuild(url, buildIds, function(){ |
185 | "<div class=\"span5 lead\">" + buildlist.join(" ") + | 175 | btn.parents(".alert").fadeOut(); |
186 | "</div><div class=\"span4 lead\">Build queued <i title=\"This build will start as soon as a build server is available\" class=\"icon-question-sign get-help get-help-blue heading-help\"></i></div></div></div>"); | 176 | }, null); |
187 | }); | 177 | }); |
188 | } | 178 | }); |
189 | 179 | ||
190 | </script> | 180 | </script> |
191 | 181 | ||
diff --git a/bitbake/lib/toaster/toastergui/templates/mrb_section.html b/bitbake/lib/toaster/toastergui/templates/mrb_section.html index 432955ab88..c7bddf0372 100644 --- a/bitbake/lib/toaster/toastergui/templates/mrb_section.html +++ b/bitbake/lib/toaster/toastergui/templates/mrb_section.html | |||
@@ -50,9 +50,6 @@ | |||
50 | <span class="lead{%if not MANAGED or not build.project%} pull-right{%endif%}"> | 50 | <span class="lead{%if not MANAGED or not build.project%} pull-right{%endif%}"> |
51 | Build time: <a href="{% url 'buildtime' build.pk %}">{{ build.timespent|sectohms }}</a> | 51 | Build time: <a href="{% url 'buildtime' build.pk %}">{{ build.timespent|sectohms }}</a> |
52 | </span> | 52 | </span> |
53 | {% if MANAGED and build.project %} | ||
54 | <a class="btn {%if build.outcome == build.SUCCEEDED%}btn-success{%elif build.outcome == build.FAILED%}btn-danger{%else%}btn-info{%endif%} pull-right" onclick="scheduleBuild({% url 'xhr_projectbuild' build.project.id as bpi%}{{bpi|json}}, {{build.project.name|json}}, {{build.get_sorted_target_list|mapselect:'target'|json}})">Run again</a> | ||
55 | {% endif %} | ||
56 | </div> | 53 | </div> |
57 | {%endif%} | 54 | {%endif%} |
58 | {%if build.outcome == build.IN_PROGRESS %} | 55 | {%if build.outcome == build.IN_PROGRESS %} |
@@ -68,41 +65,5 @@ | |||
68 | 65 | ||
69 | {% endfor %} | 66 | {% endfor %} |
70 | </div> | 67 | </div> |
71 | |||
72 | <script> | ||
73 | |||
74 | function _makeXHRBuildCall(url, data, onsuccess, onfail) { | ||
75 | $.ajax( { | ||
76 | type: "POST", | ||
77 | url: url, | ||
78 | data: data, | ||
79 | headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, | ||
80 | success: function (_data) { | ||
81 | if (_data.error != "ok") { | ||
82 | console.warn(_data.error); | ||
83 | } else { | ||
84 | if (onsuccess != undefined) onsuccess(_data); | ||
85 | } | ||
86 | }, | ||
87 | error: function (_data) { | ||
88 | console.warn("Call failed"); | ||
89 | console.warn(_data); | ||
90 | if (onfail) onfail(data); | ||
91 | } }); | ||
92 | } | ||
93 | |||
94 | |||
95 | function scheduleBuild(url, projectName, buildlist) { | ||
96 | console.warn("scheduleBuild"); | ||
97 | _makeXHRBuildCall(url, {targets: buildlist.join(" ")}, function (_data) { | ||
98 | |||
99 | $('#latest-builds').prepend('<div class="alert alert-info" style="padding-top:0px">' + '<span class="label label-info" style="font-weight: normal; margin-bottom: 5px; margin-left:-15px; padding-top:5px;">'+projectName+'</span><div class="row-fluid">' + | ||
100 | '<div class="span4 lead">' + buildlist.join(" ") + | ||
101 | '</div><div class="span4 lead pull-right">Build queued. Your build will start shortly.</div></div></div>'); | ||
102 | }); | ||
103 | } | ||
104 | |||
105 | </script> | ||
106 | |||
107 | {%endif%} | 68 | {%endif%} |
108 | 69 | ||
diff --git a/bitbake/lib/toaster/toastergui/templates/projects.html b/bitbake/lib/toaster/toastergui/templates/projects.html index 88d5bd32df..88ee4bcd66 100644 --- a/bitbake/lib/toaster/toastergui/templates/projects.html +++ b/bitbake/lib/toaster/toastergui/templates/projects.html | |||
@@ -7,7 +7,7 @@ | |||
7 | {% block pagecontent %} | 7 | {% block pagecontent %} |
8 | 8 | ||
9 | 9 | ||
10 | {% include "mrb_section.html" %} | 10 | {% include "managed_mrb_section.html" %} |
11 | 11 | ||
12 | 12 | ||
13 | <div class="page-header top-air"> | 13 | <div class="page-header top-air"> |
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 661023e523..26c876080d 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py | |||
@@ -1871,8 +1871,7 @@ if toastermain.settings.MANAGED: | |||
1871 | 1871 | ||
1872 | # build view-specific information; this is rendered specifically in the builds page, at the top of the page (i.e. Recent builds) | 1872 | # build view-specific information; this is rendered specifically in the builds page, at the top of the page (i.e. Recent builds) |
1873 | # most recent build is like projects' most recent builds, but across all projects | 1873 | # most recent build is like projects' most recent builds, but across all projects |
1874 | build_mru = BuildRequest.objects.all() | 1874 | build_mru = _managed_get_latest_builds() |
1875 | build_mru = list(build_mru.filter(Q(state__lt=BuildRequest.REQ_COMPLETED) or Q(state=BuildRequest.REQ_DELETED)).order_by("-pk")) + list(build_mru.filter(state__in=[BuildRequest.REQ_COMPLETED, BuildRequest.REQ_FAILED]).order_by("-pk")[:3]) | ||
1876 | 1875 | ||
1877 | fstypes_map = {}; | 1876 | fstypes_map = {}; |
1878 | for build_request in build_info: | 1877 | for build_request in build_info: |
@@ -3130,6 +3129,12 @@ if toastermain.settings.MANAGED: | |||
3130 | } | 3129 | } |
3131 | return render(request, "unavailable_artifact.html", context) | 3130 | return render(request, "unavailable_artifact.html", context) |
3132 | 3131 | ||
3132 | # This returns the mru object that is needed for the | ||
3133 | # managed_mrb_section.html template | ||
3134 | def _managed_get_latest_builds(): | ||
3135 | build_mru = BuildRequest.objects.all() | ||
3136 | build_mru = list(build_mru.filter(Q(state__lt=BuildRequest.REQ_COMPLETED) or Q(state=BuildRequest.REQ_DELETED)).order_by("-pk")) + list(build_mru.filter(state__in=[BuildRequest.REQ_COMPLETED, BuildRequest.REQ_FAILED]).order_by("-pk")[:3]) | ||
3137 | return build_mru | ||
3133 | 3138 | ||
3134 | 3139 | ||
3135 | def projects(request): | 3140 | def projects(request): |
@@ -3153,7 +3158,7 @@ if toastermain.settings.MANAGED: | |||
3153 | project_info = _build_page_range(Paginator(queryset, pagesize), request.GET.get('page', 1)) | 3158 | project_info = _build_page_range(Paginator(queryset, pagesize), request.GET.get('page', 1)) |
3154 | 3159 | ||
3155 | # build view-specific information; this is rendered specifically in the builds page, at the top of the page (i.e. Recent builds) | 3160 | # build view-specific information; this is rendered specifically in the builds page, at the top of the page (i.e. Recent builds) |
3156 | build_mru = Build.objects.order_by("-started_on")[:3] | 3161 | build_mru = _managed_get_latest_builds() |
3157 | 3162 | ||
3158 | # translate the project's build target strings | 3163 | # translate the project's build target strings |
3159 | fstypes_map = {}; | 3164 | fstypes_map = {}; |