mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-29 00:14:41 +08:00
Fix recent work service and move templates to html
This commit is contained in:
parent
180b736769
commit
c13721f842
4 changed files with 113 additions and 108 deletions
|
@ -4,11 +4,11 @@
|
||||||
var DasboardRecentWorkWidget = (function() {
|
var DasboardRecentWorkWidget = (function() {
|
||||||
function renderRecentWorkItem(data, container) {
|
function renderRecentWorkItem(data, container) {
|
||||||
$.each(data, (i, item) => {
|
$.each(data, (i, item) => {
|
||||||
var recentWorkItem = `<a href="${item.url}" class="recent-work-item">
|
var recentWorkItem = $($('#recent-work-item-template').html());
|
||||||
<div class="object-name">${item.name}</div>
|
recentWorkItem.attr('href', item.url);
|
||||||
<div class="object-type">${I18n.t('dashboard.recent_work.subject_type.' + item.subject_type)}</div>
|
recentWorkItem.find('.object-name').html(item.name);
|
||||||
<div class="object-changed">${item.last_change}</div>
|
recentWorkItem.find('.object-type').html(I18n.t('dashboard.recent_work.subject_type.' + item.subject_type));
|
||||||
</a>`;
|
recentWorkItem.find('.object-changed').html(item.last_change);
|
||||||
container.append(recentWorkItem);
|
container.append(recentWorkItem);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -22,13 +22,7 @@ var DasboardRecentWorkWidget = (function() {
|
||||||
if (result.length) {
|
if (result.length) {
|
||||||
renderRecentWorkItem(result, container);
|
renderRecentWorkItem(result, container);
|
||||||
} else {
|
} else {
|
||||||
container.append(`<div class="no-results">
|
container.append($('#recent-work-no-results-template').html());
|
||||||
<div class="no-results-title">${I18n.t('dashboard.recent_work.no_results.title')}</div>
|
|
||||||
<div class="no-results-description">${I18n.t('dashboard.recent_work.no_results.description')}</div>
|
|
||||||
<div class="no-results-arrow">
|
|
||||||
<i class="fas fa-angle-double-left"></i>
|
|
||||||
</div>
|
|
||||||
</div>`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PerfectSb().update_all();
|
PerfectSb().update_all();
|
||||||
|
|
|
@ -21,6 +21,30 @@ class Activity < ApplicationRecord
|
||||||
validates :subject_type, inclusion: { in: Extends::ACTIVITY_SUBJECT_TYPES,
|
validates :subject_type, inclusion: { in: Extends::ACTIVITY_SUBJECT_TYPES,
|
||||||
allow_blank: true }
|
allow_blank: true }
|
||||||
|
|
||||||
|
scope :subjects_joins, -> { joins("
|
||||||
|
LEFT JOIN results ON
|
||||||
|
subject_type = 'Result'
|
||||||
|
AND subject_id = results.id
|
||||||
|
LEFT JOIN protocols ON
|
||||||
|
subject_type = 'Protocol'
|
||||||
|
AND subject_id = protocols.id
|
||||||
|
LEFT JOIN my_modules ON
|
||||||
|
(subject_type = 'MyModule' AND subject_id = my_modules.id)
|
||||||
|
OR protocols.my_module_id = my_modules.id
|
||||||
|
OR results.my_module_id = my_modules.id
|
||||||
|
LEFT JOIN experiments ON
|
||||||
|
(subject_type = 'Experiment' AND subject_id = experiments.id)
|
||||||
|
OR experiments.id = my_modules.experiment_id
|
||||||
|
LEFT JOIN projects ON
|
||||||
|
(subject_type = 'Project' AND subject_id = projects.id)
|
||||||
|
OR projects.id = experiments.project_id
|
||||||
|
LEFT JOIN repositories ON
|
||||||
|
subject_type = 'Repository'
|
||||||
|
AND subject_id = repositories.id
|
||||||
|
LEFT JOIN reports ON subject_type = 'Report'
|
||||||
|
AND subject_id = reports.id
|
||||||
|
") }
|
||||||
|
|
||||||
store_accessor :values, :message_items, :breadcrumbs
|
store_accessor :values, :message_items, :breadcrumbs
|
||||||
|
|
||||||
default_values(
|
default_values(
|
||||||
|
|
|
@ -13,43 +13,25 @@ module Dashboard
|
||||||
|
|
||||||
def call
|
def call
|
||||||
visible_projects = Project.viewable_by_user(@user, @team)
|
visible_projects = Project.viewable_by_user(@user, @team)
|
||||||
visible_by_team = activities_with_filter.where(project: nil, team_id: @team.id)
|
|
||||||
visible_by_projects = activities_with_filter.where(project_id: visible_projects.pluck(:id))
|
|
||||||
query = Activity.from("((#{visible_by_team.to_sql}) UNION ALL (#{visible_by_projects.to_sql})) AS activities")
|
|
||||||
|
|
||||||
# Join subjects
|
activities = Activity.where("(values #>> '{message_items, user, id}') :: BIGINT = ?", @user.id)
|
||||||
query = query.joins("
|
.where('((project_id IS NULL AND team_id = ?) OR project_id IN (?))',
|
||||||
LEFT JOIN results ON
|
@team.id,
|
||||||
subject_type = 'Result'
|
visible_projects.pluck(:id))
|
||||||
AND subject_id = results.id
|
.select('MAX(created_at) AS last_change',
|
||||||
LEFT JOIN protocols ON
|
:subject_id,
|
||||||
subject_type = 'Protocol'
|
:subject_type)
|
||||||
AND subject_id = protocols.id
|
.group(:subject_id, :subject_type)
|
||||||
LEFT JOIN my_modules ON
|
.order(last_change: :desc)
|
||||||
(subject_type = 'MyModule' AND subject_id = my_modules.id)
|
|
||||||
OR protocols.my_module_id = my_modules.id
|
|
||||||
OR results.my_module_id = my_modules.id
|
|
||||||
LEFT JOIN experiments ON
|
|
||||||
(subject_type = 'Experiment' AND subject_id = experiments.id)
|
|
||||||
OR experiments.id = my_modules.experiment_id
|
|
||||||
LEFT JOIN projects ON
|
|
||||||
(subject_type = 'Project' AND subject_id = projects.id)
|
|
||||||
OR projects.id = experiments.project_id
|
|
||||||
LEFT JOIN repositories ON
|
|
||||||
subject_type = 'Repository'
|
|
||||||
AND subject_id = repositories.id
|
|
||||||
LEFT JOIN reports ON subject_type = 'Report'
|
|
||||||
AND subject_id = reports.id
|
|
||||||
")
|
|
||||||
.where("
|
|
||||||
(projects.archived != 'true' OR projects.archived IS NULL)
|
|
||||||
AND (experiments.archived != 'true' OR experiments.archived IS NULL)
|
|
||||||
AND (my_modules.archived != 'true' OR my_modules.archived IS NULL)
|
|
||||||
AND (protocols.protocol_type != 4 OR protocols.protocol_type IS NULL)
|
|
||||||
")
|
|
||||||
.select('
|
|
||||||
DISTINCT ON (group_id)
|
|
||||||
|
|
||||||
|
query = Activity.from("(#{activities.to_sql}) AS activities")
|
||||||
|
.subjects_joins
|
||||||
|
.where('projects.archived IS NOT TRUE')
|
||||||
|
.where('experiments.archived IS NOT TRUE')
|
||||||
|
.where('my_modules.archived IS NOT TRUE')
|
||||||
|
.where('protocols.protocol_type != ? OR protocols.protocol_type IS NULL',
|
||||||
|
Protocol.protocol_types[:in_repository_archived])
|
||||||
|
.select('
|
||||||
CASE
|
CASE
|
||||||
WHEN my_modules.id IS NOT NULL THEN
|
WHEN my_modules.id IS NOT NULL THEN
|
||||||
CONCAT(\'tsk\', my_modules.id)
|
CONCAT(\'tsk\', my_modules.id)
|
||||||
|
@ -63,100 +45,87 @@ module Dashboard
|
||||||
CONCAT(\'inv\', repositories.id)
|
CONCAT(\'inv\', repositories.id)
|
||||||
WHEN reports.id IS NOT NULL THEN
|
WHEN reports.id IS NOT NULL THEN
|
||||||
CONCAT(\'rpt\', reports.id)
|
CONCAT(\'rpt\', reports.id)
|
||||||
END as group_id,
|
END AS group_id,
|
||||||
|
|
||||||
CASE
|
COALESCE (
|
||||||
WHEN my_modules.name IS NOT NULL THEN
|
my_modules.name,
|
||||||
my_modules.name
|
experiments.name,
|
||||||
WHEN experiments.name IS NOT NULL THEN
|
projects.name,
|
||||||
experiments.name
|
protocols.name,
|
||||||
WHEN projects.name IS NOT NULL THEN
|
repositories.name,
|
||||||
projects.name
|
|
||||||
WHEN protocols.name IS NOT NULL THEN
|
|
||||||
protocols.name
|
|
||||||
WHEN repositories.name IS NOT NULL THEN
|
|
||||||
repositories.name
|
|
||||||
WHEN reports.name IS NOT NULL THEN
|
|
||||||
reports.name
|
reports.name
|
||||||
END as name,
|
) AS name,
|
||||||
|
|
||||||
reports.project_id as report_project_id,
|
reports.project_id AS report_project_id,
|
||||||
subject_id,
|
subject_id,
|
||||||
subject_type,
|
subject_type,
|
||||||
last_change
|
last_change
|
||||||
')
|
')
|
||||||
|
|
||||||
query_filter = []
|
ordered_query = Activity.from("(#{query.to_sql}) AS activities").where.not(group_id: nil)
|
||||||
if %w(all projects).include? @mode
|
.select(:group_id,
|
||||||
query_filter.push("group_id LIKE '%tsk%' OR group_id LIKE '%exp%' OR group_id LIKE '%pro%'")
|
:name,
|
||||||
end
|
'MAX(last_change) AS last_change',
|
||||||
|
'MAX(report_project_id) AS report_project_id')
|
||||||
|
.group(:group_id, :name)
|
||||||
|
.order('MAX(last_change) DESC').limit(Constants::SEARCH_LIMIT)
|
||||||
|
|
||||||
query_filter.push("group_id LIKE '%prt%'") if %w(all protocols).include? @mode
|
query_filter = "(group_id LIKE 'tsk%' OR group_id LIKE 'exp%' OR group_id LIKE 'pro%')" if @mode == 'projects'
|
||||||
|
query_filter = "group_id LIKE 'prt%'" if @mode == 'protocols'
|
||||||
|
query_filter = "group_id LIKE 'inv%'" if @mode == 'repositories'
|
||||||
|
query_filter = "group_id LIKE 'rpt%'" if @mode == 'reports'
|
||||||
|
ordered_query = ordered_query.where(query_filter) unless @mode == 'all'
|
||||||
|
|
||||||
query_filter.push("group_id LIKE '%inv%'") if %w(all repositories).include? @mode
|
recent_objects = ordered_query.as_json.map do |recent_object|
|
||||||
|
recent_object.deep_symbolize_keys!
|
||||||
|
recent_object.delete_if { |_k, v| v.nil? }
|
||||||
|
|
||||||
query_filter.push("group_id LIKE '%rpt%'") if %w(all reports).include? @mode
|
recent_object[:last_change] = I18n.l(
|
||||||
|
DateTime.parse(recent_object[:last_change]).in_time_zone(@user.settings[:time_zone] || 'UTC'),
|
||||||
ordered_query = Activity.from("(#{query.to_sql}) AS activities").where(query_filter.join(' OR '))
|
|
||||||
.order('last_change DESC').limit(Constants::SEARCH_LIMIT)
|
|
||||||
|
|
||||||
activities = ordered_query.as_json.map do |activity|
|
|
||||||
activity.deep_symbolize_keys!
|
|
||||||
activity.delete_if { |_k, v| v.nil? }
|
|
||||||
|
|
||||||
activity[:last_change] = I18n.l(
|
|
||||||
DateTime.parse(activity[:last_change]).in_time_zone(@user.settings[:time_zone] || 'UTC'),
|
|
||||||
format: :full_with_comma
|
format: :full_with_comma
|
||||||
)
|
)
|
||||||
activity[:subject_type] = override_subject_type(activity)
|
recent_object[:subject_type] = override_subject_type(recent_object)
|
||||||
activity[:name] = escape_input(activity[:name])
|
recent_object[:name] = escape_input(recent_object[:name])
|
||||||
activity[:url] = generate_url(activity)
|
recent_object[:url] = generate_url(recent_object)
|
||||||
activity
|
recent_object
|
||||||
end
|
end
|
||||||
|
|
||||||
activities
|
recent_objects
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def generate_url(activity)
|
def generate_url(recent_object)
|
||||||
case activity[:subject_type]
|
object_id = recent_object[:group_id].gsub(/[^0-9]/, '')
|
||||||
|
|
||||||
|
case recent_object[:subject_type]
|
||||||
when 'MyModule'
|
when 'MyModule'
|
||||||
protocols_my_module_path(activity[:subject_id])
|
protocols_my_module_path(object_id)
|
||||||
when 'Experiment'
|
when 'Experiment'
|
||||||
canvas_experiment_path(activity[:subject_id])
|
canvas_experiment_path(object_id)
|
||||||
when 'Project'
|
when 'Project'
|
||||||
project_path(activity[:subject_id])
|
project_path(object_id)
|
||||||
when 'Protocol'
|
when 'Protocol'
|
||||||
edit_protocol_path(activity[:subject_id])
|
edit_protocol_path(object_id)
|
||||||
when 'Repository'
|
when 'Repository'
|
||||||
repository_path(activity[:subject_id])
|
repository_path(object_id)
|
||||||
when 'Report'
|
when 'Report'
|
||||||
edit_project_report_path(activity[:report_project_id], activity[:subject_id]) if activity[:report_project_id]
|
edit_project_report_path(recent_object[:report_project_id], object_id) if recent_object[:report_project_id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def activities_with_filter
|
def override_subject_type(recent_object)
|
||||||
Activity.where("(values #>> '{message_items, user, id}') :: BIGINT = ?", @user.id)
|
if recent_object[:group_id].include?('pro')
|
||||||
.select('MAX(created_at) as last_change,
|
|
||||||
subject_id,
|
|
||||||
subject_type')
|
|
||||||
.group(:subject_id, :subject_type)
|
|
||||||
.order(last_change: :desc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def override_subject_type(activity)
|
|
||||||
if activity[:group_id].include?('pro')
|
|
||||||
'Project'
|
'Project'
|
||||||
elsif activity[:group_id].include?('exp')
|
elsif recent_object[:group_id].include?('exp')
|
||||||
'Experiment'
|
'Experiment'
|
||||||
elsif activity[:group_id].include?('tsk')
|
elsif recent_object[:group_id].include?('tsk')
|
||||||
'MyModule'
|
'MyModule'
|
||||||
elsif activity[:group_id].include?('prt')
|
elsif recent_object[:group_id].include?('prt')
|
||||||
'Protocol'
|
'Protocol'
|
||||||
elsif activity[:group_id].include?('inv')
|
elsif recent_object[:group_id].include?('inv')
|
||||||
'Repository'
|
'Repository'
|
||||||
elsif activity[:group_id].include?('rpt')
|
elsif recent_object[:group_id].include?('rpt')
|
||||||
'Report'
|
'Report'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,3 +15,21 @@
|
||||||
<div class="recent-work-container perfect-scrollbar" data-url="<%= dashboard_recent_works_path %>"></div>
|
<div class="recent-work-container perfect-scrollbar" data-url="<%= dashboard_recent_works_path %>"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<template id="recent-work-item-template">
|
||||||
|
<a href="" class="recent-work-item">
|
||||||
|
<div class="object-name"></div>
|
||||||
|
<div class="object-type"></div>
|
||||||
|
<div class="object-changed"></div>
|
||||||
|
</a>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template id="recent-work-no-results-template">
|
||||||
|
<div class="no-results">
|
||||||
|
<div class="no-results-title"><%= t('dashboard.recent_work.no_results.title') %></div>
|
||||||
|
<div class="no-results-description"><%= t('dashboard.recent_work.no_results.description') %></div>
|
||||||
|
<div class="no-results-arrow">
|
||||||
|
<i class="fas fa-angle-double-left"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
Loading…
Add table
Reference in a new issue