mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-11 23:54:43 +08:00
Make storage locations toggleable [SCI-10950]
This commit is contained in:
parent
838bce9ac1
commit
333d62bfde
7 changed files with 38 additions and 11 deletions
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class StorageLocationRepositoryRowsController < ApplicationController
|
||||
before_action :check_storage_locations_enabled, except: :destroy
|
||||
before_action :load_storage_location_repository_row, only: %i(update destroy move)
|
||||
before_action :load_storage_location
|
||||
before_action :load_repository_row, only: %i(create update destroy move)
|
||||
|
@ -80,6 +81,10 @@ class StorageLocationRepositoryRowsController < ApplicationController
|
|||
|
||||
private
|
||||
|
||||
def check_storage_locations_enabled
|
||||
render_403 unless StorageLocation.storage_locations_enabled?
|
||||
end
|
||||
|
||||
def load_storage_location_repository_row
|
||||
@storage_location_repository_row = StorageLocationRepositoryRow.find(
|
||||
storage_location_repository_row_params[:id]
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class StorageLocationsController < ApplicationController
|
||||
before_action :check_storage_locations_enabled, except: :unassign_rows
|
||||
before_action :load_storage_location, only: %i(update destroy duplicate move show available_positions unassign_rows)
|
||||
before_action :check_read_permissions, except: %i(index create tree actions_toolbar)
|
||||
before_action :check_create_permissions, only: :create
|
||||
before_action :check_manage_permissions, only: %i(update destroy duplicate move)
|
||||
before_action :check_manage_permissions, only: %i(update destroy duplicate move unassign_rows)
|
||||
before_action :set_breadcrumbs_items, only: %i(index show)
|
||||
|
||||
def index
|
||||
|
@ -107,6 +108,10 @@ class StorageLocationsController < ApplicationController
|
|||
|
||||
private
|
||||
|
||||
def check_storage_locations_enabled
|
||||
render_403 unless StorageLocation.storage_locations_enabled?
|
||||
end
|
||||
|
||||
def storage_location_params
|
||||
params.permit(:id, :parent_id, :name, :container, :description,
|
||||
metadata: [:display_type, dimensions: [], parent_coordinations: []])
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<template>
|
||||
<div v-if="repositoryRow">
|
||||
<div class="flex items-center gap-4">
|
||||
<h4>{{ i18n.t('repositories.locations.title', { count: repositoryRow.locations.length }) }}</h4>
|
||||
<button class="btn btn-light">
|
||||
<h4>{{ i18n.t('repositories.locations.title', { count: repositoryRow.storage_locations.locations.length }) }}</h4>
|
||||
<button v-if="repositoryRow.permissions.can_manage && repositoryRow.storage_locations.enabled" class="btn btn-light">
|
||||
{{ i18n.t('repositories.locations.assign') }}
|
||||
</button>
|
||||
</div>
|
||||
<template v-for="(location, index) in repositoryRow.locations" :key="location.id">
|
||||
<template v-for="(location, index) in repositoryRow.storage_locations.locations" :key="location.id">
|
||||
<div>
|
||||
<div class="sci-divider my-4" v-if="index > 0"></div>
|
||||
<div class="flex items-center gap-2 mb-3">
|
||||
|
@ -17,7 +17,7 @@
|
|||
<div v-for="(position) in location.positions" :key="position.id">
|
||||
<div v-if="position.metadata.position" class="flex items-center font-sm gap-1 uppercase bg-sn-grey-300 rounded pl-1.5 pr-2">
|
||||
{{ formatPosition(position.metadata.position) }}
|
||||
<i class="sn-icon sn-icon-unlink-italic-s cursor-pointer"></i>
|
||||
<i v-if="repositoryRow.permissions.can_manage" class="sn-icon sn-icon-unlink-italic-s cursor-pointer"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -64,7 +64,10 @@ export default {
|
|||
type: String,
|
||||
required: true
|
||||
},
|
||||
createUrl: {
|
||||
createLocationUrl: {
|
||||
type: String
|
||||
},
|
||||
createLocationInstanceUrl: {
|
||||
type: String
|
||||
},
|
||||
directUploadUrl: {
|
||||
|
@ -137,21 +140,24 @@ export default {
|
|||
},
|
||||
toolbarActions() {
|
||||
const left = [];
|
||||
if (this.createUrl) {
|
||||
if (this.createLocationUrl) {
|
||||
left.push({
|
||||
name: 'create_location',
|
||||
icon: 'sn-icon sn-icon-new-task',
|
||||
label: this.i18n.t('storage_locations.index.new_location'),
|
||||
type: 'emit',
|
||||
path: this.createUrl,
|
||||
path: this.createLocationUrl,
|
||||
buttonStyle: 'btn btn-primary'
|
||||
});
|
||||
}
|
||||
|
||||
if (this.createLocationInstanceUrl) {
|
||||
left.push({
|
||||
name: 'create_container',
|
||||
icon: 'sn-icon sn-icon-item',
|
||||
label: this.i18n.t('storage_locations.index.new_container'),
|
||||
type: 'emit',
|
||||
path: this.createUrl,
|
||||
path: this.createLocationInstanceUrl,
|
||||
buttonStyle: 'btn btn-secondary'
|
||||
});
|
||||
}
|
||||
|
@ -174,6 +180,9 @@ export default {
|
|||
];
|
||||
|
||||
return filters;
|
||||
},
|
||||
createUrl() {
|
||||
return this.editModalMode === 'location' ? this.createLocationUrl : this.createLocationInstanceUrl;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
|
@ -65,6 +65,10 @@ class StorageLocation < ApplicationRecord
|
|||
rows
|
||||
end
|
||||
|
||||
def self.storage_locations_enabled?
|
||||
ApplicationSettings.instance.values['storage_locations_enabled']
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def recursive_duplicate(old_parent_id = nil, new_parent_id = nil)
|
||||
|
|
|
@ -37,7 +37,10 @@ json.actions do
|
|||
end
|
||||
end
|
||||
|
||||
json.locations @repository_row.grouped_storage_locations
|
||||
json.storage_locations do
|
||||
json.locations @repository_row.grouped_storage_locations
|
||||
json.enabled StorageLocation.storage_locations_enabled?
|
||||
end
|
||||
|
||||
json.default_columns do
|
||||
json.name @repository_row.name
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
actions-url="<%= actions_toolbar_storage_locations_path(current_team) %>"
|
||||
data-source="<%= storage_locations_path(format: :json, parent_id: params[:parent_id]) %>"
|
||||
direct-upload-url="<%= rails_direct_uploads_url %>"
|
||||
create-url="<%= storage_locations_path(parent_id: params[:parent_id]) if can_create_storage_locations?(current_team) %>"
|
||||
create-location-url="<%= storage_locations_path(parent_id: params[:parent_id]) if can_create_storage_locations?(current_team) %>"
|
||||
create-location-instance-url="<%= storage_locations_path(parent_id: params[:parent_id]) if can_create_storage_location_containers?(current_team) %>"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue