-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/open file in UI #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4f92b43
d81f6d3
9b43a59
d90e238
b9b512f
58ce1ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -39,8 +39,8 @@ <h3>Filer</h3> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <li th:each="file : ${files}" class="case-file-item file-row"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="case-file-info"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <span class="case-file-reference" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| th:text="${file.documentReference}">KS26-1-1</span> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <span class="case-file-reference" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| th:text="${file.documentReference}">KS26-1-1</span> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <span class="case-file-name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| th:text="${file.displayName}">dokument.pdf</span> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -56,10 +56,16 @@ <h3>Filer</h3> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Ladda ner | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </a> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <button th:if="${file.canDownload}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type="button" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| th:data-preview-url="@{/dashboard/case-management/case-records/{caseId}/files/{fileId}/preview-frame(caseId=${caseRecordId}, fileId=${file.id})}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title="Öppna fil" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onclick="togglePreview(this)">👁</button> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <span th:unless="${file.canDownload}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class="case-file-restricted-text"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Ingen behörighet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </span> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Ingen behörighet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </span> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <button type="button" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| th:attr="hx-delete=@{/dashboard/case-management/case-records/{caseId}/files/{fileId}(caseId=${caseRecordId}, fileId=${file.id})}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -71,4 +77,28 @@ <h3>Filer</h3> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </li> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </ul> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <script> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function togglePreview(btn) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const item = btn.closest('.case-file-item'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const existing = item.querySelector('.file-preview-frame'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (existing) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| existing.remove(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const url = btn.getAttribute('data-preview-url'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fetch(url) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .then(res => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!res.ok) throw new Error('Preview failed'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return res.text(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .then(html => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| item.insertAdjacentHTML('beforeend', html); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .catch(err => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error('Failed to load preview:', err); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+81
to
+101
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for the fetch request. The 🐛 Proposed fix with error handling <script>
function togglePreview(btn) {
const item = btn.closest('.case-file-item');
const existing = item.querySelector('.file-preview-frame');
if (existing) {
existing.remove();
return;
}
const url = btn.getAttribute('data-preview-url');
fetch(url)
- .then(res => res.text())
+ .then(res => {
+ if (!res.ok) throw new Error('Preview failed');
+ return res.text();
+ })
.then(html => {
item.insertAdjacentHTML('beforeend', html);
+ })
+ .catch(err => {
+ console.error('Failed to load preview:', err);
});
}
</script>📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </script> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <div th:fragment="frame" class="file-preview-frame"> | ||
| <iframe | ||
| th:src="@{/api/cases/{caseId}/files/{fileId}/preview(caseId=${caseId}, fileId=${fileId})}" | ||
| width="100%" | ||
| height="600px" | ||
| style="border: none;"> | ||
| </iframe> | ||
| </div> |
Uh oh!
There was an error while loading. Please reload this page.