mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-03 19:24:48 +08:00
small refactor
This commit is contained in:
parent
f22f076e6c
commit
e9959747d6
8 changed files with 80 additions and 92 deletions
|
@ -291,45 +291,34 @@ function initTagsSelector() {
|
|||
}
|
||||
|
||||
function initAssignedUsersSelector() {
|
||||
var manageUsersModal = null;
|
||||
var manageUsersModalBody = null;
|
||||
var manageUsersModal = $('#manage-module-users-modal');
|
||||
var manageUsersModalBody = manageUsersModal.find('.modal-body');
|
||||
|
||||
// Initialize users editing modal remote loading
|
||||
function initUsersEditLink() {
|
||||
$('.task-details .manage-users-link').on('ajax:success', function(e, data) {
|
||||
$('.task-details').on('ajax:success', '.manage-users-link', function(e, data) {
|
||||
manageUsersModal.modal('show');
|
||||
manageUsersModal.find('#manage-module-users-modal-module').text(data.my_module.name);
|
||||
initUsersModalBody(data);
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize reloading manage user modal content after posting new user
|
||||
function initAddUserForm() {
|
||||
manageUsersModalBody.find('.add-user-form')
|
||||
.on('ajax:success', function(e, data) {
|
||||
initUsersModalBody(data);
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize remove user from my_module links
|
||||
function initRemoveUserLinks() {
|
||||
manageUsersModalBody.find('.remove-user-link')
|
||||
.on('ajax:success', function(e, data) {
|
||||
initUsersModalBody(data);
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize ajax listeners and elements style on modal body.
|
||||
// This function must be called when modal body is changed.
|
||||
function initUsersModalBody(data) {
|
||||
manageUsersModalBody.html(data.html);
|
||||
manageUsersModalBody.find('.selectpicker').selectpicker();
|
||||
initAddUserForm();
|
||||
initRemoveUserLinks();
|
||||
}
|
||||
|
||||
manageUsersModal = $('#manage-module-users-modal');
|
||||
manageUsersModalBody = manageUsersModal.find('.modal-body');
|
||||
// Initialize reloading manage user modal content after posting new user
|
||||
manageUsersModalBody.on('ajax:success', '.add-user-form', function(e, data) {
|
||||
initUsersModalBody(data);
|
||||
});
|
||||
|
||||
// Initialize remove user from my_module links
|
||||
manageUsersModalBody.on('ajax:success', '.remove-user-link', function(e, data) {
|
||||
initUsersModalBody(data);
|
||||
});
|
||||
|
||||
// Reload users HTML element when modal is closed
|
||||
manageUsersModal.on('hide.bs.modal', function() {
|
||||
|
@ -341,7 +330,6 @@ function initAssignedUsersSelector() {
|
|||
dataType: 'json',
|
||||
success: function(data) {
|
||||
$('.task-assigned-users').replaceWith(data.html);
|
||||
initUsersEditLink();
|
||||
},
|
||||
error: function() {
|
||||
// TODO
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
class UserMyModulesController < ApplicationController
|
||||
before_action :load_vars
|
||||
before_action :check_view_permissions, only: :index
|
||||
before_action :check_view_permissions, only: %i(index index_old)
|
||||
before_action :check_manage_permissions, only: %i(create index_edit destroy)
|
||||
|
||||
def index
|
||||
def index_old
|
||||
@user_my_modules = @my_module.user_my_modules
|
||||
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {
|
||||
html: render_to_string(
|
||||
partial: 'index.html.erb'
|
||||
partial: 'index_old.html.erb'
|
||||
),
|
||||
my_module_id: @my_module.id,
|
||||
counter: @my_module.users.count # Used for counter badge
|
||||
|
@ -19,12 +19,12 @@ class UserMyModulesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def index_compact
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {
|
||||
html: render_to_string(
|
||||
partial: 'index_compact.html.erb'
|
||||
partial: 'index.html.erb'
|
||||
)
|
||||
}
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
data-module-x="<%= my_module.x %>"
|
||||
data-module-y="<%= my_module.y %>"
|
||||
data-module-conns="<%= construct_module_connections(my_module) %>"
|
||||
data-module-users-tab-url="<%= my_module_user_my_modules_url(my_module_id: my_module.id, format: :json) %>"
|
||||
data-module-users-tab-url="<%= index_old_my_module_user_my_modules_url(my_module_id: my_module.id, format: :json) %>"
|
||||
data-module-tags-url="<%= my_module_tags_experiment_path(my_module.experiment, format: :json) %>">
|
||||
|
||||
<% if can_manage_module?(my_module) %>
|
||||
|
@ -47,7 +47,7 @@
|
|||
<ul class="nav nav-tabs nav-tabs-less" role="tablist">
|
||||
<% if can_read_experiment?(my_module.experiment) %>
|
||||
<li role="presentation">
|
||||
<a class="btn btn-link task-card-view-users" href="<%= my_module_user_my_modules_url(my_module_id: my_module.id, format: :json) %>" aria-controls="<%= my_module.id %>_users" role="tab" data-remote="true">
|
||||
<a class="btn btn-link task-card-view-users" href="<%= index_old_my_module_user_my_modules_url(my_module_id: my_module.id, format: :json) %>" aria-controls="<%= my_module.id %>_users" role="tab" data-remote="true">
|
||||
<span class="fas fa-users" aria-hidden="true"></span>
|
||||
<span class="badge badge-indicator users-badge-indicator <%= 'hidden' unless my_module.users.count.positive? %>"
|
||||
data-linked-id="<%= my_module.id %>">
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
<span class="fas block-icon fa-users"></span>
|
||||
<%= t('my_modules.details.assigned_users') %>
|
||||
</div>
|
||||
<%= render partial: "user_my_modules/index_compact" %>
|
||||
<%= render partial: "user_my_modules/index" %>
|
||||
</div>
|
||||
|
||||
<div class="module-tags">
|
||||
|
|
|
@ -1,34 +1,27 @@
|
|||
<h5 class="text-center"><%=t "experiments.canvas.popups.users_tab" %></h5>
|
||||
<hr>
|
||||
<ul class="no-style content-users">
|
||||
<% if @user_my_modules.size == 0 then %>
|
||||
<li><em><%= t "experiments.canvas.popups.no_users" %></em></li>
|
||||
<% else %>
|
||||
<% @user_my_modules.each_with_index do |user_my_module, i| %>
|
||||
<% user = user_my_module.user %>
|
||||
<li>
|
||||
<% if i > 0 %><hr><% end %>
|
||||
<div class="row">
|
||||
<div class="col-xs-2">
|
||||
<span class='global-avatar-container'>
|
||||
<%= image_tag avatar_path(user, :icon_small), class: "img-circle pull-left" %>
|
||||
</div>
|
||||
<div class="col-xs-10" style="line-height: 15px">
|
||||
<span><%= user.full_name %></span><br>
|
||||
<span class="text-muted" title="<%=t "experiments.canvas.popups.module_user_join_full", user: user.full_name, date: l(user_my_module.created_at, format: :full_date), time: l(user_my_module.created_at, format: :time) %>">
|
||||
<em>
|
||||
<%=t "experiments.canvas.popups.module_user_join", date: l(user_my_module.created_at, format: :full_date) %>
|
||||
</em>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% user_my_modules = @my_module.user_my_modules %>
|
||||
<% if can_manage_users_in_module?(@my_module) %>
|
||||
<p>
|
||||
<hr>
|
||||
<%= link_to t('experiments.canvas.popups.manage_users'), my_module_users_edit_path(@my_module, format: :json), remote: true, class: "manage-users-link" %>
|
||||
</p>
|
||||
<a class="task-assigned-users manage-users-link"
|
||||
data-remote="true"
|
||||
href="<%= my_module_users_edit_path(@my_module, format: :json) %>"
|
||||
data-module-id="<%= @my_module.id %>"
|
||||
data-module-users-url="<%= my_module_user_my_modules_url(@my_module, format: :json) %>">
|
||||
<% user_my_modules.each do |user_my_module| %>
|
||||
<% user = user_my_module.user %>
|
||||
<span class='global-avatar-container'>
|
||||
<%= image_tag avatar_path(user, :icon_small) %>
|
||||
</span>
|
||||
<% end %>
|
||||
<span class='global-avatar-container assign-new-user'>
|
||||
<i class="fas fa-plus"></i>
|
||||
</span>
|
||||
</a>
|
||||
<% else %>
|
||||
<div class="task-assigned-users">
|
||||
<% user_my_modules.each do |user_my_module| %>
|
||||
<% user = user_my_module.user %>
|
||||
<span class='global-avatar-container'>
|
||||
<%= image_tag avatar_path(user, :icon_small) %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
<% user_my_modules = @my_module.user_my_modules %>
|
||||
<% if can_manage_users_in_module?(@my_module) %>
|
||||
<a class="task-assigned-users manage-users-link"
|
||||
data-remote="true"
|
||||
href="<%= my_module_users_edit_path(@my_module, format: :json) %>"
|
||||
data-module-id="<%= @my_module.id %>"
|
||||
data-module-users-url="<%= index_compact_my_module_user_my_modules_url(@my_module, format: :json) %>">
|
||||
<% user_my_modules.each_with_index do |user_my_module, i| %>
|
||||
<% user = user_my_module.user %>
|
||||
<span class='global-avatar-container'>
|
||||
<%= image_tag avatar_path(user, :icon_small) %>
|
||||
</span>
|
||||
<% end %>
|
||||
<span class='global-avatar-container assign-new-user'>
|
||||
<i class="fas fa-plus"></i>
|
||||
</span>
|
||||
</a>
|
||||
<% else %>
|
||||
<div class="task-assigned-users">
|
||||
<% user_my_modules.each_with_index do |user_my_module, i| %>
|
||||
<% user = user_my_module.user %>
|
||||
<span class='global-avatar-container'>
|
||||
<%= image_tag avatar_path(user, :icon_small) %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
34
app/views/user_my_modules/_index_old.html.erb
Normal file
34
app/views/user_my_modules/_index_old.html.erb
Normal file
|
@ -0,0 +1,34 @@
|
|||
<h5 class="text-center"><%=t "experiments.canvas.popups.users_tab" %></h5>
|
||||
<hr>
|
||||
<ul class="no-style content-users">
|
||||
<% if @user_my_modules.size == 0 then %>
|
||||
<li><em><%= t "experiments.canvas.popups.no_users" %></em></li>
|
||||
<% else %>
|
||||
<% @user_my_modules.each_with_index do |user_my_module, i| %>
|
||||
<% user = user_my_module.user %>
|
||||
<li>
|
||||
<% if i > 0 %><hr><% end %>
|
||||
<div class="row">
|
||||
<div class="col-xs-2">
|
||||
<span class='global-avatar-container'>
|
||||
<%= image_tag avatar_path(user, :icon_small), class: "img-circle pull-left" %>
|
||||
</div>
|
||||
<div class="col-xs-10" style="line-height: 15px">
|
||||
<span><%= user.full_name %></span><br>
|
||||
<span class="text-muted" title="<%=t "experiments.canvas.popups.module_user_join_full", user: user.full_name, date: l(user_my_module.created_at, format: :full_date), time: l(user_my_module.created_at, format: :time) %>">
|
||||
<em>
|
||||
<%=t "experiments.canvas.popups.module_user_join", date: l(user_my_module.created_at, format: :full_date) %>
|
||||
</em>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% if can_manage_users_in_module?(@my_module) %>
|
||||
<p>
|
||||
<hr>
|
||||
<%= link_to t('experiments.canvas.popups.manage_users'), my_module_users_edit_path(@my_module, format: :json), remote: true, class: "manage-users-link" %>
|
||||
</p>
|
||||
<% end %>
|
|
@ -377,7 +377,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
resources :user_my_modules, path: '/users', only: %i(index create destroy) do
|
||||
collection do
|
||||
get :index_compact
|
||||
get :index_old
|
||||
end
|
||||
end
|
||||
resources :my_module_comments,
|
||||
|
|
Loading…
Reference in a new issue