Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Sage Validation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
Sage Validation
Merge requests
!2
Feature/unit test for validations
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Feature/unit test for validations
feature/unit-test-for-validations
into
develop
Overview
0
Commits
9
Pipelines
0
Changes
5
Merged
Neda Moeini
requested to merge
feature/unit-test-for-validations
into
develop
4 weeks ago
Overview
0
Commits
9
Pipelines
0
Changes
5
Expand
0
0
Merge request reports
Viewing commit
144ca6ca
Show latest version
5 files
+
50
−
80
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
144ca6ca
Replace FormView with APIView
· 144ca6ca
Neda Moeini
authored
3 weeks ago
sage_validation/file_validator/templates/upload.html
+
15
−
43
Options
@@ -40,21 +40,18 @@
</div>
</div>
<script>
const
form
=
document
.
getElementById
(
'
uploadForm
'
);
const
fileInput
=
document
.
getElementById
(
'
fileInput
'
);
const
errorSection
=
document
.
getElementById
(
'
errorSection
'
);
const
errorList
=
document
.
getElementById
(
'
errorList
'
);
const
successSection
=
document
.
getElementById
(
'
successSection
'
);
const
successMessage
=
document
.
getElementById
(
'
successMessage
'
);
const
downloadSection
=
document
.
getElementById
(
'
downloadSection
'
);
const
downloadLink
=
document
.
getElementById
(
'
downloadLink
'
);
form
.
addEventListener
(
'
submit
'
,
async
function
(
e
)
{
document
.
getElementById
(
'
uploadForm
'
).
addEventListener
(
'
submit
'
,
async
function
(
e
)
{
e
.
preventDefault
();
// Clear previous messages
const
fileInput
=
document
.
getElementById
(
'
fileInput
'
);
const
errorSection
=
document
.
getElementById
(
'
errorSection
'
);
const
errorList
=
document
.
getElementById
(
'
errorList
'
);
const
successSection
=
document
.
getElementById
(
'
successSection
'
);
const
successMessage
=
document
.
getElementById
(
'
successMessage
'
);
const
downloadSection
=
document
.
getElementById
(
'
downloadSection
'
);
const
downloadLink
=
document
.
getElementById
(
'
downloadLink
'
);
errorList
.
innerHTML
=
''
;
successMessage
.
innerHTML
=
''
;
errorSection
.
classList
.
add
(
'
hidden
'
);
@@ -65,7 +62,7 @@
formData
.
append
(
'
file
'
,
fileInput
.
files
[
0
]);
try
{
const
response
=
await
fetch
(
''
,
{
const
response
=
await
fetch
(
"
{% url 'upload-file' %}
"
,
{
method
:
'
POST
'
,
body
:
formData
,
headers
:
{
@@ -81,38 +78,13 @@
downloadLink
.
href
=
result
.
download_url
;
downloadSection
.
classList
.
remove
(
'
hidden
'
);
}
else
if
(
response
.
status
===
400
&&
result
.
status
===
'
error
'
)
{
errorList
.
innerHTML
=
''
;
if
(
Array
.
isArray
(
result
.
errors
))
{
result
.
errors
.
forEach
(
errorObj
=>
{
if
(
typeof
errorObj
===
'
string
'
)
{
const
li
=
document
.
createElement
(
'
li
'
);
li
.
textContent
=
errorObj
;
errorList
.
appendChild
(
li
);
}
else
{
for
(
const
[
field
,
messages
]
of
Object
.
entries
(
errorObj
))
{
messages
.
forEach
(
message
=>
{
const
li
=
document
.
createElement
(
'
li
'
);
li
.
textContent
=
`
${
field
}
:
${
message
}
`
;
errorList
.
appendChild
(
li
);
});
}
}
for
(
const
[
field
,
messages
]
of
Object
.
entries
(
result
.
errors
))
{
messages
.
forEach
(
message
=>
{
const
li
=
document
.
createElement
(
'
li
'
);
li
.
textContent
=
`
${
field
}
:
${
message
}
`
;
errorList
.
appendChild
(
li
);
});
}
else
if
(
typeof
result
.
errors
===
'
object
'
)
{
for
(
const
[
field
,
messages
]
of
Object
.
entries
(
result
.
errors
))
{
messages
.
forEach
(
message
=>
{
const
li
=
document
.
createElement
(
'
li
'
);
li
.
textContent
=
`
${
field
}
:
${
message
}
`
;
errorList
.
appendChild
(
li
);
});
}
}
else
{
const
li
=
document
.
createElement
(
'
li
'
);
li
.
textContent
=
result
.
errors
;
errorList
.
appendChild
(
li
);
}
errorSection
.
classList
.
remove
(
'
hidden
'
);
}
}
catch
(
error
)
{
Loading