Enable edit for empty box and fix team import/export [SCI-10947][SCI-11032]

This commit is contained in:
Anton 2024-09-11 12:55:21 +02:00
parent 87aa86dcfe
commit 5e299cef65
7 changed files with 26 additions and 49 deletions

View file

@ -26,13 +26,13 @@
</div>
<span v-if="this.errors.name" class="text-sn-coral text-xs">{{ this.errors.name }}</span>
</div>
<div v-if="editModalMode == 'container'" class="mb-6">
<div v-if="editModalMode == 'container'" :title="warningBoxNotEmpty" class="mb-6">
<label class="sci-label">
{{ i18n.t(`storage_locations.index.edit_modal.dimensions_label`) }}
</label>
<div class="flex items-center gap-2 mb-4">
<div class="sci-radio-container">
<input type="radio" class="sci-radio" :disabled="object.code" v-model="object.metadata.display_type" name="display_type" value="no_grid" >
<input type="radio" class="sci-radio" :disabled="!canChangeGrid" v-model="object.metadata.display_type" name="display_type" value="no_grid" >
<span class="sci-radio-label"></span>
</div>
<span>{{ i18n.t('storage_locations.index.edit_modal.no_grid') }}</span>
@ -40,16 +40,16 @@
</div>
<div class="flex items-center gap-2 mb-4">
<div class="sci-radio-container">
<input type="radio" class="sci-radio" :disabled="object.code" v-model="object.metadata.display_type" name="display_type" value="grid" >
<input type="radio" class="sci-radio" :disabled="!canChangeGrid" v-model="object.metadata.display_type" name="display_type" value="grid" >
<span class="sci-radio-label"></span>
</div>
<span>{{ i18n.t('storage_locations.index.edit_modal.grid') }}</span>
<div class="sci-input-container-v2 !w-28">
<input type="number" :disabled="object.code" v-model="object.metadata.dimensions[0]" min="1" max="24">
<input type="number" :disabled="!canChangeGrid" v-model="object.metadata.dimensions[0]" min="1" max="24">
</div>
<i class="sn-icon sn-icon-close-small"></i>
<div class="sci-input-container-v2 !w-28">
<input type="number" :disabled="object.code" v-model="object.metadata.dimensions[1]" min="1" max="24">
<input type="number" :disabled="!canChangeGrid" v-model="object.metadata.dimensions[1]" min="1" max="24">
</div>
</div>
</div>
@ -134,6 +134,15 @@ export default {
mode() {
return this.editStorageLocation ? 'edit' : 'create';
},
canChangeGrid() {
return !this.object.code || this.object.is_empty;
},
warningBoxNotEmpty() {
if (this.canChangeGrid) {
return '';
}
return this.i18n.t('storage_locations.index.edit_modal.warning_box_not_empty');
},
validObject() {
this.errors = {};

View file

@ -53,6 +53,10 @@ class StorageLocation < ApplicationRecord
storage_location
end
def empty?
storage_location_repository_rows.count.zero?
end
def duplicate!
ActiveRecord::Base.transaction do
new_storage_location = dup

View file

@ -6,12 +6,16 @@ module Lists
include ShareableSerializer
attributes :id, :code, :name, :container, :description, :owned_by, :created_by,
:created_on, :urls, :metadata, :file_name, :sub_location_count
:created_on, :urls, :metadata, :file_name, :sub_location_count, :is_empty
def owned_by
object.team.name
end
def is_empty
object.empty?
end
def metadata
{
display_type: object.metadata['display_type'],

View file

@ -93,7 +93,7 @@ module ModelExporters
element_json = element.as_json
case element.orderable_type
when 'ResultText'
element_json['step_text'] = element.orderable.as_json
element_json['result_text'] = element.orderable.as_json
when 'ResultTable'
element_json['table'] = table(element.orderable.table)
end

View file

@ -47,10 +47,6 @@ module ModelExporters
user_assignments: team.user_assignments.map do |ua|
user_assignment(ua)
end,
notifications: Notification
.includes(:user_notifications)
.where('user_notifications.user_id': team.users)
.map { |n| notification(n) },
repositories: team.repositories.map { |r| repository(r) },
tiny_mce_assets: team.tiny_mce_assets.map { |tma| tiny_mce_asset_data(tma) },
protocols: team.protocols.where(my_module: nil).map do |pr|
@ -68,15 +64,6 @@ module ModelExporters
}
end
def notification(notification)
notification_json = notification.as_json
notification_json['type_of'] = Extends::NOTIFICATIONS_TYPES
.key(notification
.read_attribute('type_of'))
.to_s
notification_json
end
def label_templates(templates)
templates.where.not(type: 'FluicsLabelTemplate').map do |template|
template_json = template.as_json
@ -97,7 +84,6 @@ module ModelExporters
copy_files([user], :avatar, File.join(@dir_to_export, 'avatars'))
{
user: user_json,
user_notifications: user.user_notifications,
user_identities: user.user_identities,
repository_table_states:
user.repository_table_states.where(repository: @team.repositories)

View file

@ -71,7 +71,6 @@ class TeamImporter
# Find new id of the first admin in the team
@admin_id = @user_mappings[team_json['default_admin_id']]
create_notifications(team_json['notifications'])
create_protocol_keywords(team_json['protocol_keywords'], team)
create_protocols(team_json['protocols'], nil, team)
create_project_folders(team_json['project_folders'], team)
@ -83,17 +82,6 @@ class TeamImporter
# Second run, we needed it because of some models should be created
team_json['users'].each do |user_json|
user_json['user_notifications'].each do |user_notification_json|
user_notification = UserNotification.new(user_notification_json)
user_notification.id = nil
user_notification.user_id = find_user(user_notification.user_id)
user_notification.notification_id =
@notification_mappings[user_notification.notification_id]
next if user_notification.notification_id.blank?
user_notification.save!
end
user_json['repository_table_states'].each do |rep_tbl_state_json|
rep_tbl_state = RepositoryTableState.new(rep_tbl_state_json)
rep_tbl_state.id = nil
@ -423,21 +411,6 @@ class TeamImporter
end
end
def create_notifications(notifications_json)
puts 'Creating notifications...'
notifications_json.each do |notification_json|
notification = Notification.new(notification_json)
next if notification.type_of.blank?
orig_notification_id = notification.id
notification.id = nil
notification.generator_user_id = find_user(notification.generator_user_id)
notification.save!
@notification_mappings[orig_notification_id] = notification.id
@notification_counter += 1
end
end
def create_repositories(repositories_json, team, snapshots = false)
puts 'Creating repositories...'
repositories_json.each do |repository_json|
@ -756,7 +729,7 @@ class TeamImporter
def create_protocols(protocols_json, my_module = nil, team = nil,
user_id = nil)
sorted_protocols = protocols_json.sort_by { |p| p['id'] }
sorted_protocols = protocols_json.sort_by { |p| p['protocol']['id'] }
puts 'Creating protocols...'
sorted_protocols.each do |protocol_json|

View file

@ -2745,6 +2745,7 @@ en:
name_label_container: "Box name"
image_label_container: "Image of box"
drag_and_drop_supporting_text: ".png or .jpg file"
warning_box_not_empty: "Box dimensions can be updated only when the box is empty."
description_label: "Description"
name_placeholder: "Big freezer"
description_placeholder: "Keep everyone on the same page. You can also use smart annotations."