From: Thierry Parmentelat Date: Fri, 5 Apr 2013 14:38:01 +0000 (+0200) Subject: new 'Messages' plugin X-Git-Tag: myslice-django-0.1-3~11 X-Git-Url: http://git.onelab.eu/?p=myslice.git;a=commitdiff_plain;h=945c1a3a74cae297f5300be3896a0a390e7bb0d8 new 'Messages' plugin --- diff --git a/plugins/messages/__init__.py b/plugins/messages/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/plugins/messages/messages.css b/plugins/messages/messages.css new file mode 100644 index 00000000..bde7799c --- /dev/null +++ b/plugins/messages/messages.css @@ -0,0 +1,9 @@ +.messages { + background-color: #f4f8f4; +} +// http://www.w3schools.com/html/html_colornames.asp +li.fatal { background-color: Chocolate;} +li.error { background-color: Coral; } +li.warning { background-color: BurlyWood; } +li.info { background-color: LightGreen; } +li.debug { background-color: Azure; } diff --git a/plugins/messages/messages.html b/plugins/messages/messages.html new file mode 100644 index 00000000..9f4d65a9 --- /dev/null +++ b/plugins/messages/messages.html @@ -0,0 +1,2 @@ +{# xxx could use radio buttons to filter out messages, and one for clearing up #} + diff --git a/plugins/messages/messages.js b/plugins/messages/messages.js new file mode 100644 index 00000000..d4265a30 --- /dev/null +++ b/plugins/messages/messages.js @@ -0,0 +1,96 @@ +/** + * MySlice Messages plugin + * Version: 0.1.0 + * URL: http://www.myslice.info + * Description: Display debug messages in a DIV + * Requires: + * Author: The MySlice Team + * Copyright: Copyright 2012 UPMC Sorbonne Universités + * License: GPLv3 + */ + +( function($) { + + /* Method calling logic */ + $.fn.Messages = function( method ) { + if ( methods[method] ) { + return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); + } else if ( typeof method === 'object' || ! method ) { + return methods.init.apply( this, arguments ); + } else { + $.error( 'Method ' + method + ' does not exist on $.Messages' ); + } + }; + + var methods = { + init : function( options ) { + + return this.each(function(){ + var $this = $(this), + data = $this.data('Messages'), + Messages = $('
', { text : $this.attr('title') }); + + // If the plugin hasn't been initialized yet + if ( ! data ) { + $(this).data('Messages', { + plugin_uuid: options.plugin_uuid, + target : $this, + Messages : Messages, + }); + + /* Plugin initialization */ + $.subscribe("messages:fatal", {'plugindiv': $this,'level':'fatal'}, display_message); + $.subscribe("messages:error", {'plugindiv': $this,'level':'error'}, display_message); + $.subscribe("messages:warning", {'plugindiv': $this,'level':'warning'}, display_message); + $.subscribe("messages:info", {'plugindiv': $this,'level':'info'}, display_message); + $.subscribe("messages:debug", {'plugindiv': $this,'level':'debug'}, display_message); + $.publish ("messages:info", 'Subscribed to all 5 message channels'); + /* End of plugin initialization */ + } + }); + }, + destroy : function( ) { + + return this.each(function(){ + var $this = $(this), data = $this.data('Messages'); + $(window).unbind('Messages'); + data.Messages.remove(); + $this.removeData('Messages'); + }); + }, +/* + reposition : function( ) { // ... }, + show : function( ) { // ... }, + hide : function( ) { // ... }, +*/ + update : function( content ) { }, + }; + + /* Private methods */ + + function display_message(e, message) { + var level=e.data.level; + var domid=e.data.plugindiv.data('Messages').plugin_uuid; + var html=""; + html += "
  • "; + html += "[" + level + "]"; + html += " " + new Date() + " "; +// html += "[" + domid + "]"; + html += " " + message + "
  • "; + $("ul#"+domid+".messages").append(html); + } + +})(jQuery); + +// temporary + +var tests=true; +if (tests) // arm this with a timeout rather + window.setInterval( + function () { + $.publish("messages:fatal","a fatal message"); + $.publish("messages:error","an error message"); + $.publish("messages:warning","a warning message"); + $.publish("messages:info","an info message"); + $.publish("messages:debug","a debug message"); + }, 5000); diff --git a/plugins/messages/messages.py b/plugins/messages/messages.py new file mode 100644 index 00000000..020ad1bc --- /dev/null +++ b/plugins/messages/messages.py @@ -0,0 +1,26 @@ +from unfold.plugin import Plugin + +class Messages (Plugin): + + def __init__ (self, **settings): + Plugin.__init__ (self, **settings) + + def template_file (self): + return "messages.html" + + def requirements (self): + return { + 'js_files' : "js/messages.js", + 'css_files' : "css/messages.css", + } + + # although this has no query, we need a plugin instance to be created in the js output + def export_json_settings (self): + return True + # the js plugin expects a domid + def json_settings_list (self): + return [ 'plugin_uuid' ] + + # and we don't need a spin wheel + def start_with_spin (self): + return False diff --git a/trash/sliceview.py b/trash/sliceview.py index 436346bf..b7fe2c9f 100644 --- a/trash/sliceview.py +++ b/trash/sliceview.py @@ -10,12 +10,13 @@ from manifold.manifoldquery import ManifoldQuery from plugins.stack.stack import Stack from plugins.tabs.tabs import Tabs +from plugins.lists.slicelist import SliceList from plugins.hazelnut.hazelnut import Hazelnut from plugins.googlemap.googlemap import GoogleMap from plugins.senslabmap.senslabmap import SensLabMap -from plugins.lists.slicelist import SliceList from plugins.querycode.querycode import QueryCode from plugins.quickfilter.quickfilter import QuickFilter +from plugins.messages.messages import Messages from myslice.viewutils import quickfilter_criterias @@ -115,6 +116,11 @@ def slice_view (request, slicename=tmp_default_slice): domid='filters', toggled=False, ), + Messages ( + page=page, + title="Runtime messages", + domid="msgs", + ) ]) # variables that will get passed to the view-unfold1.html template