console-filters.js revision 4db02d4b38afe802ad625f6c389e106fdc7c26fa
/**
* source (global, event, attribute, etc).
* Checkboxes are added to the Console footer to control the visibility of each
* category and source.
*
* @module console-filters
* @namespace Plugin
* @class ConsoleFilters
*/
// Some common strings and functions
CONSOLE = 'console',
FILTERS = 'filters',
FILTER = 'filter',
CATEGORY = 'category',
SOURCE = 'source',
CATEGORY_DOT = 'category.',
SOURCE_DOT = 'source.',
HOST = 'host',
PARENT_NODE = 'parentNode',
CHECKED = 'checked',
DEF_VISIBILITY = 'defaultVisibility',
DOT = '.',
EMPTY = '',
// IE8 doesn't permit breaking _between_ nowrap elements AND it doesn't
// understand the (non spec) wbr tag AND it doesn't create text nodes for
// spaces between elements in innerHTML strings. The en-space entity
// suffices, but is less that beautiful in other browsers.
SEL_CHECK = 'input[type=checkbox].';
function ConsoleFilters() {
}
Y.mix(ConsoleFilters,{
/**
* Plugin name.
*
* @property ConsoleFilters.NAME
* @type String
* @readOnly
* @static
* @default 'consoleFilters'
*/
NAME : 'consoleFilters',
/**
* The namespace hung off the host object that this plugin will inhabit.
*
* @property ConsoleFilters.NS
* @type String
* @readOnly
* @static
* @default 'filter'
*/
/**
* Markup template used to create the container for the category filters.
*
* @property ConsoleFilters.CATEGORIES_TEMPLATE
* @type String
* @static
*/
'<div class="{categories}"></div>',
/**
* Markup template used to create the container for the source filters.
*
* @property ConsoleFilters.SOURCES_TEMPLATE
* @type String
* @static
*/
'<div class="{sources}"></div>',
/**
* Markup template used to create the category and source filter checkboxes.
*
* @property ConsoleFilters.FILTER_TEMPLATE
* @type String
* @static
*/
'<label class="{filter_label}">'+
'<input type="checkbox" value="{filter_name}" '+
'class="{filter} {filter_class}"> {filter_name}'+
'</label>'+SEP,
/**
* Classnames used by the templates when creating nodes.
*
* @property ConsoleFilters.CHROME_CLASSES
* @type Object
* @static
* @protected
*/
CHROME_CLASSES : {
},
ATTRS : {
/**
* Default visibility applied to new categories and sources.
*
* @attribute defaultVisibility
* @type {Boolean}
* @default true
*/
value : true,
},
/**
* <p>Map of entry categories to their visibility status. Update a
* particular category's visibility by setting the subattribute to true
* (visible) or false (hidden).</p>
*
* <p>For example, yconsole.filter.set('category.info', false) to hide
*
* <p>Similarly, yconsole.filter.get('category.warn') will return a
* boolean indicating whether that category is currently being included
* in the UI.</p>
*
* <p>Unlike the YUI instance configuration's logInclude and logExclude
* properties, filtered entries are only hidden from the UI, but
* can be made visible again.</p>
*
* @attribute category
* @type Object
*/
category : {
value : {},
validator : function (v,k) {
return this._validateCategory(k,v);
}
},
/**
* <p>Map of entry sources to their visibility status. Update a
* particular sources's visibility by setting the subattribute to true
* (visible) or false (hidden).</p>
*
* <p>For example, yconsole.filter.set('sources.slider', false) to hide
* log entries originating from Y.Slider.</p>
*
* @attribute source
* @type Object
*/
source : {
value : {},
validator : function (v,k) {
return this._validateSource(k,v);
}
}
}
});
/**
* Collection of all log messages passed through since the plugin's
* instantiation. This holds all messages regardless of filter status.
* Used as a single source of truth for repopulating the Console body when
* filters are changed.
*
* @property _entries
* @type Array
* @protected
*/
_entries : null,
/**
* The container node created to house the category filters.
*
* @property _categories
* @type Node
* @protected
*/
_categories : null,
/**
* The container node created to house the source filters.
*
* @property _sources
* @type Node
* @protected
*/
_sources : null,
/**
* Initialize entries collection and attach listeners to host events and
* methods.
*
* @method initializer
*/
initializer : function () {
this._entries = [];
this.renderUI();
this.syncUI();
this.bindUI();
}
},
/**
* Removes the plugin UI and unwires events.
*
* @method destructor
*/
destructor : function () {
//TODO: grab last {consoleLimit} entries and update the console with
//them (no filtering)
this._entries = [];
if (this._categories) {
}
if (this._sources) {
}
},
/**
* Adds the category and source filter sections to the Console footer.
*
* @method renderUI
*/
renderUI : function () {
html;
if (foot) {
html = Y.substitute(
html = Y.substitute(
}
},
/**
* Binds to checkbox click events and internal attribute change events to
* maintain the UI state.
*
* @method bindUI
*/
bindUI : function () {
},
/**
* Updates the UI to be in accordance with the current state of the plugin.
*
* @method syncUI
*/
syncUI : function () {
this._uiSetCheckbox(CATEGORY, k, v);
}, this);
this._uiSetCheckbox(SOURCE, k, v);
}, this);
this.refreshConsole();
},
/**
* Ensures a filter is set up for any new categories or sources and
* collects the messages in _entries. If the message is stamped with a
* category or source that is currently being filtered out, the message
* will not pass to the Console's print buffer.
*
* @method _onEntry
* @param e {Event} the custom event object
* @protected
*/
_onEntry : function (e) {
if (cat_filter === undefined) {
}
if (src_filter === undefined) {
}
if (!cat_filter || !src_filter) {
e.preventDefault();
}
},
/**
* Flushes the cached entries after a call to the Console's clearConsole().
*
* @method _afterClearConsole
* @protected
*/
_afterClearConsole : function () {
this._entries = [];
},
/**
* Triggers the Console to update if a known category filter
* changes value (e.g. visible => hidden). Updates the appropriate
* checkbox's checked state if necessary.
*
* @method _afterCategoryChange
* @param e {Event} the attribute change event object
* @protected
*/
_afterCategoryChange : function (e) {
// Don't update the console for new categories
this.refreshConsole();
this._filterBuffer();
}
}
},
/**
* Triggers the Console to update if a known source filter
* changes value (e.g. visible => hidden). Updates the appropriate
* checkbox's checked state if necessary.
*
* @method _afterSourceChange
* @param e {Event} the attribute change event object
* @protected
*/
_afterSourceChange : function (e) {
// Don't update the console for new sources
this.refreshConsole();
this._filterBuffer();
}
}
},
/**
* Flushes the Console's print buffer of any entries that have a category
* or source that is currently being excluded.
*
* @method _filterBuffer
* @protected
*/
_filterBuffer : function () {
start = null,
i;
} else if (start) {
start = null;
}
}
if (start) {
}
},
/**
* Repopulates the Console with entries appropriate to the current filter
* settings.
*
* @method refreshConsole
*/
refreshConsole : function () {
buffer = [],
i,e;
if (body) {
// Capture from bottom up. Entry order reversed.
e = entries[i];
--remaining;
}
}
host.printBuffer();
}
},
/**
* Updates the checked property of a filter checkbox of the specified type.
* If no checkbox is found for the input params, one is created.
*
* @method _uiSetCheckbox
* @param type {String} 'category' or 'source'
* @param item {String} the name of the filter (e.g. 'info', 'event')
* @param checked {Boolean} value to set the checkbox's checked property
* @protected
*/
this._categories :
this._sources,
host;
if (!checkbox) {
}
}
},
/**
* Passes checkbox clicks on to the category attribute.
*
* @metho _onCategoryCheckboxClick
* @param e {Event} the DOM event
*/
_onCategoryCheckboxClick : function (e) {
}
}
},
/**
* Passes checkbox clicks on to the source attribute.
*
* @method _onSourceCheckboxClick
* @param e {Event} the DOM event
*/
_onSourceCheckboxClick : function (e) {
}
}
},
/**
* Hides any number of categories from the UI. Convenience method for
* myConsole.filter.set('category.foo', false); set('category.bar', false);
* and so on.
*
* @method hideCategory
* @param cat* {String} 1..n categories to filter out of the UI
*/
if (multiple) {
} else {
}
},
/**
* Shows any number of categories in the UI. Convenience method for
* myConsole.filter.set('category.foo', true); set('category.bar', true);
* and so on.
*
* @method showCategory
* @param cat* {String} 1..n categories to allow to display in the UI
*/
if (multiple) {
} else {
}
},
/**
* Hides any number of sources from the UI. Convenience method for
* myConsole.filter.set('source.foo', false); set('source.bar', false);
* and so on.
*
* @method hideSource
* @param src* {String} 1..n sources to filter out of the UI
*/
if (multiple) {
} else {
}
},
/**
* Shows any number of sources in the UI. Convenience method for
* myConsole.filter.set('category.foo', true); set('category.bar', true);
* and so on.
*
* @method showSource
* @param cat* {String} 1..n sources to allow to display in the UI
*/
if (multiple) {
} else {
}
},
/**
* Creates a checkbox and label from the ConsoleFilters.FILTER_TEMPLATE for
* the provided type and name. The checkbox and label are appended to the
* container node passes as the first arg.
*
* @method _createCheckbox
* @param container {Node} the parentNode of the new checkbox and label
* @param name {String} the identifier of the filter
*/
filter_name : name,
}),
},
/**
* Validates category updates are objects and the subattribute is not too
* deep.
*
* @method _validateCategory
* @param cat {String} the new category:visibility map
* @param v {String} the subattribute path updated
* return Boolean
*/
_validateCategory : function (cat, v) {
},
/**
* Validates source updates are objects and the subattribute is not too
* deep.
*
* @method _validateSource
* @param cat {String} the new source:visibility map
* @param v {String} the subattribute path updated
* return Boolean
*/
_validateSource : function (src, v) {
}
});