Skip to content

Commit

Permalink
remove whats new modal & add changelog modal
Browse files Browse the repository at this point in the history
  • Loading branch information
FreddleSpl0it committed Nov 16, 2022
1 parent 0cdb1e6 commit 3ebd801
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 83 deletions.
60 changes: 0 additions & 60 deletions data/web/js/build/014-mailcow.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,66 +312,6 @@ $(document).ready(function() {
localStorage.setItem('darkmode', 'true');
}
}

// show whats new modal
if (mailcow_cc_role === "admin" || mailcow_cc_role === "domainadmin"){
if (mailcow_info.updatedAt > last_login){
var parsedSeenTimestamp = parseInt(localStorage.getItem("seenChangelog"));
if (!isNaN(parsedSeenTimestamp) && mailcow_info.updatedAt < parsedSeenTimestamp) {
console.log("changelog seen");
return;
}
$.ajax({
type: 'GET',
url: 'https://api.github.com/repos/' + mailcow_info.project_owner + '/' + mailcow_info.project_repo + '/releases/tags/' + mailcow_info.version_tag,
dataType: 'json',
success: function (data) {
var md = window.markdownit();
var result = md.render(data.body);
result = parseGithubMarkdownLinks(result);

$('#showWhatsNewModal').find(".modal-body").html(`
<h3>` + data.name + `</h3>
<span class="mt-4">` + result + `</span>
`);

localStorage.setItem("seenChangelog", Math.floor(Date.now() / 1000).toString());

new bootstrap.Modal(document.getElementById("showWhatsNewModal"), {
backdrop: 'static',
keyboard: false
}).show();
}
});

}
}

function parseGithubMarkdownLinks(inputText) {
var replacedText, replacePattern1;

replacePattern1 = /(\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
replacedText = inputText.replace(replacePattern1, (matched, index, original, input_string) => {
if (matched.includes('github.com')){
// return short link if it's github link
last_uri_path = matched.split('/');
last_uri_path = last_uri_path[last_uri_path.length - 1];

// adjust Full Changelog link to match last git version and new git version, if link is a compare link
if (matched.includes('/compare/') && mailcow_info.last_version_tag !== ''){
matched = matched.replace(last_uri_path, mailcow_info.last_version_tag + '...' + mailcow_info.version_tag);
last_uri_path = mailcow_info.last_version_tag + '...' + mailcow_info.version_tag;
}

return '<a href="' + matched + '" target="_blank">' + last_uri_path + '</a><br>';
};

// if it's not a github link, return complete link
return '<a href="' + matched + '" target="_blank">' + matched + '</a>';
});

return replacedText;
}
});


