From: Jordan Augé Date: Tue, 9 Jul 2013 23:17:44 +0000 (+0200) Subject: added messaging thanks to jquery-notify X-Git-Tag: myslice-0.2-1~99 X-Git-Url: http://git.onelab.eu/?p=myslice.git;a=commitdiff_plain;h=07411e389a9d39ddccfd93cd53ac895393a8ae3a added messaging thanks to jquery-notify --- diff --git a/Makefile b/Makefile index 7752b109..74438a43 100644 --- a/Makefile +++ b/Makefile @@ -85,6 +85,10 @@ THIRD-PARTY-RESOURCES += $(shell ls third-party/syntaxhighlighter/styles/shTheme THIRD-PARTY-RESOURCES += $(shell ls third-party/smartwizard-1636c86/js/jquery.smartWizard-2.0.js) #THIRD-PARTY-RESOURCES += $(shell ls third-party/smartwizard-1636c86/js/jquery.smartWizard-2.0.min.js) THIRD-PARTY-RESOURCES += $(shell ls third-party/smartwizard-1636c86/styles/smart_wizard.css) +# jquery.notify +THIRD-PARTY-RESOURCES += $(shell ls third-party/jquery-notify/jquery.notify.js) +THIRD-PARTY-RESOURCES += $(shell ls third-party/jquery-notify/jquery.notify.min.js) +THIRD-PARTY-RESOURCES += $(shell ls third-party/jquery-notify/ui.notify.css) thirdparty-js: diff --git a/manifold/js/manifold.js b/manifold/js/manifold.js index 221986df..c3aac9fb 100644 --- a/manifold/js/manifold.js +++ b/manifold/js/manifold.js @@ -29,9 +29,12 @@ var CLEAR_FIELDS = 6; var NEW_RECORD = 7; var CLEAR_RECORDS = 8; -var IN_PROGRESS = 101; +var IN_PROGRESS = 101; var DONE = 102; +var SET_ADD = 201; +var SET_REMOVED = 202; + /*! * This namespace holds functions for globally managing query objects * \Class Manifold @@ -122,7 +125,7 @@ var manifold = { } query.iter_subqueries(function (sq) { - $('.plugin').trigger(manifold.get_record_channel(sq.query_uuid), [IN_PROGRESS]); + manifold.raise_record_event(sq.query_uuid, IN_PROGRESS); }); // not quite sure what happens if we send a string directly, as POST data is named.. @@ -157,6 +160,34 @@ var manifold = { return true; }, + raise_event_handler: function(type, query_uuid, event_type, value) + { + if (type == 'query') { + var channels = [ manifold.get_query_channel(query_uuid), manifold.get_query_channel('*') ]; + } else if (type == 'record') { + var channels = [ manifold.get_record_channel(query_uuid), manifold.get_record_channel('*') ]; + + } else { + throw 'Incorrect type for manifold.raise_event()'; + } + $.each(channels, function(i, channel) { + if (value === undefined) + $('.plugin').trigger(channel, [event_type]); + else + $('.plugin').trigger(channel, [event_type, value]); + }); + }, + + raise_query_event: function(query_uuid, event_type, value) + { + manifold.raise_event_handler('query', query_uuid, event_type, value); + }, + + raise_record_event: function(query_uuid, event_type, value) + { + manifold.raise_event_handler('record', query_uuid, event_type, value); + }, + /*! * Publish result * \fn publish_result(query, results) @@ -169,12 +200,11 @@ var manifold = { result = []; // NEW PLUGIN API - var channel = manifold.get_record_channel(query.query_uuid); - $('.plugin').trigger(channel, [CLEAR_RECORDS]); + manifold.raise_record_event(query.query_uuid, CLEAR_RECORDS); $.each(result, function(i, record) { - $('.plugin').trigger(channel, [NEW_RECORD, record]); + manifold.raise_record_event(query.query_uuid, NEW_RECORD, record); }); - $('.plugin').trigger(channel, [DONE]); + manifold.raise_record_event(query.query_uuid, DONE); // OLD PLUGIN API BELOW /* Publish an update announce */ @@ -247,6 +277,18 @@ var manifold = { } }, + raise_event: function(uuid, event_type, value) + { + switch(event_type) { + case SET_ADD: + // Query uuid has been updated with the key of a new element + break; + case SET_REMOVED: + // Query uuid has been updated with the key of a removed element + break; + } + }, + /* Publish/subscribe channels for internal use */ get_query_channel: function(uuid) { return '/query/' + uuid }, get_record_channel: function(uuid) { return '/record/' + uuid }, diff --git a/manifold/manifoldapi.py b/manifold/manifoldapi.py index cc38ba74..d2a4a512 100644 --- a/manifold/manifoldapi.py +++ b/manifold/manifoldapi.py @@ -58,6 +58,7 @@ class ManifoldAPI: return ManifoldResult(code=result['code'], value=result['value']) else: if debug: print "KO (new API) - raising ManifoldException" + print "RESULT=", result raise ManifoldException(ManifoldResult(code=result['code'], output=result['description'])) else: if debug: print "taken as old API" diff --git a/manifold/manifoldproxy.py b/manifold/manifoldproxy.py index fd4c5ad9..a8bec589 100644 --- a/manifold/manifoldproxy.py +++ b/manifold/manifoldproxy.py @@ -87,6 +87,7 @@ with the query passed using POST""" try: answer=manifold_api.send_manifold_query (manifold_query) except ManifoldException, manifold_result: + print "MANIFOLD EXCEPTION" answer=manifold_result print "="*80 print "ANSWER IN PROXY", answer diff --git a/plugins/hazelnut/hazelnut.js b/plugins/hazelnut/hazelnut.js index e63baccd..84be66ed 100644 --- a/plugins/hazelnut/hazelnut.js +++ b/plugins/hazelnut/hazelnut.js @@ -178,78 +178,78 @@ /* methods */ - this.set_query = function(query) { - messages.info('hazelnut.set_query'); - var options = this.options; - /* Compare current and advertised query to get added and removed fields */ - previous_query = this.current_query; - /* Save the query as the current query */ - this.current_query = query; - if (debug) - messages.debug("hazelnut.set_query, current_query is now -> " + this.current_query); - - /* We check all necessary fields : in column editor I presume XXX */ - // XXX ID naming has no plugin_uuid - if (typeof(query.fields) != 'undefined') { - $.each (query.fields, function(index, value) { - if (!$('#hazelnut-checkbox-' + options.plugin_uuid + "-" + value).attr('checked')) - $('#hazelnut-checkbox-' + options.plugin_uuid + "-" + value).attr('checked', true); - }); - } - - /* Process updates in filters / current_query must be updated before this call for filtering ! */ - this.table.fnDraw(); - - /* - * Process updates in fields - */ - if (typeof(query.fields) != 'undefined') { - /* DataTable Settings */ - var oSettings = this.table.dataTable().fnSettings(); - var cols = oSettings.aoColumns; - var colnames = cols.map(function(x) {return x.sTitle}); - colnames = $.grep(colnames, function(value) {return value != "+/-";}); - - if (previous_query == null) { - var added_fields = query.fields; - var removed_fields = colnames; - removed_fields = $.grep(colnames, function(x) { return $.inArray(x, added_fields) == -1}); - } else { - var tmp = previous_query.diff_fields(query); - var added_fields = tmp.added; - var removed_fields = tmp.removed; - } - - /* Hide/unhide columns to match added/removed fields */ - var object = this; - $.each(added_fields, function (index, field) { - var index = object.getColIndex(field,cols); - if(index != -1) - object.table.fnSetColumnVis(index, true); - }); - $.each(removed_fields, function (index, field) { - var index = object.getColIndex(field,cols); - if(index != -1) - object.table.fnSetColumnVis(index, false); - }); - } - } - - this.set_resources = function(resources, instance) { - if (debug) - messages.debug("entering hazelnut.set_resources"); - var options = this.options; - var previous_resources = this.current_resources; - this.current_resources = resources; - - /* We uncheck all checkboxes ... */ - $('hazelnut-checkbox-' + options.plugin_uuid).attr('checked', false); - /* ... and check the ones specified in the resource list */ - $.each(this.current_resources, function(index, urn) { - $('#hazelnut-checkbox-' + options.plugin_uuid + "-" + urn).attr('checked', true) - }); - - } +// DEPRECATED // this.set_query = function(query) { +// DEPRECATED // messages.info('hazelnut.set_query'); +// DEPRECATED // var options = this.options; +// DEPRECATED // /* Compare current and advertised query to get added and removed fields */ +// DEPRECATED // previous_query = this.current_query; +// DEPRECATED // /* Save the query as the current query */ +// DEPRECATED // this.current_query = query; +// DEPRECATED // if (debug) +// DEPRECATED // messages.debug("hazelnut.set_query, current_query is now -> " + this.current_query); +// DEPRECATED // +// DEPRECATED // /* We check all necessary fields : in column editor I presume XXX */ +// DEPRECATED // // XXX ID naming has no plugin_uuid +// DEPRECATED // if (typeof(query.fields) != 'undefined') { +// DEPRECATED // $.each (query.fields, function(index, value) { +// DEPRECATED // if (!$('#hazelnut-checkbox-' + options.plugin_uuid + "-" + value).attr('checked')) +// DEPRECATED // $('#hazelnut-checkbox-' + options.plugin_uuid + "-" + value).attr('checked', true); +// DEPRECATED // }); +// DEPRECATED // } +// DEPRECATED // +// DEPRECATED // /* Process updates in filters / current_query must be updated before this call for filtering ! */ +// DEPRECATED // this.table.fnDraw(); +// DEPRECATED // +// DEPRECATED // /* +// DEPRECATED // * Process updates in fields +// DEPRECATED // */ +// DEPRECATED // if (typeof(query.fields) != 'undefined') { +// DEPRECATED // /* DataTable Settings */ +// DEPRECATED // var oSettings = this.table.dataTable().fnSettings(); +// DEPRECATED // var cols = oSettings.aoColumns; +// DEPRECATED // var colnames = cols.map(function(x) {return x.sTitle}); +// DEPRECATED // colnames = $.grep(colnames, function(value) {return value != "+/-";}); +// DEPRECATED // +// DEPRECATED // if (previous_query == null) { +// DEPRECATED // var added_fields = query.fields; +// DEPRECATED // var removed_fields = colnames; +// DEPRECATED // removed_fields = $.grep(colnames, function(x) { return $.inArray(x, added_fields) == -1}); +// DEPRECATED // } else { +// DEPRECATED // var tmp = previous_query.diff_fields(query); +// DEPRECATED // var added_fields = tmp.added; +// DEPRECATED // var removed_fields = tmp.removed; +// DEPRECATED // } +// DEPRECATED // +// DEPRECATED // /* Hide/unhide columns to match added/removed fields */ +// DEPRECATED // var object = this; +// DEPRECATED // $.each(added_fields, function (index, field) { +// DEPRECATED // var index = object.getColIndex(field,cols); +// DEPRECATED // if(index != -1) +// DEPRECATED // object.table.fnSetColumnVis(index, true); +// DEPRECATED // }); +// DEPRECATED // $.each(removed_fields, function (index, field) { +// DEPRECATED // var index = object.getColIndex(field,cols); +// DEPRECATED // if(index != -1) +// DEPRECATED // object.table.fnSetColumnVis(index, false); +// DEPRECATED // }); +// DEPRECATED // } +// DEPRECATED // } + +// DEPRECATED // this.set_resources = function(resources, instance) { +// DEPRECATED // if (debug) +// DEPRECATED // messages.debug("entering hazelnut.set_resources"); +// DEPRECATED // var options = this.options; +// DEPRECATED // var previous_resources = this.current_resources; +// DEPRECATED // this.current_resources = resources; +// DEPRECATED // +// DEPRECATED // /* We uncheck all checkboxes ... */ +// DEPRECATED // $('hazelnut-checkbox-' + options.plugin_uuid).attr('checked', false); +// DEPRECATED // /* ... and check the ones specified in the resource list */ +// DEPRECATED // $.each(this.current_resources, function(index, urn) { +// DEPRECATED // $('#hazelnut-checkbox-' + options.plugin_uuid + "-" + urn).attr('checked', true) +// DEPRECATED // }); +// DEPRECATED // +// DEPRECATED // } /** * @brief Determine index of key in the table columns @@ -261,30 +261,30 @@ return (tabIndex.length > 0) ? tabIndex[0] : -1; } - /** - * @brief - * XXX will be removed/replaced - */ - this.selected_changed = function(e, change) { - if (debug) messages.debug("entering hazelnut.selected_changed"); - var actions = change.split("/"); - if (actions.length > 1) { - var oNodes = this.table.fnGetNodes(); - var myNode = $.grep(oNodes, function(value) { - if (value.id == actions[1]) { return value; } - }); - if( myNode.length>0 ) { - if ((actions[2]=="add" && actions[0]=="cancel") || actions[0]=="del") - checked=''; - else - checked="checked='checked' "; - var newValue = this.checkbox(actions[1], 'node', checked, false); - var columnPos = this.table.fnSettings().aoColumns.length - 1; - this.table.fnUpdate(newValue, myNode[0], columnPos); - this.table.fnDraw(); - } - } - } +// DEPRECATED // /** +// DEPRECATED // * @brief +// DEPRECATED // * XXX will be removed/replaced +// DEPRECATED // */ +// DEPRECATED // this.selected_changed = function(e, change) { +// DEPRECATED // if (debug) messages.debug("entering hazelnut.selected_changed"); +// DEPRECATED // var actions = change.split("/"); +// DEPRECATED // if (actions.length > 1) { +// DEPRECATED // var oNodes = this.table.fnGetNodes(); +// DEPRECATED // var myNode = $.grep(oNodes, function(value) { +// DEPRECATED // if (value.id == actions[1]) { return value; } +// DEPRECATED // }); +// DEPRECATED // if( myNode.length>0 ) { +// DEPRECATED // if ((actions[2]=="add" && actions[0]=="cancel") || actions[0]=="del") +// DEPRECATED // checked=''; +// DEPRECATED // else +// DEPRECATED // checked="checked='checked' "; +// DEPRECATED // var newValue = this.checkbox(actions[1], 'node', checked, false); +// DEPRECATED // var columnPos = this.table.fnSettings().aoColumns.length - 1; +// DEPRECATED // this.table.fnUpdate(newValue, myNode[0], columnPos); +// DEPRECATED // this.table.fnDraw(); +// DEPRECATED // } +// DEPRECATED // } +// DEPRECATED // } this.update_plugin = function(e, rows) { // e.data is what we passed in second argument to subscribe @@ -604,8 +604,17 @@ } function check_click (e) { + var object = e.data.instance; - var value = this.value; + + /* The key of the object to be added */ + // XXX What about multiple keys ? + var value = this.value; + + // NEW PLUGIN API + manifold.raise_event(object.options.query_uuid, this.checked?SET_ADD:SET_REMOVED, value); + + // OLD PLUGIN API BELOW if (this.checked) { object.current_resources.push(value); diff --git a/portal/templates/dashboard.html b/portal/templates/dashboard.html new file mode 100644 index 00000000..14892f3b --- /dev/null +++ b/portal/templates/dashboard.html @@ -0,0 +1,43 @@ +{% extends "layout-unfold1.html" %} + +{% block head %} + +{% endblock %} + +{% block unfold1_main %} + +
+
+ +
+
+

