introduce CustomField scope

This commit is contained in:
Alexander Meindl 2020-07-30 20:59:04 +02:00
parent 3e567d0d22
commit 6c14692107
6 changed files with 24 additions and 20 deletions

View File

@ -196,15 +196,18 @@ module DashboardsHelper
if dashboard.editable?
icons = []
blocks = dashboard.content.available_blocks
unless blocks[block].present? && blocks[block][:no_settings]
icons << link_to_function(l(:label_options),
"$('##{block}-settings').toggle();",
class: 'icon-only icon-settings',
title: l(:label_options))
block_specs = blocks[block]
if block_specs.present? && block_specs[:no_settings].blank?
if !block_specs.key?(:with_settings_if) || block_specs[:with_settings_if].call(@project)
icons << link_to_function(l(:label_options),
"$('##{block}-settings').toggle();",
class: 'icon-only icon-settings',
title: l(:label_options))
end
end
icons << tag.span('', class: 'icon-only icon-sort-handle sort-handle', title: l(:button_move))
icons << link_to(l(:button_delete),
_remove_block_dashboard_path(@project, @dashboard, block: block),
_remove_block_dashboard_path(@project, dashboard, block: block),
remote: true, method: 'post',
class: 'icon-only icon-close', title: l(:button_delete))

View File

@ -3,7 +3,9 @@
- unless with_async
h3 = settings[:title].presence || block_definition[:label]
- if @can_edit && block_definition[:no_settings].blank?
- if @can_edit && \
block_definition[:no_settings].blank? && \
(!block_definition.key?(:with_settings_if) || block_definition[:with_settings_if].call(@project))
= render partial: block_definition[:settings_partial].presence || "#{async[:partial]}_settings",
locals: build_dashboard_partial_locals(block,
block_definition,

View File

@ -154,6 +154,16 @@ module Additionals
[value, options]
end
def custom_fields_with_format(entity, format, project = nil)
scope = if project.nil?
Object.const_get "#{entity}CustomField"
else
project.send "#{entity.underscore}_custom_fields"
end
scope.where field_format: format
end
private
def settings

View File

@ -220,17 +220,6 @@ module Additionals
classes.join(' ')
end
def options_with_custom_fields(type, format, current, options = {})
klass = Object.const_get("#{type}CustomField")
fields = []
fields << ["- #{l(:label_disabled)} -", 0] if options[:include_disabled]
klass.sorted.each do |field|
fields << [field.name, field.id] if Array(format).include?(field.field_format)
end
options_for_select(fields, current)
end
def addtionals_textarea_cols(text, options = {})
[[(options[:min].presence || 8), text.to_s.length / 50].max, (options[:max].presence || 20)].min
end

View File

@ -30,7 +30,7 @@ module Additionals
raise ::Unauthorized unless @dashboard.visible?
raise ::Unauthorized unless @dashboard.project.nil? || @dashboard.project == @project
rescue ActiveRecord::RecordNotFound
render_404
return render_404
end
else
@dashboard = Dashboard.default DashboardContentProject::TYPE_NAME, @project

View File

@ -28,7 +28,7 @@ module Additionals
@dashboard = Dashboard.welcome_only.find(params[:dashboard_id])
raise ::Unauthorized unless @dashboard.visible?
rescue ActiveRecord::RecordNotFound
render_404
return render_404
end
else
@dashboard = Dashboard.default(DashboardContentWelcome::TYPE_NAME)