Skip to content

Commit

Permalink
Search result list ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Guo Yunhe committed Jul 1, 2017
1 parent 2923528 commit bd3d410
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 88 deletions.
98 changes: 63 additions & 35 deletions app/views/package/_download_rows.html.erb
Original file line number Diff line number Diff line change
@@ -1,40 +1,68 @@
<% packages.flatten.sort_by(&:project).group_by(&:project).each do |result| %>
<li>
<% if result.first == distro[:project] || result.first == "#{distro[:project]}:NonFree"
name = _("<b>official release</b>")
elsif result.first == "#{distro[:project]}:Update"
name = _("<b>official update</b>")
else
name = shorten result.first, 22
end
<% if result.first == distro[:project] || result.first == "#{distro[:project]}:NonFree"
name = _("<b>official release</b>")
elsif result.first == "#{distro[:project]}:Update"
name = _("<b>official update</b>")
else
name = shorten result.first, 40
end

if result.last.first.package.nil?
pkg_link = "https://build.opensuse.org/project/show/#{CGI.escape result.first}"
else
pkg_link = "https://build.opensuse.org/package/show/#{CGI.escape result.first}/#{CGI.escape result.last.first.package}"
end -%>
<%= link_to name, pkg_link %>
if result.last.first.package.nil?
pkg_link = "https://build.opensuse.org/project/show/#{CGI.escape result.first}"
else
pkg_link = "https://build.opensuse.org/package/show/#{CGI.escape result.first}/#{CGI.escape result.last.first.package}"
end -%>

<div class="card mb-2">
<div class="card-block row">

<div class="col-md-6">
<%= link_to name, pkg_link %>
<% if type.eql? 'official' %>
<span class="badge badge-success"><%= _('Official') %></span>
<% end %>
<% if type.eql? 'experimental' %>
<span class="badge badge-warning"><%= _('Experimental') %></span>
<% end %>
<% if type.eql? 'community' %>
<span class="badge badge-danger"><%= _('Community') %></span>
<% end %>
</div><!-- /.col- -->

<div class="col-md-2">
<%# only use the latest version, obs bug: some outdated versions still listed. %>
<% version = result.last.map{|r| r.version }.max %>
<%= shorten version, 23 %>
</div><!-- /.col- -->

<div class="col-md-4 text-right">
<% release = result.last.select{|r| r.version == version }.map{|v| "#{v.release}".sub(".", "").to_i}.max %>
<% items = result.last.select{|r| r.version == version && "#{r.release}".sub(".", "").to_i == release } %>
<% archs = items.map{|item| human_arch( item.arch ) }.uniq.sort %>
<% archs << _("Source") if archs.delete(_("Source")) %>

<%# only use the latest version, obs bug: some outdated versions still listed. %>
<% version = result.last.map{|r| r.version }.max %>
<!-- 1-click install button -->
<% if oneclick && distro[:project].match(/SUSE/) && !(archs.uniq == [_("Source")]) %>
<% url = url_for :controller => 'download', :action => 'ymp_without_arch_and_version',
:project => result.first, :repository => result.last.first.repository, :package => @pkgname,
:base => result.last.first.baseproject, :query => @pkgname%>
<a class="btn btn-sm btn-primary" href="<%= url %>"><span class="typcn typcn-flash-outline"></span> <%= _("1 Click Install") %></a>
<% end %>

