Skip to content

Commit

Permalink
Zenoss 4.2 compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
cluther committed Aug 6, 2012
1 parent ab7cd07 commit 3b39f0f
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 63 deletions.
150 changes: 99 additions & 51 deletions ZenPacks/zenoss/PostgreSQL/browser/resources/js/PostgreSQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,35 @@ ZC.registerName('PostgreSQLDatabase', _t('Database'), _t('Databases'));
ZC.registerName('PostgreSQLTable', _t('Table'), _t('Tables'));

/*
* Register types so jumpToEntity will work.
* Endpoint-local custom renderers.
*/
Ext.apply(Zenoss.render, {
PostgreSQL_entityLinkFromGrid: function(obj, col, record) {
if (!obj)
return;

// The DeviceClass matcher got too greedy in 3.1.x branch. Throttling it.
Zenoss.types.TYPES.DeviceClass[0] = new RegExp(
"^/zport/dmd/Devices(/(?!devices)[^/*])*/?$");
if (typeof(obj) == 'string')
obj = record.data;

Zenoss.types.register({
'PostgreSQLDatabase':
"^/zport/dmd/Devices.*/devices/.*/pgDatabases/[^/]*/?$",
'PostgreSQLTable':
"^/zport/dmd/Devices.*/devices/.*/pgDatabases/.*/tables/[^/]*/?$"
});
if (!obj.title && obj.name)
obj.title = obj.name;

/*
* Endpoint-local custom renderers.
*/
Ext.apply(Zenoss.render, {
entityLinkFromGrid: function(obj) {
if (obj && obj.uid && obj.name) {
var fmt = Ext.isDefined(Ext.String) ? Ext.String.format : String.format;
if ( !this.panel || this.panel.subComponentGridPanel) {
return fmt(
'<a href="javascript:Ext.getCmp(\'component_card\').componentgrid.jumpToEntity(\'{0}\', \'{1}\');">{1}</a>',
obj.uid, obj.name);
} else {
return obj.name;
}
var isLink = false;

if (this.refName == 'componentgrid') {
// Zenoss >= 4.2 / ExtJS4
if (this.subComponentGridPanel || this.componentType != obj.meta_type)
isLink = true;
} else {
// Zenoss < 4.2 / ExtJS3
if (!this.panel || this.panel.subComponentGridPanel)
isLink = true;
}

if (isLink) {
return '<a href="javascript:Ext.getCmp(\'component_card\').componentgrid.jumpToEntity(\''+obj.uid+'\', \''+obj.meta_type+'\');">'+obj.title+'</a>';
} else {
return obj.title;
}
}
});
Expand All @@ -46,21 +47,54 @@ Ext.apply(Zenoss.render, {
*/
ZC.PostgreSQLComponentGridPanel = Ext.extend(ZC.ComponentGridPanel, {
subComponentGridPanel: false,

jumpToEntity: function(uid, name) {
var tree = Ext.getCmp('deviceDetailNav').treepanel,
sm = tree.getSelectionModel(),
compsNode = tree.getRootNode().findChildBy(function(n){
return n.text=='Components';

jumpToEntity: function(uid, meta_type) {
var tree = Ext.getCmp('deviceDetailNav').treepanel;
var tree_selection_model = tree.getSelectionModel();
var components_node = tree.getRootNode().findChildBy(
function(n) {
if (n.data) {
// Zenoss >= 4.2 / ExtJS4
return n.data.text == 'Components';
}

// Zenoss < 4.2 / ExtJS3
return n.text == 'Components';
});

var compType = Zenoss.types.type(uid);
var componentCard = Ext.getCmp('component_card');
componentCard.setContext(compsNode.id, compType);
componentCard.selectByToken(uid);
sm.suspendEvents();
compsNode.findChildBy(function(n){return n.id==compType;}).select();
sm.resumeEvents();

// Reset context of component card.
var component_card = Ext.getCmp('component_card');

if (components_node.data) {
// Zenoss >= 4.2 / ExtJS4
component_card.setContext(components_node.data.id, meta_type);
} else {
// Zenoss < 4.2 / ExtJS3
component_card.setContext(components_node.id, meta_type);
}

// Select chosen row in component grid.
component_card.selectByToken(uid);

// Select chosen component type from tree.
var component_type_node = components_node.findChildBy(
function(n) {
if (n.data) {
// Zenoss >= 4.2 / ExtJS4
return n.data.id == meta_type;
}

// Zenoss < 4.2 / ExtJS3
return n.id == meta_type;
});

if (component_type_node.select) {
tree_selection_model.suspendEvents();
component_type_node.select();
tree_selection_model.resumeEvents();
} else {
tree_selection_model.select([component_type_node], false, true);
}
}
});

Expand All @@ -70,17 +104,18 @@ ZC.PostgreSQLComponentGridPanel = Ext.extend(ZC.ComponentGridPanel, {
ZC.PostgreSQLDatabasePanel = Ext.extend(ZC.PostgreSQLComponentGridPanel, {
constructor: function(config) {
config = Ext.applyIf(config||{}, {
autoExpandColumn: 'entity',
autoExpandColumn: 'name',
componentType: 'PostgreSQLDatabase',
fields: [
{name: 'uid'},
{name: 'name'},
{name: 'meta_type'},
{name: 'severity'},
{name: 'entity'},
{name: 'dbSize'},
{name: 'tableCount'},
{name: 'monitor'},
{name: 'monitored'}
{name: 'monitored'},
{name: 'locking'}
],
columns: [{
id: 'severity',
Expand All @@ -90,10 +125,10 @@ ZC.PostgreSQLDatabasePanel = Ext.extend(ZC.PostgreSQLComponentGridPanel, {
sortable: true,
width: 50
},{
id: 'entity',
dataIndex: 'entity',
id: 'name',
dataIndex: 'name',
header: _t('Name'),
renderer: Zenoss.render.entityLinkFromGrid,
renderer: Zenoss.render.PostgreSQL_entityLinkFromGrid,
panel: this
},{
id: 'dbSize',
Expand All @@ -115,6 +150,12 @@ ZC.PostgreSQLDatabasePanel = Ext.extend(ZC.PostgreSQLComponentGridPanel, {
renderer: Zenoss.render.checkbox,
sortable: true,
width: 65
},{
id: 'locking',
dataIndex: 'locking',
header: _t('Locking'),
renderer: Zenoss.render.locking_icons,
width: 65
}]
});
ZC.PostgreSQLDatabasePanel.superclass.constructor.call(this, config);
Expand All @@ -129,19 +170,20 @@ Ext.reg('PostgreSQLDatabasePanel', ZC.PostgreSQLDatabasePanel);
ZC.PostgreSQLTablePanel = Ext.extend(ZC.PostgreSQLComponentGridPanel, {
constructor: function(config) {
config = Ext.applyIf(config||{}, {
autoExpandColumn: 'entity',
autoExpandColumn: 'name',
componentType: 'PostgreSQLTable',
fields: [
{name: 'uid'},
{name: 'name'},
{name: 'meta_type'},
{name: 'severity'},
{name: 'entity'},
{name: 'database'},
{name: 'tableSchema'},
{name: 'tableSize'},
{name: 'totalTableSize'},
{name: 'monitor'},
{name: 'monitored'}
{name: 'monitored'},
{name: 'locking'}
],
columns: [{
id: 'severity',
Expand All @@ -151,16 +193,16 @@ ZC.PostgreSQLTablePanel = Ext.extend(ZC.PostgreSQLComponentGridPanel, {
sortable: true,
width: 50
},{
id: 'entity',
dataIndex: 'entity',
id: 'name',
dataIndex: 'name',
header: _t('Name'),
renderer: Zenoss.render.entityLinkFromGrid,
renderer: Zenoss.render.PostgreSQL_entityLinkFromGrid,
panel: this
},{
id: 'database',
dataIndex: 'database',
header: _t('Database'),
renderer: Zenoss.render.entityLinkFromGrid,
renderer: Zenoss.render.PostgreSQL_entityLinkFromGrid,
width: 80
},{
id: 'tableSchema',
Expand Down Expand Up @@ -189,6 +231,12 @@ ZC.PostgreSQLTablePanel = Ext.extend(ZC.PostgreSQLComponentGridPanel, {
renderer: Zenoss.render.checkbox,
sortable: true,
width: 65
},{
id: 'locking',
dataIndex: 'locking',
header: _t('Locking'),
renderer: Zenoss.render.locking_icons,
width: 65
}]
});
ZC.PostgreSQLTablePanel.superclass.constructor.call(this, config);
Expand Down
13 changes: 3 additions & 10 deletions ZenPacks/zenoss/PostgreSQL/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,8 @@
from .Database import Database
from .Table import Table

class PostgreSQLComponentInfo(ComponentInfo):
@property
def entity(self):
return {
'uid': self._object.getPrimaryUrlPath(),
'name': self._object.titleOrId(),
}

class DatabaseInfo(PostgreSQLComponentInfo):
class DatabaseInfo(ComponentInfo):
implements(IDatabaseInfo)
adapts(Database)

Expand All @@ -50,7 +43,8 @@ def dbSizeString(self):
def tableCount(self):
return self._object.tables.countObjects()

class TableInfo(PostgreSQLComponentInfo):

class TableInfo(ComponentInfo):
implements(ITableInfo)
adapts(Table)

Expand All @@ -74,4 +68,3 @@ def database(self):
def tableSizeString(self):
return convToUnits(
self._object.getIntForValue('tableSize'), 1024, 'B')

3 changes: 2 additions & 1 deletion ZenPacks/zenoss/PostgreSQL/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
from Products.Zuul.interfaces.component import IComponentInfo
from Products.Zuul.utils import ZuulMessageFactory as _t


class IDatabaseInfo(IComponentInfo):
dbName = schema.Text(title=_t(u"Database Name"))
dbOid = schema.Int(title=_t(u"Database OID"))
dbSizeString = schema.Int(title=_t(u"Database Size"))
tableCount = schema.Int(title=_t(u"Table Count"))


class ITableInfo(IComponentInfo):
tableName = schema.Text(title=_t(u"Table Name"))
tableOid = schema.Int(title=_t(u"Table OID"))
tableSchema = schema.Text(title=_t(u"Table Schema"))
tableSizeString = schema.Int(title=_t(u"Table Size"))
totalTableSizeString = schema.Int(title=_t(u"Total Table Size"))
database = schema.Entity(title=_t(u"Database"))

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# or saved. Do not modify them directly here.
# NB: PACKAGES is deprecated
NAME = "ZenPacks.zenoss.PostgreSQL"
VERSION = "1.0.5"
VERSION = "1.0.6"
AUTHOR = "Zenoss"
LICENSE = "GPLv2"
NAMESPACE_PACKAGES = ['ZenPacks', 'ZenPacks.zenoss']
Expand Down

0 comments on commit 3b39f0f

Please sign in to comment.