toaster: handle multiple imagefs types
PATCH 1/3 toaster: handle multiple imagefs types
From: Sujith H <[email protected]>
This functionality helps users to add custom image fs types available other than the checkboxes in the UI. User can add imagefs types in the text box and use them in the build.
[YOCTO #7828]
--- .../toaster/toastergui/templates/projectconf.html | 111 +++++++++++++-------- 1 file changed, 70 insertions(+), 41 deletions(-)
bitbake/lib/toaster/toastergui/templates/projectconf.html +70 -41
@@ -62,12 +62,16 @@ <span id="image_fstypes">{{fstypes}}</span> <i class="icon-pencil" id="change-image_fstypes-icon"></i> <form id="change-image_fstypes-form" style="display:none;"> + <div class="input-append" id="validate-image_fstypes"> + <input type="text" class="input-xlarge" id="new-imagefs_types"> + <button id="apply-change-image_fstypes" type="button" class="btn">Save</button> + <button id="cancel-change-image_fstypes" type="button" class="btn btn-link">Cancel</button> + </div> + </br><span class="help-block error" style="display:none;" id="hintError-image-fs_type">A valid image type cannot include underscores.</span> + <p>Choose from known image types</p> <input id="filter-image_fstypes" type="text" placeholder="Search image types" class="span4"> <div id="all-image_fstypes" class="scrolling"> </div> - <span class="help-block" id="fstypes-error-message">You must select at least one image type</span> - <button id="apply-change-image_fstypes" type="button" class="btn">Save</button> - <button id="cancel-change-image_fstypes" type="button" class="btn btn-link">Cancel</button> </form> </dd> {% endif %}
@@ -322,22 +326,6 @@ return true; } - // Test to insure at least one FS Type is checked - function enableFsTypesSave() { - var any_checked = 0; - $(".fs-checkbox-fstypes:checked").each(function(){ - any_checked = 1; - }); - if ( 0 == any_checked ) { - $("#apply-change-image_fstypes").attr("disabled","disabled"); - $('#fstypes-error-message').show(); - } - else { - $("#apply-change-image_fstypes").removeAttr("disabled"); - $('#fstypes-error-message').hide(); - } - } - // Preset or reset the Package Class checkbox labels function updatePackageClassCheckboxes() { $('#package_class_1, #package_class_2').hide();
@@ -603,6 +591,46 @@ {% if fstypes_defined %} // change IMAGE_FSTYPES variable + // get value of fstypes and add to the textbox + $("#new-imagefs_types").val("{{fstypes}}"); + + // If value of new-imagefs_types is empty disable save button + $("#new-imagefs_types").on("input", function() { + $(this).val($(this).val().replace(/\s+/g,' ')); + if ($(this).val().length === 0) { + //$('#apply-change-image_fstypes').prop('disabled', true); + $('#apply-change-image_fstypes').attr("disabled", "disabled"); + } else { + //$('#apply-change-image_fstypes').prop('disabled', false); + $('#apply-change-image_fstypes').removeAttr("disabled"); + } + + /*If user types imagefs do the action on checkboxes. + Lets say if an imagefstype typed by user and the same + imagefs is unchecked in the checkbox, then checkbox needs + to get checked. Similarly when user deletes imagefs from + textbox the checkbox which is checked gets unchecked. + */ + $('#all-image_fstypes input').each(function(){ + var imagefs_userval = $('#new-imagefs_types').val(); + if( imagefs_userval.indexOf($(this).val()) > -1) { + $(this).prop('checked', true); + } else { + $(this).prop('checked', false); + } + }); + + // Validate underscore in image fs types + if ($(this).val().indexOf('_') > -1) { + $('#validate-image_fstypes').addClass('control-group error'); + $('#hintError-image-fs_type').show(); + $("#apply-change-image_fstypes").prop("disabled", true); + } else { + $('#validate-image_fstypes').removeClass('control-group error'); + $('#hintError-image-fs_type').hide(); + } + }); + $('#change-image_fstypes-icon').click(function() { $('#change-image_fstypes-icon, #image_fstypes').hide(); $("#change-image_fstypes-form").slideDown();
@@ -630,19 +658,33 @@ document.getElementById("all-image_fstypes").innerHTML = html; $('#no-match-fstypes').hide(); - // Watch elements to disable Save when none are checked - $(".fs-checkbox-fstypes").each(function(){ - $(this).click(function() { - enableFsTypesSave(); - }); - }); - // clear the previous filter values and warning messages $("input#filter-image_fstypes").val(""); - $('#fstypes-error-message').hide(); + }); + + // When checkbox is checked/unchecked kindly update the text + $(document).on("change", "#all-image_fstypes :checkbox", function() { + var imagefs = $(this); + var imagefs_obj = $('#new-imagefs_types'); + var imagefs_userval = imagefs_obj.val(); + if ($(this).is(':checked')) { + if (imagefs_userval.indexOf($(imagefs).val()) === -1) { + imagefs_obj.val(imagefs_userval + " " + $(imagefs).val()); + } + } else { + if (imagefs_userval.indexOf($(imagefs).val()) > -1) { + imagefs_obj.val(imagefs_userval.replace($(imagefs).val(), '').trim()); + } + } + if ($('#new-imagefs_types').val().length === 0) { + $("#apply-change-image_fstypes").prop("disabled", true); + } else { + $("#apply-change-image_fstypes").prop("disabled", false); + } }); $('#cancel-change-image_fstypes').click(function(){ + $("#new-imagefs_types").val("{{fstypes}}"); $("#change-image_fstypes-form").slideUp(function() { $('#image_fstypes, #change-image_fstypes-icon').show(); });
@@ -670,20 +712,7 @@ }); $('#apply-change-image_fstypes').click(function(){ - // extract the selected fstypes and sort them - var fstypes_array = []; - var checkboxes = document.getElementsByClassName('fs-checkbox-fstypes'); - $(".fs-checkbox-fstypes:checked").each(function(){ - fstypes_array.push($(this).val()); - }); - fstypes_array.sort(); - - // now make a string of them - var fstypes = ''; - for (var i = 0, length = fstypes_array.length; i < length; i++) { - fstypes += fstypes_array[i] + ' '; - } - fstypes = fstypes.trim(); + var fstypes = $('#new-imagefs_types').val(); postEditAjaxRequest({"configvarChange" : 'IMAGE_FSTYPES:'+fstypes}); $('#image_fstypes').text(fstypes);
Signature · 12 lines
1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH 2/3 toaster: projectconf Small tweaks to IMAGE_FSTYPES form
From: Belen Barros Pena <[email protected]>
Add a label to clarify the purpose of the first input field, replace <p> with <label> for the second set of controls, and give some top margin to the validation message.
--- bitbake/lib/toaster/toastergui/templates/projectconf.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
bitbake/lib/toaster/toastergui/templates/projectconf.html +3 -2
@@ -62,13 +62,14 @@ <span id="image_fstypes">{{fstypes}}</span> <i class="icon-pencil" id="change-image_fstypes-icon"></i> <form id="change-image_fstypes-form" style="display:none;"> + <label>Type the image types you want to build:</label> <div class="input-append" id="validate-image_fstypes"> <input type="text" class="input-xlarge" id="new-imagefs_types"> <button id="apply-change-image_fstypes" type="button" class="btn">Save</button> <button id="cancel-change-image_fstypes" type="button" class="btn btn-link">Cancel</button> </div> - </br><span class="help-block error" style="display:none;" id="hintError-image-fs_type">A valid image type cannot include underscores.</span> - <p>Choose from known image types</p> + <p class="help-block error" style="display:none;margin-top:10px;" id="hintError-image-fs_type">A valid image type cannot include underscores</p> + <label>Or choose from known image types:</label> <input id="filter-image_fstypes" type="text" placeholder="Search image types" class="span4"> <div id="all-image_fstypes" class="scrolling"> </div>
Signature · 12 lines
1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH 3/3 bitbake: toaster-tests: tests for project config
In reply to Elliot SmithFrom: Sujith H <[email protected]>
Add basic tests to validate the value user types in the text box for IMAGEFS_TYPES. Added a test case to show the checkbox get automatically selected when user types value available in the check list. Added a test case to verify if the check box is enabled then the text box should also get updated accordingly.
[YOCTO #7828]
--- .../tests/browser/test_project_config_page.py | 115 +++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 bitbake/lib/toaster/tests/browser/test_project_config_page.py
bitbake/lib/toaster/tests/browser/test_project_config_page.py new file +115 -0
@@ -0,0 +1,115 @@ +#! /usr/bin/env python +# ex:ts=4:sw=4:sts=4:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- +# +# BitBake Toaster Implementation +# +# Copyright (C) 2013-2016 Intel Corporation +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import re + +from django.core.urlresolvers import reverse +from django.utils import timezone +from tests.browser.selenium_helpers import SeleniumTestCase + +from orm.models import BitbakeVersion, Release, Project, ProjectVariable + +class TestProjectConfigsPage(SeleniumTestCase): + """ Test data at /project/X/builds is displayed correctly """ + + PROJECT_NAME = 'test project' + + def setUp(self): + bbv = BitbakeVersion.objects.create(name='bbv1', giturl='/tmp/', + branch='master', dirpath='') + release = Release.objects.create(name='release1', + bitbake_version=bbv) + self.project1 = Project.objects.create_project(name=self.PROJECT_NAME, + release=release) + self.project1.save() + + + def test_no_underscore_iamgefs_type(self): + """ + Should not accept IMAGEFS_TYPE with an underscore + """ + + imagefs_type = "foo_bar" + + ProjectVariable.objects.get_or_create(project = self.project1, name = "IMAGE_FSTYPES", value = "abcd ") + url = reverse('projectconf', args=(self.project1.id,)); + self.get(url); + + self.click('#change-image_fstypes-icon') + + self.enter_text('#new-imagefs_types', imagefs_type) + + element = self.wait_until_visible('#hintError-image-fs_type') + + self.assertTrue(("A valid image type cannot include underscores" in element.text), + "Did not find underscore error message") + + + def test_checkbox_verification(self): + """ + Should automatically check the checkbox if user enters value + text box, if value is there in the checkbox. + """ + imagefs_type = "btrfs" + + ProjectVariable.objects.get_or_create(project = self.project1, name = "IMAGE_FSTYPES", value = "abcd ") + url = reverse('projectconf', args=(self.project1.id,)); + self.get(url); + + self.click('#change-image_fstypes-icon') + + self.enter_text('#new-imagefs_types', imagefs_type) + + checkboxes = self.driver.find_elements_by_xpath("//input[@class='fs-checkbox-fstypes']") + + for checkbox in checkboxes: + if checkbox.get_attribute("value") == "btrfs": + self.assertEqual(checkbox.is_selected(), True) + + + def test_textbox_with_checkbox_verification(self): + """ + Should automatically add or remove value in textbox, if user checks + or unchecks checkboxes. + """ + + ProjectVariable.objects.get_or_create(project = self.project1, name = "IMAGE_FSTYPES", value = "abcd ") + url = reverse('projectconf', args=(self.project1.id,)); + self.get(url); + + self.click('#change-image_fstypes-icon') + + self.wait_until_visible('#new-imagefs_types') + + checkboxes = self.driver.find_elements_by_xpath("//input[@class='fs-checkbox-fstypes']") + + for checkbox in checkboxes: + if checkbox.get_attribute("value") == "cpio": + checkbox.click() + element = self.driver.find_element_by_id('new-imagefs_types') + + self.wait_until_visible('#new-imagefs_types') + + self.assertTrue(("cpio" in element.get_attribute('value'), + "Imagefs not added into the textbox")) + checkbox.click() + self.assertTrue(("cpio" not in element.text), + "Image still present in the textbox")
Signature · 12 lines
1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.