mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2026-01-07 00:36:08 +08:00
Fix handling of deleted repositories for snapshots [SCI-4596]
This commit is contained in:
parent
c74fa3c244
commit
ba1661b40f
16 changed files with 117 additions and 89 deletions
|
|
@ -254,7 +254,7 @@ var MyModuleRepositories = (function() {
|
|||
function checkSnapshotStatus(snapshotItem) {
|
||||
$.getJSON(snapshotItem.data('status-url'), (statusData) => {
|
||||
if (statusData.status === 'ready') {
|
||||
$.getJSON(snapshotItem.data('item-url'), (itemData) => {
|
||||
$.getJSON(snapshotItem.data('version-item-url'), (itemData) => {
|
||||
snapshotItem.replaceWith(itemData.html);
|
||||
});
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class MyModuleRepositoriesController < ApplicationController
|
|||
end
|
||||
|
||||
def repositories_list_html
|
||||
@assigned_repositories = @my_module.assigned_repositories
|
||||
@assigned_repositories = @my_module.live_and_snapshot_repositories_list
|
||||
render json: { html: render_to_string(partial: 'my_modules/repositories/repositories_list') }
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
class MyModuleRepositorySnapshotsController < ApplicationController
|
||||
before_action :load_my_module
|
||||
before_action :load_repository
|
||||
before_action :load_repository_snapshot, except: %i(create full_view_versions_sidebar select)
|
||||
before_action :load_repository, only: :create
|
||||
before_action :load_repository_snapshot, except: %i(create full_view_sidebar select)
|
||||
before_action :check_view_permissions, except: %i(create destroy select)
|
||||
before_action :check_manage_permissions, only: %i(create destroy select)
|
||||
|
||||
|
|
@ -71,9 +71,15 @@ class MyModuleRepositorySnapshotsController < ApplicationController
|
|||
}
|
||||
end
|
||||
|
||||
def full_view_versions_sidebar
|
||||
@repository_snapshots = @my_module.repository_snapshots.where(original_repository: @repository)
|
||||
render json: { html: render_to_string(partial: 'my_modules/repositories/full_view_versions_sidebar') }
|
||||
def full_view_sidebar
|
||||
@repository = Repository.find_by(id: params[:repository_id])
|
||||
|
||||
if @repository.present?
|
||||
return render_403 unless can_read_repository?(@repository)
|
||||
end
|
||||
|
||||
@repository_snapshots = @my_module.repository_snapshots.where(parent_id: params[:repository_id])
|
||||
render json: { html: render_to_string(partial: 'my_modules/repositories/full_view_sidebar') }
|
||||
end
|
||||
|
||||
def select
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@ class MyModulesController < ApplicationController
|
|||
|
||||
def protocols
|
||||
@protocol = @my_module.protocol
|
||||
@assigned_repositories = @my_module.assigned_repositories
|
||||
@assigned_repositories = @my_module.live_and_snapshot_repositories_list
|
||||
current_team_switch(@protocol.team)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -58,16 +58,14 @@ module MyModulesHelper
|
|||
|
||||
def assigned_repository_full_view_table_path(my_module, repository)
|
||||
if repository.is_a?(RepositorySnapshot)
|
||||
return full_view_table_my_module_repository_snapshot_path(my_module, repository.original_repository, repository)
|
||||
return full_view_table_my_module_repository_snapshot_path(my_module, repository)
|
||||
end
|
||||
|
||||
full_view_table_my_module_repository_path(my_module, repository)
|
||||
end
|
||||
|
||||
def assigned_repository_simple_view_index_path(my_module, repository)
|
||||
if repository.is_a?(RepositorySnapshot)
|
||||
return index_dt_my_module_repository_snapshot_path(my_module, repository.original_repository, repository)
|
||||
end
|
||||
return index_dt_my_module_repository_snapshot_path(my_module, repository) if repository.is_a?(RepositorySnapshot)
|
||||
|
||||
index_dt_my_module_repository_path(my_module, repository)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -201,18 +201,28 @@ class MyModule < ApplicationRecord
|
|||
|
||||
def assigned_repositories
|
||||
team = experiment.project.team
|
||||
selected_snapshots = repository_snapshots.joins(:repository_rows)
|
||||
.where(selected: true)
|
||||
.group(:parent_id, :id)
|
||||
live_repositories = team.repositories
|
||||
.joins(repository_rows: :my_module_repository_rows)
|
||||
.where(my_module_repository_rows: { my_module_id: id })
|
||||
.where.not(id: selected_snapshots.select(:parent_id))
|
||||
.group(:id)
|
||||
team.repositories
|
||||
.joins(repository_rows: :my_module_repository_rows)
|
||||
.where(my_module_repository_rows: { my_module_id: id })
|
||||
.group(:id)
|
||||
end
|
||||
|
||||
selector = 'repositories.*, COUNT(repository_rows.id) AS assigned_rows_count'
|
||||
def live_and_snapshot_repositories_list
|
||||
snapshots = repository_snapshots.left_outer_joins(:original_repository)
|
||||
|
||||
live_repositories.select(selector) + selected_snapshots.select(selector)
|
||||
selected_snapshots = snapshots.where(selected: true)
|
||||
selected_snapshots = selected_snapshots.or(snapshots.where(original_repositories_repositories: { id: nil }))
|
||||
selected_snapshots = selected_snapshots.select('DISTINCT ON ("repositories"."parent_id") "repositories".*')
|
||||
.select('COUNT(repository_rows.id) AS assigned_rows_count')
|
||||
.joins(:repository_rows)
|
||||
.group(:parent_id, :id)
|
||||
.order(:parent_id, updated_at: :desc)
|
||||
|
||||
live_repositories = assigned_repositories
|
||||
.select('repositories.*, COUNT(repository_rows.id) AS assigned_rows_count')
|
||||
.where.not(id: repository_snapshots.where(selected: true).select(:parent_id))
|
||||
|
||||
(live_repositories + selected_snapshots).sort_by { |r| r.name.downcase }
|
||||
end
|
||||
|
||||
def unassigned_users
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ class Repository < RepositoryBase
|
|||
has_many :repository_snapshots,
|
||||
class_name: 'RepositorySnapshot',
|
||||
foreign_key: :parent_id,
|
||||
inverse_of: :original_repository,
|
||||
dependent: :nullify
|
||||
inverse_of: :original_repository
|
||||
|
||||
validates :name,
|
||||
presence: true,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@
|
|||
class RepositorySnapshot < RepositoryBase
|
||||
enum status: { provisioning: 0, ready: 1, failed: 2 }
|
||||
|
||||
belongs_to :original_repository, foreign_key: :parent_id, class_name: 'Repository', inverse_of: :repository_snapshots
|
||||
belongs_to :original_repository, foreign_key: :parent_id,
|
||||
class_name: 'Repository',
|
||||
inverse_of: :repository_snapshots,
|
||||
optional: true
|
||||
belongs_to :my_module, optional: true
|
||||
|
||||
validates :name, presence: true, length: { maximum: Constants::NAME_MAX_LENGTH }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
<div class="repository-versions-header">
|
||||
<h4><%= t('my_modules.repository.snapshots.full_view.header') %>
|
||||
<a id="collapseVersionsSidebar" class="pull-right sidebar-collapse-button" href="#">
|
||||
<i class="fas fa-angle-double-right"></i>
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div class="list-group repository-versions-list">
|
||||
<% if @repository.present? %>
|
||||
<div class="list-group-item live-version-item" data-id="<%= @repository.id %>" data-selected="<%= @repository_snapshots.select{ |s| s.selected == true }.blank? %>">
|
||||
<a id="selectLiveVersionButton" class="version-button" href="#" data-table-url="<%= full_view_table_my_module_repository_path(@my_module, @repository) %>">
|
||||
<h2 class="list-group-item-heading">
|
||||
<%= t('my_modules.repository.snapshots.full_view.live') %>
|
||||
</h2>
|
||||
</a>
|
||||
<p class="list-group-item-text">
|
||||
<%= t('my_modules.repository.snapshots.full_view.live_description') %>
|
||||
</p>
|
||||
</div>
|
||||
<% else %>
|
||||
<div class="list-group-item">
|
||||
<h2 class="list-group-item-heading">
|
||||
<%= t('my_modules.repository.snapshots.full_view.no_live_version') %>
|
||||
</h2>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="repository-snapshots-container">
|
||||
<div class="snapshots-container-scrollbody">
|
||||
<% if @repository.present? %>
|
||||
<div class="create-snapshot-item">
|
||||
<% if @repository_snapshots.blank? %>
|
||||
<p>
|
||||
<%= t('my_modules.repository.snapshots.full_view.no_snapshots_label') %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<button id="createRepositorySnapshotButton" class="btn btn-secondary" data-action-path="<%= my_module_repository_snapshots_path(@my_module, @repository) %>">
|
||||
<i class="fas fa-camera"></i>
|
||||
<%= t('my_modules.repository.snapshots.full_view.create_button') %>
|
||||
</button>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= render partial: 'my_modules/repositories/full_view_version', collection: @repository_snapshots, as: :repository_snapshot %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="list-group-item text-center">
|
||||
<a id="setDefaultVersionButton" class="btn btn-primary default-version-button hidden" data-select-path="<%= my_module_select_default_snapshot_path(@my_module) %>">
|
||||
<%= t('my_modules.repository.snapshots.full_view.set_default_button') %>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
<table class="table"
|
||||
data-id="<%= @repository_snapshot.id %>"
|
||||
data-type="snapshot"
|
||||
data-source="<%= index_dt_my_module_repository_snapshot_path(@my_module, @repository, @repository_snapshot) %>"
|
||||
data-source="<%= index_dt_my_module_repository_snapshot_path(@my_module, @repository_snapshot) %>"
|
||||
data-default-order="<%= default_snapshot_table_order_as_js_array %>"
|
||||
data-default-table-columns="<%= default_snapshot_table_columns %>"
|
||||
data-load-state-url="<%= repository_load_table_state_path(@repository_snapshot) %>"
|
||||
data-versions-sidebar-url="<%= my_module_repository_full_view_versions_sidebar_path(@my_module, @repository) %>"
|
||||
data-versions-sidebar-url="<%= full_view_sidebar_my_module_repository_snapshots_path(@my_module, @repository_snapshot.parent_id) %>"
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
data-default-order="<%= default_table_order_as_js_array %>"
|
||||
data-default-table-columns="<%= default_table_columns %>"
|
||||
data-load-state-url="<%= repository_load_table_state_path(@repository) %>"
|
||||
data-versions-sidebar-url="<%= my_module_repository_full_view_versions_sidebar_path(@my_module, @repository) %>"
|
||||
data-versions-sidebar-url="<%= full_view_sidebar_my_module_repository_snapshots_path(@my_module, @repository) %>"
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<div class="list-group-item repository-snapshot-item <%= repository_snapshot.status %>"
|
||||
data-id="<%= repository_snapshot.id %>"
|
||||
data-selected="<%= repository_snapshot.selected %>"
|
||||
data-status-url="<%= status_my_module_repository_snapshot_path(@my_module, @repository, repository_snapshot) %>"
|
||||
data-item-url="<%= my_module_repository_snapshot_path(@my_module, @repository, repository_snapshot) %>">
|
||||
data-status-url="<%= status_my_module_repository_snapshot_path(@my_module, repository_snapshot) %>"
|
||||
data-version-item-url="<%= my_module_repository_snapshot_path(@my_module, repository_snapshot) %>">
|
||||
<div class="row">
|
||||
<div class="col-xs-8">
|
||||
<% if repository_snapshot.status == 'provisioning' %>
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
<a class="version-button select-snapshot-button <%= 'disabled' if repository_snapshot.status == 'provisioning' %>"
|
||||
href="#"
|
||||
data-status="<%= repository_snapshot.status %>"
|
||||
data-table-url="<%= full_view_table_my_module_repository_snapshot_path(@my_module, @repository, repository_snapshot) %>">
|
||||
data-table-url="<%= full_view_table_my_module_repository_snapshot_path(@my_module, repository_snapshot) %>">
|
||||
<h4 class="list-group-item-heading">
|
||||
<%= l(repository_snapshot.updated_at, format: :full) %>
|
||||
</h4>
|
||||
|
|
@ -28,7 +28,7 @@
|
|||
<% end %>
|
||||
</div>
|
||||
<div class="col-xs-4">
|
||||
<a class="pull-right btn version-button delete-snapshot-button" href="#" data-action-path="<%= my_module_repository_snapshot_path(@my_module, @repository, repository_snapshot) %>">
|
||||
<a class="pull-right btn version-button delete-snapshot-button" href="#" data-action-path="<%= my_module_repository_snapshot_path(@my_module, repository_snapshot) %>">
|
||||
<i class="fas fa-trash"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
<div class="repository-versions-header">
|
||||
<h4><%= t('my_modules.repository.snapshots.full_view.header') %>
|
||||
<a id="collapseVersionsSidebar" class="pull-right sidebar-collapse-button" href="#">
|
||||
<i class="fas fa-angle-double-right"></i>
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div class="list-group repository-versions-list">
|
||||
<div class="list-group-item live-version-item" data-id="<%= @repository.id %>" data-selected="<%= @repository_snapshots.select{ |s| s.selected == true }.blank? %>">
|
||||
<a id="selectLiveVersionButton" class="version-button" href="#" data-table-url="<%= full_view_table_my_module_repository_path(@my_module, @repository) %>">
|
||||
<h2 class="list-group-item-heading">
|
||||
<%= t('my_modules.repository.snapshots.full_view.live') %>
|
||||
</h2>
|
||||
</a>
|
||||
<p class="list-group-item-text">
|
||||
<%= t('my_modules.repository.snapshots.full_view.live_description') %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="repository-snapshots-container">
|
||||
<div class="snapshots-container-scrollbody">
|
||||
<div class="create-snapshot-item">
|
||||
<% if @repository_snapshots.blank? %>
|
||||
<p>
|
||||
<%= t('my_modules.repository.snapshots.full_view.no_snapshots_label') %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<button id="createRepositorySnapshotButton" class="btn btn-secondary" data-action-path="<%= my_module_repository_snapshots_path(@my_module, @repository) %>">
|
||||
<i class="fas fa-camera"></i>
|
||||
<%= t('my_modules.repository.snapshots.full_view.create_button') %>
|
||||
</button>
|
||||
</div>
|
||||
<%= render partial: 'my_modules/repositories/full_view_version', collection: @repository_snapshots, as: :repository_snapshot %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="list-group-item text-center">
|
||||
<a id="setDefaultVersionButton" class="btn btn-primary default-version-button hidden" data-select-path="<%= select_my_module_repository_snapshots_path(@my_module, @repository) %>">
|
||||
<%= t('my_modules.repository.snapshots.full_view.set_default_button') %>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
json.draw @draw
|
||||
json.data do
|
||||
json.array! prepare_snapshot_row_columns(@repository_rows, @columns_mappings, @repository.team)
|
||||
json.array! prepare_snapshot_row_columns(@repository_rows, @columns_mappings, @repository_snapshot.team)
|
||||
end
|
||||
json.recordsFiltered @repository_rows.first ? @repository_rows.first.filtered_count : 0
|
||||
json.recordsTotal @all_rows_count
|
||||
|
|
|
|||
|
|
@ -799,6 +799,7 @@ en:
|
|||
header: 'Versions'
|
||||
live: 'Live version'
|
||||
live_description: 'Regularly updated from the inventory'
|
||||
no_live_version: 'Only snapshots are available'
|
||||
no_snapshots_label: 'You have not created any snapshots yet. To do so click the button bellow.'
|
||||
versions_sidebar_button: 'View versions'
|
||||
create_button: 'Create snapshot'
|
||||
|
|
|
|||
|
|
@ -394,24 +394,25 @@ Rails.application.routes.draw do
|
|||
get :assign_repository_records_modal, as: :assign_modal
|
||||
get :update_repository_records_modal, as: :update_modal
|
||||
end
|
||||
end
|
||||
|
||||
resources :snapshots, controller: :my_module_repository_snapshots,
|
||||
only: %i(create destroy show) do
|
||||
|
||||
member do
|
||||
get :full_view_table
|
||||
post :index_dt
|
||||
get :status
|
||||
end
|
||||
|
||||
collection do
|
||||
post :select
|
||||
end
|
||||
resources :repository_snapshots, controller: :my_module_repository_snapshots, only: %i(destroy show) do
|
||||
member do
|
||||
get :full_view_table
|
||||
post :index_dt
|
||||
get :status
|
||||
end
|
||||
|
||||
get :full_view_versions_sidebar, controller: :my_module_repository_snapshots
|
||||
collection do
|
||||
get ':repository_id/full_view_sidebar',
|
||||
to: 'my_module_repository_snapshots#full_view_sidebar',
|
||||
as: :full_view_sidebar
|
||||
post ':repository_id', to: 'my_module_repository_snapshots#create', as: ''
|
||||
end
|
||||
end
|
||||
|
||||
post :select_default_snapshot, to: 'my_module_repository_snapshots#select'
|
||||
|
||||
# resources :sample_my_modules, path: '/samples_index', only: [:index]
|
||||
resources :result_texts, only: [:new, :create]
|
||||
resources :result_assets, only: [:new, :create]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue