Skip to content

Commit

Permalink
Rename groups-common to common-utilities
Browse files Browse the repository at this point in the history
move some dupliated code to common-utilities

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
  • Loading branch information
PromoFaux committed May 22, 2020
1 parent 97fd829 commit a758394
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 142 deletions.
2 changes: 1 addition & 1 deletion groups-adlists.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
</div>
</div>

<script src="scripts/pi-hole/js/groups-common.js"></script>
<script src="scripts/pi-hole/js/common-utilities.js"></script>
<script src="scripts/pi-hole/js/groups-adlists.js"></script>

<?php
Expand Down
2 changes: 1 addition & 1 deletion groups-clients.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</div>

<script src="scripts/pi-hole/js/ip-address-sorting.js"></script>
<script src="scripts/pi-hole/js/groups-common.js"></script>
<script src="scripts/pi-hole/js/common-utilities.js"></script>
<script src="scripts/pi-hole/js/groups-clients.js"></script>

<?php
Expand Down
4 changes: 2 additions & 2 deletions groups-domains.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<li role="presentation">
<a href="#tab_regex" aria-controls="tab_regex" aria-expanded="false" role="tab" data-toggle="tab">RegEx filter</a>
</li>
</ul>
</ul>
<div class="tab-content">
<!-- Domain tab -->
<div id="tab_domain" class="tab-pane active fade in">
Expand Down Expand Up @@ -139,7 +139,7 @@
</div>
</div>

<script src="scripts/pi-hole/js/groups-common.js"></script>
<script src="scripts/pi-hole/js/common-utilities.js"></script>
<script src="scripts/pi-hole/js/groups-domains.js"></script>

<?php
Expand Down
2 changes: 1 addition & 1 deletion groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
</div>
</div>

<script src="scripts/pi-hole/js/groups-common.js"></script>
<script src="scripts/pi-hole/js/common-utilities.js"></script>
<script src="scripts/pi-hole/js/groups.js"></script>

<?php
Expand Down
2 changes: 1 addition & 1 deletion messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</div>
</div>

<script src="scripts/pi-hole/js/groups-common.js"></script>
<script src="scripts/pi-hole/js/common-utilities.js"></script>
<script src="scripts/pi-hole/js/messages.js"></script>

<?php
Expand Down
1 change: 1 addition & 0 deletions network.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@
require "scripts/pi-hole/php/footer.php";
?>

<script src="scripts/pi-hole/js/common-utilities.js"></script>
<script src="scripts/pi-hole/js/ip-address-sorting.js"></script>
<script src="scripts/pi-hole/js/network.js"></script>
1 change: 1 addition & 0 deletions queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
</div>
<!-- /.row -->

<script src="scripts/pi-hole/js/common-utilities.js"></script>
<script src="scripts/pi-hole/js/queries.js"></script>

<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,29 @@ function bsSelect_defaults() {
};
}

function stateSaveCallback(itemName,data)
{
localStorage.setItem(itemName, JSON.stringify(data));
}

function stateLoadCallback(itemName)
{
// Receive previous state from client's local storage area
var data = localStorage.getItem(itemName);
// Return if not available
if (data === null) {
return null;
}

data = JSON.parse(data);
// Always start on the first page to show most recent queries
data.start = 0;
// Always start with empty search field
data.search.search = "";
// Apply loaded state to table
return data;
}

window.utils = (function () {
return {
showAlert: showAlert,
Expand All @@ -157,6 +180,8 @@ window.utils = (function () {
enableAll: enableAll,
validateIPv4CIDR: validateIPv4CIDR,
validateIPv6CIDR: validateIPv6CIDR,
bsSelect_defaults: bsSelect_defaults
bsSelect_defaults: bsSelect_defaults,
stateSaveCallback: stateSaveCallback,
stateLoadCallback: stateLoadCallback
};
})();
16 changes: 2 additions & 14 deletions scripts/pi-hole/js/groups-adlists.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,10 @@ function initTable() {
],
stateSave: true,
stateSaveCallback: function (settings, data) {
// Store current state in client's local storage area
localStorage.setItem("groups-adlists-table", JSON.stringify(data));
utils.stateSaveCallback("groups-adlists-table",data);
},
stateLoadCallback: function () {
// Receive previous state from client's local storage area
var data = localStorage.getItem("groups-adlists-table");
// Return if not available
if (data === null) {
return null;
}

data = JSON.parse(data);
// Always start on the first page to show most recent queries
data.start = 0;
// Always start with empty search field
data.search.search = "";
var data = utils.stateLoadCallback("groups-adlists-table");
// Reset visibility of ID column
data.columns[0].visible = false;
// Apply loaded state to table
Expand Down
16 changes: 2 additions & 14 deletions scripts/pi-hole/js/groups-clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,10 @@ function initTable() {
],
stateSave: true,
stateSaveCallback: function (settings, data) {
// Store current state in client's local storage area
localStorage.setItem("groups-clients-table", JSON.stringify(data));
utils.stateSaveCallback("groups-clients-table",data);
},
stateLoadCallback: function () {
// Receive previous state from client's local storage area
var data = localStorage.getItem("groups-clients-table");
// Return if not available
if (data === null) {
return null;
}

data = JSON.parse(data);
// Always start on the first page to show most recent queries
data.start = 0;
// Always start with empty search field
data.search.search = "";
var data = utils.stateLoadCallback("groups-clients-table");
// Reset visibility of ID column
data.columns[0].visible = false;
// Apply loaded state to table
Expand Down
16 changes: 2 additions & 14 deletions scripts/pi-hole/js/groups-domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,10 @@ function initTable() {
],
stateSave: true,
stateSaveCallback: function (settings, data) {
// Store current state in client's local storage area
localStorage.setItem("groups-domains-table", JSON.stringify(data));
utils.stateSaveCallback("groups-domains-table",data);
},
stateLoadCallback: function () {
// Receive previous state from client's local storage area
var data = localStorage.getItem("groups-domains-table");
// Return if not available
if (data === null) {
return null;
}

data = JSON.parse(data);
// Always start on the first page to show most recent queries
data.start = 0;
// Always start with empty search field
data.search.search = "";
var data = utils.stateLoadCallback("groups-domains-table");
// Reset visibility of ID column
data.columns[0].visible = false;
// Show group assignment column only on full page
Expand Down
16 changes: 2 additions & 14 deletions scripts/pi-hole/js/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,10 @@ $(document).ready(function () {
],
stateSave: true,
stateSaveCallback: function (settings, data) {
// Store current state in client's local storage area
localStorage.setItem("groups-table", JSON.stringify(data));
utils.stateSaveCallback("groups-table",data);
},
stateLoadCallback: function () {
// Receive previous state from client's local storage area
var data = localStorage.getItem("groups-table");
// Return if not available
if (data === null) {
return null;
}

data = JSON.parse(data);
// Always start on the first page to show most recent queries
data.start = 0;
// Always start with empty search field
data.search.search = "";
var data = utils.stateLoadCallback("groups-table");
// Reset visibility of ID column
data.columns[0].visible = false;
// Apply loaded state to table
Expand Down
17 changes: 2 additions & 15 deletions scripts/pi-hole/js/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,10 @@ $(document).ready(function () {
},
stateSave: true,
stateSaveCallback: function (settings, data) {
// Store current state in client's local storage area
localStorage.setItem("messages-table", JSON.stringify(data));
utils.stateSaveCallback("messages-table",data);
},
stateLoadCallback: function () {
// Receive previous state from client's local storage area
var data = localStorage.getItem("messages-table");
// Return if not available
if (data === null) {
return null;
}

// Parse loaded data
data = JSON.parse(data);
// Always start on the first page to show most recent queries
data.start = 0;
// Always start with empty search field
data.search.search = "";
var data = utils.stateLoadCallback("messages-table");
// Reset visibility of ID and blob columns
var hiddenCols = [0, 4, 5, 6, 7, 8];
for (var key in hiddenCols) {
Expand Down
18 changes: 2 additions & 16 deletions scripts/pi-hole/js/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,24 +186,10 @@ $(document).ready(function () {
],
stateSave: true,
stateSaveCallback: function (settings, data) {
// Store current state in client's local storage area
localStorage.setItem("network_table", JSON.stringify(data));
utils.stateSaveCallback("network_table",data);
},
stateLoadCallback: function () {
// Receive previous state from client's local storage area
var data = localStorage.getItem("network_table");
// Return if not available
if (data === null) {
return null;
}

data = JSON.parse(data);
// Always start on the first page
data.start = 0;
// Always start with empty search field
data.search.search = "";
// Apply loaded state to table
return data;
return utils.stateLoadCallback("network_table");
},
columnDefs: [
{
Expand Down
18 changes: 2 additions & 16 deletions scripts/pi-hole/js/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,24 +399,10 @@ $(document).ready(function () {
],
stateSave: true,
stateSaveCallback: function (settings, data) {
// Store current state in client's local storage area
localStorage.setItem("query_log_table", JSON.stringify(data));
utils.stateSaveCallback("query_log_table",data);
},
stateLoadCallback: function () {
// Receive previous state from client's local storage area
var data = localStorage.getItem("query_log_table");
// Return if not available
if (data === null) {
return null;
}

data = JSON.parse(data);
// Always start on the first page to show most recent queries
data.start = 0;
// Always start with empty search field
data.search.search = "";
// Apply loaded state to table
return data;
return utils.stateLoadCallback("query_log_table");
},
columnDefs: [
{
Expand Down
36 changes: 4 additions & 32 deletions scripts/pi-hole/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,24 +177,10 @@ $(document).ready(function () {
order: [[2, "asc"]],
stateSave: true,
stateSaveCallback: function(settings, data) {
// Store current state in client's local storage area
localStorage.setItem("activeDhcpLeaseTable", JSON.stringify(data));
utils.stateSaveCallback("activeDhcpLeaseTable",data);
},
stateLoadCallback: function() {
// Receive previous state from client's local storage area
var data = localStorage.getItem("activeDhcpLeaseTable");
// Return if not available
if (data === null) {
return null;
}

data = JSON.parse(data);
// Always start on the first page to show most recent queries
data.start = 0;
// Always start with empty search field
data.search.search = "";
// Apply loaded state to table
return data;
return utils.stateLoadCallback("activeDhcpLeaseTable");
}
});
}
Expand All @@ -210,24 +196,10 @@ $(document).ready(function () {
order: [[2, "asc"]],
stateSave: true,
stateSaveCallback: function(settings, data) {
// Store current state in client's local storage area
localStorage.setItem("staticDhcpLeaseTable", JSON.stringify(data));
utils.stateSaveCallback("staticDhcpLeaseTable",data);
},
stateLoadCallback: function() {
// Receive previous state from client's local storage area
var data = localStorage.getItem("staticDhcpLeaseTable");
// Return if not available
if (data === null) {
return null;
}

data = JSON.parse(data);
// Always start on the first page to show most recent queries
data.start = 0;
// Always start with empty search field
data.search.search = "";
// Apply loaded state to table
return data;
return utils.stateLoadCallback("staticDhcpLeaseTable");
}
});
}
Expand Down
1 change: 1 addition & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,7 @@ function convertseconds($argument)
</div>
</div>

<script src="scripts/pi-hole/js/common-utilities.js"></script>
<script src="scripts/vendor/jquery.confirm.min.js"></script>
<script src="scripts/pi-hole/js/settings.js"></script>

Expand Down

0 comments on commit a758394

Please sign in to comment.