From f91efc95a19798a04a6d0a573fdc7f01438430f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saray=20Cabrera=20Padr=C3=B3n?= Date: Fri, 14 Dec 2018 12:15:22 +0100 Subject: [PATCH] Migrate project index page to bootstrap The content of the public projects' table is added by javascript. We keep it like it was with small changes only: the table itself is written by the view not by JS, we add "Search" placeholder and remove some unnecessary params. Co-authored-by: David Kang --- .../assets/javascripts/webui2/application.js | 1 + .../app/assets/javascripts/webui2/project.js | 29 +++++++++++ .../controllers/webui/project_controller.rb | 1 + .../app/views/layouts/webui2/webui.html.haml | 1 + .../views/webui2/webui/project/list.html.haml | 52 +++++++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 src/api/app/assets/javascripts/webui2/project.js create mode 100644 src/api/app/views/webui2/webui/project/list.html.haml diff --git a/src/api/app/assets/javascripts/webui2/application.js b/src/api/app/assets/javascripts/webui2/application.js index c800c8c3de6..d50413666ef 100644 --- a/src/api/app/assets/javascripts/webui2/application.js +++ b/src/api/app/assets/javascripts/webui2/application.js @@ -42,5 +42,6 @@ //= require webui2/cm2/use-codemirror.js //= require webui2/package-view_file.js //= require webui2/staging_workflow.js +//= require webui2/project.js //= require webui2/project_monitor.js //= require rails-timeago diff --git a/src/api/app/assets/javascripts/webui2/project.js b/src/api/app/assets/javascripts/webui2/project.js new file mode 100644 index 00000000000..a35d22c6e96 --- /dev/null +++ b/src/api/app/assets/javascripts/webui2/project.js @@ -0,0 +1,29 @@ +function renderProjectsTable(length) { // jshint ignore:line + length = length || 25; + var projects = mainProjects; + if (!$('#excludefilter').is(":checked")) + projects = projects.concat(exclProjects); + var projecturl = $("#projects-table-wrapper").data("url"); + $("#projects-table").DataTable({ + "data": projects, + "columns": [ + { + "title": "Name", + "width": "60%", + "className": "text-word-break-all", + "render": function (obj, type, dataRow) { + var url = projecturl.replace(/REPLACEIT/, dataRow[0]); + return '' + dataRow[0] + ''; + } + }, + { + "title": "Title", + "width": "40%", + "className": "text-nowrap" + } + ], + "pageLength": length, + "stateSave": true, + "language": { "search": '', "searchPlaceholder": "Search..." } + }); +} diff --git a/src/api/app/controllers/webui/project_controller.rb b/src/api/app/controllers/webui/project_controller.rb index 9d719c9f57c..fe9ea059d36 100644 --- a/src/api/app/controllers/webui/project_controller.rb +++ b/src/api/app/controllers/webui/project_controller.rb @@ -51,6 +51,7 @@ def index if @spider_bot render :list_simple, status: params[:nextstatus] else + switch_to_webui2 render :list, status: params[:nextstatus] end end diff --git a/src/api/app/views/layouts/webui2/webui.html.haml b/src/api/app/views/layouts/webui2/webui.html.haml index 8225498b701..8f15ef001ab 100644 --- a/src/api/app/views/layouts/webui2/webui.html.haml +++ b/src/api/app/views/layouts/webui2/webui.html.haml @@ -17,6 +17,7 @@ %style{ type: 'text/css' } = yield :head_style = javascript_tag do + = yield :head_javascript var _paq = _paq || []; $(function() { #{yield :ready_function} }); diff --git a/src/api/app/views/webui2/webui/project/list.html.haml b/src/api/app/views/webui2/webui/project/list.html.haml new file mode 100644 index 00000000000..7a3e4e83fac --- /dev/null +++ b/src/api/app/views/webui2/webui/project/list.html.haml @@ -0,0 +1,52 @@ +:ruby + @pagetitle = 'Public Projects' +.card + - if @important_projects.present? + .card-body + %h3 Main Projects + .table-responsive + %table.table.table-sm.table-striped.table-bordered + %thead + %tr + %th Name + %th Title + %tbody + - @important_projects.each do |project| + %tr + %td + = link_to(project.first, action: :show, project: project.first) + %td + #{project.second} + .card-body + %h3= @pagetitle + %ul.list-inline + - if @show_all + %li.list-inline-item.mr-3 + = link_to(projects_path) do + %i.fas.fa-toggle-on.text-primary + Exclude #{::Configuration.unlisted_projects_filter_description} + - else + %li.list-inline-item.mr-3 + = link_to(projects_path(show_all: true)) do + %i.fas.fa-toggle-off.text-primary + Include #{::Configuration.unlisted_projects_filter_description} + - unless User.current.is_nobody? + %li.list-inline-item + = link_to(new_project_path) do + %i.fas.fa-plus-circle.text-primary + Add New Project + - cachekey = Digest::MD5.hexdigest(@projects.join) + - projecturl = project_show_path('REPLACEIT') + #project-list + - if @projects.blank? + %p + %i No projects found + - else + #projects-table-wrapper{ 'data-url' => projecturl } + %table.responsive.table.table-sm.table-striped.table-bordered.w-100#projects-table + - content_for :head_javascript do + - cache ['list_public_arrays', cachekey] do + var mainProjects = [ #{escape_nested_list(@projects)} ]; + var exclProjects = []; + - content_for :ready_function do + renderProjectsTable();