<% release = result.last.select{|r| r.version == version }.map{|v| "#{v.release}".sub(".", "").to_i}.max %>
<ul class="pkg-typ-options">
<li><%= shorten version, 23 %></li>
<% items = result.last.select{|r| r.version == version && "#{r.release}".sub(".", "").to_i == release } %>
<% archs = items.map{|item| human_arch( item.arch ) }.uniq.sort %>
<% archs << _("Source") if archs.delete(_("Source")) %>
<% archs.each do |arch| %>
<% items.select{|item| human_arch( item.arch ) == arch}.each do |bin| %>
<li><%= link_to human_arch( bin.arch ), "http://download.opensuse.org/repositories/" + bin.filepath %> </li>
<% end -%>
<% end -%>
</ul>
<% if oneclick && distro[:project].match(/SUSE/) && !(archs.uniq == [_("Source")]) %>
<% url = url_for :controller => 'download', :action => 'ymp_without_arch_and_version',
:project => result.first, :repository => result.last.first.repository, :package => @pkgname,
:base => result.last.first.baseproject, :query => @pkgname%>
<a class="pkg-options-one-click" href="<%= url %>">1 Click Install</a>
<% end %>
</li>
<div class="btn-group">
<button class="btn btn-sm btn-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="typcn typcn-download-outline"></span> Download
</button>
<div class="dropdown-menu dropdown-menu-right">
<% archs.each do |arch| %>
<% items.select{|item| human_arch( item.arch ) == arch}.each do |bin| %>
<%= link_to _(human_arch( bin.arch )), "http://download.opensuse.org/repositories/" + bin.filepath, :class => 'dropdown-item' %>
<% end -%>
<% end -%>
</div>
</div>

</div><!-- /.col- -->
</div><!-- /.card-block -->
</div><!-- /.card -->
<% end -%>
94 changes: 41 additions & 53 deletions app/views/package/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,68 +54,56 @@
</div><!-- /.container -->
</header>

<div id="pkg-options">
<ul>
<% @distributions.each do |distro| -%>
<% if (pkgs = @packages.select{|s| s.baseproject == distro[:project]}).size > 0
%>

<li>
<a href="#" onclick=" toggle_dist('<%= distro[:dist_id] %>'); return false;"
class="distro-toggle" id="distro-toggle-<%= distro[:dist_id] %>"><b><%= distro[:name] %></b></a>
<ul class="pkg-options-details " id="dist_<%= distro[:dist_id] %>" >
<div class="container">
<h3 class="mt-5 mb-4"><%= _("Distributions") %></h3>

<%
official, pkgs = pkgs.partition{|s| s.project == distro[:project] || s.project == "#{distro[:project]}:NonFree" }
update, pkgs = pkgs.partition{|s| s.project == "#{distro[:project]}:Update"}
stable, pkgs = pkgs.partition{|s| s.quality == "Stable"} %>
<% @distributions.each do |distro| -%>
<% if (pkgs = @packages.select{|s| s.baseproject == distro[:project]}).size > 0 %>

<%= render( :partial => 'package/download_rows', :locals => {:packages => official, :distro => distro, :oneclick => true} ) if update.blank? %>
<%= render :partial => 'package/download_rows', :locals => {:packages => update, :distro => distro, :oneclick => true} %>
<%= render :partial => 'package/download_rows', :locals => {:packages => stable, :distro => distro, :oneclick => true} %>
<h4 class="mt-4 mb-3"><%= distro[:name] %></h4>

