64 行
2.5 KiB
Ruby
64 行
2.5 KiB
Ruby
# Only confirmed combinations belong here; all others retain the existing behaviour.
|
|
class CountsDefaults
|
|
POST_COLUMNS = ['resource_id', 'version_no', 'is_latest', 'title', 'url',
|
|
'thumbnail_base', 'tags', 'parents', 'original_created_from',
|
|
'original_created_before', 'event_type', 'user', 'created_at'].freeze
|
|
|
|
def self.entries(resource)
|
|
result = [{ definition: 'history', mode: 'summary', params: {
|
|
'rows' => 'created_at:month',
|
|
'cols' => 'event_type',
|
|
'sort' => 'a0:desc', 'conditions' => '' } }]
|
|
result << { definition: 'latest', mode: 'summary', params: {
|
|
'rows' => '', 'cols' => '', 'conditions' => '', 'tags' => '' } }
|
|
details = detail_params(resource)
|
|
if details
|
|
['latest', 'history'].each do |definition|
|
|
result << { definition:, mode: 'details', params: details }
|
|
end
|
|
end
|
|
result
|
|
end
|
|
|
|
def self.detail_params(resource)
|
|
if resource == 'posts'
|
|
return { 'columns' => POST_COLUMNS.join(' '), 'order' => POST_COLUMNS.join(' '),
|
|
'children' => 'tags.name parents.id', 'nested_json' => '0',
|
|
'conditions' => '', 'tags' => '' }
|
|
end
|
|
unless resource == 'tags'
|
|
return { 'columns' => CountsExportProjection.default_columns(resource).join(' '),
|
|
'children' => CountsExportProjection.default_children(resource).join(' ') }
|
|
end
|
|
|
|
columns = ['resource_id', 'version_no', 'is_latest', 'name', 'category',
|
|
'aliases', 'parents', 'deprecated', 'event_type', 'user', 'created_at']
|
|
{ 'columns' => columns.join(' '), 'order' => columns.join(' '),
|
|
'children' => 'aliases.name parents.name', 'nested_json' => '0' }
|
|
end
|
|
|
|
def self.for(params)
|
|
settings = entries(params.fetch('resource', 'posts')).find do |entry|
|
|
entry[:definition] == params.fetch('definition', 'latest') &&
|
|
entry[:mode] == params.fetch('mode', 'summary')
|
|
end&.fetch(:params) || {}
|
|
if settings.key?('sort') && params.key?('rows')
|
|
actual = QueryState.axes(params['rows'])
|
|
expected = QueryState.axes(settings.fetch('rows'))
|
|
compatible = actual.is_a?(Array) && actual.first.is_a?(Hash) &&
|
|
actual.first['field'] == expected.first['field'] &&
|
|
actual.first.fetch('grain', 'month') == expected.first['grain']
|
|
unless compatible
|
|
settings = settings.except('sort')
|
|
end
|
|
end
|
|
settings
|
|
end
|
|
|
|
def self.metadata(resource)
|
|
entries(resource).map do |entry|
|
|
entry.merge(params: entry[:params].map { |key, value| { key:, value: } })
|
|
end
|
|
end
|
|
end
|