Expand Down
75 changes: 68 additions & 7 deletions data/web/js/site/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ $(document).ready(function() {
if (mailcow_info.branch === "master"){
check_update(mailcow_info.version_tag, mailcow_info.project_url);
}
$("#maiclow_version").click(function(){
if (mailcow_cc_role !== "admin" && mailcow_cc_role !== "domainadmin")
return;

showVersionModal("Version " + mailcow_info.version_tag, mailcow_info.version_tag);
})
// get public ips
get_public_ips();
update_container_stats();
Expand Down Expand Up @@ -1227,11 +1233,11 @@ function get_public_ips(){
}).then(function(data) {
console.log(data);

if (data){
// display host ips
// display host ips
if (data.ipv4)
$("#host_ipv4").text(data.ipv4);
if (data.ipv6)
$("#host_ipv6").text(data.ipv6);
}
});
}
// format hosts uptime seconds to readable string
Expand Down Expand Up @@ -1452,10 +1458,13 @@ function check_update(current_version, github_repo_url){
} else {
// update available
$("#mailcow_update").removeClass("text-danger text-success").addClass("text-warning");
$("#mailcow_update").html(
`<b>` + lang_debug.update_available + `
<a target="_blank" href="https://github.com/`+github_account+`/`+github_repo_name+`/releases/tag/`+latest_data.tag_name+`">`+latest_data.tag_name+`</a></b>`
);
$("#mailcow_update").html(lang_debug.update_available + ` <a href="#" id="mailcow_update_changelog">`+latest_data.tag_name+`</a>`);
$("#mailcow_update_changelog").click(function(){
if (mailcow_cc_role !== "admin" && mailcow_cc_role !== "domainadmin")
return;

showVersionModal("New Release " + latest_data.tag_name, latest_data.tag_name);
})
}
}).catch(err => {
// err
Expand All @@ -1470,3 +1479,55 @@ function check_update(current_version, github_repo_url){
$("#mailcow_update").html("<b>"+ lang_debug.update_failed +"</b>");
});
}
// show version changelog modal
function showVersionModal(title, version){
$.ajax({
type: 'GET',
url: 'https://api.github.com/repos/' + mailcow_info.project_owner + '/' + mailcow_info.project_repo + '/releases/tags/' + version,
dataType: 'json',
success: function (data) {
var md = window.markdownit();
var result = md.render(data.body);
result = parseGithubMarkdownLinks(result);

$('#showVersionModal').find(".modal-title").html(title);
$('#showVersionModal').find(".modal-body").html(`
<h3>` + data.name + `</h3>
<span class="mt-4">` + result + `</span>
<span><b>Github Link:</b>
<a target="_blank" href="https://github.com/` + mailcow_info.project_owner + `/` + mailcow_info.project_repo + `/releases/tag/` + version + `">` + version + `</a>
</span>
`);

new bootstrap.Modal(document.getElementById("showVersionModal"), {
backdrop: 'static',
keyboard: false
}).show();
}
});
}
function parseGithubMarkdownLinks(inputText) {
var replacedText, replacePattern1;

replacePattern1 = /(\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
replacedText = inputText.replace(replacePattern1, (matched, index, original, input_string) => {
if (matched.includes('github.com')){
// return short link if it's github link
last_uri_path = matched.split('/');
last_uri_path = last_uri_path[last_uri_path.length - 1];

// adjust Full Changelog link to match last git version and new git version, if link is a compare link
if (matched.includes('/compare/') && mailcow_info.last_version_tag !== ''){
matched = matched.replace(last_uri_path, mailcow_info.last_version_tag + '...' + mailcow_info.version_tag);
last_uri_path = mailcow_info.last_version_tag + '...' + mailcow_info.version_tag;
}

return '<a href="' + matched + '" target="_blank">' + last_uri_path + '</a><br>';
};

// if it's not a github link, return complete link
return '<a href="' + matched + '" target="_blank">' + matched + '</a>';
});

return replacedText;
}
18 changes: 6 additions & 12 deletions data/web/templates/debug.twig
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,13 @@
</tr>
<tr>
<td>Version</td>
<td class="text-break"><div>
<p><b>{{ mailcow_info.version_tag }}</b></p>
<p id="mailcow_update"></p>
</div></td>
</tr>
{% if mailcow_info.mailcow_branch|lower == "master" %}
<tr>
<td>Changelog</td>
<td class="text-break"><a href="{{ mailcow_info.project_url }}/releases/tag/{{ mailcow_info.version_tag }}" target="_blank">
{{ mailcow_info.project_url }}/releases/tag/{{ mailcow_info.version_tag }}
</a></td>
<td class="text-break">
<div class="fw-bolder">
<p ><a href="#" id="maiclow_version">{{ mailcow_info.version_tag }}</a></p>
<p id="mailcow_update"></p>
</div>
</td>
</tr>
{% endif %}
<tr>
<td>{{ lang.debug.current_time }}</td>
<td id="host_date" class="text-break">-</td>
Expand Down
8 changes: 4 additions & 4 deletions data/web/templates/modals/footer.twig
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,12 @@
</div>
</div>
</div>
<!-- whats new modal -->
<div class="modal fade" id="showWhatsNewModal" tabindex="-1" role="dialog" aria-hidden="true">
<!-- version modal -->
<div class="modal fade" id="showVersionModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">What's new?</h5>
<h5 class="modal-title"></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body d-flex flex-column mt-2 p-4">
Expand All @@ -362,4 +362,4 @@
</div>
</div>
</div>
</div><!-- whats new modal -->
</div><!-- version modal -->

0 comments on commit 3ebd801

Please sign in to comment.