User profile

+
+
+ +
+
+ +
+
+

Testbeds access

+
+
+ {{networks}} +
+
+ +
+
+

Slices

+
+
+ {{slices}} +
+
+
+ +{% endblock %} diff --git a/portal/views.py b/portal/views.py index f03befa9..815c16a1 100644 --- a/portal/views.py +++ b/portal/views.py @@ -22,6 +22,7 @@ from django.conf import settings from django.contrib.sites.models import Site, RequestSite +from django.contrib import messages from django.views.generic import View from django.views.generic.base import TemplateView from django.shortcuts import render @@ -40,6 +41,9 @@ class DashboardView(TemplateView): def get_context_data(self, **kwargs): user_hrn = 'ple.upmc.jordan_auge' + messages.info(self.request, 'You have logged in') + + page = Page(self.request) # Slow... diff --git a/third-party/jquery-notify/alert.png b/third-party/jquery-notify/alert.png new file mode 100644 index 00000000..d64c533f Binary files /dev/null and b/third-party/jquery-notify/alert.png differ diff --git a/third-party/jquery-notify/jquery.notify.js b/third-party/jquery-notify/jquery.notify.js new file mode 100644 index 00000000..dd1d7486 --- /dev/null +++ b/third-party/jquery-notify/jquery.notify.js @@ -0,0 +1,156 @@ +/* jQuery Notify UI Widget 1.5 by Eric Hynds + * http://www.erichynds.com/jquery/a-jquery-ui-growl-ubuntu-notification-widget/ + * + * Depends: + * - jQuery 1.4+ + * - jQuery UI 1.8 widget factory + * + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html +*/ +(function($){ + + $.widget("ech.notify", { + + options: { + speed: 500, + expires: 5000, + stack: "below", + custom: false, + queue: false + }, + + _create: function(){ + var self = this; + this.templates = {}; + this.keys = []; + + // build and save templates + this.element.addClass("ui-notify").children().addClass("ui-notify-message ui-notify-message-style").each(function(i){ + var key = this.id || i; + self.keys.push(key); + self.templates[key] = $(this).removeAttr("id").wrap("
").parent().html(); // because $(this).andSelf().html() no workie + }).end().empty().show(); + }, + + create: function(template, msg, opts){ + if(typeof template === "object"){ + opts = msg; + msg = template; + template = null; + } + + var tpl = this.templates[ template || this.keys[0]]; + + // remove default styling class if rolling w/ custom classes + if(opts && opts.custom){ + tpl = $(tpl).removeClass("ui-notify-message-style").wrap("
").parent().html(); + } + + this.openNotifications = this.openNotifications || 0; + + // return a new notification instance + return new $.ech.notify.instance(this)._create(msg, $.extend({}, this.options, opts), tpl); + } + }); + + // instance constructor + $.extend($.ech.notify, { + instance: function(widget){ + this.__super = widget; + this.isOpen = false; + } + }); + + // instance methods + $.extend($.ech.notify.instance.prototype, { + + _create: function(params, options, template){ + this.options = options; + + var self = this, + + // build html template + html = template.replace(/#(?:\{|%7B)(.*?)(?:\}|%7D)/g, function($1, $2){ + return ($2 in params) ? params[$2] : ''; + }), + + // the actual message + m = (this.element = $(html)), + + // close link + closelink = m.find(".ui-notify-close"); + + // clickable? + if(typeof this.options.click === "function"){ + m.addClass("ui-notify-click").bind("click", function(e){ + self._trigger("click", e, self); + }); + } + + // show close link? + if(closelink.length){ + closelink.bind("click", function(){ + self.close(); + return false; + }); + } + + this.__super.element.queue("notify", function(){ + self.open(); + + // auto expire? + if(typeof options.expires === "number" && options.expires > 0){ + setTimeout($.proxy(self.close, self), options.expires); + } + }); + + if(!this.options.queue || this.__super.openNotifications <= this.options.queue - 1) { + this.__super.element.dequeue("notify"); + } + + return this; + }, + + close: function(){ + var speed = this.options.speed; + + this.element.fadeTo(speed, 0).slideUp(speed, $.proxy(function(){ + this._trigger("close"); + this.isOpen = false; + this.element.remove(); + this.__super.openNotifications -= 1; + this.__super.element.dequeue("notify"); + }, this)); + + return this; + }, + + open: function(){ + if(this.isOpen || this._trigger("beforeopen") === false){ + return this; + } + + var self = this; + + this.__super.openNotifications += 1; + + this.element[this.options.stack === "above" ? "prependTo" : "appendTo"](this.__super.element).css({ display:"none", opacity:"" }).fadeIn(this.options.speed, function(){ + self._trigger("open"); + self.isOpen = true; + }); + + return this; + }, + + widget: function(){ + return this.element; + }, + + _trigger: function(type, e, instance){ + return this.__super._trigger.call( this, type, e, instance ); + } + }); + +})(jQuery); diff --git a/third-party/jquery-notify/jquery.notify.min.js b/third-party/jquery-notify/jquery.notify.min.js new file mode 100644 index 00000000..4a076e1b --- /dev/null +++ b/third-party/jquery-notify/jquery.notify.min.js @@ -0,0 +1,12 @@ +/* jQuery Notify UI Widget 1.5 by Eric Hynds + * http://www.erichynds.com/jquery/a-jquery-ui-growl-ubuntu-notification-widget/ + * + * Depends: + * - jQuery 1.4 + * - jQuery UI 1.8 widget factory + * + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html +*/ +(function(d){d.widget("ech.notify",{options:{speed:500,expires:5E3,stack:"below",custom:!1,queue:!1},_create:function(){var a=this;this.templates={};this.keys=[];this.element.addClass("ui-notify").children().addClass("ui-notify-message ui-notify-message-style").each(function(b){b=this.id||b;a.keys.push(b);a.templates[b]=d(this).removeAttr("id").wrap("
").parent().html()}).end().empty().show()},create:function(a,b,c){"object"===typeof a&&(c=b,b=a,a=null);a=this.templates[a||this.keys[0]];c&&c.custom&&(a=d(a).removeClass("ui-notify-message-style").wrap("
").parent().html());this.openNotifications=this.openNotifications||0;return(new d.ech.notify.instance(this))._create(b,d.extend({},this.options,c),a)}});d.extend(d.ech.notify,{instance:function(a){this.__super=a;this.isOpen=!1}});d.extend(d.ech.notify.instance.prototype,{_create:function(a,b,c){this.options=b;var e=this,c=c.replace(/#(?:\{|%7B)(.*?)(?:\}|%7D)/g,function(b,c){return c in a?a[c]:""}),c=this.element=d(c),f=c.find(".ui-notify-close");"function"===typeof this.options.click&&c.addClass("ui-notify-click").bind("click",function(a){e._trigger("click",a,e)});f.length&&f.bind("click",function(){e.close();return!1});this.__super.element.queue("notify",function(){e.open();"number"===typeof b.expires&&0 MySlice - {{ title }} {# This is where insert_str will end up #}{% media_container prelude %} +{% include 'messages-header.html' %} {{ header_prelude }} @@ -19,6 +20,7 @@ {% block topmenu %} {% include 'widget-topmenu.html' %} {% endblock topmenu %} +{% include 'messages.html' %}
diff --git a/views/templates/messages-header.html b/views/templates/messages-header.html new file mode 100644 index 00000000..0c292e74 --- /dev/null +++ b/views/templates/messages-header.html @@ -0,0 +1,38 @@ + + + + + + diff --git a/views/templates/messages.html b/views/templates/messages.html new file mode 100644 index 00000000..b6843361 --- /dev/null +++ b/views/templates/messages.html @@ -0,0 +1,38 @@ + +