Commit 94ed3cba authored by Dmitry Kiselev's avatar Dmitry Kiselev
Browse files

WIP: added filterpanel

parent fc68c17d
Pipeline #16216 passed with stages
in 12 minutes
......@@ -12,6 +12,7 @@ from mongoengine import Q
# NOC modules
from noc.lib.app.extapplication import ExtApplication, view
from noc.sa.models.managedobject import ManagedObject
from noc.services.web.apps.sa.objectlist.views import ObjectListApplication
from noc.sa.models.useraccess import UserAccess
from noc.inv.models.interface import Interface
from noc.inv.models.subinterface import SubInterface
......@@ -183,6 +184,16 @@ class InterfaceAppplication(ExtApplication):
"url": self.convert_mo_interface_url(o.id),
}
@staticmethod
def qdict_to_dict(qdict):
"""Convert a Django QueryDict to a Python dict.
Single-value fields are put in directly, and for multi-value fields, a list
of all values is stored at the field's key.
"""
return {k: v[0] if len(v) == 1 else v for k, v in qdict.lists()}
# api
@view(url="^(?P<managed_object>\d+)/$", method=["GET"], access="view", api=True)
def api_get_interfaces(self, request, managed_object):
......@@ -343,7 +354,21 @@ class InterfaceAppplication(ExtApplication):
:param description:
:return:
"""
params = self.qdict_to_dict(request.GET)
mos = ManagedObject.objects.all()
if params and "is_managed" in params:
if not params.get("is_managed") == "all":
is_managed = params.get("is_managed") == "true"
mos = mos.filter(is_managed=is_managed)
del params["is_managed"]
if params:
q = ObjectListApplication.cleaned_query(
ObjectListApplication(ObjectListApplication), params
)
if q:
mos = mos.filter(**q)
if "__query" in params.keys():
mos = mos.filter(name__icontains=params["__query"])
if not request.user.is_superuser:
mos = mos.filter(administrative_domain__in=UserAccess.get_domains(request.user))
l1 = (
......
......@@ -6,12 +6,15 @@
//---------------------------------------------------------------------
console.debug("Defining NOC.inv.interface.Application");
Ext.define("NOC.inv.interface.Application", {
extend: "NOC.core.Application",
requires: [
"NOC.sa.managedobject.LookupField"
"NOC.sa.managedobject.LookupField",
"NOC.core.filter.Filter",
],
initComponent: function() {
var me = this;
......@@ -46,66 +49,178 @@ Ext.define("NOC.inv.interface.Application", {
//
me.searchField = Ext.create({
xtype: "searchfield",
tooltip: __("When you found some descriptions in DB,<br/>" +
"you can specify here more detailed search"),
name: "search",
fieldLabel: __('Detailed'),
labelWidth: 50,
disabled: true,
emptytext: __("Search ..."),
typeAhead: true,
scope: me,
handler: me.onSearch
handler: me.onSearch,
listeners: {
render: me.addTooltip
}
});
me.searchDescriptionField = Ext.create("Ext.ux.form.SearchField", {
fieldLabel: __("Description Search"),
tooltip: __("Put your Search Description end press ENTER<br/>" +
"Returns only first 300 strings with match description."),
"Returns only first 300 strings with matched description."),
labelWidth: 100,
width: "500",
explicitSubmit: true,
scope: me,
handler: me.onSearchDescriptionField,
listeners: {
render: me.addTooltip
render: me.addTooltip
}
});
//
Ext.apply(me, {
items: [
Ext.create("Ext.tab.Panel", {
name: "tab",
itemId: "tab",
border: false,
activeTab: 0,
layout: "fit",
autoScroll: true,
defaults: {
autoScroll: true
},
items: [
me.l1Panel,
me.lagPanel,
me.l2Panel,
me.l3Panel
]
})
],
tbar: [
"Object:",
{
xtype: "sa.managedobject.LookupField",
name: "managedobject",
itemId: "managedobject",
emptytext: __("Select managed object ..."),
listeners: {
select: {
scope: me,
fn: me.onObjectChange
}
}
me.filterPan = Ext.create({
xtype: 'NOC.Filter',
appId: me.appId,
reference: 'filterPanel',
itemId: "filterPanel",
width: 300,
collapsed: false,
border: true,
split: true,
resizable: false,
stateful: true,
selectionStore: 'interface.selectionStore',
}),
me.radioForm = Ext.create({
xtype: 'radiogroup',
fieldLabel: __("is managed"),
labelWidth: 55,
defaultType: 'radiofield',
itemId: 'radio',
defaults: {
flex: 1
},
me.searchField,
me.searchDescriptionField
]
});
layout: 'hbox',
items: [{
boxLabel: 'true',
name: 'is_managed',
inputValue: 'true',
id: 'only_is_managed'
},
{
boxLabel: 'false',
name: 'is_managed',
inputValue: 'false',
id: 'only_is_not_managed'
},
{
boxLabel: 'all',
name: 'is_managed',
inputValue: 'all',
id: 'both'
},
]
}),
//
Ext.apply(me, {
items: [
Ext.create("Ext.panel.Panel", {
id: "search-description-panel",
layout: 'border',
items: [
Ext.create("Ext.tab.Panel", {
name: "tab",
region: 'center',
deferredRender: false,
itemId: "tab",
border: false,
activeTab: 0,
layout: "fit",
autoScroll: true,
defaults: {
autoScroll: true
},
items: [
me.l1Panel,
me.lagPanel,
me.l2Panel,
me.l3Panel
]
}),
{
xtype: 'tabpanel',
region: 'east',
title: 'Filter Panel',
animCollapse: true,
collapsible: true,
split: true,
width: 225,
minsize: 175,
maxSize: 400,
margins: '0 5 0 0',
activeTab: 0,
tabPosition: 'bottom',
items: [
me.filterPan,
{
xtype: 'panel',
title: 'One MO',
layout: {
type: 'vbox',
align: 'stretch'
},
items: [{
xtype: "sa.managedobject.LookupField",
fieldLabel: __('Object'),
labelWidth: 50,
tooltip: __("Choose MO, and you'll see all it's interfaces"),
name: "managedobject",
itemId: "managedobject",
emptytext: __("Select managed object ..."),
listeners: {
render: me.addTooltip,
select: {
scope: me,
fn: me.onObjectChange
}
},
},
{
xtype: "searchfield",
tooltip: __("When you found some descriptions in DB,<br/>" +
"you can specify here more detailed search"),
name: "search",
fieldLabel: __('Detailed'),
labelWidth: 50,
disabled: false,
emptytext: __("Search ..."),
typeAhead: true,
scope: me,
handler: me.onSearch,
listeners: {
render: me.addTooltip
}
},
]
}
]
},
]
})
],
tbar: [
me.searchDescriptionField,
me.radioForm,
{
xtype: 'tbspacer',
width: 20
},
me.searchField,
]
});
me.callParent();
me.radio1 = Ext.getCmp('only_is_managed')
me.radio1.setValue(true);
me.tabPanel = me.getComponent("tab");
},
// Called when managed object changed
......@@ -147,47 +262,46 @@ Ext.define("NOC.inv.interface.Application", {
me.l3Store.loadData(data.l3 || []);
//
me.searchField.setDisabled(false);
me.tabPanel.setActiveTab(0);
me.searchField.setValue("");
},
//
onSearch: function(value) {
var me = this,
s = value.toLowerCase(),
// Match substring
smatch = function(record, field, s) {
return record.get(field).toLowerCase().indexOf(s) != -1;
};
var me = this;
s = value.toLowerCase();
// Match substring
smatch = function(record, field, s) {
return record.get(field).toLowerCase().indexOf(s) != -1;
};
// Search L1
me.l1Store.filterBy(function(r) {
return (
!s
|| smatch(r, "name", s)
|| smatch(r, "description", s)
|| smatch(r, "mac", s)
|| smatch(r, "lag"));
!s ||
smatch(r, "name", s) ||
smatch(r, "description", s) ||
smatch(r, "mac", s) ||
smatch(r, "lag"));
});
// Search LAG
me.lagStore.filterBy(function(r) {
return (
!s
|| smatch(r, "name", s)
|| smatch(r, "description", s));
!s ||
smatch(r, "name", s) ||
smatch(r, "description", s));
});
// Search L2
me.l2Store.filterBy(function(r) {
return (
!s
|| smatch(r, "name", s)
|| smatch(r, "description", s));
!s ||
smatch(r, "name", s) ||
smatch(r, "description", s));
});
// Search L3
me.l3Store.filterBy(function(r) {
return (
!s
|| smatch(r, "name", s)
|| smatch(r, "description", s)
|| smatch(r, "vrf", s));
!s ||
smatch(r, "name", s) ||
smatch(r, "description", s) ||
smatch(r, "vrf", s));
});
},
//search_description handler
......@@ -198,9 +312,17 @@ Ext.define("NOC.inv.interface.Application", {
method: "GET",
scope: me,
success: me.onLoadInterfaces,
params: me.onGetFilterParams,
failure: function() {
NOC.error("Failed to get interfaces");
}
});
},
});
onGetFilterParams: function() {
var me = this;
var is_managed = Ext.getCmp('only_is_managed').getGroupValue()
columnsStore = me.down('[itemId=filterPanel]').viewModel.get('filterObject')
columnsStore['is_managed'] = is_managed
return columnsStore
}
});
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment