Skip to content

Commit

Permalink
Merge pull request #282 from rvanbaalen/master
Browse files Browse the repository at this point in the history
Alphabetically sort loaded resources
  • Loading branch information
Foddy authored Jan 17, 2022
2 parents 7ee4cb3 + 9e5f87a commit 5972266
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 7 deletions.
16 changes: 15 additions & 1 deletion huemagic/hue-brightness.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@
buttonIcon.removeClass("fa-pencil");
buttonIcon.addClass("fa-search");
}

function sortResourcesBy(prop, resources)
{
return resources.sort((a, b) => {
if ( a[prop] < b[prop] ){
return -1;
}
if ( a[prop] > b[prop] ){
return 1;
}
return 0;
});
}

function searchAndSelect()
{
Expand All @@ -98,6 +111,7 @@
$.get('hue/resources', { bridge: bridgeConfig.bridge, key: bridgeConfig.key, type: "motion" })
.done( function(data) {
var allResources = JSON.parse(data);
allResources = sortResourcesBy('name', allResources);
if(allResources.length <= 0)
{
notification.close();
Expand Down Expand Up @@ -194,4 +208,4 @@
}
}
});
</script>
</script>
14 changes: 14 additions & 0 deletions huemagic/hue-buttons.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@
buttonIcon.removeClass("fa-pencil");
buttonIcon.addClass("fa-search");
}

function sortResourcesBy(prop, resources)
{
return resources.sort((a, b) => {
if ( a[prop] < b[prop] ){
return -1;
}
if ( a[prop] > b[prop] ){
return 1;
}
return 0;
});
}

function searchAndSelect()
{
Expand All @@ -98,6 +111,7 @@
$.get('hue/resources', { bridge: bridgeConfig.bridge, key: bridgeConfig.key, type: "button" })
.done( function(data) {
var allResources = JSON.parse(data);
allResources = sortResourcesBy('name', allResources);
if(allResources.length <= 0)
{
notification.close();
Expand Down
16 changes: 15 additions & 1 deletion huemagic/hue-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@
buttonIcon.removeClass("fa-pencil");
buttonIcon.addClass("fa-search");
}

function sortResourcesBy(prop, resources)
{
return resources.sort((a, b) => {
if ( a[prop] < b[prop] ){
return -1;
}
if ( a[prop] > b[prop] ){
return 1;
}
return 0;
});
}

function searchAndSelect()
{
Expand All @@ -98,6 +111,7 @@
$.get('hue/resources', { bridge: bridgeConfig.bridge, key: bridgeConfig.key, type: "group" })
.done( function(data) {
var allResources = JSON.parse(data);
allResources = sortResourcesBy('name', allResources);
if(allResources.length <= 0)
{
notification.close();
Expand Down Expand Up @@ -205,4 +219,4 @@
}
}
});
</script>
</script>
16 changes: 15 additions & 1 deletion huemagic/hue-light.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@
buttonIcon.removeClass("fa-pencil");
buttonIcon.addClass("fa-search");
}

function sortResourcesBy(prop, resources)
{
return resources.sort((a, b) => {
if ( a[prop] < b[prop] ){
return -1;
}
if ( a[prop] > b[prop] ){
return 1;
}
return 0;
});
}

function searchAndSelect()
{
Expand All @@ -105,6 +118,7 @@
$.get('hue/resources', { bridge: bridgeConfig.bridge, key: bridgeConfig.key, type: "light" })
.done( function(data) {
var allResources = JSON.parse(data);
allResources = sortResourcesBy('name', allResources);
if(allResources.length <= 0)
{
notification.close();
Expand Down Expand Up @@ -201,4 +215,4 @@
}
}
});
</script>
</script>
16 changes: 15 additions & 1 deletion huemagic/hue-motion.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@
buttonIcon.removeClass("fa-pencil");
buttonIcon.addClass("fa-search");
}

function sortResourcesBy(prop, resources)
{
return resources.sort((a, b) => {
if ( a[prop] < b[prop] ){
return -1;
}
if ( a[prop] > b[prop] ){
return 1;
}
return 0;
});
}

function searchAndSelect()
{
Expand All @@ -98,6 +111,7 @@
$.get('hue/resources', { bridge: bridgeConfig.bridge, key: bridgeConfig.key, type: "motion" })
.done( function(data) {
var allResources = JSON.parse(data);
allResources = sortResourcesBy('name', allResources);
if(allResources.length <= 0)
{
notification.close();
Expand Down Expand Up @@ -194,4 +208,4 @@
}
}
});
</script>
</script>
16 changes: 15 additions & 1 deletion huemagic/hue-rules.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@
buttonIcon.removeClass("fa-pencil");
buttonIcon.addClass("fa-search");
}

function sortResourcesBy(prop, resources)
{
return resources.sort((a, b) => {
if ( a[prop] < b[prop] ){
return -1;
}
if ( a[prop] > b[prop] ){
return 1;
}
return 0;
});
}

function searchAndSelect()
{
Expand All @@ -98,6 +111,7 @@
$.get('hue/resources', { bridge: bridgeConfig.bridge, key: bridgeConfig.key, type: "rule" })
.done( function(data) {
var allResources = JSON.parse(data);
allResources = sortResourcesBy('name', allResources);
if(allResources.length <= 0)
{
notification.close();
Expand Down Expand Up @@ -187,4 +201,4 @@
}
}
});
</script>
</script>
16 changes: 15 additions & 1 deletion huemagic/hue-scene.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@
buttonIcon.removeClass("fa-pencil");
buttonIcon.addClass("fa-search");
}

function sortResourcesBy(prop, resources)
{
return resources.sort((a, b) => {
if ( a[prop] < b[prop] ){
return -1;
}
if ( a[prop] > b[prop] ){
return 1;
}
return 0;
});
}

function searchAndSelectScenes()
{
Expand All @@ -84,6 +97,7 @@
$.get('hue/resources', { bridge: bridgeConfig.bridge, key: bridgeConfig.key, type: "scene" })
.done( function(data) {
var allResources = JSON.parse(data);
allResources = sortResourcesBy('name', allResources);
if(allResources.length <= 0)
{
notification.close();
Expand Down Expand Up @@ -167,4 +181,4 @@
}
}
});
</script>
</script>
16 changes: 15 additions & 1 deletion huemagic/hue-temperature.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@
buttonIcon.removeClass("fa-pencil");
buttonIcon.addClass("fa-search");
}

function sortResourcesBy(prop, resources)
{
return resources.sort((a, b) => {
if ( a[prop] < b[prop] ){
return -1;
}
if ( a[prop] > b[prop] ){
return 1;
}
return 0;
});
}

function searchAndSelect()
{
Expand All @@ -98,6 +111,7 @@
$.get('hue/resources', { bridge: bridgeConfig.bridge, key: bridgeConfig.key, type: "temperature" })
.done( function(data) {
var allResources = JSON.parse(data);
allResources = sortResourcesBy('name', allResources);
if(allResources.length <= 0)
{
notification.close();
Expand Down Expand Up @@ -194,4 +208,4 @@
}
}
});
</script>
</script>

0 comments on commit 5972266

Please sign in to comment.