mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-29 08:24:40 +08:00
changed logic
This commit is contained in:
parent
e381651df2
commit
3c588709be
3 changed files with 95 additions and 111 deletions
|
@ -71,11 +71,6 @@ class Project < ApplicationRecord
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
scope :not_assigned_to_user, lambda { |user|
|
|
||||||
left_joins(:user_assignments)
|
|
||||||
.where('user_assignments.user_id = ? AND user_assignments.id IS NULL', user.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
scope :templates, -> { where(template: true) }
|
scope :templates, -> { where(template: true) }
|
||||||
|
|
||||||
after_create :auto_assign_project_members, if: :visible?
|
after_create :auto_assign_project_members, if: :visible?
|
||||||
|
|
|
@ -17,6 +17,9 @@ module Toolbars
|
||||||
|
|
||||||
@single = @items.length == 1
|
@single = @items.length == 1
|
||||||
|
|
||||||
|
@team_owner = @current_user.current_team.user_assignments.find { |ua| ua.user == current_user }&.user_role.owner?
|
||||||
|
@unassigned_team_owner = @team_owner && !can_read_project?(@items.first)
|
||||||
|
|
||||||
@item_type = if project_ids.blank? && project_folder_ids.blank?
|
@item_type = if project_ids.blank? && project_folder_ids.blank?
|
||||||
:none
|
:none
|
||||||
elsif project_ids.present? && project_folder_ids.present?
|
elsif project_ids.present? && project_folder_ids.present?
|
||||||
|
@ -30,7 +33,7 @@ module Toolbars
|
||||||
|
|
||||||
def actions
|
def actions
|
||||||
return [] if @item_type == :none
|
return [] if @item_type == :none
|
||||||
return [access_action] if @not_assigned
|
return [access_action] if @unassigned_team_owner
|
||||||
|
|
||||||
[
|
[
|
||||||
restore_action,
|
restore_action,
|
||||||
|
@ -86,7 +89,7 @@ module Toolbars
|
||||||
|
|
||||||
project = @items.first
|
project = @items.first
|
||||||
|
|
||||||
return unless can_read_project?(project)
|
return unless @team_owner || can_read_project?(project)
|
||||||
|
|
||||||
path = if can_manage_project_users?(project)
|
path = if can_manage_project_users?(project)
|
||||||
edit_access_permissions_project_path(project)
|
edit_access_permissions_project_path(project)
|
||||||
|
|
|
@ -3,112 +3,98 @@
|
||||||
<% project_form = f %>
|
<% project_form = f %>
|
||||||
<%= f.hidden_field :archived, value: !project.archived %>
|
<%= f.hidden_field :archived, value: !project.archived %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% assigned = project.assigned_users.include?(current_user) %>
|
|
||||||
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="projectActionsDropdown">
|
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="projectActionsDropdown">
|
||||||
<% if assigned %>
|
<!-- Restore project -->
|
||||||
|
<% if project.archived? && can_restore_project?(project) %>
|
||||||
<!-- Restore project -->
|
|
||||||
<% if project.archived? && can_restore_project?(project) %>
|
|
||||||
<li class="form-dropdown-item">
|
|
||||||
<%= link_to(project_path(project, format: :json) + '?project[archived]=false',
|
|
||||||
method: :put,
|
|
||||||
remote: true,
|
|
||||||
class: 'project-archive-restore-form') do %>
|
|
||||||
<i class="sn-icon sn-icon-restore"></i>
|
|
||||||
<span><%= t('projects.index.restore_option') %></span>
|
|
||||||
<% end %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<!-- Edit project -->
|
|
||||||
<% if project.active? && can_manage_project?(project) %>
|
|
||||||
<li>
|
|
||||||
<a href="<%= edit_project_path(project, format: :json) %>"
|
|
||||||
class="edit-project-btn"
|
|
||||||
data-action="edit"
|
|
||||||
data-remote="true">
|
|
||||||
<i class="sn-icon sn-icon-edit"></i>
|
|
||||||
<span><%= t('projects.index.edit_option') %></span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<!-- Project members access -->
|
|
||||||
<li class="form-dropdown-item">
|
<li class="form-dropdown-item">
|
||||||
<%= link_to can_manage_project_users?(project) ? edit_access_permissions_project_path(project) : access_permissions_project_path(project),
|
<%= link_to(project_path(project, format: :json) + '?project[archived]=false',
|
||||||
data: { action: 'remote-modal'} do %>
|
method: :put,
|
||||||
<i class="sn-icon sn-icon-project-member-access"></i>
|
remote: true,
|
||||||
<%= I18n.t('projects.index.project_members_access') %>
|
class: 'project-archive-restore-form') do %>
|
||||||
<% end %>
|
<i class="sn-icon sn-icon-restore"></i>
|
||||||
</li>
|
<span><%= t('projects.index.restore_option') %></span>
|
||||||
|
<% end %>
|
||||||
<!-- Move project -->
|
|
||||||
<% if can_manage_team?(project.team) %>
|
|
||||||
<li class="form-dropdown-item">
|
|
||||||
<a href="#" data-project-id="<%= project.id %>" data-url="/project_folders/move_to_modal" class="move-projects-btn">
|
|
||||||
<i class="sn-icon sn-icon-move"></i>
|
|
||||||
<%= I18n.t('projects.index.move_button') %>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<!-- Export project -->
|
|
||||||
<% if can_export_project?(project) %>
|
|
||||||
<li class="form-dropdown-item">
|
|
||||||
<a href="#" data-project-id="<%= project.id %>" data-url="<%= export_projects_modal_team_path(project.team) %>" class="export-projects-btn">
|
|
||||||
<i class="sn-icon sn-icon-export"></i>
|
|
||||||
<%= I18n.t('projects.export_projects.export_button') %>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<!-- Archive project -->
|
|
||||||
<% if project.active? && can_archive_project?(project) %>
|
|
||||||
<li class="form-dropdown-item">
|
|
||||||
<%= link_to(project_path(project, format: :json) + '?project[archived]=true',
|
|
||||||
method: :put,
|
|
||||||
remote: true,
|
|
||||||
class: 'project-archive-restore-form',
|
|
||||||
data: { confirm: t('projects.index.archive_confirm') }) do %>
|
|
||||||
<i class="sn-icon sn-icon-archive"></i>
|
|
||||||
<span><%= t('projects.index.archive_option') %></span>
|
|
||||||
<% end %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
<!-- Show comments -->
|
|
||||||
<li>
|
|
||||||
<a href="#"
|
|
||||||
class="open-comments-sidebar"
|
|
||||||
data-turbolinks="false"
|
|
||||||
data-object-type="Project"
|
|
||||||
data-object-id="<%= project.id %>">
|
|
||||||
<i class="sn-icon sn-icon-comments"></i>
|
|
||||||
<span id="comment-count-<%= project.id %>">
|
|
||||||
<% unseen_comment_count = project.comments.unseen_by(current_user).count %>
|
|
||||||
<% if unseen_comment_count.positive? %>
|
|
||||||
<%= t('projects.index.comments_option_with_unread', comments_count: unseen_comment_count) %>
|
|
||||||
<% else %>
|
|
||||||
<%= t('projects.index.comments_option') %>
|
|
||||||
<% end %>
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<!-- Open activities -->
|
|
||||||
<li>
|
|
||||||
<a href="/global_activities?<%= Activity.url_search_query({ subjects: { Project: [project] } }) %>">
|
|
||||||
<i class="sn-icon sn-icon-activities"></i>
|
|
||||||
<span><%= t('projects.index.activities_option') %></span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<% else %>
|
|
||||||
<!-- Project members access -->
|
|
||||||
<li class="form-dropdown-item">
|
|
||||||
<%= link_to can_manage_project_users?(project) ? edit_access_permissions_project_path(project) : access_permissions_project_path(project),
|
|
||||||
data: { action: 'remote-modal'} do %>
|
|
||||||
<i class="sn-icon sn-icon-project-member-access"></i>
|
|
||||||
<%= I18n.t('projects.index.project_members_access') %>
|
|
||||||
<% end %>
|
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<!-- Edit project -->
|
||||||
|
<% if project.active? && can_manage_project?(project) %>
|
||||||
|
<li>
|
||||||
|
<a href="<%= edit_project_path(project, format: :json) %>"
|
||||||
|
class="edit-project-btn"
|
||||||
|
data-action="edit"
|
||||||
|
data-remote="true">
|
||||||
|
<i class="sn-icon sn-icon-edit"></i>
|
||||||
|
<span><%= t('projects.index.edit_option') %></span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<!-- Project members access -->
|
||||||
|
<li class="form-dropdown-item">
|
||||||
|
<%= link_to can_manage_project_users?(project) ? edit_access_permissions_project_path(project) : access_permissions_project_path(project),
|
||||||
|
data: { action: 'remote-modal'} do %>
|
||||||
|
<i class="sn-icon sn-icon-project-member-access"></i>
|
||||||
|
<%= I18n.t('projects.index.project_members_access') %>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<!-- Move project -->
|
||||||
|
<% if can_manage_team?(project.team) %>
|
||||||
|
<li class="form-dropdown-item">
|
||||||
|
<a href="#" data-project-id="<%= project.id %>" data-url="/project_folders/move_to_modal" class="move-projects-btn">
|
||||||
|
<i class="sn-icon sn-icon-move"></i>
|
||||||
|
<%= I18n.t('projects.index.move_button') %>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<!-- Export project -->
|
||||||
|
<% if can_export_project?(project) %>
|
||||||
|
<li class="form-dropdown-item">
|
||||||
|
<a href="#" data-project-id="<%= project.id %>" data-url="<%= export_projects_modal_team_path(project.team) %>" class="export-projects-btn">
|
||||||
|
<i class="sn-icon sn-icon-export"></i>
|
||||||
|
<%= I18n.t('projects.export_projects.export_button') %>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<!-- Archive project -->
|
||||||
|
<% if project.active? && can_archive_project?(project) %>
|
||||||
|
<li class="form-dropdown-item">
|
||||||
|
<%= link_to(project_path(project, format: :json) + '?project[archived]=true',
|
||||||
|
method: :put,
|
||||||
|
remote: true,
|
||||||
|
class: 'project-archive-restore-form',
|
||||||
|
data: { confirm: t('projects.index.archive_confirm') }) do %>
|
||||||
|
<i class="sn-icon sn-icon-archive"></i>
|
||||||
|
<span><%= t('projects.index.archive_option') %></span>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
<!-- Show comments -->
|
||||||
|
<li>
|
||||||
|
<a href="#"
|
||||||
|
class="open-comments-sidebar"
|
||||||
|
data-turbolinks="false"
|
||||||
|
data-object-type="Project"
|
||||||
|
data-object-id="<%= project.id %>">
|
||||||
|
<i class="sn-icon sn-icon-comments"></i>
|
||||||
|
<span id="comment-count-<%= project.id %>">
|
||||||
|
<% unseen_comment_count = project.comments.unseen_by(current_user).count %>
|
||||||
|
<% if unseen_comment_count.positive? %>
|
||||||
|
<%= t('projects.index.comments_option_with_unread', comments_count: unseen_comment_count) %>
|
||||||
|
<% else %>
|
||||||
|
<%= t('projects.index.comments_option') %>
|
||||||
|
<% end %>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<!-- Open activities -->
|
||||||
|
<li>
|
||||||
|
<a href="/global_activities?<%= Activity.url_search_query({ subjects: { Project: [project] } }) %>">
|
||||||
|
<i class="sn-icon sn-icon-activities"></i>
|
||||||
|
<span><%= t('projects.index.activities_option') %></span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Add table
Reference in a new issue