Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Icons in the item picker #207

Merged
merged 1 commit into from
Jul 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions web/app/widgets/widgets.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
.factory('Widgets', WidgetsService)
.directive('genericWidget', GenericWidgetDirective)
.directive('widgetIcon', WidgetIcon)
.directive('itemTypeIcon', ItemTypeIcon)
.directive('itemPicker', ItemPicker)
.filter('themeValue', ThemeValueFilter)

Expand Down Expand Up @@ -99,6 +100,42 @@
}
}

function ItemTypeIcon() {
var directive = {
link: link,
restrict: 'AE',
template:
'<strong ng-if="type === \'Number\'" title="Number" style="font-size: 1.2em; line-height: 0.9em; margin: -0.2em 0.1em;">#</strong>' +
'<i ng-if="type !== \'Number\'" title="{{type}}" class="glyphicon glyphicon-{{getGlyph()}}"></i>',
scope: {
type: '='
}
};
return directive;

function link(scope, element, attrs) {
scope.getGlyph = function () {
switch (scope.type) {
case 'Group': return 'th-large';
case 'Switch': return 'off';
case 'String': return 'font';
case 'Number': return 'usd';
case 'Color': return 'tint';
case 'DateTime': return 'calendar';
case 'Dimmer': return 'sort-by-attributes';
case 'Rollershutter': return 'oil';
case 'Contact': return 'resize-small';
case 'Player': return 'fast-forward';
case 'Image': return 'picture';
case 'Location': return 'map-marker';
case 'Call': return 'earphone';
default: return 'asterisk';
}
};
}
}


ItemPicker.$inject = ['$filter', 'OHService'];

function ItemPicker($filter, OHService) {
Expand All @@ -110,9 +147,9 @@
restrict: 'AE',
template:
'<ui-select ng-model="vm.selectedItem" theme="selectize" title="Choose an openHAB item">' +
' <ui-select-match placeholder="Search or select an openHAB item">{{$select.selected.name}}</ui-select-match>' +
' <ui-select-match placeholder="Search or select an openHAB item"><item-type-icon type="$select.selected.type"></item-type-icon>&nbsp;{{$select.selected.name}}</ui-select-match>' +
' <ui-select-choices repeat="item in vm.itemlist | filter: $select.search">' +
' <div ng-bind-html="item.name | highlight: $select.search"></div>' +
' <div><item-type-icon type="item.type"></item-type-icon>&nbsp;<span ng-bind-html="item.name | highlight: $select.search"></div>' +
' <small ng-bind-html="item.label | highlight: $select.search"></small>' +
' </ui-select-choices>' +
'</ui-select>',
Expand All @@ -135,9 +172,9 @@
if (this.filterType) {
vm.itemlist = $filter('filter')(vm.itemlist, function (item) {
if (vm.includeGroups) {
return item.type.startsWith(vm.filterType) || item.type.startsWith('Group');
return !item.type.indexOf(vm.filterType) || !item.type.indexOf('Group');
} else {
return item.type.startsWith(vm.filterType);
return !item.type.indexOf(vm.filterType);
}
});
}
Expand Down