-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a result browser for the temp folder
- Loading branch information
Showing
8 changed files
with
197 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.gw.web; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.core.io.UrlResource; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
import com.gw.utils.BaseTool; | ||
|
||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
import java.nio.file.*; | ||
import java.util.stream.Collectors; | ||
import java.util.List; | ||
|
||
@Controller | ||
public class ResultBrowserController { | ||
|
||
@Autowired BaseTool bt; | ||
|
||
// Inject the directory path from application.properties | ||
|
||
// Endpoint to list image files in the directory | ||
@GetMapping("/results") | ||
@ResponseBody | ||
public List<String> listImageFiles() throws IOException { | ||
String resultfolder = bt.getFileTransferFolder(); | ||
Path rootLocation = Paths.get(resultfolder); | ||
return Files.walk(rootLocation, 1) // 1: only files in the current folder | ||
.filter(Files::isRegularFile) | ||
.map(path -> path.getFileName().toString()) // Return file names | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
// Endpoint to serve images by filename | ||
@GetMapping("/results/{filename:.+}") | ||
@ResponseBody | ||
public ResponseEntity<Resource> serveFile(@PathVariable String filename) { | ||
try { | ||
String resultfolder = bt.getFileTransferFolder(); | ||
Path file = Paths.get(resultfolder).resolve(filename); | ||
Resource resource = new UrlResource(file.toUri()); | ||
if (resource.exists() || resource.isReadable()) { | ||
return ResponseEntity.ok() | ||
.header(HttpHeaders.CONTENT_DISPOSITION, | ||
"inline; filename=\"" + filename + "\"") | ||
.body(resource); | ||
} else { | ||
throw new RuntimeException("Could not read file: " + filename); | ||
} | ||
} catch (MalformedURLException e) { | ||
throw new RuntimeException("Could not read file: " + filename, e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
GW.result.browser = { | ||
|
||
init: function () { | ||
|
||
GW.result.browser.loadFileList(); | ||
|
||
}, | ||
|
||
loadFileList: function() { | ||
$.ajax({ | ||
url: '/Geoweaver/results', | ||
method: 'GET', | ||
success: function(data) { | ||
// Populate the file list | ||
$('#result-file-list').empty(); | ||
data.forEach(function(filename) { | ||
$('#result-file-list').append(` | ||
<li class="list-group-item file-item" data-filename="${filename}">${filename}</li> | ||
`); | ||
}); | ||
|
||
// Add click event to each file item | ||
$('.file-item').click(function() { | ||
let selectedFile = $(this).data('filename'); | ||
GW.result.browser.previewFile(selectedFile); | ||
}); | ||
}, | ||
error: function(err) { | ||
console.error("Error fetching file list", err); | ||
} | ||
}); | ||
}, | ||
|
||
previewFile: function(filename) { | ||
// Determine if file is an image or text based on file extension | ||
const isImage = /\.(jpg|jpeg|png|gif)$/.test(filename); | ||
|
||
if (isImage) { | ||
// Display image | ||
$('#image-preview').attr('src', `/Geoweaver/results/${filename}`).show(); | ||
$('#text-preview').hide(); | ||
} else { | ||
// Display text content | ||
$.ajax({ | ||
url: `/Geoweaver/results/${filename}`, | ||
method: 'GET', | ||
success: function(data) { | ||
$('#text-preview').text(data).show(); | ||
$('#image-preview').hide(); | ||
}, | ||
error: function(err) { | ||
console.error("Error fetching file content", err); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/resources/templates/fragments/content/workspace/result-browser.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
<div id="main-result" class="tabcontent" style="height:100%; left:0; margin:0; padding: 0;padding-bottom:0px;"> | ||
<div id="main-result-content" style="width:100%; height:100%; overflow-y: scroll; padding: 10px; "> | ||
<div class="container-fluid"> | ||
<div class="row result-full-height"> | ||
<!-- Left Panel: Full height and scrollable --> | ||
<div id="left-panel" class="col-md-4"> | ||
<ul class="result-list-group" id="result-file-list"> | ||
<!-- Files will be populated here dynamically --> | ||
<!-- Add more items as needed --> | ||
</ul> | ||
</div> | ||
|
||
<!-- Right Panel: Preview Section --> | ||
<div id="right-panel" class="col-md-8"> | ||
<div id="result-file-preview" class="result-card"> | ||
<div class="result-card-body"> | ||
<img id="image-preview" class="img-fluid" style="display: none;" /> | ||
<pre id="text-preview" style="display: none;"></pre> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters