Skip to content

Commit

Permalink
chg: [website] Replaced moment.js by Luxon.
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricbonhomme committed Jul 9, 2024
1 parent 53d6c25 commit 24ca924
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 60 deletions.
1 change: 1 addition & 0 deletions website/web/static/js/luxon.min.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions website/web/static/js/moment.min.js

This file was deleted.

5 changes: 3 additions & 2 deletions website/web/templates/bundles/bundles.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{ super() }}
<script src="{{ url_for('static', filename='js/showdown.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/lodash.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/moment.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/luxon.min.js') }}"></script>
{% endblock %}
{% block title %}Bundles{% endblock %}
{% block content %}
Expand All @@ -27,6 +27,7 @@ <h1>Recent bundles</h1>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
var DateTime = luxon.DateTime;
var converter = new showdown.Converter();
var bundleTemplate = _.template(
'<div class="card">' +
Expand Down Expand Up @@ -55,7 +56,7 @@ <h1>Recent bundles</h1>
'uuid': bundle.uuid,
'name': bundle.name,
'description': converter.makeHtml(bundle.description),
'timestamp': moment(bundle.timestamp).fromNow(),
'timestamp': DateTime.fromISO(bundle.timestamp).toRelative(),
'related_vulnerabilities': bundle.related_vulnerabilities,
'author_name': author.name,
'author_login': author.login
Expand Down
99 changes: 50 additions & 49 deletions website/web/templates/comments/comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{ super() }}
<script src="{{ url_for('static', filename='js/showdown.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/lodash.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/moment.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/luxon.min.js') }}"></script>
{% endblock %}
{% block title %}Comments{% endblock %}
{% block content %}
Expand All @@ -21,54 +21,55 @@ <h1>Recent comments</h1>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
var converter = new showdown.Converter()
var commentTemplate = _.template(
'<div class="card">' +
'<div class="card-body">' +
'<h5 class="card-title"><a href="/comment/<%= uuid %>"><%= title %></a> on <%= vulnerability_id %></h5>' +
'<h6 class="card-subtitle mb-2 text-body-secondary"><%= timestamp %> by <a href="/user/<%= author_login %>"><%= author_name %></a></h6>' +
'<p class="card-text"><%= description %></p>' +
'<% _.forEach(related_vulnerabilities, function(vuln) ' +
'{ %><a href="/vuln/<%= vuln %>"><%- vuln %></a> <% }); %><br />' +
'<a role="button" class="btn btn-primary" data-bs-toggle="collapse" data-bs-target="#collapseJsonComment<%= uuid %>" aria-expanded="false" aria-controls="collapseJsonComment<%= uuid %>">JSON</a>' +
'<div class="collapse" id="collapseJsonComment<%= uuid %>"><br /><pre class="json-container"><%= comment %></pre></div>' +
'<p class="card-text">More details about <a href="/vuln/<%= vulnerability_id %>"><%= vulnerability_id %></a>.</p>' +
'</div>');
fetch("{{ url_for('apiv1.comment_comments_list') }}")
.then(response => response.json())
.then(result => {
document.getElementById("list-comments").innerHTML = "";
if (result.metadata.count == 0) {
document.getElementById("list-comments").innerHTML = "<p>No comment.</p>";
}
result.data
.sort(function (a, b) {
return new Date(b.updated_at) - new Date(a.updated_at);
})
.map(function (comment) {
var author = comment.author
delete comment.author;
var cardHTML = commentTemplate({
'comment': JSON.stringify(comment, null, 2),
'uuid': comment.uuid,
'title': comment.title,
'description': converter.makeHtml(comment.description),
'timestamp': moment(comment.timestamp).fromNow(),
'vulnerability_id': comment.vulnerability,
'related_vulnerabilities': comment.related_vulnerabilities,
'author_name': author.name,
'author_login': author.login
});
var element = document.createElement("div");
var element_br = document.createElement("br");
element.innerHTML = cardHTML;
document.getElementById("list-comments").appendChild(element.firstChild);
document.getElementById("list-comments").append(element_br);
})
})
.catch((error) => {
console.error('Error:', error);
});
var DateTime = luxon.DateTime;
var converter = new showdown.Converter()
var commentTemplate = _.template(
'<div class="card">' +
'<div class="card-body">' +
'<h5 class="card-title"><a href="/comment/<%= uuid %>"><%= title %></a> on <%= vulnerability_id %></h5>' +
'<h6 class="card-subtitle mb-2 text-body-secondary"><%= timestamp %> by <a href="/user/<%= author_login %>"><%= author_name %></a></h6>' +
'<p class="card-text"><%= description %></p>' +
'<% _.forEach(related_vulnerabilities, function(vuln) ' +
'{ %><a href="/vuln/<%= vuln %>"><%- vuln %></a> <% }); %><br />' +
'<a role="button" class="btn btn-primary" data-bs-toggle="collapse" data-bs-target="#collapseJsonComment<%= uuid %>" aria-expanded="false" aria-controls="collapseJsonComment<%= uuid %>">JSON</a>' +
'<div class="collapse" id="collapseJsonComment<%= uuid %>"><br /><pre class="json-container"><%= comment %></pre></div>' +
'<p class="card-text">More details about <a href="/vuln/<%= vulnerability_id %>"><%= vulnerability_id %></a>.</p>' +
'</div>');
fetch("{{ url_for('apiv1.comment_comments_list') }}")
.then(response => response.json())
.then(result => {
document.getElementById("list-comments").innerHTML = "";
if (result.metadata.count == 0) {
document.getElementById("list-comments").innerHTML = "<p>No comment.</p>";
}
result.data
.sort(function (a, b) {
return new Date(b.updated_at) - new Date(a.updated_at);
})
.map(function (comment) {
var author = comment.author
delete comment.author;
var cardHTML = commentTemplate({
'comment': JSON.stringify(comment, null, 2),
'uuid': comment.uuid,
'title': comment.title,
'description': converter.makeHtml(comment.description),
'timestamp': DateTime.fromISO(comment.timestamp).toRelative(),
'vulnerability_id': comment.vulnerability,
'related_vulnerabilities': comment.related_vulnerabilities,
'author_name': author.name,
'author_login': author.login
});
var element = document.createElement("div");
var element_br = document.createElement("br");
element.innerHTML = cardHTML;
document.getElementById("list-comments").appendChild(element.firstChild);
document.getElementById("list-comments").append(element_br);
})
})
.catch((error) => {
console.error('Error:', error);
});
});
</script>
{% endblock %}
7 changes: 4 additions & 3 deletions website/web/templates/user/user.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{ super() }}
<script src="{{ url_for('static', filename='js/showdown.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/lodash.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/moment.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/luxon.min.js') }}"></script>
{% endblock %}
{% block title %}User: {{ user.login }}{% endblock %}
{% block content %}
Expand Down Expand Up @@ -67,6 +67,7 @@ <h3>Recent bundles</h3>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
var DateTime = luxon.DateTime;
var converter = new showdown.Converter()
var commentTemplate = _.template(
'<div class="card">' +
Expand All @@ -92,7 +93,7 @@ <h3>Recent bundles</h3>
'uuid': comment.uuid,
'title': comment.title,
'description': converter.makeHtml(comment.description),
'timestamp': moment(comment.timestamp).fromNow(),
'timestamp': DateTime.fromISO(comment.timestamp).toRelative(),
'vulnerability_id': comment.vulnerability,
});
var element = document.createElement("div");
Expand Down Expand Up @@ -139,7 +140,7 @@ <h3>Recent bundles</h3>
'uuid': bundle.uuid,
'name': bundle.name,
'description': converter.makeHtml(bundle.description),
'timestamp': moment(bundle.timestamp).fromNow(),
'timestamp': DateTime.fromISO(bundle.timestamp).toRelative(),
'related_vulnerabilities': bundle.related_vulnerabilities,
});
var element = document.createElement("div");
Expand Down
9 changes: 5 additions & 4 deletions website/web/templates/vuln.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{{ super() }}
<script src="{{ url_for('static', filename='js/showdown.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/lodash.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/moment.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/luxon.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/jsoneditor.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/pretty-print-json.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/easymde.min.js') }}"></script>
Expand Down Expand Up @@ -179,7 +179,6 @@ <h5 class="modal-title">Action not permitted</h5>
let COMMENTS = {};

