Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions scripts/cover.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var checked_proglangs_session = sessionStorage.getItem('checked_proglangs');
var checked_labels_session = sessionStorage.getItem('checked_labels');
var checked_repo_names_session = sessionStorage.getItem('checked_repo_names');
var minimum_repo_stars_session = sessionStorage.getItem('minimum_repo_stars');
var maximal_repo_stars_session = sessionStorage.getItem('maximal_repo_stars');
var entries_per_page = 10;

function killSpinner() {
Expand Down Expand Up @@ -131,12 +132,12 @@ function main(data_list) {

// call setChecked() from "filter.js" that sets the items accessed from storage to "checked" state.
// The setChecked() method returns the selected items. Any newly checked items or items unchecked are manipulated in the returned array
let [checked_proglangs, checked_labels, checked_repo_names, minimum_repo_stars] = setChecked(checked_proglangs_session, checked_labels_session, checked_repo_names_session, minimum_repo_stars_session);
let [checked_proglangs, checked_labels, checked_repo_names, minimum_repo_stars, maximal_repo_stars] = setChecked(checked_proglangs_session, checked_labels_session, checked_repo_names_session, maximal_repo_stars_session);

$("input").change(function() {
let inputform_id = $(this).attr("id");

if (inputform_id == "inputformrepostars") {
if (inputform_id == "inputforminrepostars") {
var value = document.getElementById(inputform_id).value
if (Number(value) > 0) {
minimum_repo_stars = value
Expand All @@ -145,11 +146,24 @@ function main(data_list) {
}
sessionStorage.setItem('minimum_repo_stars', minimum_repo_stars)
}


let inputformax_id = $(this).attr("id");

if (inputformax_id == "inputformaxrepostars") {
var value = document.getElementById(inputformax_id).value
if (Number(value) > 0) {
maximal_repo_stars = value
} else {
maximal_repo_stars = ""
}
sessionStorage.setItem('maximal_repo_stars', maximal_repo_stars)
}

filter(
issues_list,
sorted_issues_html_list,
checked_proglangs, checked_labels, checked_repo_names, minimum_repo_stars
checked_proglangs, checked_labels, checked_repo_names, minimum_repo_stars, maximal_repo_stars
);
});

Expand Down Expand Up @@ -216,7 +230,7 @@ function main(data_list) {
filter(
issues_list,
sorted_issues_html_list,
checked_proglangs, checked_labels, checked_repo_names, minimum_repo_stars
checked_proglangs, checked_labels, checked_repo_names, minimum_repo_stars, maximal_repo_stars
);

});
Expand All @@ -240,14 +254,15 @@ function main(data_list) {
function filter(
issues_list,
sorted_issues_html_list,
checked_proglangs, checked_labels, checked_repo_names, minimum_repo_stars
checked_proglangs, checked_labels, checked_repo_names, minimum_repo_stars, maximal_repo_stars
) {

// Perform filtering
if (_.isEmpty(checked_proglangs) &&
_.isEmpty(checked_labels) &&
_.isEmpty(checked_repo_names) &&
(minimum_repo_stars == "")) {
(minimum_repo_stars == "") &&
(maximal_repo_stars == "")) {
renderFilteredList(sorted_issues_html_list, entries_per_page);
} else {
let filtered_list = [];
Expand All @@ -256,7 +271,7 @@ function filter(

for (let j = 0; j < issues_list.length; j++) {
let issue_item = issues_list[j];
if (issue_item.getRepoStars() < minimum_repo_stars) {
if (issue_item.getRepoStars() < minimum_repo_stars || issue_item.getRepoStars() > maximal_repo_stars) {
continue
}

Expand Down
53 changes: 41 additions & 12 deletions scripts/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,45 @@ function createInputFormRepoStars(title, attrId) {
filter_header.appendChild(document.createTextNode("Filter by " + title + ":"));
filter_row.appendChild(filter_header);

let form_element = document.createElement("input");
form_element.setAttribute("class", "selectpicker drop form-control mb-3");
form_element.setAttribute("id", "inputform" + attrId);
form_element.setAttribute("placeholder", "Any number");
form_element.setAttribute("type", "number");
filter_row.appendChild(form_element);
// Create "From" label
let label_from = document.createElement("label");
label_from.setAttribute("for", "inputform" + attrId + "_min");
label_from.textContent = "From: ";

// Create minimum input element
let form_element_min = document.createElement("input");
form_element_min.setAttribute("class", "selectpicker drop form-control mb-3");
form_element_min.setAttribute("id", "inputfor" + "min" + attrId); // Unique ID for minimum
form_element_min.setAttribute("placeholder", "Minimum value");
form_element_min.setAttribute("type", "number");

// Create "To" label
let label_to = document.createElement("label");
label_to.setAttribute("for", "inputform" + attrId + "_max");
label_to.textContent = "To: ";

// Create maximum input element
let form_element_max = document.createElement("input");
form_element_max.setAttribute("class", "selectpicker drop form-control mb-3");
form_element_max.setAttribute("id", "inputfor" + "max" + attrId); // Unique ID for maximum
form_element_max.setAttribute("placeholder", "Maximum value");
form_element_max.setAttribute("type", "number");

// Append elements to the filter row
filter_row.appendChild(label_from);
filter_row.appendChild(form_element_min);
filter_row.appendChild(document.createTextNode(" ")); // Space between "From" and "To"
filter_row.appendChild(label_to);
filter_row.appendChild(form_element_max);

filter_row_parent.appendChild(filter_row);
}

// Array to return the checked items found in storage. Empty if no items were checked before.
var checked_proglangs = [], checked_labels = [], checked_repo_names = [], minimum_repo_stars = [];
var checked_proglangs = [], checked_labels = [], checked_repo_names = [], minimum_repo_stars = [], maximal_repo_stars = [];

// arguments contain the checked items accessed from storage
function setChecked(checked_proglangs_session, checked_labels_session, checked_repo_names_session, minimum_repo_stars_session) {
function setChecked(checked_proglangs_session, checked_labels_session, checked_repo_names_session, minimum_repo_stars_session, maximal_repo_stars_session) {
$(document).ready(function(){
if(!checked_proglangs_session) {
sessionStorage.setItem('checked_proglangs', []);
Expand Down Expand Up @@ -185,18 +210,21 @@ function setChecked(checked_proglangs_session, checked_labels_session, checked_r
}
if(!minimum_repo_stars_session) {
sessionStorage.setItem('minimum_repo_stars', "");
sessionStorage.setItem('maximal_repo_stars', "");
}
else {
minimum_repo_stars = minimum_repo_stars_session;
document.getElementById("inputformrepostars").setAttribute('value', minimum_repo_stars);
maximal_repo_stars = minimum_repo_stars_session;
document.getElementById("inputforminrepostars").setAttribute('value', minimum_repo_stars);
document.getElementById("inputformaxrepostars").setAttribute('value', maximal_repo_stars);
}

// filter the checked items obtained from the session storage.
filterResult();
})

// return the checked options to main()
return [checked_proglangs, checked_labels, checked_repo_names, minimum_repo_stars];
return [checked_proglangs, checked_labels, checked_repo_names, minimum_repo_stars, maximal_repo_stars];

}

Expand Down Expand Up @@ -235,7 +263,8 @@ function filterResult() {
if (_.isEmpty(checked_proglangs) &&
_.isEmpty(checked_labels) &&
_.isEmpty(checked_repo_names) &&
(minimum_repo_stars == "")) {
(minimum_repo_stars == "") &&
(maximal_repo_stars == "")) {
let sorted_issues_html_list = _.map(issues_list, o => createListGroupItemForIssue(o));
renderFilteredList(sorted_issues_html_list, entries_per_page);
} else {
Expand All @@ -245,7 +274,7 @@ function filterResult() {

for (let j = 0; j < issues_list.length; j++) {
let issue_item = issues_list[j];
if (issue_item.getRepoStars() < minimum_repo_stars) {
if (issue_item.getRepoStars() < minimum_repo_stars || issue_item.getRepoStars() > maximal_repo_stars) {
continue
}
let repo_langs = issue_item.getRepoProgLangs();
Expand Down