<%
home, pkgs = pkgs.partition{|s| s.project.match( /^home\:/ )}
devel = pkgs.reject{|s| @official_projects.include?( s.project ) || s.project.match( /^home\:/ ) || s.project.match( /#{distro[:project]}\:Update/ ) ||
s.project.match( /#{distro[:project]}\:NonFree/ ) || s.project.match( /openSUSE\:Maintenance\:/ ) } %>
<!-- official packages -->
<%
official, pkgs = pkgs.partition{|s| s.project == distro[:project] || s.project == "#{distro[:project]}:NonFree" }
update, pkgs = pkgs.partition{|s| s.project == "#{distro[:project]}:Update"}
stable, pkgs = pkgs.partition{|s| s.quality == "Stable"} %>
<% unless home.blank? && devel.blank? %>
<li id="unsupported_link_<%= distro[:dist_id] %>" class="show-unstable-packages hidden">
<a class="trigger-show-more" href="#" onclick="toggle_unsupported('<%= distro[:dist_id] %>'); return false;"><%= _("Show unstable packages") %></a></li>
<% end -%>
</ul>
<ul class="pkg-options-details pkg-options-unsupported" id="dist_home_<%= distro[:dist_id] %>" >
<%= render :partial => 'package/download_rows', :locals => {:packages => devel, :distro => distro, :oneclick => true} %>
<%= render :partial => 'package/download_rows', :locals => {:packages => home, :distro => distro, :oneclick => true} %>
</ul>
<%= render( :partial => 'package/download_rows', :locals => {:packages => official, :distro => distro, :oneclick => true, :type => 'official'} ) if update.blank? %>
<%= render :partial => 'package/download_rows', :locals => {:packages => update, :distro => distro, :oneclick => true, :type => 'official'} %>
<%= render :partial => 'package/download_rows', :locals => {:packages => stable, :distro => distro, :oneclick => true, :type => 'official'} %>
</li>
<% end -%>
<% end -%>
<%
home, pkgs = pkgs.partition{|s| s.project.match( /^home\:/ )}
devel = pkgs.reject{|s| @official_projects.include?( s.project ) || s.project.match( /^home\:/ ) || s.project.match( /#{distro[:project]}\:Update/ ) ||
s.project.match( /#{distro[:project]}\:NonFree/ ) || s.project.match( /openSUSE\:Maintenance\:/ ) } %>

<% unless @extra_dists.blank? %>
<!-- experimental packages -->
<%= render :partial => 'package/download_rows', :locals => {:packages => devel, :distro => distro, :oneclick => true, :type => 'experimental' } %>

<!-- community packages -->
<%= render :partial => 'package/download_rows', :locals => {:packages => home, :distro => distro, :oneclick => true, :type => 'community'} %>
<% end -%>
<% end -%>
<div id="unsupported-title"><h3><%= _("Unsupported distributions:") %></h3></div>
<% @extra_dists.each do |distro| -%>
<li class="extra-dists">
<a href="#" onclick=" toggle_dist('<%= escape_for_id distro[:project] %>'); return false;"
class="distro-toggle" id="distro-toggle-<%= escape_for_id distro[:project] %>"><b><%= distro[:project].gsub(":", " ").sub("DISCONTINUED", "") %></b></a>
<% pks = @extra_packages.select{|p| p.baseproject == distro[:project] } %>
<ul class="pkg-options-details pkg-options-unsupported" id="dist_<%= escape_for_id distro[:project] %>" >
<%= render :partial => 'download_rows', :locals => {:packages => pks, :distro => distro, :oneclick => false} %>
</ul>
</li>
<% end %>
<% end %>
<% unless @extra_dists.blank? %>

<%= image_tag "expand_all.png", :style => "float: right; ", :class => "hidden", :title => _("Expand all sections ('e')"), :id => "expand-all" %>
<a id="show-extra-dists" class="hidden" href="#"><%= _("Show more packages for unsupported distributions") %></a>
<h3 class="mt-5 mb-4"><%= _("Unsupported distributions") %></h3>

</ul>
</div>
<div class="alert alert-danger">
<%= _("The following distributions are not officially supported. Use these packages at your own risk.") %>
<button type="button" class="btn btn-danger" data-toggle="collapse" data-target="#unsupported-distributions"><%= _("Show") %></button>
</div>

<div id="unsupported-distributions" class="collapse">
<% @extra_dists.each do |distro| -%>
<h4 class="mt-4 mb-3"><%= distro[:project] %></h4>
<% pks = @extra_packages.select{|p| p.baseproject == distro[:project] } %>
<%= render :partial => 'download_rows', :locals => {:packages => pks, :distro => distro, :oneclick => false, :type => 'unsupported'} %>
<% end %>
</div>
<% end %>

</div><!-- /.container -->

<% end -%>
</div>
</div>
</div>
<% end -%>

0 comments on commit bd3d410

Please sign in to comment.