diff options
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js/importlayer.js')
-rw-r--r-- | bitbake/lib/toaster/toastergui/static/js/importlayer.js | 59 |
1 files changed, 45 insertions, 14 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/importlayer.js b/bitbake/lib/toaster/toastergui/static/js/importlayer.js index 191b30ffee..570ca3369b 100644 --- a/bitbake/lib/toaster/toastergui/static/js/importlayer.js +++ b/bitbake/lib/toaster/toastergui/static/js/importlayer.js | |||
@@ -17,7 +17,9 @@ function importLayerPageInit (ctx) { | |||
17 | var currentLayerDepSelection; | 17 | var currentLayerDepSelection; |
18 | var validLayerName = /^(\w|-)+$/; | 18 | var validLayerName = /^(\w|-)+$/; |
19 | 19 | ||
20 | libtoaster.makeTypeahead(layerDepInput, libtoaster.ctx.layersTypeAheadUrl, { include_added: "true" }, function(item){ | 20 | libtoaster.makeTypeahead(layerDepInput, |
21 | libtoaster.ctx.layersTypeAheadUrl, | ||
22 | { include_added: "true" }, function(item){ | ||
21 | currentLayerDepSelection = item; | 23 | currentLayerDepSelection = item; |
22 | }); | 24 | }); |
23 | 25 | ||
@@ -95,7 +97,8 @@ function importLayerPageInit (ctx) { | |||
95 | 97 | ||
96 | $("#layer-deps-list").append(newLayerDep); | 98 | $("#layer-deps-list").append(newLayerDep); |
97 | 99 | ||
98 | libtoaster.getLayerDepsForProject(currentLayerDepSelection.layerdetailurl, function (data){ | 100 | libtoaster.getLayerDepsForProject(currentLayerDepSelection.layerdetailurl, |
101 | function (data){ | ||
99 | /* These are the dependencies of the layer added as a dependency */ | 102 | /* These are the dependencies of the layer added as a dependency */ |
100 | if (data.list.length > 0) { | 103 | if (data.list.length > 0) { |
101 | currentLayerDepSelection.url = currentLayerDepSelection.layerdetailurl; | 104 | currentLayerDepSelection.url = currentLayerDepSelection.layerdetailurl; |
@@ -150,7 +153,9 @@ function importLayerPageInit (ctx) { | |||
150 | var body = "<strong>"+layer.name+"</strong>'s dependencies ("+ | 153 | var body = "<strong>"+layer.name+"</strong>'s dependencies ("+ |
151 | depNames.join(", ")+"</span>) require some layers that are not added to your project. Select the ones you want to add:</p>"; | 154 | depNames.join(", ")+"</span>) require some layers that are not added to your project. Select the ones you want to add:</p>"; |
152 | 155 | ||
153 | showLayerDepsModal(layer, depDepsArray, title, body, false, function(layerObsList){ | 156 | showLayerDepsModal(layer, |
157 | depDepsArray, | ||
158 | title, body, false, function(layerObsList){ | ||
154 | /* Add the accepted layer dependencies' ids to the allDeps array */ | 159 | /* Add the accepted layer dependencies' ids to the allDeps array */ |
155 | for (var key in layerObsList){ | 160 | for (var key in layerObsList){ |
156 | allDeps.push(layerObsList[key].id); | 161 | allDeps.push(layerObsList[key].id); |
@@ -191,9 +196,8 @@ function importLayerPageInit (ctx) { | |||
191 | if (data.error != "ok") { | 196 | if (data.error != "ok") { |
192 | console.log(data.error); | 197 | console.log(data.error); |
193 | } else { | 198 | } else { |
194 | /* Success layer import now go to the project page */ | 199 | createImportedNotification(data); |
195 | $.cookie('layer-imported-alert', JSON.stringify(data), { path: '/'}); | 200 | window.location.replace(libtoaster.ctx.projectPageUrl); |
196 | window.location.replace(libtoaster.ctx.projectPageUrl+'?notify=layer-imported'); | ||
197 | } | 201 | } |
198 | }, | 202 | }, |
199 | error: function (data) { | 203 | error: function (data) { |
@@ -204,6 +208,30 @@ function importLayerPageInit (ctx) { | |||
204 | } | 208 | } |
205 | }); | 209 | }); |
206 | 210 | ||
211 | /* Layer imported notification */ | ||
212 | function createImportedNotification(imported){ | ||
213 | var message = "Layer imported"; | ||
214 | |||
215 | if (imported.deps_added.length === 0) { | ||
216 | message = "You have imported <strong><a class=\"alert-link\" href=\""+imported.imported_layer.layerdetailurl+"\">"+imported.imported_layer.name+"</a></strong> and added it to your project."; | ||
217 | } else { | ||
218 | |||
219 | var links = "<a href=\""+imported.imported_layer.layerdetailurl+"\">"+imported.imported_layer.name+"</a>, "; | ||
220 | |||
221 | imported.deps_added.map (function(item, index){ | ||
222 | links +='<a href="'+item.layerdetailurl+'">'+item.name+'</a>'; | ||
223 | /*If we're at the last element we don't want the trailing comma */ | ||
224 | if (imported.deps_added[index+1] !== undefined) | ||
225 | links += ', '; | ||
226 | }); | ||
227 | |||
228 | /* Length + 1 here to do deps + the imported layer */ | ||
229 | message = 'You have imported <strong><a href="'+imported.imported_layer.layerdetailurl+'">'+imported.imported_layer.name+'</a></strong> and added <strong>'+(imported.deps_added.length+1)+'</strong> layers to your project: <strong>'+links+'</strong>'; | ||
230 | } | ||
231 | |||
232 | libtoaster.setNotification("layer-imported", message); | ||
233 | } | ||
234 | |||
207 | function enable_import_btn(enabled) { | 235 | function enable_import_btn(enabled) { |
208 | var importAndAddHint = $("#import-and-add-hint"); | 236 | var importAndAddHint = $("#import-and-add-hint"); |
209 | 237 | ||
@@ -230,10 +258,13 @@ function importLayerPageInit (ctx) { | |||
230 | } | 258 | } |
231 | 259 | ||
232 | if (valid) { | 260 | if (valid) { |
233 | if ($("#local-dir-radio").prop("checked") && localDirPath.val().length > 0) { | 261 | if ($("#local-dir-radio").prop("checked") && |
262 | localDirPath.val().length > 0) { | ||
234 | enable_import_btn(true); | 263 | enable_import_btn(true); |
235 | } | 264 | } |
236 | if ($("#git-repo-radio").prop("checked") && vcsURLInput.val().length > 0 && gitRefInput.val().length > 0) { | 265 | |
266 | if ($("#git-repo-radio").prop("checked") && | ||
267 | vcsURLInput.val().length > 0 && gitRefInput.val().length > 0) { | ||
237 | enable_import_btn(true); | 268 | enable_import_btn(true); |
238 | } | 269 | } |
239 | } | 270 | } |
@@ -266,13 +297,13 @@ function importLayerPageInit (ctx) { | |||
266 | } | 297 | } |
267 | 298 | ||
268 | layerNameInput.on('blur', function() { | 299 | layerNameInput.on('blur', function() { |
269 | if (!$(this).val()){ | 300 | if (!$(this).val()){ |
270 | return; | 301 | return; |
271 | } | 302 | } |
272 | var name = $(this).val(); | 303 | var name = $(this).val(); |
273 | 304 | ||
274 | /* Check if the layer name exists */ | 305 | /* Check if the layer name exists */ |
275 | $.getJSON(libtoaster.ctx.layersTypeAheadUrl, | 306 | $.getJSON(libtoaster.ctx.layersTypeAheadUrl, |
276 | { include_added: "true" , search: name, format: "json" }, | 307 | { include_added: "true" , search: name, format: "json" }, |
277 | function(layer) { | 308 | function(layer) { |
278 | if (layer.results.length > 0) { | 309 | if (layer.results.length > 0) { |