Skip to content

Commit 59a8576

Browse files
committed
Added Next/Previous buttons to file viewer when viewing from a dataset
1 parent ba6dd8d commit 59a8576

File tree

3 files changed

+84
-3
lines changed

3 files changed

+84
-3
lines changed

app/controllers/Files.scala

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,37 @@ class Files @Inject() (
220220
}
221221
}
222222

223+
224+
225+
//val fileList = files.
226+
val pager: Option[models.Pager] = dataset match {
227+
case None => None
228+
case Some(dsId) => {
229+
datasets.get(new UUID(dsId)) match {
230+
case None => None
231+
case Some(ds) => {
232+
val lastIndex = ds.files.length - 1
233+
val index = ds.files.indexOf(id)
234+
235+
// Set prevFile / nextFile, if applicable
236+
if (index > 0 && index < lastIndex) {
237+
// Yields UUID of prevFile and nextFile
238+
Some(Pager(Some(ds.files(index - 1)), Some(ds.files(index + 1))))
239+
}else if (index == 0 && index < lastIndex) {
240+
// This is the first file in the list, but not the last
241+
Some(Pager(None, Some(ds.files(index + 1))))
242+
} else if (index > 0 && index == lastIndex) {
243+
// This is the last file in the list, but not the first
244+
Some(Pager(Some(ds.files(index - 1)), None))
245+
} else {
246+
// There is one item on the list, disable paging
247+
None
248+
}
249+
}
250+
}
251+
}
252+
}
253+
223254
//call Polyglot to get all possible output formats for this file's content type
224255
current.plugin[PolyglotPlugin] match {
225256
case Some(plugin) => {
@@ -238,7 +269,7 @@ class Files @Inject() (
238269
plugin.getOutputFormats(contentTypeEnding).map(outputFormats =>
239270
Ok(views.html.file(file, id.stringify, commentsByFile, previewsWithPreviewer, sectionsWithPreviews,
240271
extractorsActive, decodedDatasetsContaining.toList, foldersContainingFile,
241-
mds, isRDFExportEnabled, extractionGroups, outputFormats, space, access, folderHierarchy.reverse.toList, decodedSpacesContaining.toList, allDecodedDatasets.toList, view_count, view_date)))
272+
mds, isRDFExportEnabled, extractionGroups, outputFormats, space, access, folderHierarchy.reverse.toList, decodedSpacesContaining.toList, allDecodedDatasets.toList, view_count, view_date, pager)))
242273
}
243274
case None =>
244275
Logger.debug("Polyglot plugin not found")
@@ -249,7 +280,7 @@ class Files @Inject() (
249280
//passing None as the last parameter (list of output formats)
250281
Future(Ok(views.html.file(file, id.stringify, commentsByFile, previewsWithPreviewer, sectionsWithPreviews,
251282
extractorsActive, decodedDatasetsContaining.toList, foldersContainingFile,
252-
mds, isRDFExportEnabled, extractionGroups, None, space, access, folderHierarchy.reverse.toList, decodedSpacesContaining.toList, allDecodedDatasets.toList, view_count, view_date)))
283+
mds, isRDFExportEnabled, extractionGroups, None, space, access, folderHierarchy.reverse.toList, decodedSpacesContaining.toList, allDecodedDatasets.toList, view_count, view_date, pager)))
253284
}
254285
}
255286

app/models/Pager.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package models
2+
3+
case class Pager(
4+
prev: Option[models.UUID],
5+
next: Option[models.UUID]
6+
)

app/views/file.scala.html

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
rdfExported: Boolean,
77
extractionsStatus: Map[String, ExtractionGroup], outputFormats: Option[List[String]], spaceId: Option[String], access:String,
88
folderHierarchy: List[Folder], spaces:List[ProjectSpace], allDatasets: List[Dataset],
9-
view_count: Int, view_date: java.util.Date)(implicit user: Option[models.User], request: RequestHeader)
9+
view_count: Int, view_date: java.util.Date, pager: Option[models.Pager])(implicit user: Option[models.User], request: RequestHeader)
1010

1111
@import helper._
1212
@import play.api.Play.current
@@ -588,6 +588,50 @@ <h4>Sections</h4>
588588
}
589589

590590

591+
@** Only enable paging when viewing from a dataset? *@
592+
@if(allDatasets.length == 1) {
593+
@allDatasets.map { ds =>
594+
@pager match {
595+
case None => {}
596+
case Some(pg) => {
597+
<div class="row bottom-padding">
598+
<div class="col-sm-12 col-md-12 col-lg-12">
599+
@pg.prev match {
600+
case None => {}
601+
case Some(prev) => {
602+
<a class="btn btn-sm btn-link pull-left" style="border-radius:15px;border-color:lightgray;" href="@routes.Files.file(prev, if(datasets.length > 0) {
603+
Some(datasets.head.id.stringify)
604+
} else {
605+
None
606+
}, spaceId, if(folders.length > 0) {
607+
Some(folders.head.id.stringify)
608+
} else {
609+
None
610+
})"><i class="glyphicon glyphicon-arrow-left"></i> Prev</a>
611+
}
612+
}
613+
@pg.next match {
614+
case None => {}
615+
case Some(next) => {
616+
<a class="btn btn-sm btn-link pull-right" style="border-radius:15px;border-color:lightgray;" href="@routes.Files.file(next, if(datasets.length > 0) {
617+
Some(datasets.head.id.stringify)
618+
} else {
619+
None
620+
}, spaceId, if(folders.length > 0) {
621+
Some(folders.head.id.stringify)
622+
} else {
623+
None
624+
})">Next <i class="glyphicon glyphicon-arrow-right"></i></a>
625+
}
626+
}
627+
628+
</div>
629+
</div>
630+
}
631+
}
632+
}
633+
}
634+
591635

592636
<div class="tabbable" id="bottomDatasetTabbable"> <!-- Only required for left/right tabs -->
593637
<ul class="nav nav-tabs margin-bottom-20" >

0 commit comments

Comments
 (0)