Browse Source

More work on search (still hidden)

master
Chris Smith 12 years ago
parent
commit
4d77f3646a
5 changed files with 149 additions and 0 deletions
  1. 1
    0
      .htaccess
  2. 18
    0
      index.html
  3. 53
    0
      res/js/viewer.js
  4. 54
    0
      res/js/viewer/viewer.js
  5. 23
    0
      res/style.less

+ 1
- 0
.htaccess View File

@@ -1,3 +1,4 @@
1 1
 RewriteEngine On
2 2
 RewriteRule ^/?res/data/layouts/([A-Za-z0-9]+).js http://backend.layoutviewer.co.uk/getLayout/$1.js [P]
3 3
 RewriteRule ^/?res/data/layouts/new http://backend.layoutviewer.co.uk/saveLayout [P]
4
+RewriteRule ^/?res/data/layouts/search(.*) http://backend.layoutviewer.co.uk/search$1 [P]

+ 18
- 0
index.html View File

@@ -69,6 +69,7 @@
69 69
     <div class="container">
70 70
      <h2>Search layouts</h2>
71 71
      <div id="searchterms">
72
+      <h3>Search parameters</h3>
72 73
       <form>
73 74
        <div class="formrow">
74 75
         <label for="search_map">Level</label>
@@ -114,6 +115,23 @@
114 115
        </div>
115 116
       </form>
116 117
      </div>
118
+     <div id="searchresults">
119
+      <h3>Search results</h3>
120
+      <table>
121
+       <thead>
122
+        <tr>
123
+         <th>Layout</th>
124
+         <th>Level</th>
125
+         <th>Difficulty</th>
126
+         <th>Type</th>
127
+         <th>Modes</th>
128
+         <th>Classes</th>
129
+        </tr>
130
+       </thead>
131
+       <tbody>
132
+       </tbody>
133
+      </table>
134
+     </div>
117 135
     </div>
118 136
    </div>
119 137
   </div>

+ 53
- 0
res/js/viewer.js View File

@@ -175,6 +175,59 @@ $(function() {
175 175
   $.each(levels, function(key) {
176 176
    $('<option>').val(key + 1).text(this.name).appendTo(sel);
177 177
   });
178
+
179
+  function showSearch() {
180
+   $('#searchcontainer').show();
181
+  }
182
+
183
+  function hideSearch() {
184
+   $('#searchcontainer').hide();
185
+  }
186
+
187
+  function clearSearchResults() {
188
+   $('#searchresults tbody tr').remove();
189
+  }
190
+
191
+  function buildSearchQuery() {
192
+   var query = {};
193
+
194
+   var level = $('select[name=search_map]').val();
195
+   if (level != 'any') {
196
+    query.map = level;
197
+   }
198
+
199
+   doSearch(query);
200
+   return false;
201
+  }
202
+
203
+  function doSearch(data) {
204
+   clearSearchResults();
205
+
206
+   $.ajax({
207
+    url: 'res/data/layouts/search',
208
+    data: data,
209
+    success: handleSearch
210
+   });
211
+  }
212
+
213
+  function handleSearch(data) {
214
+   var body = $('#searchresults tbody');
215
+   $.each(data, function() {
216
+    this.difficulty = this.difficulty || 'unknown';
217
+
218
+    var tr = $('<tr>');
219
+    tr.append($('<td>').append($('<a>').attr('href', '#' + this.id).text(this.id).click(hideSearch)));
220
+    tr.append($('<td>').text(levels[this.level - 1] ? levels[this.level - 1].name : 'Unknown!'));
221
+    tr.append($('<td>').addClass(this.difficulty).text(this.difficulty));
222
+    tr.append($('<td>').addClass(this.type).text(this.type));
223
+    body.append(tr);
224
+   });
225
+  }
226
+
227
+  $('#search_submit').click(buildSearchQuery);
228
+  $('#search').click(showSearch);
229
+  $('#searchmask').click(hideSearch);
230
+  $('#searchclose').click(hideSearch);
178 231
  })();
179 232
 
180 233
  var thisLevel;

+ 54
- 0
res/js/viewer/viewer.js View File

@@ -153,6 +153,60 @@ $(function() {
153 153
   $.each(levels, function(key) {
154 154
    $('<option>').val(key + 1).text(this.name).appendTo(sel);
155 155
   });
156
+
157
+  function showSearch() {
158
+   $('#searchcontainer').show();
159
+  }
160
+
161
+  function hideSearch() {
162
+   $('#searchcontainer').hide();
163
+  }
164
+
165
+  function clearSearchResults() {
166
+   $('#searchresults tbody tr').remove();
167
+  }
168
+
169
+  function buildSearchQuery() {
170
+   var query = {};
171
+
172
+   var level = $('select[name=search_map]').val();
173
+   if (level != 'any') {
174
+    query.map = level;
175
+   }
176
+
177
+   doSearch(query);
178
+   return false;
179
+  }
180
+
181
+  function doSearch(data) {
182
+   clearSearchResults();
183
+
184
+   $.ajax({
185
+    url: 'res/data/layouts/search',
186
+    data: data,
187
+    success: handleSearch
188
+   });
189
+  }
190
+
191
+  function handleSearch(data) {
192
+   var body = $('#searchresults tbody');
193
+   $.each(data, function() {
194
+    this.difficulty = this.difficulty || 'unknown';
195
+    this.type = (this.type && this.type != 'none') ? this.type : 'unknown';
196
+
197
+    var tr = $('<tr>');
198
+    tr.append($('<td>').append($('<a>').attr('href', '#' + this.id).text(this.id).click(hideSearch)));
199
+    tr.append($('<td>').text(levels[this.level - 1] ? levels[this.level - 1].name : 'Unknown!'));
200
+    tr.append($('<td>').addClass(this.difficulty).text(this.difficulty));
201
+    tr.append($('<td>').addClass(this.type).text(this.type));
202
+    body.append(tr);
203
+   });
204
+  }
205
+
206
+  $('#search_submit').click(buildSearchQuery);
207
+  $('#search').click(showSearch);
208
+  $('#searchmask').click(hideSearch);
209
+  $('#searchclose').click(hideSearch);
156 210
  })();
157 211
 
158 212
  var thisLevel;

+ 23
- 0
res/style.less View File

@@ -182,6 +182,12 @@ body .tower.ui-draggable-dragging { z-index: 101; }
182 182
  right: 200px;
183 183
  bottom: 100px;
184 184
 
185
+ h3 {
186
+  color: @heading-color;
187
+  text-align: left;
188
+  border-bottom: 1px solid @border-color;
189
+ }
190
+
185 191
  #searchterms {
186 192
   width: 300px;
187 193
   float: left;
@@ -227,6 +233,23 @@ body .tower.ui-draggable-dragging { z-index: 101; }
227 233
    }
228 234
   }
229 235
  }
236
+
237
+ #searchresults {
238
+  margin-left: 330px;
239
+
240
+  table {
241
+   width: 100%;
242
+
243
+   thead tr {
244
+    color: @heading-color;
245
+    font-weight: bold;
246
+   }
247
+
248
+   tr {
249
+    text-align: left;
250
+   }
251
+  }
252
+ }
230 253
 }
231 254
 
232 255
 #layoutpicker {

Loading…
Cancel
Save