mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 14:45:56 +08:00
Merge branch 'develop' into features/september-release
This commit is contained in:
commit
160d9775d8
|
@ -65,13 +65,17 @@ class GlobalActivitiesController < ApplicationController
|
|||
end
|
||||
|
||||
def team_filter
|
||||
render json: current_user.teams.ordered.global_activity_filter(activity_filters, params[:query])
|
||||
teams = current_user.teams.ordered.global_activity_filter(activity_filters, params[:query])
|
||||
render json: teams.select(:id, :name)
|
||||
.map { |i| { value: i[:id], label: escape_input(i[:name]) } }
|
||||
end
|
||||
|
||||
def user_filter
|
||||
filter = activity_filters
|
||||
filter = { subjects: { MyModule: [params[:my_module_id].to_i] } } if params[:my_module_id]
|
||||
render json: current_user.global_activity_filter(filter, params[:query])
|
||||
users = current_user.global_activity_filter(filter, params[:query])
|
||||
render json: users.select(:full_name, :id)
|
||||
.map { |i| { label: escape_input(i[:full_name]), value: i[:id] } }
|
||||
end
|
||||
|
||||
def project_filter
|
||||
|
|
|
@ -39,18 +39,20 @@
|
|||
fileUrl: { type: String },
|
||||
fileName: { type: String },
|
||||
updateUrl: { type: String },
|
||||
canEditFile: { type: Boolean, default: false },
|
||||
oveEnabledDaysLeft: { type: Number }
|
||||
canEditFile: { type: String },
|
||||
oveEnabledDaysLeftString: { type: String }
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
editor: null,
|
||||
sequenceName: null,
|
||||
closeAfterSave: false,
|
||||
readOnly: !this.canEditFile
|
||||
readOnly: this.canEditFile !== 'true',
|
||||
oveEnabledDaysLeft: 0
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.oveEnabledDaysLeft = parseInt(this.oveEnabledDaysLeftString);
|
||||
let editorConfig = {
|
||||
onSave: this.saveFile,
|
||||
generatePng: true,
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module TeamBySubjectModel
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
def team_by_subject(subjects)
|
||||
teams = []
|
||||
valid_subjects = Extends::ACTIVITY_SUBJECT_CHILDREN
|
||||
# Check all activity subject
|
||||
valid_subjects.each do |subject, _children|
|
||||
subject = subject.to_s.camelize.to_sym
|
||||
next unless subjects[subject]
|
||||
|
||||
parent_array = [subject.to_s.underscore]
|
||||
find_parent = true
|
||||
# Trying to build parent array
|
||||
while find_parent
|
||||
possible_parent = valid_subjects.find { |_sub, ch| ((ch || []).include? parent_array[-1].pluralize.to_sym) }
|
||||
possible_parent = { Project: nil } if parent_array[-1] == 'experiment'
|
||||
if possible_parent
|
||||
parent_array.push(possible_parent.flatten[0].to_s.underscore)
|
||||
else
|
||||
find_parent = false
|
||||
end
|
||||
end
|
||||
# Remove initial object from parent array
|
||||
parent_array.shift
|
||||
subjects[subject].each do |child|
|
||||
child_subject = subject.to_s.constantize.find_by_id(child)
|
||||
next unless child_subject
|
||||
|
||||
# Call all parent subjects
|
||||
parent_array.each do |parent|
|
||||
temp_child_subject = child_subject.public_send(parent)
|
||||
# Some fix for protocols in repository
|
||||
break unless temp_child_subject
|
||||
|
||||
child_subject = temp_child_subject
|
||||
end
|
||||
teams.push(child_subject.team_id)
|
||||
end
|
||||
end
|
||||
teams.uniq
|
||||
end
|
||||
end
|
||||
end
|
|
@ -11,6 +11,7 @@ class RepositoryRow < ApplicationRecord
|
|||
include PrefixedIdModel
|
||||
|
||||
belongs_to :repository, class_name: 'RepositoryBase'
|
||||
delegate :team, to: :repository
|
||||
belongs_to :parent, class_name: 'RepositoryRow', optional: true
|
||||
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||
belongs_to :last_modified_by, foreign_key: :last_modified_by_id, class_name: 'User'
|
||||
|
|
|
@ -16,6 +16,7 @@ class Result < ApplicationRecord
|
|||
belongs_to :archived_by, class_name: 'User', optional: true
|
||||
belongs_to :restored_by, class_name: 'User', optional: true
|
||||
belongs_to :my_module, inverse_of: :results
|
||||
delegate :team, to: :my_module
|
||||
has_many :result_orderable_elements, inverse_of: :result, dependent: :destroy
|
||||
has_many :result_assets, inverse_of: :result, dependent: :destroy
|
||||
has_many :assets, through: :result_assets
|
||||
|
|
|
@ -32,6 +32,7 @@ class Step < ApplicationRecord
|
|||
belongs_to :user, inverse_of: :steps
|
||||
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User', optional: true
|
||||
belongs_to :protocol, inverse_of: :steps
|
||||
delegate :team, to: :protocol
|
||||
has_many :step_orderable_elements, inverse_of: :step, dependent: :destroy
|
||||
has_many :checklists, inverse_of: :step, dependent: :destroy
|
||||
has_many :step_comments, foreign_key: :associated_id, dependent: :destroy
|
||||
|
|
|
@ -5,7 +5,6 @@ class Team < ApplicationRecord
|
|||
include ViewableModel
|
||||
include Assignable
|
||||
include PermissionCheckableModel
|
||||
include TeamBySubjectModel
|
||||
include TinyMceImages
|
||||
|
||||
# Not really MVC-compliant, but we just use it for logger
|
||||
|
@ -169,14 +168,26 @@ class Team < ApplicationRecord
|
|||
ProtocolKeyword.where(team: self).pluck(:name)
|
||||
end
|
||||
|
||||
def self.by_activity_subjects(subjects)
|
||||
team_ids = []
|
||||
valid_subjects = subjects.select { |k| Extends::SEARCHABLE_ACTIVITY_SUBJECT_TYPES.include?(k.to_s) }
|
||||
valid_subjects.each do |subject_name, subject_id|
|
||||
subject = subject_name.to_s.constantize.find_by(id: subject_id)
|
||||
next if subject.blank?
|
||||
|
||||
team_ids << subject.team.id
|
||||
end
|
||||
where(id: team_ids.uniq)
|
||||
end
|
||||
|
||||
def self.global_activity_filter(filters, search_query)
|
||||
query = where('name ILIKE ?', "%#{search_query}%")
|
||||
query = where_attributes_like(:name, search_query)
|
||||
if filters[:users]
|
||||
user_teams = User.where(id: filters[:users]).joins(:teams).group(:team_id).select(:team_id)
|
||||
query = query.where(id: user_teams)
|
||||
end
|
||||
query = query.where(id: team_by_subject(filters[:subjects])) if filters[:subjects]
|
||||
query.select(:id, :name).map { |i| { value: i[:id], label: ApplicationController.helpers.escape_input(i[:name]) } }
|
||||
query = query.by_activity_subjects(filters[:subjects]) if filters[:subjects].present?
|
||||
query
|
||||
end
|
||||
|
||||
def self.search_by_object(obj)
|
||||
|
|
|
@ -4,7 +4,6 @@ class User < ApplicationRecord
|
|||
include SearchableModel
|
||||
include SettingsModel
|
||||
include VariablesModel
|
||||
include TeamBySubjectModel
|
||||
include InputSanitizeHelper
|
||||
include ActiveStorageConcerns
|
||||
|
||||
|
@ -581,13 +580,11 @@ class User < ApplicationRecord
|
|||
end
|
||||
|
||||
def global_activity_filter(filters, search_query)
|
||||
query_teams = teams.pluck(:id)
|
||||
query_teams &= filters[:teams].map(&:to_i) if filters[:teams]
|
||||
query_teams &= User.team_by_subject(filters[:subjects]) if filters[:subjects]
|
||||
query_teams = teams
|
||||
query_teams = query_teams.where(id: filters[:teams].map(&:to_i)) if filters[:teams].present?
|
||||
query_teams = query_teams.by_activity_subjects(filters[:subjects]) if filters[:subjects].present?
|
||||
User.where(id: UserAssignment.where(assignable_id: query_teams, assignable_type: 'Team').select(:user_id))
|
||||
.search(false, search_query)
|
||||
.select(:full_name, :id)
|
||||
.map { |i| { label: escape_input(i[:full_name]), value: i[:id] } }
|
||||
end
|
||||
|
||||
def file_name
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
file-url="<%= @file_url %>"
|
||||
file-name="<%= @file_name %>"
|
||||
update-url="<%= @asset ? gene_sequence_asset_url(@asset) : gene_sequence_assets_url(parent_type: params[:parent_type], parent_id: params[:parent_id]) %>"
|
||||
:can-edit-file="<%= asset_managable? %>"
|
||||
:ove-enabled-days-left="<%= OpenVectorEditorService.evaluation_period_left %>"
|
||||
can-edit-file="<%= asset_managable? %>"
|
||||
ove-enabled-days-left-string="<%= OpenVectorEditorService.evaluation_period_left %>"
|
||||
/>
|
||||
</div>
|
||||
<%= javascript_include_tag 'open_vector_editor' %>
|
||||
|
|
Loading…
Reference in a new issue