mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-12-16 21:59:00 +08:00
Add task results to global search page [SCi-10474]
This commit is contained in:
parent
6e94650add
commit
e6741a79f5
3 changed files with 109 additions and 3 deletions
|
|
@ -101,6 +101,21 @@ class SearchController < ApplicationController
|
||||||
next_page: results.try(:next_page)
|
next_page: results.try(:next_page)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
when 'results'
|
||||||
|
@result_search_count = fetch_cached_count(Result)
|
||||||
|
search_results
|
||||||
|
results = if params[:preview] == 'true'
|
||||||
|
@result_results.limit(Constants::GLOBAL_SEARCH_PREVIEW_LIMIT)
|
||||||
|
else
|
||||||
|
@result_results.page(params[:page]).per(Constants::SEARCH_LIMIT)
|
||||||
|
end
|
||||||
|
render json: results.includes(my_module: { experiment: { project: :team } }),
|
||||||
|
each_serializer: GlobalSearch::ResultSerializer,
|
||||||
|
meta: {
|
||||||
|
total: @search_count,
|
||||||
|
next_page: results.try(:next_page)
|
||||||
|
}
|
||||||
|
return
|
||||||
when 'protocols'
|
when 'protocols'
|
||||||
@protocol_search_count = fetch_cached_count(Protocol)
|
@protocol_search_count = fetch_cached_count(Protocol)
|
||||||
search_protocols
|
search_protocols
|
||||||
|
|
@ -420,7 +435,7 @@ class SearchController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_results
|
def search_results
|
||||||
@result_results = []
|
@result_results = Result.none
|
||||||
@result_results = search_by_name(Result) if @result_search_count.positive?
|
@result_results = search_by_name(Result) if @result_search_count.positive?
|
||||||
@search_count = @result_search_count
|
@search_count = @result_search_count
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,63 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="bg-white rounded p-4 mb-4">
|
<div v-if="total" class="bg-white rounded p-4 mb-4">
|
||||||
<h2 class="flex items-center gap-2 mt-0 mb-4">
|
<h2 class="flex items-center gap-2 mt-0 mb-4">
|
||||||
<i class="sn-icon sn-icon-results"></i>
|
<i class="sn-icon sn-icon-results"></i>
|
||||||
{{ i18n.t('search.index.task_results') }}
|
{{ i18n.t('search.index.task_results') }}
|
||||||
|
[{{ total }}]
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<div class="grid grid-cols-[auto_auto_auto_auto_auto_auto] items-center">
|
||||||
|
<template v-for="row in preparedResults" :key="row.id">
|
||||||
|
<a :href="row.attributes.url" target="_blank" class="h-full py-2 px-4 overflow-hidden font-bold border-0 border-b border-solid border-sn-light-grey">
|
||||||
|
<StringWithEllipsis class="w-full" :text="row.attributes.name"></StringWithEllipsis>
|
||||||
|
</a>
|
||||||
|
<div class="h-full py-2 px-4 flex items-center gap-1 text-xs border-0 border-b border-solid border-sn-light-grey max-w-[200px]">
|
||||||
|
<b class="shrink-0">{{ i18n.t('search.index.created_at') }}:</b>
|
||||||
|
<span class="truncate">{{ row.attributes.created_at }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="h-full py-2 px-4 flex items-center gap-1 text-xs border-0 border-b border-solid border-sn-light-grey max-w-[200px]">
|
||||||
|
<b class="shrink-0">{{ i18n.t('search.index.updated_at') }}:</b>
|
||||||
|
<span class="truncate">{{ row.attributes.updated_at }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="h-full py-2 px-4 grid grid-cols-[auto_1fr] items-center gap-1 text-xs border-0 border-b border-solid border-sn-light-grey">
|
||||||
|
<b class="shrink-0">{{ i18n.t('search.index.team') }}:</b>
|
||||||
|
<a :href="row.attributes.team.url" class="shrink-0 overflow-hidden" target="_blank">
|
||||||
|
<StringWithEllipsis class="w-full" :text="row.attributes.team.name"></StringWithEllipsis>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="h-full py-2 px-4 grid grid-cols-[auto_1fr] items-center gap-1 text-xs border-0 border-b border-solid border-sn-light-grey">
|
||||||
|
<b class="shrink-0">{{ i18n.t('search.index.task') }}:</b>
|
||||||
|
<a :href="row.attributes.my_module.url" class="shrink-0 overflow-hidden" target="_blank">
|
||||||
|
<StringWithEllipsis class="w-full" :text="row.attributes.my_module.name"></StringWithEllipsis>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="h-full py-2 px-4 border-0 border-b border-solid border-sn-light-grey">
|
||||||
|
<div class="grid grid-cols-[auto_1fr] items-center gap-1 text-xs w-full">
|
||||||
|
<b class="shrink-0">{{ i18n.t('search.index.experiment') }}:</b>
|
||||||
|
<a :href="row.attributes.experiment.url" class="shrink-0 overflow-hidden" target="_blank">
|
||||||
|
<StringWithEllipsis class="w-full" :text="row.attributes.experiment.name"></StringWithEllipsis>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
<div v-if="viewAll" class="mt-4">
|
||||||
|
<button class="btn btn-light" @click="$emit('selectGroup', 'ResultsComponent')">View all</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import searchMixin from './search_mixin';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ResultsComponent'
|
name: 'ResultsComponent',
|
||||||
|
mixins: [searchMixin],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
group: 'results'
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
42
app/serializers/global_search/result_serializer.rb
Normal file
42
app/serializers/global_search/result_serializer.rb
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module GlobalSearch
|
||||||
|
class ResultSerializer < ActiveModel::Serializer
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
|
attributes :id, :name, :created_at, :updated_at, :team, :experiment, :my_module, :archived, :url
|
||||||
|
|
||||||
|
def team
|
||||||
|
{
|
||||||
|
name: object.my_module.experiment.project.team.name,
|
||||||
|
url: projects_path(team_id: object.my_module.experiment.project.team.id)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def experiment
|
||||||
|
{
|
||||||
|
name: object.my_module.experiment.name,
|
||||||
|
url: my_modules_experiment_path(object.my_module.experiment.id)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def my_module
|
||||||
|
{
|
||||||
|
name: object.my_module.name,
|
||||||
|
url: protocols_my_module_path(object.my_module.id)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def created_at
|
||||||
|
I18n.l(object.created_at, format: :full_date)
|
||||||
|
end
|
||||||
|
|
||||||
|
def updated_at
|
||||||
|
I18n.l(object.updated_at, format: :full_date)
|
||||||
|
end
|
||||||
|
|
||||||
|
def url
|
||||||
|
my_module_results_path(my_module_id: object.my_module.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Add table
Reference in a new issue