Skip to content

Commit aedcdf2

Browse files
committed
Merge branch 'develop' into filtering-on-dataset-files
# Conflicts: # CHANGELOG.md
2 parents 073a3d7 + 6028f86 commit aedcdf2

File tree

4 files changed

+132
-35
lines changed

4 files changed

+132
-35
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ of these changes a reindex of Elasticsearch is required. This can be started by
1616
- Ability to search by creator name and email address for all resources.
1717
- List Spaces/Datasets/Collections created by each user on their User Profile.
1818
[CATS-1056](https://opensource.ncsa.illinois.edu/jira/browse/CATS-1056)
19+
- Allow user to easily flip through the files in a dataset.
20+
[CATS-1058](https://opensource.ncsa.illinois.edu/jira/browse/CATS-1058)
1921
- Ability to filter the files and folders in a dataset when sorting is enabled.
2022

2123
### Fixed
22-
- Ability to delete tags on file page.
23-
[CATS-1042](https://opensource.ncsa.illinois.edu/jira/browse/CATS-1042)
2424
- When adding tags to a section of an image, show the new tag without having to refresh the page.
2525
[CATS-1053](https://opensource.ncsa.illinois.edu/jira/browse/CATS-1053)
2626

app/controllers/Files.scala

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

223+
val pager: models.Pager = dataset match {
224+
case None => Pager(None, None)
225+
case Some(dsId) => {
226+
datasets.get(new UUID(dsId)) match {
227+
case None => Pager(None, None)
228+
case Some(ds) => {
229+
val lastIndex = ds.files.length - 1
230+
val index = ds.files.indexOf(id)
231+
232+
// Set prevFile / nextFile, if applicable
233+
if (index > 0 && index < lastIndex) {
234+
// Yields UUID of prevFile and nextFile respectively
235+
Pager(Some(ds.files(index + 1)), Some(ds.files(index - 1)))
236+
}else if (index == 0 && index < lastIndex) {
237+
// This is the first file in the list, but not the last
238+
Pager(Some(ds.files(index + 1)), None)
239+
} else if (index > 0 && index == lastIndex) {
240+
// This is the last file in the list, but not the first
241+
Pager(None, Some(ds.files(index - 1)))
242+
} else {
243+
// There is one item on the list, disable paging
244+
Pager(None, None)
245+
}
246+
}
247+
}
248+
}
249+
}
250+
223251
//call Polyglot to get all possible output formats for this file's content type
224252
current.plugin[PolyglotPlugin] match {
225253
case Some(plugin) => {
@@ -238,7 +266,7 @@ class Files @Inject() (
238266
plugin.getOutputFormats(contentTypeEnding).map(outputFormats =>
239267
Ok(views.html.file(file, id.stringify, commentsByFile, previewsWithPreviewer, sectionsWithPreviews,
240268
extractorsActive, decodedDatasetsContaining.toList, foldersContainingFile,
241-
mds, isRDFExportEnabled, extractionGroups, outputFormats, space, access, folderHierarchy.reverse.toList, decodedSpacesContaining.toList, allDecodedDatasets.toList, view_count, view_date)))
269+
mds, isRDFExportEnabled, extractionGroups, outputFormats, space, access, folderHierarchy.reverse.toList, decodedSpacesContaining.toList, allDecodedDatasets.toList, view_count, view_date, pager)))
242270
}
243271
case None =>
244272
Logger.debug("Polyglot plugin not found")
@@ -249,7 +277,7 @@ class Files @Inject() (
249277
//passing None as the last parameter (list of output formats)
250278
Future(Ok(views.html.file(file, id.stringify, commentsByFile, previewsWithPreviewer, sectionsWithPreviews,
251279
extractorsActive, decodedDatasetsContaining.toList, foldersContainingFile,
252-
mds, isRDFExportEnabled, extractionGroups, None, space, access, folderHierarchy.reverse.toList, decodedSpacesContaining.toList, allDecodedDatasets.toList, view_count, view_date)))
280+
mds, isRDFExportEnabled, extractionGroups, None, space, access, folderHierarchy.reverse.toList, decodedSpacesContaining.toList, allDecodedDatasets.toList, view_count, view_date, pager)))
253281
}
254282
}
255283