document.addEventListener("DOMContentLoaded", function() {

var jsonContainers = document.querySelectorAll(".json-container");
Array.prototype.forEach.call(jsonContainers, function(jsonContainer) {
jsonContainer.innerHTML = prettyPrintJson.toHtml(JSON.parse(jsonContainer.innerText));
Expand Down Expand Up @@ -318,6 +317,7 @@ <h5 class="modal-title">Action not permitted</h5>
autoRefresh: { delay: 300 }
});
}
var DateTime = luxon.DateTime;
var converter = new showdown.Converter()
var commentTemplate = _.template(
'<div class="card">' +
Expand Down Expand Up @@ -352,7 +352,7 @@ <h5 class="modal-title">Action not permitted</h5>
'uuid': comment.uuid,
'title': comment.title,
'description': converter.makeHtml(comment.description),
'timestamp': moment(comment.timestamp).fromNow(),
'timestamp': DateTime.fromISO(comment.timestamp).toRelative(),
'related': comment.related_vulnerabilities,
'author_name': author.name,
'author_login': author.login
Expand Down Expand Up @@ -431,6 +431,7 @@ <h5 class="modal-title">Action not permitted</h5>
};

function loadBundles() {
var DateTime = luxon.DateTime;
var converter = new showdown.Converter()
var bundleTemplate = _.template(
'<div class="card">' +
Expand Down Expand Up @@ -464,7 +465,7 @@ <h5 class="modal-title">Action not permitted</h5>
'uuid': bundle.uuid,
'name': bundle.name,
'description': converter.makeHtml(bundle.description),
'timestamp': moment(bundle.timestamp).fromNow(),
'timestamp': DateTime.fromISO(bundle.timestamp).toRelative(),
'related_vulnerabilities': bundle.related_vulnerabilities,
'author_name': author.name,
'author_login': author.login
Expand Down

0 comments on commit 24ca924

Please sign in to comment.