/*
* Copyright 2015 Anyware Services
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This tool displays the cache statistics of the back
*/
Ext.define('Ametys.plugins.web.administration.CacheStatisticsServersTool', {
extend: 'Ametys.tool.Tool',
/**
* @private
* @property {Ext.tree.Panel} _tree The tree panel
*/
/**
* @private
* @property {String} _siteName The selected site
*/
getMBSelectionInteraction: function()
{
return Ametys.tool.Tool.MB_TYPE_NOSELECTION;
},
createPanel: function ()
{
this._tree = this._drawCacheStatisticsServersTree();
return this._tree;
},
setParams: function (params)
{
this.callParent(arguments);
this._siteName = params.siteName;
var toolTitle = "{{i18n PLUGINS_WEB_ADMINISTRATOR_UITOOL_SITE_CACHE_STATISTICS_SERVERS_TITLE}}";
toolTitle += params.siteTitle ? " " + params.siteTitle + " (" + this._siteName + ")" : this._siteName;
this.setTitle(toolTitle);
this._tree.getStore().setRoot({id: 'root'});
this.refresh();
},
refresh: function ()
{
this.showRefreshing();
this._tree.getRootNode().expand(false, Ext.bind(this.showRefreshed, this), this);
},
/**
* Get the tree panel of the tool
* @return the tree panel of the tool
*/
getTree: function()
{
return this._tree;
},
/**
* @private
* Draw the tree panel representing the servers' cache statistics
* @return a tree panel
*/
_drawCacheStatisticsServersTree: function()
{
var columns = [{
text: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_COL_FIRST}}",
flex: 1,
xtype: 'treecolumn',
stateId: 'grid-label',
dataIndex: 'label'
}, {
text: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_FIRST_ROWHD_FIRST}}",
columns: [{
header: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_COL_CACHEABLE}}",
stateId: 'grid-cacheable',
dataIndex: 'cacheable',
align: 'center'
}]
}, {
text: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_FIRST_ROWHD_EFFICIENCY}}",
columns: [{
header: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_COL_EFFICIENCY_TOTAL}}",
stateId: 'grid-eff',
dataIndex: 'eff',
align: 'center'
}, {
header: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_COL_EFFICIENCY_HTTPSERVER}}",
stateId: 'grid-eff-a',
dataIndex: 'effA',
hidden: true,
align: 'center'
}, {
header: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_COL_EFFICIENCY_FRONT}}",
stateId: 'grid-eff-f',
dataIndex: 'effF',
hidden: true,
align: 'center'
}]
}, {
text: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_FIRST_ROWHD_HITS}}",
columns: [{
header: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_COL_HITS_TOTAL}}",
stateId: 'grid-hits',
dataIndex: 'hits',
align: 'center'
}, {
header: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_COL_HITS_HTTPSERVER}}",
stateId: 'grid-hits-a',
dataIndex: 'hitsA',
hidden: true,
align: 'center'
}, {
header: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_COL_HITS_FRONT}}",
stateId: 'grid-hits-f',
dataIndex: 'hitsF',
hidden: true,
align: 'center'
}]
}, {
text: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_FIRST_ROWHD_CACHE_HITS}}",
columns: [{
header: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_COL_CACHE_HITS_TOTAL}}",
stateId: 'grid-cache-hits',
dataIndex: 'cacheHits',
align: 'center'
}, {
header: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_COL_CACHE_HITS_HTTPSERVER}}",
stateId: 'grid-cache-hits-a',
dataIndex: 'cacheHitsA',
hidden: true,
align: 'center'
}, {
header: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_COL_CACHE_HITS_FRONT}}",
stateId: 'grid-cache-hits-f',
dataIndex: 'cacheHitsF',
hidden: true,
align: 'center'
}]
}, {
text: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_COL_HITS_BACK}}",
columns: [{
header: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_FIRST_ROWHD_BACK}}",
stateId: 'grid-hits-b',
dataIndex: 'hitsB',
align: 'center'
}]
}];
return Ext.create ('Ext.tree.Panel', {
stateful: true,
stateId: this.self.getName() + "$grid",
rootVisible: false,
dockedItems: {
dock: 'top',
ui: 'tool-hintmessage',
xtype: 'component',
html: "{{i18n PLUGINS_WEB_ADMINISTRATOR_CACHE_SERVERS_STATISTICS_HELP_TEXT}}"
},
columns: columns,
store: Ext.create('Ext.data.TreeStore', {
model: 'Ametys.plugins.web.administration.CacheStatisticsServersTool.CacheStatisticsServersEntry',
root: {
id: 'dummy',
text : 'dummy',
name: 'dummy',
path: 'dummy',
expanded: false
},
proxy: {
type: 'ametys',
plugin: 'web',
url: '/administrator/sites/cache-statistics-servers-tree.json',
reader: {
type: 'json'
}
},
listeners: {
'beforeload': Ext.bind(this._onBeforeLoad, this),
'itemmouseenter': Ext.bind(this._createQtip, this)
}
}),
scrollable: true,
border: false
});
},
/**
* @private
* Destroy and create the node tooltip when the mouse enters the node
* @param {Ext.view.View} view The tree view
* @param {Ext.data.Model} node The tree node
* @param {HTMLElement} el The node's element
*/
_createQtip: function (view, node, el)
{
Ext.QuickTips.unregister(el);
var tooltipCfg = {
target: el,
id: el.id + '-tooltip',
inribbon: false,
text: node.get('tooltipText')
};
Ext.QuickTips.register(tooltipCfg);
},
/**
* @private
* Handle the before load event of the store in order to cancel the load request on the root node.
* Be careful, this is mandatory is our case only because we have an hidden root node, which automatically perform a load when the node is created.
* @param {Ext.data.TreeStore} store The tree store
* @param {Object} operation The Ext.data.operation.Operation object that will be passed to the Proxy to
* load the Store
*/
_onBeforeLoad: function(store, operation)
{
var node = operation.node,
id = node != null ? node.getId() : null;
// Cancel load
if (!id || id === 'dummy')
{
return false;
}
operation.setParams(Ext.apply(operation.getParams() || {}, {
siteName: this._siteName
}));
}
});