Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PropTrackr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
kerdo
PropTrackr
Commits
34129b22
Commit
34129b22
authored
4 months ago
by
Kerdo Kurs
Browse files
Options
Downloads
Patches
Plain Diff
add implementation for similar properties
#28
parent
c6ae7755
No related branches found
No related tags found
1 merge request
!19
Resolve "FR-18: Display Similar Properties on Listing View"
Pipeline
#45369
passed
4 months ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/proptrackr_web/controllers/properties_controller.ex
+20
-1
20 additions, 1 deletion
lib/proptrackr_web/controllers/properties_controller.ex
lib/proptrackr_web/controllers/properties_html/show.html.heex
+26
-0
26 additions, 0 deletions
...proptrackr_web/controllers/properties_html/show.html.heex
with
46 additions
and
1 deletion
lib/proptrackr_web/controllers/properties_controller.ex
+
20
−
1
View file @
34129b22
...
...
@@ -57,10 +57,13 @@ defmodule PropTrackrWeb.PropertiesController do
)
end
similar_properties
=
get_similar_properties
(
property
)
render
(
conn
,
"show.html"
,
property:
property
,
can_edit:
can_edit
,
favorites:
favorites
favorites:
favorites
,
similar_properties:
similar_properties
,
)
end
end
...
...
@@ -181,4 +184,20 @@ defmodule PropTrackrWeb.PropertiesController do
end
end
end
defp
get_similar_properties
(
property
)
do
Repo
.
all
(
from
p
in
Property
,
where:
p
.
state
==
:available
and
p
.
id
!=
^
property
.
id
,
order_by:
[
desc:
fragment
(
"abs(? - ?)"
,
p
.
price
,
^
property
.
price
),
desc:
fragment
(
"abs(? - ?)"
,
p
.
room_count
,
^
property
.
room_count
),
desc:
fragment
(
"abs(? - ?)"
,
p
.
area
,
^
property
.
area
),
desc:
fragment
(
"abs(? - ?)"
,
p
.
floor
,
^
property
.
floor
)
],
limit:
5
,
select:
p
)
end
end
This diff is collapsed.
Click to expand it.
lib/proptrackr_web/controllers/properties_html/show.html.heex
+
26
−
0
View file @
34129b22
...
...
@@ -103,4 +103,30 @@
<p
class=
"text-sm text-gray-600"
>
Email:
<%=
@property
.
user
.
email
%>
</p>
</div>
</div>
<div
class=
"bg-white shadow rounded-lg p-6"
>
<h3
class=
"text-lg font-medium text-gray-900"
>
Similar properties
</h3>
<div
class=
"mt-4"
>
<%=
if
@similar_properties
==
[]
do
%>
<p
class=
"text-sm text-gray-600"
>
No similar properties found
</p>
<%
else
%>
<%=
for
property
<-
@similar_properties
do
%>
<div
class=
"flex items-center justify-between mt-4"
>
<div>
<p
class=
"text-sm text-gray-600"
>
<%=
property
.
title
%>
</p>
<p
class=
"text-sm text-gray-600"
>
<%=
:erlang
.
float_to_binary
(
property
.
price
,
decimals:
2
)
%>
€
</p>
<p
class=
"text-sm text-gray-600"
>
<%=
property
.
location
%>
</p>
</div>
<a
href=
{~p"/properties/#{property.reference}"}
class=
"text-sm text-blue-600 hover:underline"
id=
{"view-similar-property-#{property.reference}"}
>
View
</a>
</div>
<%
end
%>
<%
end
%>
</div>
</div>
</div>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment