Skip to content

Commit

Permalink
Merge pull request #296 from guoyunhe/search-result-official-first
Browse files Browse the repository at this point in the history
Sort package by trust level and filter out packages from ports (ARM, PowerPC)
  • Loading branch information
dmacvicar authored May 30, 2018
2 parents e607462 + 4fa8128 commit 75e74b4
Show file tree
Hide file tree
Showing 17 changed files with 475 additions and 252 deletions.
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ AllCops:
- 'db/schema.rb'
- 'script/**/*'
- 'vendor/**/*'
- 'public/**/*'

# FIXME: Cop disabled as it Rubocop fails when enabling it. Enable it when the bug is solved.
# Checks for array literals made up of word-like strings, that are not using the %w() syntax.
# Checks for array literals made up of word-like strings, that are not using the %w() syntax.
Style/WordArray:
Enabled: false
66 changes: 4 additions & 62 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,5 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery-ui
//= require jquery_ujs
//
//= require jquery.cookie
//= require jquery.pjax

// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var divs_shown = false;
function toggleAllDebugDivs() {
var divs = Element.getElementsBySelector($('result'), 'div[class="debug"]');
var text = $('showdebug').firstChild
if(divs_shown) {
Element.replace(text, "Show debugging info");
divs_shown = false;
} else {
Element.replace(text, "Hide debugging info");
divs_shown = true;
}

divs.each(Element.toggle);
}


function setCookie(name, value) {
document.cookie = name + "=" + value + "; path=/";
}

function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0; i < ca.length; ++i) {
var c = ca[i];
while (c.charAt(0)==' ')
c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0)
return c.substring(nameEQ.length,c.length);
}
return null;
}

function submitquery() {
$("#q").attr('value', $(this).text());
$("#search_form > form").submit();
}

$(function() {
$(".query").click(submitquery);
});
// This is the root JavaScript files. Require other JavaScript files here and
// they will be bundled together.

//= require js-cookie
//= require search-settings
183 changes: 183 additions & 0 deletions app/assets/javascripts/js-cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*!
* JavaScript Cookie v2.2.0
* https://github.com/js-cookie/js-cookie
*
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack
* Released under the MIT license
*/
(function(factory) {
var registeredInModuleLoader = false;
if (typeof define === "function" && define.amd) {
define(factory);
registeredInModuleLoader = true;
}
if (typeof exports === "object") {
module.exports = factory();
registeredInModuleLoader = true;
}
if (!registeredInModuleLoader) {
var OldCookies = window.Cookies;
var api = (window.Cookies = factory());
api.noConflict = function() {
window.Cookies = OldCookies;
return api;
};
}
})(function() {
function extend() {
var i = 0;
var result = {};
for (; i < arguments.length; i++) {
var attributes = arguments[i];
for (var key in attributes) {
result[key] = attributes[key];
}
}
return result;
}

function init(converter) {
function api(key, value, attributes) {
var result;
if (typeof document === "undefined") {
return;
}

// Write

if (arguments.length > 1) {
attributes = extend(
{
path: "/"
},
api.defaults,
attributes
);

if (typeof attributes.expires === "number") {
var expires = new Date();
expires.setMilliseconds(
expires.getMilliseconds() + attributes.expires * 864e5
);
attributes.expires = expires;
}

// We're using "expires" because "max-age" is not supported by IE
attributes.expires = attributes.expires
? attributes.expires.toUTCString()
: "";

try {
result = JSON.stringify(value);
if (/^[\{\[]/.test(result)) {
value = result;
}
} catch (e) {}

if (!converter.write) {
value = encodeURIComponent(String(value)).replace(
/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,
decodeURIComponent
);
} else {
value = converter.write(value, key);
}

key = encodeURIComponent(String(key));
key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
key = key.replace(/[\(\)]/g, escape);

var stringifiedAttributes = "";

for (var attributeName in attributes) {
if (!attributes[attributeName]) {
continue;
}
stringifiedAttributes += "; " + attributeName;
if (attributes[attributeName] === true) {
continue;
}
stringifiedAttributes += "=" + attributes[attributeName];
}
return (document.cookie = key + "=" + value + stringifiedAttributes);
}

// Read

if (!key) {
result = {};
}

// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all. Also prevents odd result when
// calling "get()"
var cookies = document.cookie ? document.cookie.split("; ") : [];
var rdecode = /(%[0-9A-Z]{2})+/g;
var i = 0;

for (; i < cookies.length; i++) {
var parts = cookies[i].split("=");
var cookie = parts.slice(1).join("=");

if (!this.json && cookie.charAt(0) === '"') {
cookie = cookie.slice(1, -1);
}

try {
var name = parts[0].replace(rdecode, decodeURIComponent);
cookie = converter.read
? converter.read(cookie, name)
: converter(cookie, name) ||
cookie.replace(rdecode, decodeURIComponent);

if (this.json) {
try {
cookie = JSON.parse(cookie);
} catch (e) {}
}

if (key === name) {
result = cookie;
break;
}

if (!key) {
result[name] = cookie;
}
} catch (e) {}
}

return result;
}

api.set = api;
api.get = function(key) {
return api.call(api, key);
};
api.getJSON = function() {
return api.apply(
{
json: true
},
[].slice.call(arguments)
);
};
api.defaults = {};

api.remove = function(key, attributes) {
api(
key,
"",
extend(attributes, {
expires: -1
})
);
};

api.withConverter = init;

return api;
}

return init(function() {});
});
42 changes: 42 additions & 0 deletions app/assets/javascripts/search-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Control search settings modal.
* - Settings will be stored in Cookies, not shown in URL anymore.
* - Clicking OK button refresh current page.
* - Clicking Cancel or x button do nothing.
*/
$(function() {
var $modal = $("#search-settings");
var $form = $modal.find("form");
var $ok = $modal.find(".ok-button");
var $cancel = $modal.find(".cancel-button");

// For fresh new system, popup modal and let users choose their system version
if (!Cookies.get("baseproject")) {
$modal.modal("show");
}

function save_input_cookie(name) {
var value = $form.find('[name="' + name + '"]').val();
console.log(name + ": " + value);
Cookies.set(name, value, { expires: 365 });
}

function save_checkbox_cookie(name) {
var value = $form.find('[name="' + name + '"]').prop("checked");
console.log(name + ": " + value);
Cookies.set(name, value, { expires: 365 });
}

$ok.click(function() {
save_input_cookie("baseproject");
save_checkbox_cookie("search_devel");
save_checkbox_cookie("search_lang");
save_checkbox_cookie("search_debug");
$modal.modal("hide");
location.reload();
});
$cancel.click(function() {
$form[0].reset();
$modal.modal("hide");
});
});
Loading

0 comments on commit 75e74b4

Please sign in to comment.