Mercurial > hg > NetworkVis
comparison query_builder/ismi.html @ 28:5384b71df52a
querybuild.html added, beginning prototype.
author | arussell |
---|---|
date | Thu, 10 Dec 2015 07:26:40 -0500 |
parents | ed8b4e3f2a73 |
children |
comparison
equal
deleted
inserted
replaced
27:ed8b4e3f2a73 | 28:5384b71df52a |
---|---|
43 <div class="panel panel-default"> | 43 <div class="panel panel-default"> |
44 <div class="panel-heading" id="title">Query Builder</div> | 44 <div class="panel-heading" id="title">Query Builder</div> |
45 | 45 |
46 <section> | 46 <section> |
47 <div class="s2-example"> | 47 <div class="s2-example"> |
48 <div class="row"> | 48 <div id="filter" class="row"> |
49 <div class="col-sm-4 col-md-4"> | 49 <div class="col-sm-3 col-md-3"> |
50 <select class="js-example-data-array form-control"></select> | 50 <select class="js-example-data-array form-control"></select> |
51 </div> | 51 </div> |
52 <div class="col-sm-4 col-md-4"> | 52 <div class="col-sm-3 col-md-3"> |
53 <select class="js-example-data-array2 form-control"></select> | 53 <select class="js-example-data-array2 form-control"></select> |
54 </div> | 54 </div> |
55 <div class="col-sm-4 col-md-4"> | 55 <div class="col-sm-3 col-md-3"> |
56 <select class="js-example-data-array3 form-control"> | 56 <select class="js-example-data-array3 form-control"> |
57 <option value="" disabled selected>Loading...</option> | 57 <option value="" disabled selected>Loading...</option> |
58 </select> | 58 </select> |
59 </div> | 59 </div> |
60 </div> | 60 </div> |
67 </div> | 67 </div> |
68 </div> | 68 </div> |
69 </div> | 69 </div> |
70 | 70 |
71 <script type="text/javascript" class="js-code-data-array"> | 71 <script type="text/javascript" class="js-code-data-array"> |
72 // Code to interrupt ajax calls if object box switched, currently doesnt work... | |
73 (function($) { | |
74 var xhrPool = []; | |
75 $(document).ajaxSend(function(e, jqXHR, options){ | |
76 xhrPool.push(jqXHR); | |
77 }); | |
78 $(document).ajaxComplete(function(e, jqXHR, options) { | |
79 xhrPool = $.grep(xhrPool, function(x){return x!=jqXHR}); | |
80 }); | |
81 var abort = function() { | |
82 $.each(xhrPool, function(idx, jqXHR) { | |
83 jqXHR.abort(); | |
84 console.log("aborted"); | |
85 }); | |
86 }; | |
87 | |
88 var oldbeforeunload = window.onbeforeunload; | |
89 window.onbeforeunload = function() { | |
90 var r = oldbeforeunload ? oldbeforeunload() : undefined; | |
91 if (r == undefined) { | |
92 // only cancel requests if there is no prompt to stay on the page | |
93 // if there is a prompt, it will likely give the requests enough time to finish | |
94 abort(); | |
95 console.log("aborted"); | |
96 } | |
97 return r; | |
98 } | |
99 })(jQuery); | |
100 | |
101 | 72 |
102 | 73 |
103 var queryData = []; | 74 var queryData = []; |
104 | 75 |
105 var data = [{ id: 0, text: 'TEXT' }, { id: 1, text: 'CODEX' }, { id: 2, text: 'WITNESS' }, { id: 3, text: 'COLLECTION' }, { id: 4, text: 'PERSON' }]; | 76 var data = [{ id: 0, text: 'TEXT' }, { id: 1, text: 'CODEX' }, { id: 2, text: 'WITNESS' }, { id: 3, text: 'COLLECTION' }, { id: 4, text: 'PERSON' }]; |
112 ajax1("TEXT"); | 83 ajax1("TEXT"); |
113 | 84 |
114 $(".js-example-data-array2").select2({ | 85 $(".js-example-data-array2").select2({ |
115 data: relations | 86 data: relations |
116 }); | 87 }); |
88 | |
89 $(".js-example-data-array3").select2(); | |
117 | 90 |
118 // Ajax request function | 91 // Ajax request function |
119 function ajax1(q) { | 92 function ajax1(q) { |
120 var combinedQuery = "match (n:TEXT) return n"; | 93 var combinedQuery = "match (n:TEXT) return n"; |
121 if (q !== undefined) combinedQuery = "match (n:" + q + ") return n"; | 94 if (q !== undefined) combinedQuery = "match (n:" + q + ") return n"; |
122 console.log(combinedQuery); | 95 console.log(combinedQuery); |
96 $.ajaxSetup({ | |
97 headers: { | |
98 "Authorization": 'Basic ' + window.btoa("neo4j"+":"+"neo5j") | |
99 } | |
100 }); | |
123 return $.ajax({ | 101 return $.ajax({ |
124 type: "POST", | 102 type: "POST", |
125 url: "https://ismi-dev.mpiwg-berlin.mpg.de/neo4j-ismi/db/data/cypher", | 103 url: "https://ismi-dev.mpiwg-berlin.mpg.de/neo4j-ismi/db/data/cypher", |
126 accepts: "application/json", | 104 accepts: "application/json", |
127 dataType: "json", | 105 dataType: "json", |
144 more: (params.page * 30) < data.length | 122 more: (params.page * 30) < data.length |
145 } | 123 } |
146 }; | 124 }; |
147 }, | 125 }, |
148 success: function (res, textStatus, jqXHR) { | 126 success: function (res, textStatus, jqXHR) { |
149 console.log(textStatus); | 127 console.log(res); |
150 ajaxCheck(res, textStatus); | 128 ajaxCheck(res, textStatus); |
151 }, | 129 }, |
152 error: function (jqXHR, textStatus, errorThrown) { | 130 error: function (jqXHR, textStatus, errorThrown) { |
153 console.log(textStatus); | 131 console.log(textStatus); |
154 } | 132 } |
165 function dataGen(a1){ | 143 function dataGen(a1){ |
166 console.log("next started"); | 144 console.log("next started"); |
167 var d = a1.data; | 145 var d = a1.data; |
168 // Consider implementing localStorage to avoid reloading every time | 146 // Consider implementing localStorage to avoid reloading every time |
169 queryData = []; | 147 queryData = []; |
148 | |
170 for (var i= 0; i<d.length; i++) { | 149 for (var i= 0; i<d.length; i++) { |
171 var j = d[i][0].data.ismi_id; | 150 var j = d[i][0].data.ismi_id; |
172 queryData.push({ id: j, text: d[i][0].data.label }); | 151 queryData.push({ id: j, text: d[i][0].data.label }); |
173 } | 152 } |
174 // Now that queryData array has been defined we will sort it by its label value and initialize the option. | 153 // Now that queryData array has been defined we will sort it by its label value and initialize the option. |
175 queryData.sort(function(a,b){ | 154 queryData.sort(function(a,b){ |
176 return a.text.localeCompare(b.text); | 155 return a.text.localeCompare(b.text); |
177 }); | 156 }); |
178 console.log(queryData); | 157 console.log(queryData); |
179 | 158 |
180 // TODO: currently the queryData is being added onto the previous query data, need to remove old. | 159 // TODO: currently the queryData is being added onto the previous query data, need to REMOVE OLD. |
181 | 160 |
161 $(".js-example-data-array3").select2('data', null); | |
182 | 162 |
183 $(".js-example-data-array3").select2({ | 163 $(".js-example-data-array3").select2({ |
184 data: queryData | 164 data: queryData |
185 }); | 165 }); |
186 $(".js-example-data-array3").select2('val', "Select an option"); | 166 $(".js-example-data-array3").select2('val', "Select an option"); |
194 $(".js-example-data-array3").select2('data',[]); | 174 $(".js-example-data-array3").select2('data',[]); |
195 //} | 175 //} |
196 ajax1(query); | 176 ajax1(query); |
197 }); | 177 }); |
198 | 178 |
199 // TODO: ^^^^^ extend this to make a listener that will build the query dynamically | 179 |
180 $("#plus_filter_button").click(function() { | |
181 console.log("add filter"); | |
182 $("#s2-example").append("<div id='filter'/>"); | |
183 //$(".js-example-data-array").select2({ | |
184 // data: filters | |
185 //}, console.log("created")); | |
186 }); | |
187 | |
188 | |
189 | |
190 | |
191 | |
192 | |
193 | |
194 | |
195 | |
196 | |
197 | |
198 | |
199 | |
200 | |
201 | |
202 | |
203 | |
204 | |
205 | |
206 | |
207 | |
208 | |
209 // TODO: **** NOTE, could have each ajax fn be called with an extra parameter of what type of result to return **** | |
210 // TODO: (objects, attributes, attribute, relationships) | |
211 // TODO: in this way you could have each onchange trigger supply the appropriate result of the box it will modify. | |
212 // TODO: this would allow the json to be returned in the same way for each result. and we could also pass | |
213 // TODO: the return type param to the data gen | |
214 | |
215 | |
216 /* CURRENT IMPLEMENTATION | |
217 TODO: Make custom dataGen function for each dropdown type: object, attribute, display | |
218 TODO: we need to do this because we need to deal with the returned json differently depending on | |
219 TODO: what we want the dropdown to hold. This will be determined by the body.on(change function | |
220 TODO: and what the type of box is changing. Eg. changing the object type will trigger a change in | |
221 TODO: attributes and clear the display. Change in attribute will combine with object type to form | |
222 TODO: full query and trigger a dataGen of the appropriate info eg. TEXT.label in the display. | |
223 TODO: In this implementation, each box determines the next | |
224 TODO: Also, object changing can be used to update the list of relationships between it and any other object | |
225 TODO: for the next line. | |
226 | |
227 | |
228 CYPHER IMPLEMENTATION | |
229 TODO: Implement exactly like a cypher query. | |
230 TODO: first line: MATCH ---- object. relationship. object. | |
231 TODO: first object on choice sends ajax query to determine available relationships --> second box | |
232 TODO: relationship on choice determines the other types of possible objects to relate to. | |
233 TODO: second line: WHERE ---- object. attribute. equals. | |
234 TODO: the object can be either of the ones from line one. the attribute is generated by that object. | |
235 TODO: choose to return | |
236 | |
237 */ | |
238 | |
239 | |
240 | |
241 | |
242 | |
243 | |
244 | |
200 | 245 |
201 | 246 |
202 </script> | 247 </script> |
203 | 248 |
204 </body> | 249 </body> |