Skip to content

Commit 72b1ac4

Browse files
committed
Add sort and order options
1 parent c71b24a commit 72b1ac4

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

static/css/mpg.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ button, input {
9898

9999
}
100100

101+
#mpg-index-order-select, #mpg-unique-index-select {
102+
103+
width: auto;
104+
105+
}
106+
101107
#mpg-create-index-button {
102108

103109
margin-left: 10px;

static/js/mpg.database.query.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,18 @@ MPG.eventListeners.addCollections = function() {
277277
}
278278
});
279279

280+
var sortSelect = document.querySelector('#mpg-sort-select');
281+
sortSelect.innerHTML = '';
282+
283+
MPG.collectionFields.forEach(function(collectionField) {
284+
285+
sortSelect.innerHTML += '<option value="' + collectionField + '">'
286+
+ collectionField + '</option>';
287+
288+
});
289+
290+
document.querySelector('#mpg-output-code').innerHTML = '';
291+
280292
},
281293
null
282294
);
@@ -515,6 +527,17 @@ MPG.eventListeners.addFind = function() {
515527
requestBody.options = {};
516528
requestBody.options.limit = parseInt(document.querySelector('#mpg-limit-input').value);
517529

530+
var sortSelect = document.querySelector('#mpg-sort-select');
531+
532+
if ( sortSelect.value !== '' ) {
533+
534+
var order = parseInt(document.querySelector('#mpg-order-select').value);
535+
536+
requestBody.options.sort = {};
537+
requestBody.options.sort[sortSelect.value] = order;
538+
539+
}
540+
518541
MPG.helpers.doAjaxRequest(
519542
'POST',
520543
'/ajax/database/' + MPG.databaseName + '/collection/'

views/collection.indexes.tpl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@
106106

107107
<span class="align-middle">Order</span>
108108

109-
<select id="mpg-index-order-select" class="align-middle">
109+
<select id="mpg-index-order-select" class="form-control d-inline-block align-middle">
110110
<option value="1" selected>ASC</option>
111111
<option value="-1">DESC</option>
112112
</select>
113113

114114
<span class="align-middle">Unique?</span>
115115

116-
<select id="mpg-unique-index-select" class="align-middle">
116+
<select id="mpg-unique-index-select" class="form-control d-inline-block align-middle">
117117
<option value="true">Yes</option>
118118
<option value="false" selected>No</option>
119119
</select>

views/database.query.tpl.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484

8585
<div class="row">
8686

87-
<div class="col-md-8">
87+
<div class="col-md-6">
8888

8989
<h2 class="float-left">Document</h2>
9090

@@ -110,10 +110,32 @@
110110

111111
</div>
112112

113-
<div class="col-md-4">
113+
<div class="col-md-6">
114114

115115
<h2>Options</h2>
116-
Limit <input id="mpg-limit-input" type="number" value="5" min="1">
116+
117+
<div class="form-group">
118+
119+
<div>
120+
Limit <input id="mpg-limit-input" type="number" class="form-control" value="5" min="1">
121+
</div>
122+
123+
<div>
124+
Sort
125+
<select id="mpg-sort-select" class="form-control">
126+
<option value="">Please select a database and a collection.</option>
127+
</select>
128+
</div>
129+
130+
<div>
131+
Order
132+
<select id="mpg-order-select" class="form-control">
133+
<option value="1">ASC</option>
134+
<option value="-1">DESC</option>
135+
</select>
136+
</div>
137+
138+
</div>
117139

118140
</div>
119141

0 commit comments

Comments
 (0)