Merge pull request #8076 from andrej-scinote/aj_SCI_11222

Add job title to reports [SCI-11222]
This commit is contained in:
andrej-scinote 2024-11-29 12:01:20 +01:00 committed by GitHub
commit 3b6b1a9bc9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 48 additions and 5 deletions

View file

@ -1424,6 +1424,18 @@ function reportHandsonTableConverter() {
});
}
function setJobTitles(selectedClass) {
if (!selectedClass) return;
const targetElement = $(`[data-job-title-element-target="${selectedClass}"]`);
const jobTitles = dropdownSelector.getData(targetElement)
.map((item) => item.params.job_title)
.filter(Boolean)
.join(', ');
$(`#${selectedClass}`).val(jobTitles);
}
function loadDocxTemplate() {
const template = dropdownSelector.getValues('#docxTemplateSelector');
let params = {
@ -1448,7 +1460,14 @@ function reportHandsonTableConverter() {
$('.report-template-value-dropdown').each(function() {
dropdownSelector.init($(this), {
noEmptyOption: true
noEmptyOption: true,
optionClass: $(this).data('job-title-element-target'),
onSelect: function() {
setJobTitles(this.optionClass);
},
onUnSelect: function() {
setJobTitles(this.optionClass);
}
});
});
});

View file

@ -1,7 +1,14 @@
<% if @editing %>
<div class="sci-select-container">
<%= label_tag @name, @label %>
<%= select_tag @name, options_from_collection_for_select(@project_members, :id, :name, @value), placeholder: @placeholder, class: 'sci-input-field report-template-value-dropdown', data: { type: 'ProjectMembersInputComponent' }, multiple: true %>
<%= select_tag @name,
options_for_select(@project_members.map do |member|
[member.name, member.id, { data: { params: { job_title: member.job_title } } }]
end,
@value),
placeholder: @placeholder,
class: 'sci-input-field report-template-value-dropdown',
data: { type: 'ProjectMembersInputComponent', job_title_element_target: @job_title_element_target }, multiple: true %>
</div>
<% else %>
<% @project_members.where(id: @value).each do |member| %>

View file

@ -2,10 +2,11 @@
module Reports
class ProjectMembersInputComponent < TemplateValueComponent
def initialize(report:, name:, label:, placeholder: nil, editing: true, displayed_field: :full_name)
def initialize(report:, name:, label:, placeholder: nil, editing: true, displayed_field: :full_name, job_title_element_target: nil)
super(report: report, name: name, label: label, placeholder: placeholder, editing: editing)
@project_members = report.project&.users
@displayed_field = displayed_field
@job_title_element_target = job_title_element_target
end
end
end

View file

@ -262,7 +262,8 @@ class Users::RegistrationsController < Devise::RegistrationsController
:current_password,
:change_password,
:change_avatar,
:external_id
:external_id,
:job_title
)
end

View file

@ -29,8 +29,9 @@ class User < ApplicationRecord
validate :time_zone_check
validates :external_id, length: { maximum: Constants::EMAIL_MAX_LENGTH }
validates :job_title, length: { maximum: Constants::NAME_MAX_LENGTH }
store_accessor :settings, :time_zone, :notifications_settings, :external_id
store_accessor :settings, :time_zone, :notifications_settings, :external_id, :job_title
DEFAULT_SETTINGS = {
time_zone: 'UTC',

View file

@ -26,6 +26,7 @@
<%= render partial: 'users/registrations/edit_partials/full_name' %>
<%= render partial: 'users/registrations/edit_partials/initials' %>
<%= render partial: 'users/registrations/edit_partials/external_id' %>
<%= render partial: 'users/registrations/edit_partials/job_title' %>
</div>
<div class="col-md-6">
<%= render partial: 'users/registrations/edit_partials/email' %>

View file

@ -0,0 +1,12 @@
<span class="settings-job-title user-settings-block">
<h3><%= t("users.registrations.edit.job_title_label") %></h3>
<%= render partial: "shared/inline_editing",
locals: {
initial_value: @user.job_title,
config: {
params_group: 'user',
field_to_udpate: 'job_title',
path_to_update: registration_path(resource_name, format: :json)
}
} %>
</span>

View file

@ -3080,6 +3080,7 @@ en:
new_email_label: "New email"
external_id_label: 'External ID'
external_id_title: 'External Id'
job_title_label: 'Job title'
current_password_label: "Current password"
password_explanation: "(we need your current password to confirm your changes)"
waiting_for_confirm: "Currently waiting confirmation for: %{email}"