mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-06 20:56:42 +08:00
Add endpoint for fetching label template tags [SCI-7053] (#4319)
This commit is contained in:
parent
6403e2256c
commit
4e768bec04
3 changed files with 47 additions and 0 deletions
|
@ -85,6 +85,10 @@ class LabelTemplatesController < ApplicationController
|
|||
render json: { error: I18n.t('errors.general') }, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
def template_tags
|
||||
render json: LabelTemplates::TagService.new(current_team).tags
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_feature_enabled
|
||||
|
|
42
app/services/label_templates/tag_service.rb
Normal file
42
app/services/label_templates/tag_service.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module LabelTemplates
|
||||
class TagService
|
||||
DEFAULT_COLUMNS = [
|
||||
{ key: :item_id, tag: '{{ITEM_ID}}' },
|
||||
{ key: :added_by, tag: '{{ADDED_BY}}' },
|
||||
{ key: :added_on, tag: '{{ADDED_ON}}' },
|
||||
{ key: :name, tag: '{{NAME}}' }
|
||||
].freeze
|
||||
|
||||
def initialize(team)
|
||||
@team = team
|
||||
end
|
||||
|
||||
def tags
|
||||
{
|
||||
default: DEFAULT_COLUMNS,
|
||||
common: repository_tags.pluck(:tags).reduce(:&),
|
||||
repository: repository_tags
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def repository_tags
|
||||
@repository_tags ||=
|
||||
Repository.includes(:repository_columns).active.where(team: @team).map do |repository|
|
||||
{
|
||||
repository_id: repository.id,
|
||||
repository_name: repository.name,
|
||||
tags: repository.repository_columns.pluck(:name).map do |name|
|
||||
{
|
||||
key: name,
|
||||
tag: "{{COLUMN_[#{name}]}}"
|
||||
}
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -53,6 +53,7 @@ Rails.application.routes.draw do
|
|||
post :duplicate
|
||||
post :delete
|
||||
get :datatable
|
||||
get :template_tags
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue