فهرست منبع

added js to render homepage item

Henry Whitaker 2 سال پیش
والد
کامیت
5222398d61
1فایلهای تغییر یافته به همراه107 افزوده شده و 0 حذف شده
  1. 107 0
      js/functions.js

+ 107 - 0
js/functions.js

@@ -9087,6 +9087,113 @@ function homepageMonitorr(timeout){
     timeouts[timeoutTitle] = setTimeout(function(){ homepageMonitorr(timeout); }, timeout);
     delete timeout;
 }
+function buildUptimeKumaItem(array){
+    var cards = '';
+    var options = array['options'];
+    var services = array['data'];
+    var tabName = '';
+
+    var buildCard = function(name, data) {
+        if(data.status == true) {
+            var statusColor = 'success'; var imageText = 'fa fa-check-circle text-success'
+        } else {
+            var statusColor = 'danger animated-3 loop-animation flash'; var imageText = 'fa fa-times-circle text-danger'
+        }
+        tabName = data.name;
+        kumaLink = '<a href="javascript:void(0)" onclick="tabActions(event,\''+tabName+'\',1)">';
+        if(options['compact']) {
+            var card = `
+            <div class="col-xl-2 col-lg-3 col-md-4 col-sm-6 col-xs-12">
+                <div class="card bg-inverse text-white mb-3 monitorr-card">
+                    <div class="card-body bg-org-alt pt-1 pb-1">
+                        <div class="d-flex no-block align-items-center">
+                            <div class="left-health bg-`+statusColor+`"></div>
+                            <div class="ml-1 w-100">
+                                <i class="`+imageText+` font-20 pull-right mt-3 mb-2"></i>
+                                `; if (typeof data.url !== 'undefined') { card += kumaLink; }
+                                card += `<h3 class="d-flex no-block align-items-center mt-2 mb-2"><img class="lazyload loginTitle">&nbsp;`+name+`</h3>
+                                `; if (typeof data.url !== 'undefined') { card +=`</a>`; }
+                                card += `<div class="clearfix"></div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>`;
+        } else {
+            var card = `
+            <div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
+                <div class="card bg-inverse text-white mb-3 monitorr-card">
+                    <div class="card-body bg-org-alt text-center">
+                        `; if (typeof data.url !== 'undefined') { card +=`<a href="`+data.url+`" target="_blank">`; }
+                        card += `<div class="d-block">
+                            <h3 class="mt-0 mb-3">`+data.name+`</h3>
+                        </div>
+                        <div class="d-inline-block mt-4 py-2 px-4 badge indicator bg-`+statusColor+`">
+                            <p class="mb-0">`; if(data.status == true) { card += 'ONLINE' } else { card += 'OFFLINE' } card+=`</p>
+                        </div>
+                        `; if (typeof data.url !== 'undefined') { card +=`</a>`; }
+                        card += `</div>
+                </div>
+            </div>
+            `;
+        }
+        return card;
+    }
+    for(var key in services) {
+        cards += buildCard(key, services[key]);
+    };
+    return cards;
+}
+function buildUptimeKuma(array){
+    if(array === false){ return ''; }
+    if(array.error != undefined) {
+	    organizrConsole('Uptime Kuma Function',array.error, 'error');
+    } else {
+        var html = `
+        <div id="allUptimeKuma">
+            <div class="el-element-overlay row">`
+        if(array['options']['titleToggle']) {
+            html += `
+                <div class="col-md-12">
+                    <h4 class="pull-left homepage-element-title"><span lang="en">`+array['options']['title']+`</span> : </h4>
+                    <hr class="hidden-xs ml-2">
+                </div>
+                <div class="clearfix"></div>
+            `;
+        }
+        html += `
+                <div class="uptimeKumaCards">
+                    `+buildUptimeKumaItem(array)+`
+                </div>
+            </div>
+        </div>
+        <div class="clearfix"></div>
+        `;
+    }
+    return (array) ? html : '';
+}
+function homepageUptimeKuma(timeout){
+    var timeout = (typeof timeout !== 'undefined') ? timeout : activeInfo.settings.homepage.refresh.homepageUptimeKumaRefresh;
+    organizrAPI2('GET','api/v2/homepage/kuma/data').success(function(data) {
+        try {
+            let response = data.response;
+	        document.getElementById('homepageOrderUptimeKuma').innerHTML = '';
+	        if(response.data !== null){
+		        buildUptimeKuma(response.data)
+		        $('#homepageOrderUptimeKuma').html(buildUptimeKuma(response.data));
+	        }
+        }catch(e) {
+            console.log(e)
+	        organizrCatchError(e,data);
+        }
+    }).fail(function(xhr) {
+	    OrganizrApiError(xhr);
+    });
+    let timeoutTitle = 'UptimeKuma-Homepage';
+    if(typeof timeouts[timeoutTitle] !== 'undefined'){ clearTimeout(timeouts[timeoutTitle]); }
+    timeouts[timeoutTitle] = setTimeout(function(){ homepageUptimeKuma(timeout); }, timeout);
+    delete timeout;
+}
 function homepageSpeedtest(timeout){
     var timeout = (typeof timeout !== 'undefined') ? timeout : activeInfo.settings.homepage.refresh.homepageSpeedtestRefresh;
     organizrAPI2('GET','api/v2/homepage/speedtest/data').success(function(data) {