Bladeren bron

remove whats new modal & add changelog modal

FreddleSpl0it 2 jaren geleden
bovenliggende
commit
3ebd801b3d
4 gewijzigde bestanden met toevoegingen van 78 en 83 verwijderingen
  1. 0 60
      data/web/js/build/014-mailcow.js
  2. 68 7
      data/web/js/site/debug.js
  3. 6 12
      data/web/templates/debug.twig
  4. 4 4
      data/web/templates/modals/footer.twig

+ 0 - 60
data/web/js/build/014-mailcow.js

@@ -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;
-  }
 });
 
 

+ 68 - 7
data/web/js/site/debug.js

@@ -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();
@@ -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
@@ -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
@@ -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;
+}

+ 6 - 12
data/web/templates/debug.twig

@@ -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>

+ 4 - 4
data/web/templates/modals/footer.twig

@@ -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">
@@ -362,4 +362,4 @@
       </div>
     </div>
   </div>
-</div><!-- whats new modal -->
+</div><!-- version modal -->