app/models/Pager.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package models
2+
3+
/**
4+
* A simple structure to assist in handling paging through a list of resources.
5+
* `prev` and `next` contain the ID of the previous and next resources (respectively).
6+
*
7+
* Currently this class is used for paging through files in a dataset, but could
8+
* be used to handle paging for any list of arbitrary UUIDs / resources in other contexts.
9+
*
10+
* See:
11+
* {@link views.files},
12+
* {@link controllers.Files#file}
13+
*
14+
* @param prev UUID of the previous resource in the list
15+
* @param next UUID of the next resource in the list
16+
*
17+
* @author lambert8
18+
*/
19+
case class Pager(
20+
prev: Option[models.UUID],
21+
next: Option[models.UUID]
22+
)

app/views/file.scala.html

Lines changed: 78 additions & 31 deletions
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: models.Pager)(implicit user: Option[models.User], request: RequestHeader)
1010

1111
@import helper._
1212
@import play.api.Play.current
@@ -156,41 +156,90 @@
156156
<div class="row">
157157
<div class="col-md-8 col-sm-8 col-lg-8">
158158
<div class="row">
159-
<ol class="breadcrumb">
160-
@if(spaces.length == 1 ) {
161-
<li><span class="glyphicon glyphicon-hdd"></span> <a href="@routes.Spaces.getSpace(spaces.head.id)" title="@spaces.head.name"> @Html(ellipsize(spaces.head.name, 18))</a></li>
159+
<div class="col-md-10 col-sm-10 col-lg-10">
162160

163-
} else {
164-
@if(spaces.length > 1) {
165-
<li>
166-
<span class="dropdown">
167-
<button class="btn-link dropdown-toggle" type="button" id="dropdown_space_list" data-toggle="dropdown"
168-
aria-haspopup="true" aria-expanded="true">
169-
<span class="glyphicon glyphicon-hdd"></span> <span class="caret"></span>
170-
</button>
171-
<ul class="dropdown-menu" arialanelledby="dropdown_space_list">
172-
@spaces.map{ s =>
173-
<li><a href="@routes.Spaces.getSpace(s.id)" title="s.name"><span class="glyphicon glyphicon-hdd"></span> @Html(ellipsize(s.name, 18))</a></li>
174-
}
175-
</ul>
161+
<ol class="breadcrumb">
162+
@if(spaces.length == 1 ) {
163+
<li><span class="glyphicon glyphicon-hdd"></span> <a href="@routes.Spaces.getSpace(spaces.head.id)" title="@spaces.head.name"> @Html(ellipsize(spaces.head.name, 18))</a></li>
176164

177-
</span>
178-
</li>
179165
} else {
180-
<li><span class="glyphicon glyphicon-user"></span> <a href = "@routes.Profile.viewProfileUUID(file.author.id)"> @file.author.fullName</a></li>
166+
@if(spaces.length > 1) {
167+
<li>
168+
<span class="dropdown">
169+
<button class="btn-link dropdown-toggle" type="button" id="dropdown_space_list" data-toggle="dropdown"
170+
aria-haspopup="true" aria-expanded="true">
171+
<span class="glyphicon glyphicon-hdd"></span> <span class="caret"></span>
172+
</button>
173+
<ul class="dropdown-menu" arialanelledby="dropdown_space_list">
174+
@spaces.map{ s =>
175+
<li><a href="@routes.Spaces.getSpace(s.id)" title="s.name"><span class="glyphicon glyphicon-hdd"></span> @Html(ellipsize(s.name, 18))</a></li>
176+
}
177+
</ul>
178+
179+
</span>
180+
</li>
181+
} else {
182+
<li><span class="glyphicon glyphicon-user"></span> <a href = "@routes.Profile.viewProfileUUID(file.author.id)"> @file.author.fullName</a></li>
183+
}
181184
}
182-
}
183-
@if(allDatasets.length == 1 ) {
185+
@if(allDatasets.length == 1 ) {
186+
@allDatasets.map { ds =>
187+
<li> <span class="glyphicon glyphicon-briefcase"></span> <a href="@routes.Datasets.dataset(ds.id)" title="@ds.name"> @Html(ellipsize(ds.name, 18))</a></li>
188+
}
189+
}
190+
@folderHierarchy.map { fd =>
191+
<li><span class="glyphicon glyphicon-folder-close"></span> <a href="@routes.Datasets.dataset(allDatasets(0).id)#[email protected]" title="@fd.displayName">@Html(ellipsize(fd.displayName, 18))</a></li>
192+
}
193+
<li><span class="glyphicon glyphicon-file"></span> <span title="@file.filename">@Html(ellipsize(file.filename, 18))</span></li>
194+
195+
</ol>
196+
</div>
197+
<div class="col-md-2 col-sm-2 col-lg-2">
198+
@** Only enable paging when viewing from a dataset? *@
199+
@if(allDatasets.length == 1) {
184200
@allDatasets.map { ds =>
185-
<li> <span class="glyphicon glyphicon-briefcase"></span> <a href="@routes.Datasets.dataset(ds.id)" title="@ds.name"> @Html(ellipsize(ds.name, 18))</a></li>
201+
<div class="row bottom-padding">
202+
<div class="col-sm-12 col-md-12 col-lg-12">
203+
@pager.prev match {
204+
case None => {
205+
<button class="btn btn-sm btn-link disabled" title="This is the first file in this dataset" disabled="true" style="cursor:not-allowed;border-radius:15px;border-color:lightgray;"><i class="glyphicon glyphicon-chevron-left"></i> Prev</button>
206+
}
207+
case Some(prev) => {
208+
<a class="btn btn-sm btn-link" title="Previous file in this dataset" style="border-radius:15px;border-color:lightgray;" href="@routes.Files.file(prev, if(datasets.length > 0) {
209+
Some(datasets.head.id.stringify)
210+
} else {
211+
None
212+
}, spaceId, if(folders.length > 0) {
213+
Some(folders.head.id.stringify)
214+
} else {
215+
None
216+
})"><i class="glyphicon glyphicon-chevron-left"></i> Prev</a>
217+
}
218+
}
219+
@pager.next match {
220+
case None => {
221+
<button class="btn btn-sm btn-link disabled" title="This is the last file in this dataset" disabled="true" style="cursor:not-allowed;border-radius:15px;border-color:lightgray;">Next <i class="glyphicon glyphicon-chevron-right"></i></button>
222+
}
223+
case Some(next) => {
224+
<a class="btn btn-sm btn-link" title="Next file in this dataset" style="border-radius:15px;border-color:lightgray;" href="@routes.Files.file(next, if(datasets.length > 0) {
225+
Some(datasets.head.id.stringify)
226+
} else {
227+
None
228+
}, spaceId, if(folders.length > 0) {
229+
Some(folders.head.id.stringify)
230+
} else {
231+
None
232+
})">Next <i class="glyphicon glyphicon-chevron-right"></i></a>
233+
}
234+
}
235+
236+
</div>
237+
</div>
186238
}
187239
}
188-
@folderHierarchy.map { fd =>
189-
<li><span class="glyphicon glyphicon-folder-close"></span> <a href="@routes.Datasets.dataset(allDatasets(0).id)#[email protected]" title="@fd.displayName">@Html(ellipsize(fd.displayName, 18))</a></li>
190-
}
191-
<li><span class="glyphicon glyphicon-file"></span> <span title="@file.filename">@Html(ellipsize(file.filename, 18))</span></li>
192-
193-
</ol>
240+
</div>
241+
</div>
242+
<div class="row">
194243
<div id="file-name-div" class="file-title-div col-xs-12">
195244
<div id="prf-file-name" class="text-left inline">
196245
<h1 id="file-name-title" class="inline"> <span class="glyphicon glyphicon-file"></span> @Html(file.filename)</h1>
@@ -587,8 +636,6 @@ <h4>Sections</h4>
587636
}
588637
}
589638

590-
591-
592639
<div class="tabbable" id="bottomDatasetTabbable"> <!-- Only required for left/right tabs -->
593640
<ul class="nav nav-tabs margin-bottom-20" >
594641
<li role="presentation" class="active"><a href="#tab-metadata" role="tab" data-toggle="tab">Metadata </a></li>

0 commit comments

Comments
 (0)