mirror of
				https://github.com/peeringdb/peeringdb.git
				synced 2024-05-11 05:55:09 +00:00 
			
		
		
		
	IXF preview tool (#408)
This commit is contained in:
		| @@ -156,6 +156,117 @@ function moveCursorToEnd(el) { | ||||
|     } | ||||
| } | ||||
|  | ||||
| PeeringDB.IXFPreview = { | ||||
|  | ||||
|   /** | ||||
|    * Handle the IX-F import preview request and rendering | ||||
|    * to UI modal | ||||
|    * | ||||
|    * @class IXFPreview | ||||
|    * @namespace PeeringDB | ||||
|    */ | ||||
|  | ||||
|   request : function(ixlanId, renderTo) { | ||||
|  | ||||
|     /** | ||||
|      * request a preview for the ixlan with ixlanId | ||||
|      * | ||||
|      * @method request | ||||
|      * @param {Number} ixlanId | ||||
|      * @param {jQuery} renderTo - render to this element (needs to have | ||||
|      *    the appropriate children elements to work, they are not | ||||
|      *    created automatically) | ||||
|      */ | ||||
|  | ||||
|     renderTo.find('.ixf-result').empty(). | ||||
|       append($("<div>").addClass("center").text("... loading ...")); | ||||
|     renderTo.find('.ixf-error-counter').empty(); | ||||
|     $.get('/import/ixlan/'+ixlanId+'/ixf/preview', function(result) { | ||||
|       this.render(result, renderTo); | ||||
|     }.bind(this)).error(function(result) { | ||||
|       if(result.responseJSON) { | ||||
|         this.render(result.responseJSON, renderTo); | ||||
|       } else { | ||||
|         this.render({"non_field_errors": ["HTTP error "+result.status]}); | ||||
|       } | ||||
|     }.bind(this)); | ||||
|   }, | ||||
|  | ||||
|   render : function(result, renderTo) { | ||||
|  | ||||
|     /** | ||||
|      * Render preview result and errors | ||||
|      * | ||||
|      * @method render | ||||
|      * @param {Object} result - result as returned from the preview request | ||||
|      * @param {jQuery} renderTo | ||||
|      * | ||||
|      *    Needs to have child divs with the following classes | ||||
|      * | ||||
|      * | ||||
|      *    .ixf-errors-list: errors will be rendered to here | ||||
|      *    .ixf-result: changes will be rendered to here | ||||
|      *    .ixf-error-counter: will be updated with number of errors | ||||
|      * | ||||
|      */ | ||||
|  | ||||
|     renderTo.find('.ixf-errors-list').empty() | ||||
|     renderTo.find('.ixf-result').empty() | ||||
|     this.render_errors((result.errors || []).concat(result.non_field_errors || []), renderTo.find('.ixf-errors-list')); | ||||
|     this.render_data(result.data || [], renderTo.find('.ixf-result')); | ||||
|   }, | ||||
|  | ||||
|   render_errors : function(errors, renderTo) { | ||||
|     /** | ||||
|      * Render the errors, called automatically by `render` | ||||
|      * | ||||
|      * @method render_errors | ||||
|      * @param {Array} errors | ||||
|      * @param {jQuery} renderTo | ||||
|      */ | ||||
|  | ||||
|     var error, i; | ||||
|  | ||||
|     if(!errors.length) | ||||
|       return; | ||||
|  | ||||
|     $('.ixf-error-counter').text("("+errors.length+")"); | ||||
|  | ||||
|     for(i = 0; i < errors.length; i++) { | ||||
|       error = errors[i]; | ||||
|       renderTo.append($('<div>').addClass("ixf-error").text(error)); | ||||
|     } | ||||
|   }, | ||||
|  | ||||
|   render_data : function(data, renderTo) { | ||||
|     /** | ||||
|      * Renders the changes made by the ix-f import, called automatically | ||||
|      * by `render` | ||||
|      * | ||||
|      * @method render_data | ||||
|      * @param {Array} data | ||||
|      * @param {jQuery} renderTo | ||||
|      */ | ||||
|  | ||||
|     var row, i; | ||||
|     for(i = 0; i < data.length; i++) { | ||||
|       row = data[i]; | ||||
|       renderTo.append( | ||||
|         $('<div>').addClass("row ixf-row ixf-"+row.action).append( | ||||
|           $('<div>').addClass("col-sm-1").text(row.action), | ||||
|           $('<div>').addClass("col-sm-2").text("AS"+row.peer.asn), | ||||
|           $('<div>').addClass("col-sm-3").text(row.peer.ipaddr4 || "-"), | ||||
|           $('<div>').addClass("col-sm-3").text(row.peer.ipaddr6 || "-"), | ||||
|           $('<div>').addClass("col-sm-1").text(PeeringDB.pretty_speed(row.peer.speed)), | ||||
|           $('<div>').addClass("col-sm-2").text(row.peer.is_rs_peer?"yes":"no"), | ||||
|           $('<div>').addClass("col-sm-12 ixf-reason").text(row.reason) | ||||
|         ) | ||||
|       ); | ||||
|     } | ||||
|   } | ||||
|  | ||||
| } | ||||
|  | ||||
| PeeringDB.InlineSearch = { | ||||
|  | ||||
|   init_search : function() { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user