1 /*******************************************************************************
\r
2 * Copyright (c) 2017 Kumar Rishabh and others.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Apache License, Version 2.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.apache.org/licenses/LICENSE-2.0
\r
8 *******************************************************************************/
\r
10 $(document).ready( function() {
\r
11 var search_result_string_1 = `
\r
12 <div class = "container container-custom">
\r
13 <div class="card card-shadow-custom horizontal">
\r
14 <div class="row row-custom">
\r
16 <div class="col s5 card-title-div-custom">
\r
17 <span class="card-title card-title-span-custom">
\r
18 <a class="custom-href" href="/project_profile?vnf_id=%vnf_id%">%vnf_name%</a>
\r
22 <div class="col s5 card-title-div-custom">
\r
23 <i class="material-icons">grade</i>
\r
24 <span class="card-title">PenguinScore: 42</span>
\r
27 <div class="col s2 card-title-div-custom-right">
\r
29 <input id="search_result_1" type="checkbox" name="%vnf_name%"/>
\r
30 <label for="search_result_1">Compare</label>
\r
34 <div class="col s4 card-image card-image-custom">
\r
35 <img class="img-size card-image-picture-custom" src="/uploads/%photo_url%"/>
\r
38 <div class="col s8 card-stacked">
\r
39 <div class="card-content">
\r
41 <div class="collection collection-custom">
\r
42 <a class="collection-item" href="#!">
\r
44 <i class="material-icons">code</i>
\r
45 Lines Of Code: %lines_of_code%
\r
48 <a class="collection-item" href="#!">
\r
50 <i class="material-icons">person</i>
\r
51 Number of Developers: %no_of_developers%;
\r
54 <a class="collection-item" href="#!">
\r
56 <i class="material-icons">star</i>
\r
57 Number of Stars: %no_of_stars%
\r
60 <a class="collection-item" href="#!">
\r
62 <i class="material-icons">description</i>
\r
63 Number of Versions: %versions%
\r
69 <div class="card-action">
\r
72 var search_result_string_2 = `
\r
73 <div class="chip"><a class="a-custom" href="#!">tag1</a></div>
\r
74 <div class="chip"><a class="a-custom" href="#!">Tag2</a></div>
\r
75 <div class="chip"><a class="a-custom" href="#!">Tag3</a></div>
\r
76 <div class="chip"><a class="a-custom" href="#!">Tag4</a></div>
\r
77 <div class="chip"><a class="a-custom" href="#!">Tag5</a></div>
\r
79 var search_result_string_3 = `
\r
80 <a class="a-custom-more" href="/project_profile?vnf_id=%vnf_id%">
\r
86 <div class="divider"></div>
\r
88 <div class="card-action-custom col s12 card-action">
\r
89 License: <a href="#">%license%</a>
\r
90 Complexity: <a href="#">Atomic</a>
\r
91 Activity: <a href="#">Medium</a>
\r
92 OPNFV Indicator: <a href="#">%opnfv_indicator%</a>
\r
99 //var replace_search_result_string = function(search_result_string,
\r
100 var search_result = function(string1, string3, result) {
\r
101 var string_replacement = {};
\r
102 //alert(JSON.stringify(result));
\r
104 for (var k in result) {
\r
105 if (result.hasOwnProperty(k)) {
\r
106 string_replacement['%' + k + '%'] = result[k];
\r
107 if(!string_replacement['%' + k + '%']) {
\r
108 string_replacement['%' + k + '%'] = -1;
\r
112 //alert(JSON.stringify(string_replacement));
\r
114 string1 = string1.replace(/%\w+%/g, function(all) {
\r
115 return string_replacement[all] || all;
\r
118 for(index in string_replacement['%tags%']) {
\r
119 string1 += '<div class="chip"><a class="a-custom" href="#!">';
\r
120 string1 += string_replacement['%tags%'][index]['tag_name'];
\r
121 string1 += '</a></div>';
\r
124 string3 = string3.replace(/%\w+%/g, function(all) {
\r
125 return string_replacement[all] || all;
\r
128 return string1 + string3;
\r
133 var QueryString = function () {
\r
134 // This function is anonymous, is executed immediately and
\r
135 // the return value is assigned to QueryString!
\r
136 var query_string = {};
\r
137 var query = window.location.search.substring(1);
\r
138 var vars = query.split("&");
\r
139 for (var i=0;i<vars.length;i++) {
\r
140 var pair = vars[i].split("=");
\r
141 // If first entry with this name
\r
142 if (typeof query_string[pair[0]] === "undefined") {
\r
143 query_string[pair[0]] = decodeURIComponent(pair[1]);
\r
144 // If second entry with this name
\r
145 } else if (typeof query_string[pair[0]] === "string") {
\r
146 var arr = [ query_string[pair[0]],decodeURIComponent(pair[1]) ];
\r
147 query_string[pair[0]] = arr;
\r
148 // If third or later entry with this name
\r
150 query_string[pair[0]].push(decodeURIComponent(pair[1]));
\r
153 return query_string;
\r
156 $('#pagination-long').materializePagination({
\r
160 urlParameter: 'page',
\r
161 useUrlParameter: true,
\r
162 onClickCallback: function(requestedPage){
\r
163 var json_data = {};
\r
164 json_data['tags'] = QueryString()['tags'];
\r
165 json_data['page'] = requestedPage;
\r
167 console.log(json_data);
\r
170 url: '/search_projects_results',
\r
174 success: function(data) {
\r
175 //alert(JSON.stringify(data));
\r
177 for(var result in data) {
\r
178 html_string += search_result(search_result_string_1, search_result_string_3, data[result]);
\r
180 $('#content').html(html_string);
\r
181 //Materialize.toast(data, 3000, 'rounded');
\r
183 error: function (error) {
\r
184 Materialize.toast('', 3000, 'rounded');
\r
188 //window.location.href = '/search_projects?tags=' + parameters['tags'] + '&page=' + requestedPage;
\r
193 /*$('#pagination-long').pagination({
\r
197 //urlParameter: 'page',
\r
198 useUrlParameter: false,
\r
199 onClickCallback: function(requestedPage){
\r
200 var query_string = {};
\r
201 var query = window.location.search.substring(1);
\r
202 console.log(query);
\r
203 var vars = query.split("&");
\r
205 vars['page'] = requestedPage;
\r
207 var parameters = QueryString();
\r
209 console.log(parameters);
\r
212 window.location.href = '/search_projects?tags=' + parameters['tags'];
\r
215 var query_string = {};
\r
216 var query = window.location.search.substring(1);
\r
217 console.log(query);
\r
218 var vars = query.split("&");
\r
220 vars['page'] = requestedPage;
\r