mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-07 15:07:15 +08:00
Add labels template to team import/export [SCI-7089]
This commit is contained in:
parent
32c32e7b46
commit
bcc681b14d
4 changed files with 42 additions and 2 deletions
|
|
@ -33,7 +33,11 @@ class LabelTemplatesController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
label_template = ZebraLabelTemplate.default.save!
|
||||
label_template = ZebraLabelTemplate.default
|
||||
label_template.team = current_team
|
||||
label_template.created_by = current_user
|
||||
label_template.last_modified_by = current_user
|
||||
label_template.save!
|
||||
|
||||
redirect_to label_template_path(label_template, new_label: true)
|
||||
end
|
||||
|
|
@ -51,6 +55,8 @@ class LabelTemplatesController < ApplicationController
|
|||
LabelTemplate.where(team_id: current_team.id, id: params[:selected_ids]).each do |template|
|
||||
new_template = template.dup
|
||||
new_template.default = false
|
||||
new_template.created_by = current_user
|
||||
new_template.last_modified_by = current_user
|
||||
new_template.name = template.name + '(1)'
|
||||
new_template.save!
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,6 +4,12 @@ class LabelTemplate < ApplicationRecord
|
|||
include SearchableModel
|
||||
|
||||
belongs_to :team
|
||||
belongs_to :created_by,
|
||||
class_name: 'User',
|
||||
optional: true
|
||||
belongs_to :last_modified_by,
|
||||
class_name: 'User',
|
||||
optional: true
|
||||
|
||||
validates :name, presence: true, length: { minimum: Constants::NAME_MIN_LENGTH,
|
||||
maximum: Constants::NAME_MAX_LENGTH }
|
||||
|
|
|
|||
|
|
@ -57,7 +57,8 @@ module ModelExporters
|
|||
protocol_keywords: team.protocol_keywords,
|
||||
project_folders: team.project_folders,
|
||||
projects: team.projects.map { |p| project(p) },
|
||||
activities: team.activities.where(project_id: nil)
|
||||
activities: team.activities.where(project_id: nil),
|
||||
label_templates: label_templates(team.label_templates)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -70,6 +71,14 @@ module ModelExporters
|
|||
notification_json
|
||||
end
|
||||
|
||||
def label_templates(templates)
|
||||
templates.where.not(type: 'FluicsLabelTemplate').map do |template|
|
||||
template_json = template.as_json
|
||||
template_json['type'] = template.type # as_json ignore 'type' column
|
||||
template_json
|
||||
end
|
||||
end
|
||||
|
||||
def user(user)
|
||||
user_json = user.as_json
|
||||
# Looks like Devise doesn't export some fields to JSON, so add it manually
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ class TeamImporter
|
|||
@protocol_counter = 0
|
||||
@step_counter = 0
|
||||
@report_counter = 0
|
||||
@label_template_counter = 0
|
||||
@my_module_counter = 0
|
||||
@notification_counter = 0
|
||||
@result_counter = 0
|
||||
|
|
@ -82,6 +83,8 @@ class TeamImporter
|
|||
create_project_folders(team_json['project_folders'], team)
|
||||
create_projects(team_json['projects'], team)
|
||||
create_repositories(team_json['repositories'], team)
|
||||
create_label_templates(team_json['label_templates'], team)
|
||||
|
||||
|
||||
# Second run, we needed it because of some models should be created
|
||||
|
||||
|
|
@ -150,6 +153,7 @@ class TeamImporter
|
|||
puts "Imported results: #{@result_counter}"
|
||||
puts "Imported assets: #{@asset_counter}"
|
||||
puts "Imported tinyMCE assets: #{@mce_asset_counter}"
|
||||
puts "Imported label templates: #{@label_template_counter}"
|
||||
|
||||
MyModule.set_callback(:create, :before, :create_blank_protocol)
|
||||
Protocol.set_callback(:save, :after, :update_linked_children)
|
||||
|
|
@ -307,6 +311,21 @@ class TeamImporter
|
|||
end
|
||||
end
|
||||
|
||||
def create_label_templates(label_templates_json, team)
|
||||
# Destroy default templates generated on team creation
|
||||
team.label_templates.where.not(type: 'FluicsLabelTemplate').destroy_all
|
||||
label_templates_json.each do |template_json|
|
||||
template = LabelTemplate.new(template_json)
|
||||
template.id = nil
|
||||
template.team_id = team.id
|
||||
template.created_by_id = find_user(template.created_by_id) if template.created_by_id
|
||||
template.last_modified_by_id = find_user(template.last_modified_by_id) if template.last_modified_by_id
|
||||
template.save!
|
||||
|
||||
@label_template_counter += 1
|
||||
end
|
||||
end
|
||||
|
||||
def create_activities(activities_json, team)
|
||||
activities_json.each do |activity_json|
|
||||
activity = Activity.new(activity_json)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue