Skip to content

Commit

Permalink
Improve edition form and host/service/user settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mohierf committed Apr 24, 2017
1 parent 5fc7796 commit 9324608
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions alignak_webui/plugins/hosts/settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ templates_table=true

[table._is_template]
visible=false
hidden=true
templates_table=true

[table._templates]
Expand All @@ -227,11 +228,11 @@ format=multiple
resource=host
regex_search=false
visible=false
hidden=true
templates_table=true

[table._templates_with_services]
visible=false
hidden=true
templates_table=true

[table._template_fields]
Expand Down Expand Up @@ -270,7 +271,6 @@ format=ip

[table.address6]
format=ipv6
visible=false

[table.customs]
format=multiple
Expand Down
2 changes: 1 addition & 1 deletion alignak_webui/plugins/services/settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ templates_table=true

[table._is_template]
visible=false
hidden=true
templates_table=true

[table._templates]
Expand All @@ -79,7 +80,6 @@ format=multiple
resource=host
regex_search=false
visible=false
hidden=true
templates_table=true

[table._template_fields]
Expand Down
2 changes: 1 addition & 1 deletion alignak_webui/plugins/users/settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ templates_table=true

[table._is_template]
visible=false
hidden=true
templates_table=true

[table._templates]
Expand All @@ -49,7 +50,6 @@ format=multiple
resource=host
regex_search=false
visible=false
hidden=true
templates_table=true

[table._template_fields]
Expand Down
23 changes: 14 additions & 9 deletions alignak_webui/views/_form.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
%import json
%from alignak_webui.objects.element import BackendElement
%from alignak_webui.objects.element_state import ElementState

%# Default values
%setdefault('debug', False)
Expand Down Expand Up @@ -174,7 +176,6 @@
%linked_object_type = model.get('resource', '')
%icon=''
%if linked_object_type:
% from alignak_webui.objects.element_state import ElementState
% icon = ElementState().get_icon_state('realm', 'unknown')
% icon=icon['icon'] if icon else ''
%end
Expand Down Expand Up @@ -358,7 +359,6 @@
%linked_object_type = model.get('resource', '')
%icon=''
%if linked_object_type:
% from alignak_webui.objects.element_state import ElementState
% icon = ElementState().get_icon_state(linked_object_type, 'unknown')
% icon=icon['icon'] if icon else ''
%end
Expand Down Expand Up @@ -517,6 +517,7 @@
<i class="fa fa-bug"></i>{{field}} -> {{model}}<br>
%end

%# Is a list of values?
%is_list = False
%list_values = []

Expand Down Expand Up @@ -561,13 +562,11 @@
%end
%end

%from alignak_webui.objects.element import BackendElement

%if field_type=='point':
%field_value={'latitude': field_value['coordinates'][0], 'longitude': field_value['coordinates'][1]}
%end

%# Field value is a list
%# The field value is a list
%if isinstance(field_value, list):
% for v in field_value:
% if isinstance(v, BackendElement):
Expand All @@ -583,7 +582,7 @@
% is_list = True
% selectize=True

%# Field value is a dict
%# The field value is a dictionary
%elif isinstance(field_value, dict):
% for k,v in field_value.items():
% list_values.append(('%s|%s' % (k, v), '%s=%s' % (k, v)))
Expand All @@ -610,7 +609,7 @@
%if is_list:
{{' is_list %s -> %s (%s) = %s' % (field, field_type, content_type, list_values)}}
%else:
{{'not list %s -> %s = %s' % (field, content_type, field_value)}}
{{'not list %s -> %s = %s (%s)' % (field, content_type, field_value, list_values)}}
%end
<br>
%end
Expand Down Expand Up @@ -660,7 +659,6 @@
%linked_object_type = model.get('resource', '')
%icon=''
%if linked_object_type:
% from alignak_webui.objects.element_state import ElementState
% icon = ElementState().get_icon_state(linked_object_type, 'unknown')
% icon=icon['icon'] if icon else ''
%end
Expand All @@ -672,6 +670,9 @@
%if has_template and field in element['_template_fields']:
<i class="fa fa-clone" title="{{_('The value of this field is inherited from a template')}}"></i>
%end
%if is_list:
<i class="fa fa-list"></i>
%end
</span>
%if is_list:
<select id="{{field}}" name="{{field}}"
Expand Down Expand Up @@ -735,6 +736,7 @@
'</div>';
},
item: function(item, escape) {
console.log("item {{field}}: ", item);
return '<div>' +
%if icon:
'<i class="fa fa-{{icon}}"></i>&nbsp;' +
Expand Down Expand Up @@ -762,6 +764,7 @@
// 10 first items only...
// callback(res.slice(0, 10));
callback(res);
}
});
},
Expand Down Expand Up @@ -789,6 +792,7 @@
%end
});
// Add selected options / items to the control...
window.setTimeout(function() {
var $select = $('#{{field}}').selectize();
var selectize = $select[0].selectize;
%for field_id, field_value in list_values:
Expand All @@ -797,6 +801,7 @@
%for field_id, field_value in list_values:
selectize.addItem("{{field_id}}");
%end
}, 100);
</script>
%end
%continue
Expand All @@ -807,7 +812,7 @@
<script>
window.setTimeout(function() { $("div.alert-dismissible").alert('close'); }, 10000);
</script>
%if edition:
%if edition and element:
<div class="well form-group">
<button type="reset" class="btn btn-default pull-left">{{_('Cancel')}}</button>
<button type="submit" class="btn btn-primary pull-right">{{_('Submit')}}</button>
Expand Down
6 changes: 3 additions & 3 deletions test/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,16 +857,16 @@ def test_commands(self):
assert len(Command.get_cache()) == 1

print(item)
assert "%s" % item == "<command, id: command_0, name: anonymous, status: unknown>"
assert "%s" % item == "<command, id: command_0, name: Undefined command, status: unknown>"
assert item._id == 'command_0' # Because no _id in the parameters ...
assert item._type == 'command'
assert item.name == 'anonymous'
assert item.name == 'Undefined command'
assert item.status == 'unknown'

assert item.status == 'unknown'

print(item.get_html_state())
assert item.get_html_state() == '''<div class="item-state item_command " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="command" data-item-state="" title=""><span class="fa-stack " ><i class="fa fa-circle fa-stack-2x item_command"></i><i class="fa fa-bolt fa-stack-1x fa-inverse"></i></span><span></span></div>''' % item.id
assert item.get_html_state() == '''<div class="item-state item_command " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="Undefined command" data-item-type="command" data-item-state="" title=""><span class="fa-stack " ><i class="fa fa-circle fa-stack-2x item_command"></i><i class="fa fa-bolt fa-stack-1x fa-inverse"></i></span><span></span></div>''' % item.id

def test_hosts(self):
""" Items - hosts """
Expand Down

0 comments on commit 9324608

Please sign in to comment.