Add project and template selector [SCI-5570]

This commit is contained in:
aignatov-bio 2021-03-31 15:31:56 +02:00
parent c9688a58f7
commit 82be23db81
8 changed files with 95 additions and 25 deletions

View file

@ -1,4 +1,4 @@
/* globals animateSpinner GLOBAL_CONSTANTS */
/* globals animateSpinner GLOBAL_CONSTANTS dropdownSelector */
var REPORT_CONTENT = '#report-content';
var ADD_CONTENTS_FORM_ID = '#add-contents-form';
@ -990,5 +990,25 @@ function reportHandsonTableConverter() {
});
}
function initDropdowns() {
dropdownSelector.init('#projectSelector', {
singleSelect: true,
closeOnSelect: true,
selectAppearance: 'simple',
onChange: function() {
$('.continue-button').attr('disabled', false);
}
});
dropdownSelector.init('#templateSelector', {
singleSelect: true,
closeOnSelect: true,
noEmptyOption: true,
selectAppearance: 'simple',
disableSearch: true
});
}
initReportWizard();
initDropdowns();
}());

View file

@ -203,6 +203,34 @@
}
}
}
.project-selector-container {
background: $color-white;
box-shadow: $modal-shadow;
margin: 2em 20%;
padding: 1em 2em;
width: 60%;
.description {
@include font-main;
}
.project-selector,
.template-selector {
display: inline-block;
margin-bottom: 1em;
width: 100%;
label {
@include font-small;
}
}
#projectDescription {
height: 110px;
padding: .5em;
}
}
}
@media (max-width: 960px) {
@ -212,5 +240,10 @@
display: none;
}
}
.project-selector-container {
margin: 2em 1em;
width: calc(100% - 2em);
}
}
}

View file

@ -12,7 +12,7 @@
.input-field {
align-items: center;
background: $color-white;
border: 1px solid $color-alto;
border: 1px solid $color-silver-chalice;
border-radius: 4px;
display: flex;
flex-wrap: wrap;

View file

@ -25,7 +25,7 @@ class ReportsController < ApplicationController
before_action :load_vars, only: %i(edit update)
before_action :load_vars_nested, only: BEFORE_ACTION_METHODS
before_action :load_visible_projects, only: :visible_projects
before_action :load_visible_projects, only: :new
before_action :load_available_repositories,
only: %i(new edit available_repositories)
@ -49,6 +49,7 @@ class ReportsController < ApplicationController
# Report grouped by modules
def new
@templates = [['Scinote Template', 1]]
end
# Creating new report from the _save modal of the new page
@ -457,7 +458,6 @@ class ReportsController < ApplicationController
private
include StringUtility
VisibleProject = Struct.new(:path, :name)
AvailableRepository = Struct.new(:id, :name)
def load_vars
@ -477,13 +477,9 @@ class ReportsController < ApplicationController
def load_visible_projects
render_404 unless current_team
projects = Project.visible_from_user_by_name(
current_user, current_team, search_params[:q]
).limit(Constants::SEARCH_LIMIT).select(:id, :name)
@visible_projects = projects.collect do |project|
VisibleProject.new(new_project_reports_path(project),
ellipsize(project.name, 50, 40))
end
@visible_projects = Project.viewable_by_user(
current_user, current_team
).select(:id, :name)
end
def load_available_repositories

View file

@ -55,18 +55,6 @@ class Project < ApplicationRecord
scope :templates, -> { where(template: true) }
def self.visible_from_user_by_name(user, team, name)
projects = where(team: team).distinct
if user.is_admin_of_team?(team)
projects.where('projects.archived IS FALSE AND projects.name ILIKE ?', "%#{name}%")
else
projects.joins(:user_projects)
.where('user_projects.user_id = ? OR projects.visibility = 1', user.id)
.where('projects.archived IS FALSE AND projects.name ILIKE ?',
"%#{name}%")
end
end
def self.search(
user,
include_archived,

View file

@ -16,7 +16,7 @@
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="new-report-step-1">
Step 1
<%= render partial: 'reports/report_wizard/project_template_selector' %>
</div>
<div role="tabpanel" class="tab-pane" id="new-report-step-2">
Step 2
@ -50,7 +50,7 @@
<% end %>
</div>
<div class="next-button-container">
<button class="btn btn-primary continue-button">
<button class="btn btn-primary continue-button" disabled>
<%= t("projects.reports.new.continue_button") %>
</button>
<button class="btn btn-primary generate-button">

View file

@ -0,0 +1,26 @@
<div class="project-selector-container">
<h1><%= t('projects.reports.new.select_project_title') %></h1>
<p class="description">
<%= t('projects.reports.new.select_project_description') %>
</p>
<div class="row">
<div class="col-md-6">
<div class='project-selector'>
<%= label_tag :projectSelector, t('projects.reports.new.select_project') %>
<%= select_tag :projectSelector, options_from_collection_for_select(@visible_projects, :id, :name), data: { placeholder: t('projects.reports.new.select_project') } %>
</div>
<div class='template-selector'>
<%= label_tag :templateSelector, t('projects.reports.new.select_template') %>
<%= select_tag :templateSelector, options_for_select(@templates), data: { placeholder: t('projects.reports.new.select_template') } %>
</div>
</div>
<div class="col-md-6">
<div class="sci-input-container">
<%= label_tag :projectDescription, t('projects.reports.new.report_description') %>
<%= text_area_tag :projectDescription, '', placeholder: t('projects.reports.new.report_description_placeholder'), class: 'sci-input-field' %>
</div>
</div>
</div>
</div>

View file

@ -530,6 +530,13 @@ en:
step_3: "Select task contents"
continue_button: "Continue"
generate_button: "Start generating"
select_project_title: "Select project and report template"
select_project_description: "You are about to create a new report. Please select a project from which you would like to create a report, and a report template to define the desing of the report. Only projects with at least 1 task are displayed."
select_project: "Select project"
select_template: "Select template"
report_description: "Report description (optional)"
report_description_placeholder: "In this report you can see..."
head_title: "%{project} | New report"
nav_title: "Report for: "