You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ea...@apache.org on 2016/10/19 12:49:05 UTC

[06/10] qpid-dispatch git commit: DISPATCH-531 Initial version of openstack horizon plugin

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/0c58c381/console/dispatch-dashboard/dispatch/static/dashboard/dispatch/lib/slider.js
----------------------------------------------------------------------
diff --git a/console/dispatch-dashboard/dispatch/static/dashboard/dispatch/lib/slider.js b/console/dispatch-dashboard/dispatch/static/dashboard/dispatch/lib/slider.js
new file mode 100644
index 0000000..97189ae
--- /dev/null
+++ b/console/dispatch-dashboard/dispatch/static/dashboard/dispatch/lib/slider.js
@@ -0,0 +1,233 @@
+/*
+ jQuery UI Slider plugin wrapper
+*/
+angular.module('ui.slider', []).value('uiSliderConfig',{}).directive('uiSlider', ['uiSliderConfig', '$timeout', function(uiSliderConfig, $timeout) {
+    uiSliderConfig = uiSliderConfig || {};
+    return {
+        require: 'ngModel',
+        compile: function() {
+            var preLink = function (scope, elm, attrs, ngModel) {
+
+                function parseNumber(n, decimals) {
+                    return (decimals) ? parseFloat(n) : parseInt(n, 10);
+                }
+
+                var directiveOptions = angular.copy(scope.$eval(attrs.uiSlider));
+                var options = angular.extend(directiveOptions || {}, uiSliderConfig);
+                // Object holding range values
+                var prevRangeValues = {
+                    min: null,
+                    max: null
+                };
+
+                // convenience properties
+                var properties = ['min', 'max', 'step', 'lowerBound', 'upperBound'];
+                var useDecimals = (!angular.isUndefined(attrs.useDecimals)) ? true : false;
+                var updateOn = (angular.isDefined(options['updateOn'])) ? options['updateOn'] : 'slide'
+
+                var init = function() {
+                    // When ngModel is assigned an array of values then range is expected to be true.
+                    // Warn user and change range to true else an error occurs when trying to drag handle
+                    if (angular.isArray(ngModel.$viewValue) && options.range !== true) {
+                        console.warn('Change your range option of ui-slider. When assigning ngModel an array of values then the range option should be set to true.');
+                        options.range = true;
+                    }
+
+                    // Ensure the convenience properties are passed as options if they're defined
+                    // This avoids init ordering issues where the slider's initial state (eg handle
+                    // position) is calculated using widget defaults
+                    // Note the properties take precedence over any duplicates in options
+                    angular.forEach(properties, function(property) {
+                        if (angular.isDefined(attrs[property])) {
+                            options[property] = parseNumber(attrs[property], useDecimals);
+                        }
+                    });
+
+                    elm.slider(options);
+                    init = angular.noop;
+                };
+
+                // Find out if decimals are to be used for slider
+                angular.forEach(properties, function(property) {
+                    // support {{}} and watch for updates
+                    attrs.$observe(property, function(newVal) {
+                        if (!!newVal) {
+                            init();
+                            options[property] = parseNumber(newVal, useDecimals);
+                            elm.slider('option', property, parseNumber(newVal, useDecimals));
+                            ngModel.$render();
+                        }
+                    });
+                });
+                attrs.$observe('disabled', function(newVal) {
+                    init();
+                    elm.slider('option', 'disabled', !!newVal);
+                });
+
+                // Watch ui-slider (byVal) for changes and update
+                scope.$watch(attrs.uiSlider, function(newVal) {
+                    init();
+                    if(newVal !== undefined) {
+                      elm.slider('option', newVal);
+                    }
+                }, true);
+
+                // Late-bind to prevent compiler clobbering
+                $timeout(init, 0, true);
+
+                // Update model value from slider
+                elm.bind(updateOn, function(event, ui) {
+                    var valuesChanged;
+
+                    if (ui.values) {
+                        var boundedValues = ui.values.slice();
+
+                        if (options.lowerBound && boundedValues[0] < options.lowerBound) {
+                            boundedValues[0] = Math.max(boundedValues[0], options.lowerBound);
+                        }
+                        if (options.upperBound && boundedValues[1] > options.upperBound) {
+                            boundedValues[1] = Math.min(boundedValues[1], options.upperBound);
+                        }
+
+                        if (boundedValues[0] !== ui.values[0] || boundedValues[1] !== ui.values[1]) {
+                            valuesChanged = true;
+                            ui.values = boundedValues;
+                        }
+                    } else {
+                        var boundedValue = ui.value;
+
+                        if (options.lowerBound && boundedValue < options.lowerBound) {
+                            boundedValue = Math.max(boundedValue, options.lowerBound);
+                        }
+                        if (options.upperBound && boundedValue > options.upperBound) {
+                            boundedValue = Math.min(boundedValue, options.upperBound);
+                        }
+
+                        if (boundedValue !== ui.value) {
+                            valuesChanged = true;
+                            ui.value = boundedValue;
+                        }
+                    }
+
+
+                    ngModel.$setViewValue(ui.values || ui.value);
+                    $(ui.handle).find('.ui-slider-tip').text(ui.value);
+                    scope.$apply();
+
+                    if (valuesChanged) {
+                        setTimeout(function() {
+                            elm.slider('value', ui.values || ui.value);
+                        }, 0);
+
+                        return false;
+                    }
+                });
+
+                // Update slider from model value
+                ngModel.$render = function() {
+                    init();
+                    var method = options.range === true ? 'values' : 'value';
+
+                    if (options.range !== true && isNaN(ngModel.$viewValue) && !(ngModel.$viewValue instanceof Array)) {
+                        ngModel.$viewValue = 0;
+                    }
+                    else if (options.range && !angular.isDefined(ngModel.$viewValue)) {
+                            ngModel.$viewValue = [0,0];
+                    }
+
+                    // Do some sanity check of range values
+                    if (options.range === true) {
+                        // previously, the model was a string b/c it was in a text input, need to convert to a array.
+                        // make sure input exists, comma exists once, and it is a string.
+                        if (ngModel.$viewValue && angular.isString(ngModel.$viewValue) && (ngModel.$viewValue.match(/,/g) || []).length === 1) {
+                            // transform string model into array.
+                            var valueArr = ngModel.$viewValue.split(',');
+                            ngModel.$viewValue = [Number(valueArr[0]), Number(valueArr[1])];
+                        }
+                        // Check outer bounds for min and max values
+                        if (angular.isDefined(options.min) && options.min > ngModel.$viewValue[0]) {
+                            ngModel.$viewValue[0] = options.min;
+                        }
+                        if (angular.isDefined(options.max) && options.max < ngModel.$viewValue[1]) {
+                            ngModel.$viewValue[1] = options.max;
+                        }
+
+                        // Check min and max range values
+                        if (ngModel.$viewValue[0] > ngModel.$viewValue[1]) {
+                            // Min value should be less to equal to max value
+                            if (prevRangeValues.min >= ngModel.$viewValue[1]) {
+                                ngModel.$viewValue[1] = prevRangeValues.min;
+                            }
+                            // Max value should be less to equal to min value
+                            if (prevRangeValues.max <= ngModel.$viewValue[0]) {
+                                ngModel.$viewValue[0] = prevRangeValues.max;
+                            }
+                        }
+
+                        // Store values for later user
+                        prevRangeValues.min = ngModel.$viewValue[0];
+                        prevRangeValues.max = ngModel.$viewValue[1];
+
+                    }
+                    elm.slider(method, ngModel.$viewValue);
+                };
+
+                scope.$watch(attrs.ngModel, function() {
+                    if (options.range === true) {
+                        ngModel.$render();
+
+                        $(elm).find('.ui-slider-tip').each(function(i, tipElm) {
+                            $(tipElm).text(ngModel.$viewValue[i]);
+                        });
+                    } else {
+                        $(elm).find('.ui-slider-tip').text(ngModel.$viewValue);
+                    }
+                }, true);
+
+                function destroy() {
+                    if (elm.hasClass('ui-slider')) {
+                        elm.slider('destroy');
+                    }
+                }
+
+                scope.$on("$destroy", destroy);
+                elm.one('$destroy', destroy);
+            };
+
+            var postLink = function (scope, element, attrs, ngModel) {
+                // Add tick marks if 'tick' and 'step' attributes have been setted on element.
+                // Support horizontal slider bar so far. 'tick' and 'step' attributes are required.
+                var options = angular.extend({}, scope.$eval(attrs.uiSlider));
+                var properties = ['min', 'max', 'step', 'tick', 'tip'];
+                angular.forEach(properties, function(property) {
+                    if (angular.isDefined(attrs[property])) {
+                        options[property] = attrs[property];
+                    }
+                });
+                if (angular.isDefined(options['tick']) && angular.isDefined(options['step'])) {
+                    var total = parseInt( (parseInt(options['max']) - parseInt(options['min'])) /parseInt(options['step']));
+                    for (var i = total; i >= 0; i--) {
+                        var left = ((i / total) * 100) + '%';
+                        $("<div/>").addClass("ui-slider-tick").appendTo(element).css({left: left});
+                    };
+                }
+                if(angular.isDefined(options['tip'])) {
+                    $timeout(function(){
+                        var handles = element.find('.ui-slider-handle');
+                        if(handles && handles.length>1 && ngModel.$viewValue && angular.isArray(ngModel.$viewValue)){
+                            $(handles[0]).append('<div class="ui-slider-tip">'+ngModel.$viewValue[0]+'</div>');
+                            $(handles[1]).append('<div class="ui-slider-tip">'+ngModel.$viewValue[1]+'</div>');
+                        }else{
+                            element.find('.ui-slider-handle').append('<div class="ui-slider-tip">'+ngModel.$viewValue+'</div>');
+                        }
+                    },10);
+                }
+            }
+
+            return {
+                pre: preLink,
+                post: postLink
+            };
+        }
+    };
+}]);

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/0c58c381/console/dispatch-dashboard/dispatch/static/dashboard/dispatch/lib/tooltipsy.min.js
----------------------------------------------------------------------
diff --git a/console/dispatch-dashboard/dispatch/static/dashboard/dispatch/lib/tooltipsy.min.js b/console/dispatch-dashboard/dispatch/static/dashboard/dispatch/lib/tooltipsy.min.js
new file mode 100644
index 0000000..ed2c2f8
--- /dev/null
+++ b/console/dispatch-dashboard/dispatch/static/dashboard/dispatch/lib/tooltipsy.min.js
@@ -0,0 +1,20 @@
+/* tooltipsy by Brian Cray
+ * Lincensed under GPL2 - http://www.gnu.org/licenses/gpl-2.0.html
+ * Option quick reference:
+ * - alignTo: "element" or "cursor" (Defaults to "element")
+ * - offset: Tooltipsy distance from element or mouse cursor, dependent on alignTo setting. Set as array [x, y] (Defaults to [0, -1])
+ * - content: HTML or text content of tooltip. Defaults to "" (empty string), which pulls content from target element's title attribute
+ * - show: function(event, tooltip) to show the tooltip. Defaults to a show(100) effect
+ * - hide: function(event, tooltip) to hide the tooltip. Defaults to a fadeOut(100) effect
+ * - delay: A delay in milliseconds before showing a tooltip. Set to 0 for no delay. Defaults to 200
+ * - css: object containing CSS properties and values. Defaults to {} to use stylesheet for styles
+ * - className: DOM class for styling tooltips with CSS. Defaults to "tooltipsy"
+ * - showEvent: Set a custom event to bind the show function. Defaults to mouseenter
+ * - hideEvent: Set a custom event to bind the show function. Defaults to mouseleave
+ * Method quick reference:
+ * - $('element').data('tooltipsy').show(): Force the tooltip to show
+ * - $('element').data('tooltipsy').hide(): Force the tooltip to hide
+ * - $('element').data('tooltipsy').destroy(): Remove tooltip from DOM
+ * More information visit http://tooltipsy.com/
+ */
+;(function(a){a.tooltipsy=function(c,b){this.options=b;this.$el=a(c);this.title=this.$el.attr("title")||"";this.$el.attr("title","");this.random=parseInt(Math.random()*10000);this.ready=false;this.shown=false;this.width=0;this.height=0;this.delaytimer=null;this.$el.data("tooltipsy",this);this.init()};a.tooltipsy.prototype={init:function(){var e=this,d,b=e.$el,c=b[0];e.settings=d=a.extend({},e.defaults,e.options);d.delay=+d.delay;if(typeof d.content==="function"){e.readify()}if(d.showEvent===d.hideEvent&&d.showEvent==="click"){b.toggle(function(f){if(d.showEvent==="click"&&c.tagName=="A"){f.preventDefault()}if(d.delay>0){e.delaytimer=window.setTimeout(function(){e.show(f)},d.delay)}else{e.show(f)}},function(f){if(d.showEvent==="click"&&c.tagName=="A"){f.preventDefault()}window.clearTimeout(e.delaytimer);e.delaytimer=null;e.hide(f)})}else{b.bind(d.showEvent,function(f){if(d.showEvent==="click"&&c.tagName=="A"){f.preventDefault()}e.delaytimer=window.setTimeout(function(){e.show(f)},d.d
 elay||0)}).bind(d.hideEvent,function(f){if(d.showEvent==="click"&&c.tagName=="A"){f.preventDefault()}window.clearTimeout(e.delaytimer);e.delaytimer=null;e.hide(f)})}},show:function(i){if(this.ready===false){this.readify()}var b=this,f=b.settings,h=b.$tipsy,k=b.$el,d=k[0],g=b.offset(d);if(b.shown===false){if((function(m){var l=0,e;for(e in m){if(m.hasOwnProperty(e)){l++}}return l})(f.css)>0){b.$tip.css(f.css)}b.width=h.outerWidth();b.height=h.outerHeight()}if(f.alignTo==="cursor"&&i){var j=[i.clientX+f.offset[0],i.clientY+f.offset[1]];if(j[0]+b.width>a(window).width()){var c={top:j[1]+"px",right:j[0]+"px",left:"auto"}}else{var c={top:j[1]+"px",left:j[0]+"px",right:"auto"}}}else{var j=[(function(){if(f.offset[0]<0){return g.left-Math.abs(f.offset[0])-b.width}else{if(f.offset[0]===0){return g.left-((b.width-k.outerWidth())/2)}else{return g.left+k.outerWidth()+f.offset[0]}}})(),(function(){if(f.offset[1]<0){return g.top-Math.abs(f.offset[1])-b.height}else{if(f.offset[1]===0){return g.to
 p-((b.height-b.$el.outerHeight())/2)}else{return g.top+b.$el.outerHeight()+f.offset[1]}}})()]}h.css({top:j[1]+"px",left:j[0]+"px"});b.settings.show(i,h.stop(true,true))},hide:function(c){var b=this;if(b.ready===false){return}if(c&&c.relatedTarget===b.$tip[0]){b.$tip.bind("mouseleave",function(d){if(d.relatedTarget===b.$el[0]){return}b.settings.hide(d,b.$tipsy.stop(true,true))});return}b.settings.hide(c,b.$tipsy.stop(true,true))},readify:function(){this.ready=true;this.$tipsy=a('<div id="tooltipsy'+this.random+'" style="position:fixed;z-index:2147483647;display:none">').appendTo("body");this.$tip=a('<div class="'+this.settings.className+'">').appendTo(this.$tipsy);this.$tip.data("rootel",this.$el);var c=this.$el;var b=this.$tip;this.$tip.html(this.settings.content!=""?(typeof this.settings.content=="string"?this.settings.content:this.settings.content(c,b)):this.title)},offset:function(b){return this.$el[0].getBoundingClientRect()},destroy:function(){if(this.$tipsy){this.$tipsy.remove
 ();a.removeData(this.$el,"tooltipsy")}},defaults:{alignTo:"element",offset:[0,-1],content:"",show:function(c,b){b.fadeIn(100)},hide:function(c,b){b.fadeOut(100)},css:{},className:"tooltipsy",delay:200,showEvent:"mouseenter",hideEvent:"mouseleave"}};a.fn.tooltipsy=function(b){return this.each(function(){new a.tooltipsy(this,b)})}})(jQuery);
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org