Cross Reference:
xref
: /
ontohub
/
app
/
models
/
history_entries_page.rb
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
history_entries_page.rb revision a66eb4e1f6b16b8225526ae69a09eb551a078895
class
HistoryEntriesPage
PER_PAGE
=
25
attr_reader
:
repository
, :
oid
, :
path
, :
current_file
, :
commits
def
self.find
(
opts
)
begin
new
(
opts
)
rescue
GitRepository
::
PathNotFoundError
nil
end
end
def
initialize
(
opts
)
@
repository
=
Repository.find
_by_path
(
opts
[:
repository_id
])
@
commit_id
=
self.class.compute
_ref
(
repository
,
opts
[:
ref
])
@
oid
=
commit_id
[:
oid
]
@
path
=
opts
[:
path
]
@
current_file
=
repository.get
_file
(
path
,
oid
)
if
path
&& !
repository.dir
?
(
path
)
@
page
=
opts
[:
page
].
nil
? ?
1
:
opts
[:
page
].
to_i
@
offset
=
page
>
0
?
(
page
-
1
)
*
PER_PAGE
:
0
@
commits
=
repository.commits
(
start_oid
:
oid
,
path
:
path
,
offset
:
offset
,
limit
:
PER_PAGE
)
end
def
grouped_commits
@
grouped_commits
||=
commits.group
_by
do
|c|
c.committer
[:
time
].
strftime
(
"%d.%m.%Y"
)
end.map
do
|k, v|
{
commits
: v,
date
: k}
end
end
def
paginated_array
Kaminari.paginate
_array
(
commits
,
total_count
:
ensure_next_page_exists
)
.
page
(
page
)
.
per
(
PER_PAGE
)
end
protected
attr_reader
:
commit_id
, :
page
, :
offset
def
self.compute
_ref
(
repository
,
ref
)
repository.commit
_id
(
ref
||
DEFAULT_BRANCH
)
end
def
ensure_next_page_exists
page
*
(
PER_PAGE
+
1
)
end
end