Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alphabetically sort loaded resources #282

Merged
merged 11 commits into from
Jan 17, 2022
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>