Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: modify for frappe-search #269

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 32 additions & 31 deletions frontend/src/pages/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
v-if="$resources.search.params && $resources.search.data"
class="mt-4 text-base font-semibold text-gray-800"
>
About {{ $resources.search.data.total }} results for "{{
{{ $resources.search.data.total }} results for "{{
$resources.search.params?.query
}}" ({{ $resources.search.data.duration.toFixed(2) }}
}}" (in about {{ $resources.search.data.duration.toFixed(2) }}
ms)
</div>
<div
Expand All @@ -39,26 +39,27 @@
v-for="group in $resources.search.data.groups"
:key="group.title"
>

<div class="mb-3 text-base text-gray-600">
{{ group.title }}
</div>
<router-link
v-for="item in group.items"
:key="item.name + item.via_comment"
:key="item.name"
:to="getRoute(item)"
class="block overflow-hidden rounded px-2.5 py-3 hover:bg-gray-100"
>
<div class="flex items-center">
<div class="text-base font-medium" v-html="item.title" />
<div class="flex items-center" v-if="item.highlighted_title || item.title">
<div class="text-base font-medium" v-html="item.highlighted_title || item.title" />
<span class="px-1 leading-none text-gray-600"> &middot; </span>
<div class="text-sm text-gray-600">
{{ timestamp(item) }}
</div>
</div>
<div
v-if="item.content"
v-if="item.highlighted_content"
class="mt-1 text-p-base text-gray-700"
v-html="trimContent(item.content)"
v-html="trimContent(item.highlighted_content.replaceAll('|||', '·'))"
></div>
</router-link>
</div>
Expand All @@ -83,35 +84,34 @@ export default {
resources: {
search: {
cache: 'Search',
url: 'gameplan.api.search',
url: 'frappe_search.api.search',
makeParams(query) {
return { query, start: this.start }
return { query, groupby: true, start: this.start }
},
transform(data) {
let out = {
groups: [],
total: data.total,
duration: data.duration,
}
for (let doctype in data.results) {
let group = null
if (doctype === 'GP Discussion') {
group = 'Discussions'
} else if (doctype === 'GP Task') {
group = 'Tasks'
} else if (doctype === 'GP Page') {
group = 'Pages'
}
if (!group) {
continue
for (let group in data.results) {
safwansamsudeen marked this conversation as resolved.
Show resolved Hide resolved
let title
if (group === 'GP Discussion') {
title = 'Discussions'
} else if (group === 'GP Task') {
title = 'Tasks'
} else if (group === 'GP Page') {
title = 'Pages'
} else if (group === 'GP Comment') {
title = 'Comments'
}
out.groups.push({
title: group,
items: data.results[doctype],
title,
items: data.results[group],
})
}
return out
},
}
},
},
methods: {
Expand All @@ -137,19 +137,20 @@ export default {
return content.slice(start, end)
},
timestamp(d) {
let timestamp = d.modified
let timestamp = new Date(d.fields.modified)
if (this.$dayjs().diff(timestamp, 'day') < 25) {
return this.$dayjs(timestamp).fromNow()
}
return this.$dayjs(timestamp).format('D MMM YYYY')
},
getRoute(item) {
getRoute(item) {
console.log(item)
if (item.doctype === 'GP Discussion') {
return {
name: 'ProjectDiscussion',
params: {
teamId: item.team,
projectId: item.project,
teamId: item.fields.team,
projectId: item.fields.project,
postId: item.name,
},
}
Expand All @@ -158,8 +159,8 @@ export default {
return {
name: item.project ? 'ProjectTaskDetail' : 'Task',
params: {
teamId: item.team,
projectId: item.project,
teamId: item.fields.team,
projectId: item.fields.project,
taskId: item.name,
},
}
Expand All @@ -168,8 +169,8 @@ export default {
return {
name: 'ProjectPage',
params: {
teamId: item.team,
projectId: item.project,
teamId: item.fields.team,
projectId: item.fields.project,
pageId: item.name,
},
}
Expand Down
61 changes: 39 additions & 22 deletions gameplan/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# Fixtures

fixtures = [
{"dt": "Role", "filters": [["role_name", "like", "Gameplan %"]]},
{"dt": "Role", "filters": [["role_name", "like", "Gameplan %"]]},
]

# Home Pages
Expand All @@ -51,15 +51,15 @@

# website user home page (by Role)
# role_home_page = {
# "Role": "home_page"
# "Role": "home_page"
# }

website_route_rules = [
{"from_route": "/g/<path:app_path>", "to_route": "g"},
{"from_route": "/g/<path:app_path>", "to_route": "g"},
]

website_redirects = [
{"source": r"/teams(/.*)?", "target": r"/g\1"},
{"source": r"/teams(/.*)?", "target": r"/g\1"},
]

# Generators
Expand Down Expand Up @@ -122,31 +122,27 @@
# Hook on document methods and events

doc_events = {
"*": {
"on_trash": "gameplan.mixins.on_delete.on_trash",
},
"User": {
"after_insert": "gameplan.gameplan.doctype.gp_user_profile.gp_user_profile.create_user_profile",
"on_trash": [
"gameplan.gameplan.doctype.gp_user_profile.gp_user_profile.delete_user_profile",
"gameplan.gameplan.doctype.gp_guest_access.gp_guest_access.on_user_delete",
],
"on_update": "gameplan.gameplan.doctype.gp_user_profile.gp_user_profile.on_user_update"
}
"*": {
"on_trash": "gameplan.mixins.on_delete.on_trash",
},
"User": {
"after_insert": "gameplan.gameplan.doctype.gp_user_profile.gp_user_profile.create_user_profile",
"on_trash": [
"gameplan.gameplan.doctype.gp_user_profile.gp_user_profile.delete_user_profile",
"gameplan.gameplan.doctype.gp_guest_access.gp_guest_access.on_user_delete",
],
"on_update": "gameplan.gameplan.doctype.gp_user_profile.gp_user_profile.on_user_update",
},
}

on_login = 'gameplan.www.g.on_login'
on_login = "gameplan.www.g.on_login"

# Scheduled Tasks
# ---------------

scheduler_events = {
"all": [
"gameplan.search.build_index_if_not_exists"
],
"hourly": [
"gameplan.gameplan.doctype.gp_invitation.gp_invitation.expire_invitations"
],
"all": ["gameplan.search.build_index_if_not_exists"],
"hourly": ["gameplan.gameplan.doctype.gp_invitation.gp_invitation.expire_invitations"],
}

# scheduler_events = {
Expand Down Expand Up @@ -229,3 +225,24 @@
# Recommended only for DocTypes which have limited documents with untranslated names
# For example: Role, Gender, etc.
# translated_search_doctypes = []

frappe_search_doctypes = {
safwansamsudeen marked this conversation as resolved.
Show resolved Hide resolved
"GP Discussion": {
"title": "title",
"content": ["content"],
safwansamsudeen marked this conversation as resolved.
Show resolved Hide resolved
"fields": ["team", "project", "modified"],
},
"GP Task": {
"title": "title",
"content": ["description"],
"fields": ["team", "project", "modified"],
},
"GP Page": {
"title": "title",
"content": ["content"],
"fields": ["team", "project", "modified"],
},
"GP Comment": {
"content": ["content"],
},
}