mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-09 05:18:01 +08:00
Merge pull request #7426 from wandji20/wb-SCI-10475
Add asset results to global search page [SCI-10475]
This commit is contained in:
commit
6ac5ad3d71
4 changed files with 136 additions and 3 deletions
|
@ -89,6 +89,23 @@ class SearchController < ApplicationController
|
||||||
next_page: (results.next_page if results.respond_to?(:next_page))
|
next_page: (results.next_page if results.respond_to?(:next_page))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
when 'assets'
|
||||||
|
@asset_search_count = fetch_cached_count(Protocol)
|
||||||
|
search_assets
|
||||||
|
includes = [{ step: { protocol: { my_module: :experiment } } }, { result: { my_module: :experiment } }, :team]
|
||||||
|
results = if params[:preview] == 'true'
|
||||||
|
@asset_results.limit(Constants::GLOBAL_SEARCH_PREVIEW_LIMIT)
|
||||||
|
else
|
||||||
|
@asset_results.page(params[:page]).per(Constants::SEARCH_LIMIT)
|
||||||
|
end
|
||||||
|
|
||||||
|
render json: results.includes(includes),
|
||||||
|
each_serializer: GlobalSearch::AssetSerializer,
|
||||||
|
meta: {
|
||||||
|
total: @search_count,
|
||||||
|
next_page: (results.next_page if results.respond_to?(:next_page))
|
||||||
|
}
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
#@search_id = params[:search_id] ? params[:search_id] : generate_search_id
|
#@search_id = params[:search_id] ? params[:search_id] : generate_search_id
|
||||||
|
@ -395,7 +412,7 @@ class SearchController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_assets
|
def search_assets
|
||||||
@asset_results = []
|
@asset_results = Asset.none
|
||||||
@asset_results = search_by_name(Asset) if @asset_search_count.positive?
|
@asset_results = search_by_name(Asset) if @asset_search_count.positive?
|
||||||
@search_count = @asset_search_count
|
@search_count = @asset_search_count
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,14 +1,64 @@
|
||||||
<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-files"></i>
|
<i class="sn-icon sn-icon-files"></i>
|
||||||
{{ i18n.t('search.index.files') }}
|
{{ i18n.t('search.index.files') }}
|
||||||
|
[{{ total }}]
|
||||||
</h2>
|
</h2>
|
||||||
|
<div>
|
||||||
|
<div class="grid grid-cols-[auto_auto_auto_auto_auto_auto] items-center">
|
||||||
|
<template v-for="row in preparedResults" :key="row.id">
|
||||||
|
<a target="_blank" :href="row.attributes.parent.url"
|
||||||
|
class="h-full py-2 px-4 grid grid-cols-[auto_1fr] items-center gap-1 font-bold border-0 border-b border-solid border-sn-light-grey">
|
||||||
|
<span :class="row.attributes.icon" class="shrink-0"></span>
|
||||||
|
<StringWithEllipsis class="w-full" :text="row.attributes.file_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">
|
||||||
|
<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">
|
||||||
|
<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 target="_blank" :href="row.attributes.team.url" class="shrink-0 overflow-hidden">
|
||||||
|
<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.${row.attributes.parent.type}`) }}:</b>
|
||||||
|
<a target="_blank" :href="row.attributes.parent.url" class="shrink-0 overflow-hidden">
|
||||||
|
<StringWithEllipsis class="w-full" :text="row.attributes.parent.name"></StringWithEllipsis>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="s 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"
|
||||||
|
:class="{ 'invisible': !row.attributes.experiment.name }">
|
||||||
|
<b class="shrink-0">{{ i18n.t('search.index.experiment') }}:</b>
|
||||||
|
<a target="_blank" :href="row.attributes.experiment.url" class="shrink-0 overflow-hidden">
|
||||||
|
<StringWithEllipsis class="w-full" :text="row.attributes.experiment.name"></StringWithEllipsis>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
<div v-if="viewAll" class="mt-4">
|
||||||
|
<button class="btn btn-light" @click="$emit('selectGroup', 'AssetsComponent')">View all</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import searchMixin from './search_mixin';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'AssetsComponent'
|
name: 'AssetsComponent',
|
||||||
|
mixins: [searchMixin],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
group: 'assets'
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
61
app/serializers/global_search/asset_serializer.rb
Normal file
61
app/serializers/global_search/asset_serializer.rb
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module GlobalSearch
|
||||||
|
class AssetSerializer < ActiveModel::Serializer
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
|
include FileIconsHelper
|
||||||
|
attributes :id, :file_name, :icon, :created_at, :updated_at, :team, :parent, :experiment
|
||||||
|
|
||||||
|
def file_name
|
||||||
|
object.render_file_name
|
||||||
|
end
|
||||||
|
|
||||||
|
def icon
|
||||||
|
file_fa_icon_class(object)
|
||||||
|
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 team
|
||||||
|
{ name: object.team.name }
|
||||||
|
end
|
||||||
|
|
||||||
|
def experiment
|
||||||
|
return { name: '' } unless object.my_module
|
||||||
|
|
||||||
|
{
|
||||||
|
name: object.my_module.experiment.name,
|
||||||
|
url: my_modules_experiment_path(id: object.my_module.experiment.id, search: object.my_module.code)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def parent
|
||||||
|
parent = object.parent
|
||||||
|
if parent.is_a?(Result) && object.my_module
|
||||||
|
parent_type = 'task'
|
||||||
|
parent_name = object.my_module.name
|
||||||
|
parent_url = my_module_results_path(my_module_id: object.my_module.id)
|
||||||
|
elsif parent.is_a?(Step) && object.my_module
|
||||||
|
parent_type = 'task'
|
||||||
|
parent_name = object.my_module.name
|
||||||
|
parent_url = protocols_my_module_path(object.my_module.id)
|
||||||
|
elsif parent.is_a?(Step)
|
||||||
|
parent_type = 'protocol_template'
|
||||||
|
parent_name = parent.protocol.name || I18n.t('search.index.untitled_protocol')
|
||||||
|
parent_url = protocol_path(parent.protocol_id)
|
||||||
|
elsif parent.is_a?(RepositoryCell)
|
||||||
|
parent_type = 'inventory_item'
|
||||||
|
parent_name = parent.repository_row.name
|
||||||
|
parent_url = repository_repository_rows_path(repository_id: parent.repository_row.repository_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
{ name: parent_name, url: parent_url, type: parent_type }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -471,6 +471,11 @@ en:
|
||||||
team: "Team"
|
team: "Team"
|
||||||
folder: "Folder"
|
folder: "Folder"
|
||||||
project: "Project"
|
project: "Project"
|
||||||
|
experiment: "Experiment"
|
||||||
|
task: "Task"
|
||||||
|
untitled_protocol: 'Untitled protocol'
|
||||||
|
protocol_template: "Protocol template"
|
||||||
|
inventory_item: "Inventory item"
|
||||||
comments:
|
comments:
|
||||||
save_changes: "Save changes"
|
save_changes: "Save changes"
|
||||||
empty_state:
|
empty_state:
|
||||||
|
|
Loading…
Add table
Reference in a new issue