Mercurial > hg > NetworkVis
annotate query_builder/querybuild.html @ 32:acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
author | arussell |
---|---|
date | Sat, 19 Dec 2015 09:15:43 -0500 |
parents | 5384b71df52a |
children | 4bbb832c53ac |
rev | line source |
---|---|
28 | 1 <!DOCTYPE html> |
2 <html> | |
3 <head> | |
4 <meta http-equiv="Content-Type" content="text/html" charset="UTF-8"> | |
5 <title>Query Builder</title> | |
6 <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"> | |
7 <link rel="stylesheet" href="select2-4.0.1/dist/css/select2.min.css"> | |
8 | |
9 <script type="text/javascript" src="js/d3.min.js"></script> | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
10 <script type="text/javascript" src="js/underscore-min.js"></script> |
28 | 11 <script type="text/javascript" src="select2-4.0.1/vendor/jquery-2.1.0.js"></script> |
12 <script type="text/javascript" src="select2-4.0.1/dist/js/select2.full.min.js"></script> | |
13 | |
14 | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
15 |
28 | 16 </head> |
17 <body style="background:none;"> | |
18 <div role="navigation" class="navbar navbar-default navbar-static-top"> | |
19 <div class="container"> | |
20 <div class="row"> | |
21 <div class="col-sm-6 col-md-6"> | |
22 <ul class="nav navbar-nav"> | |
23 </ul> | |
24 </div> | |
25 <div class="navbar-header col-sm-6 col-md-6" style="height: auto;"> | |
26 <div class="col-md-6"> | |
27 <div class="navbar-brand"> | |
28 <div class="brand">ISMI Query Builder</div> | |
29 </div> | |
30 </div> | |
31 <div class="col-md-offset-6"> | |
32 <div class="logo-well" style="height: 60%; width: 60%;"> | |
33 <a href="//neo4j.com/developer-resources"> | |
34 <img src="//neo4j-contrib.github.io/developer-resources/language-guides/assets/img/logo-white.svg" alt="Neo4j World's Leading Graph Database" id="logo" style="max-height: 50%; width: 50%"> | |
35 </a> | |
36 </div> | |
37 </div> | |
38 </div> | |
39 </div> | |
40 </div> | |
41 </div> | |
42 <div class="container"> | |
43 <div class="row" style="width: 95%"> | |
44 <div class="col-lg"> | |
45 <div class="panel panel-default"> | |
46 <div class="panel-heading" id="title">Query Builder</div> | |
47 | |
48 <section> | |
49 <div class="s2-example"> | |
50 <div id="filters"> | |
51 <div class="row" id="startrow" style="margin-top: 15px"> | |
52 <div class="col-sm-4 col-md-4" id="select-col1"> | |
53 <select class="selected-object form-control"> | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
54 <option selected>Object type : </option> |
28 | 55 </select> |
56 </div> | |
57 <div class="col-sm-4 col-md-4" id="select-col2"> | |
58 <select class="select-object1 form-control"> | |
59 <option selected>TEXT</option> | |
60 <option>WITNESS</option> | |
61 <option>PERSON</option> | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
62 <option>CODEX</option> |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
63 <option>PLACE</option> |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
64 <option>REPOSITORY</option> |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
65 <option>COLLECTION</option> |
28 | 66 </select> |
67 </div> | |
68 </div> | |
69 <div class="row" id="row1" style="margin-top: 15px"> | |
70 <div class="col-sm-4 col-md-4" id="1filter-col1"> | |
71 <select class="filter-box1 form-control"> | |
72 <option value="" disabled selected>Choose filter...</option> | |
73 </select> | |
74 </div> | |
75 </div> | |
76 </div> | |
77 <div align="left" style="margin-top: 30px"><button id="minus_filter_button" class="btn btn-warning btn-md" type="button"> - </button> | |
78 <button id="plus_filter_button" class="btn btn-warning btn-md" type="button"> + </button> | |
79 </div> | |
80 </div> | |
81 | |
82 | |
83 <div class="container-fluid" style="margin-top: 15px"> | |
84 <form role="form"> | |
85 <div class="form-group"> | |
86 <label for="results-container">Results list</label> | |
87 <select multiple class="form-control" id="results-container" style="min-height: 300px;"> | |
88 </select> | |
89 </div> | |
90 </form> | |
91 | |
92 </div> | |
93 | |
94 <!-- <pre data-fill-from=".js-code-data-array"></pre> --> | |
95 </section> | |
96 | |
97 </div> | |
98 </div> | |
99 </div> | |
100 </div> | |
101 | |
102 | |
103 | |
104 | |
105 | |
106 | |
107 <script type="text/javascript" class="js-code-data-array"> | |
108 //var queryData = []; | |
109 | |
110 // Defining initial variables and helper functions | |
111 var sourceType = "TEXT"; | |
112 var targets = []; | |
113 var targetTypes = []; | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
114 var targetObj = []; // The current objects on the display box |
28 | 115 var numFilters = 1; |
116 var filters = [ | |
117 { id: 0, text: 'has relation' }, | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
118 { id: 1, text: 'attribute' } |
28 | 119 ]; |
120 $(".filter-box"+numFilters).select2({ | |
121 // Initialize first filter box | |
122 data: filters, | |
123 minimumResultsForSearch: Infinity | |
124 }); | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
125 var listTolerance = 100; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
126 //$("") |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
127 |
28 | 128 function filter_html(n) { |
129 return '<div class="row" id="row'+n+'" style="margin-top: 15px">' + | |
130 '<div class="col-sm-4 col-md-4" id="'+n+'filter-col1">' + | |
131 '<select class="filter-box'+n+' form-control">' + | |
132 '<option value="" disabled selected>Choose filter...</option>' + | |
133 '</select>' + | |
134 '</div>' + | |
135 '</div>'; | |
136 } | |
137 function constraint_html(classn) { | |
138 return '<div class="col-sm-4 col-md-4" id="'+classn+'filter-col2">' + | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
139 '<select class="rel-constraint-box'+classn+' form-control" >' + |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
140 '</select>' + |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
141 '</div>'; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
142 } |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
143 function attr_constraint_html(classn) { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
144 return '<div class="col-sm-4 col-md-4" id="'+classn+'filter-col2">' + |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
145 '<select class="attr-constraint-box'+classn+' form-control" >' + |
28 | 146 '</select>' + |
147 '</div>'; | |
148 } | |
149 function submit_html(classn) { | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
150 return '<div class="col-sm-4 col-md-4" id="'+classn+'filter-col3">' + |
28 | 151 '<div class="form-group'+classn+'">' + |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
152 '<form onsubmit="return false;"> ' + |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
153 '<input type="text" name="attr-field" class="form-control" id="attr-input'+classn+'">' + |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
154 '</input>' + |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
155 '</form>' + |
28 | 156 '</div>' + |
157 '</div>'; | |
158 } | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
159 function select_html(selection, n) { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
160 return '<div class="row" id="row'+n+'" style="margin-top: 15px">' + |
28 | 161 '<div class="col-sm-4 col-md-4" id="select-col1"> ' + |
162 '<select class="selected-object form-control"> ' + | |
163 '<option selected>Selected object is: </option> ' + | |
164 '</select> ' + | |
165 '</div> ' + | |
166 '<div class="col-sm-4 col-md-4" id="select-col2"> ' + | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
167 '<h4>' + selection + |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
168 '</h4>' + |
28 | 169 '</div> ' + |
170 '</div>'; | |
171 } | |
172 | |
173 | |
174 | |
175 | |
176 // Button filters | |
177 $("#plus_filter_button").click(function() { | |
178 console.log("add filter"); | |
179 numFilters++; | |
180 $("#filters").append(filter_html(numFilters)); | |
181 $(".filter-box"+numFilters).select2({ | |
182 data: filters, | |
183 minimumResultsForSearch: Infinity | |
184 }); | |
185 }); | |
186 $("#minus_filter_button").click(function() { | |
187 console.log("minus filter"); | |
188 $("#row"+numFilters).remove(); | |
189 numFilters--; | |
190 }); | |
191 $("#results-container").dblclick(function() { | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
192 var displayChoice = $("#results-container").find("option:selected").text(); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
193 console.log(displayChoice + "........."); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
194 var selection; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
195 |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
196 _.map(targetObj, function(obj){ |
28 | 197 |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
198 if (_.values(_.values(targetObj))[1] === displayChoice) { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
199 selection = (_.values(_.values(obj))[0])[1]; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
200 } |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
201 else { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
202 selection = (_.values(_.values(obj))[0])[0]; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
203 } |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
204 }); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
205 numFilters++; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
206 $("#filters").append(select_html(selection, numFilters)); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
207 // Generate inner relation list |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
208 //genRelations(sourceType, ".constraint-box"+numFilters); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
209 sourceType = selection; |
28 | 210 console.log("add filter"); |
211 }); | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
212 $(function() { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
213 $("input").submit(function(event, data) { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
214 console.log($('.form-control').find("option:selected").text()); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
215 console.log(event); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
216 console.log(data); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
217 event.preventDefault(); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
218 |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
219 }); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
220 }); |
28 | 221 |
222 | |
223 // Change Events | |
224 $('body').on('change', function(event){ | |
225 var classname = (event.target.className).substr(0, (event.target.className).indexOf(" ")); | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
226 var classnum = (event.target.className.match(/\d+\.\d+|\d+\b|\d+(?=\w)/g) || [] ).map(function (v) {return +v;}).shift(); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
227 var allclass = '.'+classname; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
228 var selectedOption = $(allclass).find('option:selected').text(); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
229 console.log("SEL "+ selectedOption); |
28 | 230 |
231 // Change is on the filter box | |
232 if (classname.indexOf("filter-box") > -1) { | |
233 if (selectedOption === "has relation") { | |
234 // Remove any other boxes in the row | |
235 $("#"+classnum+"filter-col2").remove(); | |
236 $("#row"+classnum).append(constraint_html(classnum)); | |
237 // Generate inner relation list | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
238 genRelations(sourceType, ".rel-constraint-box"+classnum); |
28 | 239 } |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
240 if (selectedOption === "attribute") { |
28 | 241 $("#"+classnum+"filter-col2").remove(); |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
242 $("#row"+classnum).append(attr_constraint_html(classnum)); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
243 genAttributes(sourceType, ".attr-constraint-box"+classnum); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
244 //$("#row"+classnum).append(submit_html(classnum)); |
28 | 245 $("#row"+classnum).append(submit_html(classnum)); |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
246 |
28 | 247 } |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
248 |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
249 // NOT IMPLEMENTED |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
250 /* |
28 | 251 if (selectedOption === "return") { |
252 $("#"+classnum+"filter-col2").remove(); | |
253 $("#row"+classnum).append(constraint_html(classnum)); | |
254 genAttributes(targetTypes, ".constraint-box"+classnum); | |
255 } | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
256 */ |
28 | 257 } |
258 | |
259 // Change is on the relationship constraint box | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
260 if (classname.indexOf("rel-constraint-box") > -1) { |
28 | 261 //$().remove(); |
262 genResults(sourceType, selectedOption, "results-container"); | |
263 } | |
264 | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
265 // Change is on the attr constraint box |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
266 if (classname.indexOf("attr-constraint-box") > -1) { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
267 //$().remove(); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
268 console.log("CHANGE ON ATTR"); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
269 console.log("changing currentqueryattr to" + selectedOption); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
270 currentQueryAttr = selectedOption; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
271 console.log("currentQueryAttr is" + currentQueryAttr); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
272 //genResults(sourceType, selectedOption, "results-container"); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
273 } |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
274 |
28 | 275 // Change is on subject scope |
276 if (classname.indexOf("select-object") > -1) { | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
277 sourceType = selectedOption; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
278 console.log("CHANGE ON SCOPE"); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
279 genResults(sourceType, "New Source", "results-container"); |
28 | 280 |
281 //ajax1(query, "results-container") | |
282 } | |
283 }); | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
284 $("#filters").submit(function (event) { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
285 var inputId = $("input:text[name=attr-field]")[0].id; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
286 var inputValue = $("input:text[name=attr-field]").val(); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
287 // Alter results list |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
288 console.log("QUERY TYPE IS ATTRIBUTE NOW"); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
289 currentQueryType = "attribute"; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
290 console.log("SUBMITTED"); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
291 genResults(sourceType, inputValue, "results-container") |
28 | 292 |
293 | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
294 }); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
295 // For use in the onchange events above |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
296 function genRelations(sourceNodeType, constraintBox) { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
297 console.log("GENERATE ALL RELATIONS"); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
298 var query = "match (source:"+sourceNodeType+")-[rel]-target return distinct rel.type"; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
299 console.log("QUERY TYPE IS RELATION NOW"); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
300 currentQueryType = "relation"; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
301 ajax1(query, constraintBox); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
302 } |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
303 function genAttributes(sourceNodeType, constraintBox) { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
304 console.log("GENERATE ALL ATTRIBUTES"); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
305 var query = "match (n:"+sourceNodeType+") with keys(n) as collection unwind collection as attributes return distinct attributes"; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
306 ajax1(query, constraintBox); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
307 } |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
308 function genResults(sourceNodeType, selected, constraintBox) { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
309 // TODO: Return first the list of current values of the display box |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
310 |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
311 if (selected === "New Source") { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
312 console.log("NEW SOURCE - UPDATE RESULTS"); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
313 var query = "match (source:"+sourceNodeType+") return source._n_label, source.type"; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
314 } |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
315 else if (currentQueryType === "attribute") { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
316 console.log("ATTR CHANGE - UPDATE RESULTS"); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
317 console.log("before update currentQueryAttr is " + currentQueryAttr); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
318 var qAttr = currentQueryAttr; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
319 var query = "match (source:"+sourceNodeType+") where "+get_result_labels()+" AND source."+qAttr+"=~\"(?i).*"+selected+".*\" return distinct source._n_label, source.type limit 5"; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
320 console.log(query); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
321 } |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
322 else if (currentQueryType === "relation") { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
323 var query = "match (source:" + sourceNodeType + ")-[rel:" + selected + "]->(target) return distinct target._n_label, target.type"; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
324 console.log("REL CHANGE - UPDATE RESULTS"); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
325 } |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
326 else { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
327 console.log("GENRESULTS IMPROPERLY CALLED"); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
328 return; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
329 } |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
330 ajax1(query, constraintBox); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
331 } |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
332 var currentQueryType; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
333 var currentQueryAttr; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
334 var resultLabelString = ""; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
335 function get_result_labels() { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
336 return resultLabelString; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
337 } |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
338 function set_result_labels(currentResults) { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
339 resultLabelString = "("; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
340 for (var i = 0; i < currentResults.length; i++) { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
341 if (i > 0) resultLabelString += " OR "; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
342 resultLabelString += 'source._n_label=\"'+currentResults[i].text.substr(1)+'\"'; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
343 } |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
344 resultLabelString += ")" |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
345 } |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
346 // to use contains |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
347 // TODO: start n = node(*) where n.Name =~ '.*SUBSTRING.*' return n.Name, n; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
348 |
28 | 349 |
350 | |
351 // Ajax request function | |
352 function ajax1(q, resBox) { | |
353 $.ajaxSetup({ | |
354 headers: { | |
355 "Authorization": 'Basic ' + window.btoa("neo4j"+":"+"neo5j") | |
356 } | |
357 }); | |
358 return $.ajax({ | |
359 type: "POST", | |
360 url: "https://ismi-dev.mpiwg-berlin.mpg.de/neo4j-ismi/db/data/cypher", | |
361 accepts: "application/json", | |
362 dataType: "json", | |
363 data: { | |
364 "query": q, | |
365 "params": {} | |
366 }, | |
367 beforeSend: function (xhr) { | |
368 xhr.setRequestHeader ("Authorization", "Basic " + btoa('neo4j'+":"+'neo5j')); | |
369 }, | |
370 processResults: function (data, params) { | |
371 // parse the results into the format expected by Select2 | |
372 // since we are using custom formatting functions we do not need to | |
373 // alter the remote JSON data, except to indicate that infinite | |
374 // scrolling can be used | |
375 params.page = params.page || 1; | |
376 return { | |
377 pagination: { | |
378 more: (params.page * 30) < data.length | |
379 } | |
380 }; | |
381 }, | |
382 success: function (res, textStatus, jqXHR) { | |
383 ajaxCheck(res, resBox, textStatus); | |
384 console.log(textStatus); | |
385 }, | |
386 error: function (jqXHR, textStatus, errorThrown) { | |
387 console.log(textStatus); | |
388 } | |
389 }); | |
390 } | |
391 // Check if request was successful | |
392 function ajaxCheck(a1, resBox, status){ | |
393 if (status === 'error') console.log("error: bad ajax request"); | |
394 //else dataGen(a1); | |
395 dataGen(a1.data, resBox); | |
396 } | |
397 // On success, generate new data | |
398 // TODO: might want to just always return nodes and then deal with the queryData different for each type of return | |
399 function dataGen(dataArr, resBox) { | |
400 var d = dataArr; | |
401 targets = []; | |
402 | |
403 // Consider implementing localStorage to avoid reloading every time | |
404 var queryData = []; | |
405 for (var i= 0; i<d.length; i++) { | |
406 var j = d[i]; | |
407 queryData.push({ id: j, text: j[0] }); | |
408 targets.push(j[1]); | |
409 } | |
410 // Now that queryData array has been defined we will sort it by its label value and initialize the option. | |
411 queryData.sort(function(a,b){ | |
412 var c = a.text.replace(/<|>/g, ''); | |
413 var d = b.text.replace(/<|>/g, ''); | |
414 return c.localeCompare(d); | |
415 }); | |
416 | |
417 // Change the displayed results | |
418 if (resBox === "results-container") { | |
419 process_display_results(queryData); | |
420 } | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
421 // Or fill any select boxes |
28 | 422 else { |
423 $(resBox).select2({ | |
424 data: queryData | |
425 }); | |
426 } | |
427 } | |
428 function process_display_results(queryData) { | |
429 var weights = []; | |
430 var resultLength = queryData.length; | |
431 targetTypes = []; | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
432 targetObj = queryData; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
433 set_result_labels(queryData); |
28 | 434 $('#results-container') |
435 .find('option') | |
436 .remove() | |
437 .end() | |
438 ; | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
439 for (var i = 0; i < targets.length; i++) { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
440 if (targetTypes.indexOf(targets[i]) == -1) { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
441 targetTypes.push(targets[i]); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
442 weights.push(1); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
443 } |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
444 else { |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
445 weights[targetTypes.indexOf(targets[i])] += 1; |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
446 } |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
447 } |
28 | 448 if (resultLength < listTolerance) { |
449 for (var i = 0; i < resultLength; i++) { | |
450 // TODO: put this jQuery call into its own function to be called if the else statement occurs | |
451 // TODO: but the user actually does want to see the entire huge list. | |
32
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
452 // This next bit removes duplicate labels if we want to use that for things like cities |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
453 // would this throw issues with other things?? |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
454 //$('#results-container option:contains('+queryData[i].text+')').each(function(){ |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
455 // $(this).remove(); |
acc60a20582c
Temporary Changes for querybuilder. Selecting attribute and having results list filter not fully working yet. Need 'ALL' option in attributes.
arussell
parents:
28
diff
changeset
|
456 //}); |
28 | 457 $('#results-container') |
458 .append($("<option></option>") | |
459 .attr("value", i) | |
460 .text(queryData[i].text)); | |
461 } | |
462 } | |
463 else { | |
464 for (var i = 0; i < targetTypes.length; i++) { | |
465 $('#results-container') | |
466 .append($("<option></option>") | |
467 .text(targetTypes[i] + " [ " + weights[i] + " ]")); | |
468 } | |
469 } | |
470 } | |
471 | |
472 </script> | |
473 | |
474 </body> | |
475 </html> |