From 2dc8cd201838794de3edf9c64ac71960de7b7507 Mon Sep 17 00:00:00 2001 From: Guo Yunhe Date: Thu, 17 May 2018 16:17:45 +0300 Subject: [PATCH 01/16] Sort package by trust level --- app/controllers/search_controller.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index ed7fdd1ca..b59bfa8fd 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -31,6 +31,12 @@ def index # only show packages @packages = @packages.reject { |p| p.first.type == 'ymp' } + + # sort by package name length + @packages.sort! { |a, b| a.name.length <=> b.name.length } + # show official package first + @packages.sort! { |a, b| trust_level(b, base) - trust_level(a, base)} + @packagenames = @packages.map { |p| p.name } # mix in searchresults from appdata, as the api can't search in summary and description atm @@ -39,7 +45,7 @@ def index a[:name].match(/#{Regexp.quote(@search_term)}/i)) }.map { |a| a[:pkgname] } @packagenames = (@packagenames + appdata_hits) end - @packagenames = @packagenames.uniq.sort_by { |x| x.length } + @packagenames = @packagenames.uniq if @packagenames.size == 1 redirect_to(:controller => :package, :action => :show, :package => @packagenames.first, :search_term => @search_term) and return @@ -51,4 +57,20 @@ def index end def find; end + + + # 3: official package + # 2: official package in Factory + # 1: experimental package + # 0: community package + def trust_level(package, project) + if package.project == project || package.project == "#{project}:Update" || package.project == "#{project}:NonFree" + return 3 + elsif package.project == "openSUSE:Factory" + return 2 + elsif (package.project.start_with?('home')) + return 0 + end + return 1 + end end From c65569b69a1ca9ff9d0d79990aacc3773f47fc2e Mon Sep 17 00:00:00 2001 From: Guo Yunhe Date: Thu, 17 May 2018 16:50:19 +0300 Subject: [PATCH 02/16] Filter out devel, lang, buildsymbols package --- app/controllers/search_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index b59bfa8fd..e854740b7 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -32,6 +32,11 @@ def index # only show packages @packages = @packages.reject { |p| p.first.type == 'ymp' } + # filter out devel, language, debug packages + if !@search_devel + @packages.reject! { |p| p.name.end_with?("-devel", "-lang", "-buildsymbols") || p.name.include?("-translations-") || p.name.include?("-l10n-") } + end + # sort by package name length @packages.sort! { |a, b| a.name.length <=> b.name.length } # show official package first From 324d36ea6012505adf502c89b950bc3585e61b2b Mon Sep 17 00:00:00 2001 From: Guo Yunhe Date: Fri, 18 May 2018 17:45:47 +0300 Subject: [PATCH 03/16] Execlude ports for other architecture --- app/controllers/package_controller.rb | 7 +++++++ app/controllers/search_controller.rb | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/app/controllers/package_controller.rb b/app/controllers/package_controller.rb index 769f4b1ae..938a4b4c2 100644 --- a/app/controllers/package_controller.rb +++ b/app/controllers/package_controller.rb @@ -36,6 +36,13 @@ def show @screenshot = url_for :controller => :package, :action => :screenshot, :package => @pkgname, :appscreen => @appscreenshot, protocol: request.protocol @thumbnail = url_for :controller => :package, :action => :thumbnail, :package => @pkgname, :appscreen => @appscreenshot, protocol: request.protocol + # filter out ports for different arch + # this rule is very basic, need further improvement + # TODO: detect user agent of aarch64, armv7l, ppc64, etc. + if request.user_agent.include?("x86_64") || request.user_agent.include?("i686") + @packages.reject! { |p| p.repository.end_with?("_ARM", "_PowerPC", "_zSystems") || p.project.include?("ARM") || p.project.include?("PowerPC") || p.project.include?("zSystems") } + end + # remove maintenance projects @packages.reject!{|p| p.project.match(/openSUSE\:Maintenance\:/) } diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index e854740b7..62dc486f9 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -37,6 +37,13 @@ def index @packages.reject! { |p| p.name.end_with?("-devel", "-lang", "-buildsymbols") || p.name.include?("-translations-") || p.name.include?("-l10n-") } end + # filter out ports for different arch + # this rule is very basic, need further improvement + # TODO: detect user agent of aarch64, armv7l, ppc64, etc. + if request.user_agent.include?("x86_64") || request.user_agent.include?("i686") + @packages.reject! { |p| p.repository.end_with?("_ARM", "_PowerPC", "_zSystems") || p.project.include?("ARM") || p.project.include?("PowerPC") || p.project.include?("zSystems") } + end + # sort by package name length @packages.sort! { |a, b| a.name.length <=> b.name.length } # show official package first From 4cee71bcce452687fde34ee6c6445cd24aa742f1 Mon Sep 17 00:00:00 2001 From: Guo Yunhe Date: Fri, 18 May 2018 17:56:25 +0300 Subject: [PATCH 04/16] Filter out openSUSE:Factory:Rebuild --- app/controllers/package_controller.rb | 2 +- app/controllers/search_controller.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/package_controller.rb b/app/controllers/package_controller.rb index 938a4b4c2..cbb0c6031 100644 --- a/app/controllers/package_controller.rb +++ b/app/controllers/package_controller.rb @@ -44,7 +44,7 @@ def show end # remove maintenance projects - @packages.reject!{|p| p.project.match(/openSUSE\:Maintenance\:/) } + @packages.reject!{|p| p.project.match(/openSUSE\:Maintenance\:/) || p.project == "openSUSE:Factory:Rebuild" } @packages.each do |package| # Backports chains up to the toolchain module for newer GCC. diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 62dc486f9..4f876154d 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -29,6 +29,9 @@ def index @distributions.map { |d| "#{d[:project]}:Update" }.include?(p.project) || @distributions.map { |d| "#{d[:project]}:NonFree" }.include?(p.project) } end + # remove maintenance projects + @packages.reject!{|p| p.project.match(/openSUSE\:Maintenance\:/) || p.project == "openSUSE:Factory:Rebuild" } + # only show packages @packages = @packages.reject { |p| p.first.type == 'ymp' } From e645db1a672e3d024c6aab9c93d9b170f03fb67c Mon Sep 17 00:00:00 2001 From: Guo Yunhe Date: Fri, 18 May 2018 18:19:28 +0300 Subject: [PATCH 05/16] Fix rubocop warnings --- .rubocop.yml | 3 ++- app/controllers/package_controller.rb | 7 +++++-- app/controllers/search_controller.rb | 27 +++++++++++++++------------ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d85534cd9..029c747ab 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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 diff --git a/app/controllers/package_controller.rb b/app/controllers/package_controller.rb index cbb0c6031..8c3c10882 100644 --- a/app/controllers/package_controller.rb +++ b/app/controllers/package_controller.rb @@ -40,11 +40,14 @@ def show # this rule is very basic, need further improvement # TODO: detect user agent of aarch64, armv7l, ppc64, etc. if request.user_agent.include?("x86_64") || request.user_agent.include?("i686") - @packages.reject! { |p| p.repository.end_with?("_ARM", "_PowerPC", "_zSystems") || p.project.include?("ARM") || p.project.include?("PowerPC") || p.project.include?("zSystems") } + @packages.reject! do |p| + p.repository.end_with?("_ARM", "_PowerPC", "_zSystems") || + p.project.include?("ARM") || p.project.include?("PowerPC") || p.project.include?("zSystems") + end end # remove maintenance projects - @packages.reject!{|p| p.project.match(/openSUSE\:Maintenance\:/) || p.project == "openSUSE:Factory:Rebuild" } + @packages.reject! { |p| p.project.match(/openSUSE\:Maintenance\:/) || p.project == "openSUSE:Factory:Rebuild" } @packages.each do |package| # Backports chains up to the toolchain module for newer GCC. diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 4f876154d..e569d8f6f 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -30,7 +30,7 @@ def index end # remove maintenance projects - @packages.reject!{|p| p.project.match(/openSUSE\:Maintenance\:/) || p.project == "openSUSE:Factory:Rebuild" } + @packages.reject! { |p| p.project.match(/openSUSE\:Maintenance\:/) || p.project == "openSUSE:Factory:Rebuild" } # only show packages @packages = @packages.reject { |p| p.first.type == 'ymp' } @@ -44,13 +44,16 @@ def index # this rule is very basic, need further improvement # TODO: detect user agent of aarch64, armv7l, ppc64, etc. if request.user_agent.include?("x86_64") || request.user_agent.include?("i686") - @packages.reject! { |p| p.repository.end_with?("_ARM", "_PowerPC", "_zSystems") || p.project.include?("ARM") || p.project.include?("PowerPC") || p.project.include?("zSystems") } + @packages.reject! do |p| + p.repository.end_with?("_ARM", "_PowerPC", "_zSystems") || + p.project.include?("ARM") || p.project.include?("PowerPC") || p.project.include?("zSystems") + end end # sort by package name length @packages.sort! { |a, b| a.name.length <=> b.name.length } # show official package first - @packages.sort! { |a, b| trust_level(b, base) - trust_level(a, base)} + @packages.sort! { |a, b| trust_level(b, base) - trust_level(a, base) } @packagenames = @packages.map { |p| p.name } @@ -73,19 +76,19 @@ def index def find; end - - # 3: official package - # 2: official package in Factory - # 1: experimental package - # 0: community package def trust_level(package, project) + # 3: official package + # 2: official package in Factory + # 1: experimental package + # 0: community package if package.project == project || package.project == "#{project}:Update" || package.project == "#{project}:NonFree" - return 3 + 3 elsif package.project == "openSUSE:Factory" - return 2 + 2 elsif (package.project.start_with?('home')) - return 0 + 0 + else + 1 end - return 1 end end From 0312363174fe57db78c377b6ad5ad0ad97f8b10e Mon Sep 17 00:00:00 2001 From: Guo Yunhe Date: Sat, 19 May 2018 16:30:38 +0300 Subject: [PATCH 06/16] Popup settings modal if no baseproject in cookies --- app/assets/javascripts/application.js | 66 +------- app/assets/javascripts/js-cookie.js | 183 ++++++++++++++++++++++ app/assets/javascripts/search-settings.js | 17 ++ app/views/layouts/application.html.erb | 5 +- app/views/search/_find_form.html.erb | 36 +---- app/views/search/_settings.html.erb | 34 ++++ 6 files changed, 243 insertions(+), 98 deletions(-) create mode 100644 app/assets/javascripts/js-cookie.js create mode 100644 app/assets/javascripts/search-settings.js create mode 100644 app/views/search/_settings.html.erb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 40b30c910..b30a12b35 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -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 diff --git a/app/assets/javascripts/js-cookie.js b/app/assets/javascripts/js-cookie.js new file mode 100644 index 000000000..3fb9b15c2 --- /dev/null +++ b/app/assets/javascripts/js-cookie.js @@ -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() {}); +}); diff --git a/app/assets/javascripts/search-settings.js b/app/assets/javascripts/search-settings.js new file mode 100644 index 000000000..4a3c38c3b --- /dev/null +++ b/app/assets/javascripts/search-settings.js @@ -0,0 +1,17 @@ +/** + * 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 $ok = $modal.find(".ok-button"); + var $cancel = $modal.find(".cancel-button"); + + $modal.modal(); + // For fresh new system, popup modal and let users choose their system version + if (!Cookies.get("search_baseproject")) { + $modal.modal("show"); + } +}); diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d89bb84e7..d1f820bc8 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,12 +10,13 @@ + <%= stylesheet_link_tag "/chameleon/css/app.css" %> <%= stylesheet_link_tag "app" %> + <%= javascript_include_tag "/chameleon/js/app.js" %> - - <%= javascript_include_tag "application" %> + <%= javascript_include_tag "application" %> <%= yield :content_for_head %> diff --git a/app/views/search/_find_form.html.erb b/app/views/search/_find_form.html.erb index 4587a30c0..be8a6fa3a 100644 --- a/app/views/search/_find_form.html.erb +++ b/app/views/search/_find_form.html.erb @@ -8,46 +8,14 @@ <%= _("Search") %> - - <% end -%> diff --git a/app/views/search/_settings.html.erb b/app/views/search/_settings.html.erb new file mode 100644 index 000000000..16f496e96 --- /dev/null +++ b/app/views/search/_settings.html.erb @@ -0,0 +1,34 @@ + From f80663adc62a89fe09d2b929fa950b50e896f675 Mon Sep 17 00:00:00 2001 From: Guo Yunhe Date: Wed, 23 May 2018 23:57:40 +0300 Subject: [PATCH 07/16] Search settings in cookies --- app/assets/javascripts/search-settings.js | 29 +++++- app/controllers/application_controller.rb | 61 +++++++---- app/controllers/package_controller.rb | 15 +-- app/controllers/search_controller.rb | 27 +---- app/views/layouts/_footer.html.erb | 118 +++++++++++----------- app/views/layouts/_navbar.html.erb | 52 +++++----- app/views/search/_find_form.html.erb | 11 +- app/views/search/_settings.html.erb | 47 ++++++--- public/search_software.xml | 2 +- 9 files changed, 191 insertions(+), 171 deletions(-) diff --git a/app/assets/javascripts/search-settings.js b/app/assets/javascripts/search-settings.js index 4a3c38c3b..b0b84b291 100644 --- a/app/assets/javascripts/search-settings.js +++ b/app/assets/javascripts/search-settings.js @@ -6,12 +6,37 @@ */ $(function() { var $modal = $("#search-settings"); + var $form = $modal.find("form"); var $ok = $modal.find(".ok-button"); var $cancel = $modal.find(".cancel-button"); - $modal.modal(); // For fresh new system, popup modal and let users choose their system version - if (!Cookies.get("search_baseproject")) { + 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"); + }); }); diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7d09cdb2b..1b5475dff 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -68,8 +68,8 @@ def set_distributions end def set_baseproject - unless (@distributions.blank? || @distributions.select{|d| d[:project] == cookies[:search_baseproject]}.blank?) - @baseproject = cookies[:search_baseproject] + unless (@distributions.blank? || @distributions.select{|d| d[:project] == cookies[:baseproject]}.blank?) + @baseproject = cookies[:baseproject] end end @@ -134,21 +134,48 @@ def valid_project_name? name def set_search_options @search_term = params[:q] || "" - @baseproject = params[:baseproject] unless @distributions.select{|d| d[:project] == params[:baseproject]}.blank? - @search_devel = cookies[:search_devel] unless cookies[:search_devel].blank? - @search_devel = params[:search_devel] unless params[:search_devel].blank? - @search_unsupported = cookies[:search_unsupported] unless cookies[:search_unsupported].blank? - @search_unsupported = params[:search_unsupported] unless params[:search_unsupported].blank? - #FIXME: remove @search_unsupported when redesigning search options - @search_unsupported = "true" - @search_devel = (@search_devel == "true" ? true : false) - @search_project = params[:search_project] - @search_unsupported = (@search_unsupported == "true" ? true : false) - @exclude_debug = @search_devel ? false : true - @exclude_filter = @search_unsupported ? nil : 'home:' - cookies[:search_devel] = { :value => @search_devel, :expires => 1.year.from_now } - cookies[:search_unsupported] = { :value => @search_unsupported, :expires => 1.year.from_now } - cookies[:search_baseproject] = { :value => @baseproject, :expires => 1.year.from_now } + if !cookies[:baseproject].nil? && @distributions.select{ |d| d[:project] == cookies[:baseproject] } + @baseproject = cookies[:baseproject] + else + @baseproject = "openSUSE:Factory" + end + @search_devel = (cookies[:search_devel] == "true" ? true : false) + @search_lang = (cookies[:search_lang] == "true" ? true : false) + @search_debug = (cookies[:search_debug] == "true" ? true : false) + end + + def filter_packages + # remove maintenance projects, they are not meant for end users + @packages.reject! { |p| p.project.match(/openSUSE\:Maintenance\:/) } + @packages.reject! { |p| p.project == "openSUSE:Factory:Rebuild" } + @packages.reject! { |p| p.project.start_with?("openSUSE:Factory:Staging") } + + # only show packages + @packages = @packages.reject { |p| p.first.type == 'ymp' } + + unless @search_devel + @packages.reject! { |p| p.name.end_with?("-devel") } + end + + unless @search_lang + @packages.reject! { |p| p.name.end_with?("-lang") || p.name.include?("-translations-") || p.name.include?("-l10n-") } + end + + unless @search_debug + @packages.reject! { |p| p.name.end_with?("-buildsymbols") || p.name.end_with?("-debuginfo") || p.name.end_with?("-debugsource") } + end + + # filter out ports for different arch + if @baseproject.end_with?("ARM") + @packages.filter! { |p| p.project.include?("ARM") || p.repository.include?("ARM") } + elsif @baseproject.end_with?("PowerPC") + @packages.filter! { |p| p.project.include?("PowerPC") || p.repository.include?("PowerPC") } + else # x86 + @packages.reject! do |p| + p.repository.end_with?("_ARM", "_PowerPC", "_zSystems") || + p.project.include?("ARM") || p.project.include?("PowerPC") || p.project.include?("zSystems") + end + end end # TODO: atm obs only offers appdata for Factory diff --git a/app/controllers/package_controller.rb b/app/controllers/package_controller.rb index 8c3c10882..b07ec9f02 100644 --- a/app/controllers/package_controller.rb +++ b/app/controllers/package_controller.rb @@ -3,7 +3,7 @@ class PackageController < ApplicationController before_action :set_search_options, :only => %i[show categories] before_action :prepare_appdata, :set_categories, :only => %i[show explore category] - skip_before_action :set_language, :set_distributions, :set_baseproject, :only => %i[thumbnail screenshot] + skip_before_action :set_language, :set_distributions, :only => %i[thumbnail screenshot] def show required_parameters :package @@ -36,18 +36,7 @@ def show @screenshot = url_for :controller => :package, :action => :screenshot, :package => @pkgname, :appscreen => @appscreenshot, protocol: request.protocol @thumbnail = url_for :controller => :package, :action => :thumbnail, :package => @pkgname, :appscreen => @appscreenshot, protocol: request.protocol - # filter out ports for different arch - # this rule is very basic, need further improvement - # TODO: detect user agent of aarch64, armv7l, ppc64, etc. - if request.user_agent.include?("x86_64") || request.user_agent.include?("i686") - @packages.reject! do |p| - p.repository.end_with?("_ARM", "_PowerPC", "_zSystems") || - p.project.include?("ARM") || p.project.include?("PowerPC") || p.project.include?("zSystems") - end - end - - # remove maintenance projects - @packages.reject! { |p| p.project.match(/openSUSE\:Maintenance\:/) || p.project == "openSUSE:Factory:Rebuild" } + filter_packages @packages.each do |package| # Backports chains up to the toolchain module for newer GCC. diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index e569d8f6f..12e988eb4 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -23,32 +23,7 @@ def index raise e if @packages.nil? end - # filter out devel projects on user setting - unless (@search_unsupported || @search_project) - @packages = @packages.select { |p| (@distributions.map { |d| d[:project] }.include? p.project) || - @distributions.map { |d| "#{d[:project]}:Update" }.include?(p.project) || @distributions.map { |d| "#{d[:project]}:NonFree" }.include?(p.project) } - end - - # remove maintenance projects - @packages.reject! { |p| p.project.match(/openSUSE\:Maintenance\:/) || p.project == "openSUSE:Factory:Rebuild" } - - # only show packages - @packages = @packages.reject { |p| p.first.type == 'ymp' } - - # filter out devel, language, debug packages - if !@search_devel - @packages.reject! { |p| p.name.end_with?("-devel", "-lang", "-buildsymbols") || p.name.include?("-translations-") || p.name.include?("-l10n-") } - end - - # filter out ports for different arch - # this rule is very basic, need further improvement - # TODO: detect user agent of aarch64, armv7l, ppc64, etc. - if request.user_agent.include?("x86_64") || request.user_agent.include?("i686") - @packages.reject! do |p| - p.repository.end_with?("_ARM", "_PowerPC", "_zSystems") || - p.project.include?("ARM") || p.project.include?("PowerPC") || p.project.include?("zSystems") - end - end + filter_packages # sort by package name length @packages.sort! { |a, b| a.name.length <=> b.name.length } diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb index ea0f4a25f..656a8a990 100644 --- a/app/views/layouts/_footer.html.erb +++ b/app/views/layouts/_footer.html.erb @@ -1,68 +1,68 @@ diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index dd6d31182..cf8f91dba 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -1,20 +1,20 @@ <% puts case @lang when 'zh_CN' - wiki_url = 'https://zh.opensuse.org/' + @wiki_url = 'https://zh.opensuse.org/' when 'zh_TW' - wiki_url = 'https://zh-tw.opensuse.org/' + @wiki_url = 'https://zh-tw.opensuse.org/' when 'pt_BR' - wiki_url = 'https://pt.opensuse.org/' + @wiki_url = 'https://pt.opensuse.org/' else - wiki_url = "https://#{@lang}.opensuse.org/" + @wiki_url = "https://#{@lang}.opensuse.org/" end puts case @lang when 'zh_CN' - forum_url = 'https://forum.suse.org.cn/' + @forum_url = 'https://forum.suse.org.cn/' else - forum_url = 'https://forums.opensuse.org/' + @forum_url = 'https://forums.opensuse.org/' end %> diff --git a/app/views/search/_find_form.html.erb b/app/views/search/_find_form.html.erb index be8a6fa3a..523b83c72 100644 --- a/app/views/search/_find_form.html.erb +++ b/app/views/search/_find_form.html.erb @@ -13,17 +13,8 @@ <%= _("Settings") %> - - <%= render :partial => 'search/settings' %> - <% end -%> - +<%= render :partial => 'search/settings' %> diff --git a/app/views/search/_settings.html.erb b/app/views/search/_settings.html.erb index 16f496e96..9c9597de8 100644 --- a/app/views/search/_settings.html.erb +++ b/app/views/search/_settings.html.erb @@ -9,26 +9,41 @@ - diff --git a/public/search_software.xml b/public/search_software.xml index f9563707d..c37038c87 100644 --- a/public/search_software.xml +++ b/public/search_software.xml @@ -3,6 +3,6 @@ openSUSE Software Search openSUSE Software Search: Search packages to install on your openSUSE system https://software.opensuse.org/favicon.ico - + UTF-8 From a8d23d2095ce772ce3fdc0b6861369f3a59601f5 Mon Sep 17 00:00:00 2001 From: Guo Yunhe Date: Thu, 24 May 2018 09:28:53 +0300 Subject: [PATCH 08/16] Format code --- app/controllers/application_controller.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0706c0499..59b2666f2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -116,7 +116,7 @@ def set_releases_parameters end def set_baseproject - unless (@distributions.blank? || @distributions.select{|d| d[:project] == cookies[:baseproject]}.blank?) + unless (@distributions.blank? || @distributions.select { |d| d[:project] == cookies[:baseproject] }.blank?) @baseproject = cookies[:baseproject] end @baseproject = "openSUSE:Leap:#{@stable_version}" if @baseproject.blank? @@ -183,11 +183,11 @@ def valid_project_name? name def set_search_options @search_term = params[:q] || "" - if !cookies[:baseproject].nil? && @distributions.select{ |d| d[:project] == cookies[:baseproject] } - @baseproject = cookies[:baseproject] - else - @baseproject = "openSUSE:Factory" - end + @baseproject = if !cookies[:baseproject].nil? && @distributions.select { |d| d[:project] == cookies[:baseproject] } + cookies[:baseproject] + else + "openSUSE:Factory" + end @search_devel = (cookies[:search_devel] == "true" ? true : false) @search_lang = (cookies[:search_lang] == "true" ? true : false) @search_debug = (cookies[:search_debug] == "true" ? true : false) @@ -202,16 +202,14 @@ def filter_packages # only show packages @packages = @packages.reject { |p| p.first.type == 'ymp' } - unless @search_devel - @packages.reject! { |p| p.name.end_with?("-devel") } - end + @packages.reject! { |p| p.name.end_with?("-devel") } unless @search_devel unless @search_lang @packages.reject! { |p| p.name.end_with?("-lang") || p.name.include?("-translations-") || p.name.include?("-l10n-") } end unless @search_debug - @packages.reject! { |p| p.name.end_with?("-buildsymbols") || p.name.end_with?("-debuginfo") || p.name.end_with?("-debugsource") } + @packages.reject! { |p| p.name.end_with?("-buildsymbols", "-debuginfo", "-debugsource") } end # filter out ports for different arch From bec21fa07368153d1a6576cab372ba1a6aed2307 Mon Sep 17 00:00:00 2001 From: Guo Yunhe Date: Thu, 24 May 2018 09:47:28 +0300 Subject: [PATCH 09/16] Fix search tests --- app/views/search/_find_form.html.erb | 1 + test/system/search_results_test.rb | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/views/search/_find_form.html.erb b/app/views/search/_find_form.html.erb index 9e9c25f2b..30880da66 100644 --- a/app/views/search/_find_form.html.erb +++ b/app/views/search/_find_form.html.erb @@ -3,6 +3,7 @@ <%= form_tag( {:controller => 'search', :action => :index}, :method => :get ) do %>
<%= text_field_tag 'q', @search_term, :size => 30, :id => "search-form", :class => 'form-control mr-2', :placeholder => _('Search packages...'), :autocomplete => "off", :autofocus => true %> + - diff --git a/test/system/search_results_test.rb b/test/system/search_results_test.rb index 2622ceb2c..d4f04a452 100644 --- a/test/system/search_results_test.rb +++ b/test/system/search_results_test.rb @@ -4,26 +4,28 @@ class SearchResultsTest < ActionDispatch::SystemTestCase def test_default_searches stub_search_random('nvidia', 'openSUSE:Leap:42.3') visit '/' - page.fill_in 'q', with: 'nvidia' - page.find(:css, 'button#settings').click within '#search-settings' do find('option[value="openSUSE:Leap:42.3"]').click end page.click_on 'OK' + page.fill_in 'q', with: 'nvidia' + page.find(:css, 'button#search-button').click + page.assert_text 'for instructions how to configure your NVIDIA graphics card' end def test_non_existing_packages stub_search_random('paralapapiricoipi', 'openSUSE:Leap:42.3', matches: 0) visit '/' - page.fill_in 'q', with: 'paralapapiricoipi' - page.find(:css, 'button#settings').click within '#search-settings' do find('option[value="openSUSE:Leap:42.3"]').click end page.click_on 'OK' + page.fill_in 'q', with: 'paralapapiricoipi' + page.find(:css, 'button#search-button').click + page.assert_text 'No packages found matching your search.' end end From 233218a1f8c7578e504a971e1a5aba3ef99d7f38 Mon Sep 17 00:00:00 2001 From: Guo Yunhe Date: Thu, 24 May 2018 18:45:47 +0300 Subject: [PATCH 11/16] Skip set_baseproject for thumbnail and screenshot --- app/controllers/package_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/package_controller.rb b/app/controllers/package_controller.rb index 6967775fa..48d0ebdec 100644 --- a/app/controllers/package_controller.rb +++ b/app/controllers/package_controller.rb @@ -3,7 +3,7 @@ class PackageController < ApplicationController before_action :set_search_options, :only => %i[show categories] before_action :prepare_appdata, :set_categories, :only => %i[show explore category thumbnail screenshot] - skip_before_action :set_language, :set_distributions, :only => %i[thumbnail screenshot] + skip_before_action :set_language, :set_distributions, :set_baseproject, :only => %i[thumbnail screenshot] def show required_parameters :package From fbe09da1483755bf48b487de265af239b5620f08 Mon Sep 17 00:00:00 2001 From: Guo Yunhe Date: Thu, 24 May 2018 18:50:29 +0300 Subject: [PATCH 12/16] Remove console output --- app/views/layouts/_navbar.html.erb | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index cf8f91dba..2c1285d65 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -1,21 +1,21 @@ <% -puts case @lang -when 'zh_CN' - @wiki_url = 'https://zh.opensuse.org/' -when 'zh_TW' - @wiki_url = 'https://zh-tw.opensuse.org/' -when 'pt_BR' - @wiki_url = 'https://pt.opensuse.org/' -else - @wiki_url = "https://#{@lang}.opensuse.org/" -end +@wiki_url = case @lang + when 'zh_CN' + 'https://zh.opensuse.org/' + when 'zh_TW' + 'https://zh-tw.opensuse.org/' + when 'pt_BR' + 'https://pt.opensuse.org/' + else + "https://#{@lang}.opensuse.org/" + end -puts case @lang -when 'zh_CN' - @forum_url = 'https://forum.suse.org.cn/' -else - @forum_url = 'https://forums.opensuse.org/' -end +@forum_url = case @lang + when 'zh_CN' + @forum_url = 'https://forum.suse.org.cn/' + else + @forum_url = 'https://forums.opensuse.org/' + end %>