summaryrefslogtreecommitdiffstats
path: root/VNF_Catalogue/public/javascripts/index_search_max.js
blob: b9693117e7ea9d40b174e7dfa5d75c6343a890b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*******************************************************************************
 * 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 = `
        <div class="box-container">
          <div class="col-md-3">
            <div class="content-box">
              <div class="content-data">
                <h1 class="content-title"><a href="/project_profile?vnf_id=%vnf_id">%vnf_name%</a></h1>
                <div class="box"><img class="img-size commit-icon" src="/uploads/%photo_url%"/>
                  <h3 class="commits">%lines_of_code%<br/>Lines Of Code</h3>
                </div>
              </div>
            </div>
          </div>
        </div>
    `;

    var no_of_developers_string = `
        <div class="box-container">
          <div class="col-md-3">
            <div class="content-box">
              <div class="content-data">
                <h1 class="content-title"><a href="/project_profile?vnf_id=%vnf_id">%vnf_name%</a></h1>
                <div class="box"><img class="img-size commit-icon" src="/uploads/%photo_url%"/>
                  <h3 class="commits">%no_of_developers%<br/>No Of Developers</h3>
                </div>
              </div>
            </div>
          </div>
        </div>
    `;

    var no_of_stars_string = `
        <div class="box-container">
          <div class="col-md-3">
            <div class="content-box">
              <div class="content-data">
                <h1 class="content-title"><a href="/project_profile?vnf_id=%vnf_id">%vnf_name%</a></h1>
                <div class="box"><img class="img-size commit-icon" src="/uploads/%photo_url%"/>
                  <h3 class="commits">%no_of_stars%<br/>No Of Stars</h3>
                </div>
              </div>
            </div>
          </div>
        </div>
    `;

    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');
            }
        });
    });

});