/** * Copyright (c) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); you * may not use this file except in compliance with the License. You may * obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. See the License for the specific language governing * permissions and limitations under the License. */ (function($) { var _isModalOpen = false; var _isReadOnly = true; var _allTestsSet = new Set(); var _allBranches = []; var _allDevices = []; var _writableSummary = 'Known test failures are acknowledged below for specific branch and \ device configurations, and corresponding test breakage alerts will be silenced. Click an \ entry to edit or see more information about the test failure.' var _readOnlySummary = 'Known test failures are acknowledged below for specific branch and \ device configurations, and corresponding test breakage alerts will be silenced. Click an \ entry to see more information about the test failure. To add, edit, or remove a test \ acknowledgment, contact a VTS Dashboard administrator.' $.widget('custom.sizedAutocomplete', $.ui.autocomplete, { options: { parent: '' }, _resizeMenu: function() { this.menu.element.outerWidth($(this.options.parent).width()); } }); /** * Remove an acknowledgment from the list. * @param ack (jQuery object) The object for acknowledgment. * @param key (String) The value to display next to the label. */ function removeAcknowledgment(ack, key) { if (ack.hasClass('disabled')) { return; } ack.addClass('disabled'); $.ajax({ url: '/api/test_acknowledgments/' + key, type: 'DELETE' }).always(function() { ack.removeClass('disabled'); }).then(function() { ack.slideUp(150, function() { ack.remove(); }); }); } /** * Callback for when a chip is removed from a chiplist. * @param text (String) The value stored in the chip. * @param allChipsSet (Set) The set of all chip values. * @param allIndicator (jQuery object) The object for "All" indicator adjacent to the chips. */ function chipRemoveCallback(text, allChipsSet, allIndicator) { allChipsSet.delete(text); if (allChipsSet.size == 0) { allIndicator.show(); } } /** * Add chips to the chip UI. * @param allChipsSet (Set) The set of all chip values. * @param container (jQuery object) The object in which to insert the chips. * @param chipList (list) The list of chip values to insert. * @param allIndicator (jQuery object) The object for "All" indicator adjacent to the chips. */ function addChips(allChipsSet, container, chipList, allIndicator) { if (chipList && chipList.length > 0) { chipList.forEach(function(text) { if (allChipsSet.has(text)) return; var chip = $('' + text + ''); if (!_isReadOnly) { var icon = $('clear').appendTo(chip); icon.click(function() { chipRemoveCallback(text, allChipsSet, allIndicator); }); } chip.appendTo(container); allChipsSet.add(text); }); allIndicator.hide(); } } /** * Create a chip input UI. * @param container (jQuery object) The object in which to insert the input box. * @param placeholder (String) The placeholder text to display in the input. * @param allChipsSet (Set) The set of all chip values. * @param chipContainer (jQuery object) The object in which to insert new chips from the input. * @param allIndicator (jQuery object) The object for "All" indicator adjacent to the chips. * @returns The chip input jQuery object. */ function addChipInput(container, placeholder, allChipsSet, chipContainer, allIndicator) { var input = $(''); input.attr('placeholder', placeholder); input.keyup(function(e) { if (e.keyCode === 13 && input.val().trim()) { addChips(allChipsSet, chipContainer, [input.val()], allIndicator); input.val(''); } }); var addButton = $('add'); addButton.click(function() { if (input.val().trim()) { addChips(allChipsSet, chipContainer, [input.val()], allIndicator); input.val(''); addButton.hide(); } }); addButton.hide(); input.focus(function() { addButton.show(); }); input.focusout(function() { if (!input.val().trim()) { addButton.hide(); } }); var holder = $('
').appendTo(container); input.appendTo(holder); addButton.appendTo(holder); return input; } /** * Callback to save changes to the acknowledgment. * @param ack (jQuery object) The object for acknowledgment. * @param modal (jQuery object) The jQueryUI modal object which invoked the callback. * @param key (String) The key associated with the acknowledgment. * @param test (String) The test name in the acknowledgment. * @param branchSet (Set) The set of all branches in the acknowledgment. * @param deviceSet (Set) The set of all devoces in the acknowledgment. * @param testCaseSet (Set) The set of all test cases in the acknowledgment. * @param note (String) The note in the acknowledgment. */ function saveCallback(ack, modal, key, test, branchSet, deviceSet, testCaseSet, note) { var allEmpty = true; var firstUnemptyInput = null; var vals = modal.find('.modal-section>.input-container>input').each(function(_, input) { if (!!$(input).val()) { allEmpty = false; if (!firstUnemptyInput) firstUnemptyInput = $(input); } }); if (!allEmpty) { firstUnemptyInput.focus(); return false; } var branches = Array.from(branchSet); branches.sort(); var devices = Array.from(deviceSet); devices.sort(); var testCaseNames = Array.from(testCaseSet); testCaseNames.sort(); var data = { 'key' : key, 'testName' : test, 'branches' : branches, 'devices' : devices, 'testCaseNames' : testCaseNames, 'note': note }; $.post('/api/test_acknowledgments', JSON.stringify(data)).done(function(newKey) { var newAck = createAcknowledgment(newKey, test, branches, devices, testCaseNames, note); if (key == null) { ack.replaceWith(newAck.hide()); newAck.slideDown(150); } else { ack.replaceWith(newAck); } }).always(function() { modal.modal({ complete: function() { _isModalOpen = false; } }); modal.modal('close'); }); } /** * Callback to save changes to the acknowledgment. * @param ack (jQuery object) The object for the acknowledgment. * @param key (String) The key associated with the acknowledgment. * @param test (String) The test name in the acknowledgment. * @param branches (list) The list of all branches in the acknowledgment. * @param devices (Set) The list of all devoces in the acknowledgment. * @param testCases (Set) The list of all test cases in the acknowledgment. * @param note (String) The note in the acknowledgment. */ function showModal(ack, key, test, branches, devices, testCases, note) { if (_isModalOpen) { return; } _isModalOpen = true; var wrapper = $('#modal'); wrapper.empty(); wrapper.modal(); var content = $(' '); var row = $('').appendTo(content); row.append('