app/controllers/management/page_steps_controller.rb
def build_current_dataset_setting
    ds_params = {}
    ds_params = page_params.to_h[:dataset_setting] if params[:site_page] && page_params.to_h && page_params.to_h[:dataset_setting]

    @dataset_setting = nil
    if ds_params[:id]
      @dataset_setting = DatasetSetting.find(ds_params[:id])
    elsif @page.dataset_setting
      @dataset_setting = @page.dataset_setting
    else
      @dataset_setting = DatasetSetting.new
      @page.dataset_setting = @dataset_setting
    end
    @dataset_setting.assign_attributes session[:dataset_setting][@page_id] if session[:dataset_setting][@page_id]

    if ds_id = ds_params[:dataset_id]

      # If the user changed the id of the dataset, the entity is reset
      if @dataset_setting.dataset_id && @dataset_setting.dataset_id != ds_id
        delete_session_key(:dataset_setting, @page_id)
        session[:invalid_steps][@page_id] = %w[type columns preview]
        @dataset_setting.filters = @dataset_setting.columns_changeable = @dataset_setting.columns_visible = nil
      end

      @dataset_setting.assign_attributes(dataset_id: ds_id)
      ds_metadata = @dataset_setting.metadata['data'].first
      if ds_metadata
        @dataset_setting.api_table_name = ds_metadata.dig('attributes', 'tableName')
        @dataset_setting.legend = ds_metadata.dig('attributes', 'legend')
      end
    end

    if fields = ds_params[:filters]
      fields = JSON.parse fields

      # Removes the "variable" param and sets the filters
      @dataset_setting.filters =
        fields.map { |h| h.select { |k| k != 'variable' } }

      # Sets the changeable fields from the params
      @dataset_setting.set_columns_changeable(
        fields.map { |h| h['name'] if h['variable'] == true }.compact
      )
    end

    if fields = ds_params[:visible_fields]
      @dataset_setting.columns_visible = fields.to_json
    end

    if fields = ds_params[:widgets]
      @dataset_setting.widgets = fields
    end
  end
# Builds the current dataset setting based on the database, session and params
Builds the current dataset setting based on the database, session and params
Builds the current dataset setting based on the database session and params
def build_current_dataset_setting
    ds_params = {}
    ds_params = page_params.to_h[:dataset_setting] if params[:site_page] && page_params.to_h && page_params.to_h[:dataset_setting]
    @dataset_setting = nil
    if ds_params[:id]
      @dataset_setting = DatasetSetting.find(ds_params[:id])
    elsif @page.dataset_setting
      @dataset_setting = @page.dataset_setting
    else
      @dataset_setting = DatasetSetting.new
      @page.dataset_setting = @dataset_setting
    end
    @dataset_setting.assign_attributes session[:dataset_setting][@page_id] if session[:dataset_setting][@page_id]
    if ds_id = ds_params[:dataset_id]
      if @dataset_setting.dataset_id && @dataset_setting.dataset_id != ds_id
        delete_session_key(:dataset_setting, @page_id)
        session[:invalid_steps][@page_id] = %w[type columns preview]
        @dataset_setting.filters = @dataset_setting.columns_changeable = @dataset_setting.columns_visible = nil
      end
      @dataset_setting.assign_attributes(dataset_id: ds_id)
      ds_metadata = @dataset_setting.metadata['data'].first
      if ds_metadata
        @dataset_setting.api_table_name = ds_metadata.dig('attributes', 'tableName')
        @dataset_setting.legend = ds_metadata.dig('attributes', 'legend')
      end
    end
    if fields = ds_params[:filters]
      fields = JSON.parse fields
      @dataset_setting.filters =
        fields.map { |h| h.select { |k| k != 'variable' } }
      @dataset_setting.set_columns_changeable(
        fields.map { |h| h['name'] if h['variable'] == true }.compact
      )
    end
    if fields = ds_params[:visible_fields]
      @dataset_setting.columns_visible = fields.to_json
    end
    if fields = ds_params[:widgets]
      @dataset_setting.widgets = fields
    end
  end
def build_current_dataset_setting ds_params = { } ds_params = page_params . to_h [ :dataset_setting ] if params [ :site_page ] && page_params . to_h && page_params . to_h [ :dataset_setting ] @dataset_setting = nil if ds_params [ :id ] @dataset_setting = DatasetSetting . find ( ds_params [ :id ] ) elsif @page . dataset_setting @dataset_setting = @page . dataset_setting else @dataset_setting = DatasetSetting . new @page . dataset_setting = @dataset_setting end @dataset_setting . assign_attributes session [ :dataset_setting ] [ @page_id ] if session [ :dataset_setting ] [ @page_id ] if ds_id = ds_params [ :dataset_id ] if @dataset_setting . dataset_id && @dataset_setting . dataset_id != ds_id delete_session_key ( :dataset_setting , @page_id ) session [ :invalid_steps ] [ @page_id ] = %w[ type columns preview ] @dataset_setting . filters = @dataset_setting . columns_changeable = @dataset_setting . columns_visible = nil end @dataset_setting . assign_attributes ( dataset_id : ds_id ) ds_metadata = @dataset_setting . metadata [ 'data' ] . first if ds_metadata @dataset_setting . api_table_name = ds_metadata . dig ( 'attributes' , 'tableName' ) @dataset_setting . legend = ds_metadata . dig ( 'attributes' , 'legend' ) end end if fields = ds_params [ :filters ] fields = JSON . parse fields @dataset_setting . filters = fields . map { | h | h . select { | k | k != 'variable' } } @dataset_setting . set_columns_changeable ( fields . map { | h | h [ 'name' ] if h [ 'variable' ] == true } . compact ) end if fields = ds_params [ :visible_fields ] @dataset_setting . columns_visible = fields . to_json end if fields = ds_params [ :widgets ] @dataset_setting . widgets = fields end end
Builds the current dataset setting based on the database, session and params
Builds the current dataset setting based on the database session and params
# If the user changed the id of the dataset, the entity is reset # Removes the "variable" param and sets the filters # Sets the changeable fields from the params