/******************************************************************************* * Copyright (c) 2017 Kumar Rishabh and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Apache License, Version 2.0 * which accompanies this distribution, and is available at * http://www.apache.org/licenses/LICENSE-2.0 *******************************************************************************/ $(document).ready( function() { //alert('index saeerch max ....'); var lines_of_code_string = `

%vnf_name%

%lines_of_code%
Lines Of Code

`; var no_of_developers_string = `

%vnf_name%

%no_of_developers%
No Of Developers

`; var no_of_stars_string = `

%vnf_name%

%no_of_stars%
No Of Stars

`; var search_max_result = function(string1, result) { var string_replacement = {}; //alert(JSON.stringify(result)); for (var k in result) { if (result.hasOwnProperty(k)) { string_replacement['%' + k + '%'] = result[k]; if(!string_replacement['%' + k + '%']) { string_replacement['%' + k + '%'] = -1; } } } //alert(JSON.stringify(string_replacement)); string1 = string1.replace(/%\w+%/g, function(all) { return string_replacement[all] || all; }); //alert(JSON.stringify(string1)); return string1; }; $("#lines_of_code").on('click',function(){ event.preventDefault(); var json_data = {}; json_data['order_key'] = 'lines_of_code'; $.ajax({ url: '/search_max', type: 'post', dataType: 'json', data: json_data, success: function(data) { html_string = ''; for(var result in data) { html_string += search_max_result(lines_of_code_string, data[result]); } $('#content').html(html_string); }, error: function (error) { Materialize.toast(error['responseJSON']['error'], 3000, 'rounded'); } }); }); $("#no_of_developers").on('click',function(){ event.preventDefault(); var json_data = {}; json_data['order_key'] = 'no_of_developers'; $.ajax({ url: '/search_max', type: 'post', dataType: 'json', data: json_data, success: function(data) { html_string = ''; for(var result in data) { html_string += search_max_result(no_of_developers_string, data[result]); } $('#content').html(html_string); }, error: function (error) { Materialize.toast('', 3000, 'rounded'); } }); }); $("#no_of_stars").on('click',function(){ event.preventDefault(); var json_data = {}; json_data['order_key'] = 'no_of_stars'; $.ajax({ url: '/search_max', type: 'post', dataType: 'json', data: json_data, success: function(data) { html_string = ''; for(var result in data) { html_string += search_max_result(no_of_stars_string, data[result]); } $('#content').html(html_string); }, error: function (error) { Materialize.toast('', 3000, 'rounded'); } }); }); });