[BS5] move showWhatsNewModal

This commit is contained in:
FreddleSpl0it 2022-08-23 14:24:10 +02:00
parent a3ddb58566
commit 77e6124b00
8 changed files with 79 additions and 76 deletions

View File

@ -111,8 +111,7 @@ $template_data = [
'password_complexity' => password_complexity('get'), 'password_complexity' => password_complexity('get'),
'show_rspamd_global_filters' => @$_SESSION['show_rspamd_global_filters'], 'show_rspamd_global_filters' => @$_SESSION['show_rspamd_global_filters'],
'lang_admin' => json_encode($lang['admin']), 'lang_admin' => json_encode($lang['admin']),
'lang_datatables' => json_encode($lang['datatables']), 'lang_datatables' => json_encode($lang['datatables'])
'last_login' => last_login('get', $_SESSION['mailcow_cc_username'], 7, 0)['ui']['time']
]; ];
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php';

View File

@ -48,6 +48,7 @@ $globalVariables = [
'app_links' => customize('get', 'app_links'), 'app_links' => customize('get', 'app_links'),
'is_root_uri' => (parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) == '/'), 'is_root_uri' => (parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) == '/'),
'uri' => $_SERVER['REQUEST_URI'], 'uri' => $_SERVER['REQUEST_URI'],
'last_login' => last_login('get', $_SESSION['mailcow_cc_username'], 7, 0)['ui']['time']
]; ];
foreach ($globalVariables as $globalVariableName => $globalVariableValue) { foreach ($globalVariables as $globalVariableName => $globalVariableValue) {

View File

@ -343,6 +343,65 @@ $(document).ready(function() {
localStorage.setItem('darkmode', 'true'); 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;
}
}); });

View File

@ -794,61 +794,4 @@ jQuery(function($){
$('#add_f2b_regex_row').click(function() { $('#add_f2b_regex_row').click(function() {
add_table_row($('#f2b_regex_table'), "f2b_regex"); add_table_row($('#f2b_regex_table'), "f2b_regex");
}); });
// show whats new modal
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 = parseLinks(result);
$('#showWhatsNew').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("showWhatsNew"), {
backdrop: 'static',
keyboard: false
}).show();
}
function parseLinks(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;
}
}); });

View File

@ -70,6 +70,5 @@ var admin_username = '{{ mailcow_cc_username }}';
var csrf_token = '{{ csrf_token }}'; var csrf_token = '{{ csrf_token }}';
var pagination_size = '{{ pagination_size }}'; var pagination_size = '{{ pagination_size }}';
var log_pagination_size = '{{ log_pagination_size }}'; var log_pagination_size = '{{ log_pagination_size }}';
var last_login = '{{ last_login }}';
</script> </script>
{% endblock %} {% endblock %}

View File

@ -135,6 +135,8 @@
var lang_tfa = {{ lang_tfa|raw }}; var lang_tfa = {{ lang_tfa|raw }};
var lang_fido2 = {{ lang_fido2|raw }}; var lang_fido2 = {{ lang_fido2|raw }};
var docker_timeout = {{ docker_timeout|raw }} * 1000; var docker_timeout = {{ docker_timeout|raw }} * 1000;
var mailcow_cc_role = '{{ mailcow_cc_role }}';
var last_login = '{{ last_login }}';
var mailcow_info = { var mailcow_info = {
version_tag: '{{ mailcow_info.version_tag }}', version_tag: '{{ mailcow_info.version_tag }}',
last_version_tag: '{{ mailcow_info.last_version_tag }}', last_version_tag: '{{ mailcow_info.last_version_tag }}',

View File

@ -261,19 +261,3 @@
</div> </div>
</div> </div>
</div><!-- priv key modal --> </div><!-- priv key modal -->
<!-- whats new modal -->
<div class="modal fade" id="showWhatsNew" 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>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body d-flex flex-column mt-2 p-4">
<div class="spinner-border mx-auto" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
</div>
</div>
</div><!-- whats new modal -->

View File

@ -238,3 +238,19 @@
</div> </div>
</div> </div>
</div> </div>
<!-- whats new modal -->
<div class="modal fade" id="showWhatsNewModal" 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>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body d-flex flex-column mt-2 p-4">
<div class="spinner-border mx-auto" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
</div>
</div>
</div><!-- whats new modal -->