Skip to content
This repository was archived by the owner on Oct 5, 2020. It is now read-only.

Commit 74669e0

Browse files
committed
Add sort toggle component #366 and detect operator states #152
1 parent 08eb2c5 commit 74669e0

File tree

13 files changed

+142
-109
lines changed

13 files changed

+142
-109
lines changed

app/templates/bower.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
"version": "0.0.0",
44
"dependencies": {
55
"jquery": "~2.1.4",
6-
"angular": "~1.4.4",
7-
"angular-animate": "~1.4.4",
6+
"angular": "~1.6.5",
7+
"angular-animate": "~1.6.5",
88
"angular-bootstrap": "^1.1",
99
"angular-bootstrap-confirm": "^2.3.0",
10-
"angular-cookies": "~1.4.4",
10+
"angular-cookies": "~1.6.5",
1111
"angular-google-maps": "2.3.2",
1212
"angular-highlightjs": "~0.6.0",
13-
"angular-messages": "~1.4.4",
14-
"angular-mocks": "~1.4.4",
15-
"angular-sanitize": "~1.4.4",
16-
"angular-ui-router": "~0.2.15",
13+
"angular-messages": "~1.6.5",
14+
"angular-mocks": "~1.6.5",
15+
"angular-sanitize": "~1.6.5",
16+
"angular-ui-router": "~0.3.1",
1717
"angular-ui-tinymce": "~0.0.9",
1818
"angular-x2js": "https://github.com/janmichaelyu/angular-x2js.git",
1919
"bootstrap": "~3.3.5",
@@ -49,15 +49,16 @@
4949
}
5050
},
5151
"devDependencies": {
52-
"angular-mocks": "~1.4.4",
52+
"angular-mocks": "~1.6.5",
5353
"bardjs": "~0.1.8",
5454
"sinon": "*"
5555
},
5656
"private": true,
5757
"resolutions": {
58-
"angular": "~1.4.4",
58+
"angular": "~1.6.5",
5959
"angular-bootstrap": "^1.1",
6060
"highcharts": "^4.2",
61-
"ng-json-explorer": "f7236fa857"
61+
"ng-json-explorer": "f7236fa857",
62+
"angular-sanitize": "~1.6.5"
6263
}
6364
}

app/templates/rest-api/config/options/all.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@
7979
</state>
8080
</operator>
8181

82+
<operator name="sort">
83+
<state name="score">
84+
<sort-order>
85+
<score/>
86+
</sort-order>
87+
</state>
88+
<state name="eyeColorAsc">
89+
<sort-order
90+
direction="ascending" type="xs:string" collation="http://marklogic.com/collation/codepoint">
91+
<path-index>eyeColor</path-index>
92+
</sort-order>
93+
</state>
94+
<state name="eyeColorDsc">
95+
<sort-order
96+
direction="descending" type="xs:string" collation="http://marklogic.com/collation/codepoint">
97+
<path-index>eyeColor</path-index>
98+
</sort-order>
99+
</state>
100+
</operator>
82101
<!-- Annotations (allowed pretty much anywhere) allow adding text or elements to feed custom components with options that would normally not validate) -->
83102
<annotation>Delta options here</annotation>
84103

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(function () {
2+
'use strict';
3+
4+
function MLSelectController() {
5+
var ctrl = this;
6+
ctrl.select = function(selectionName) {
7+
ctrl.onSelect({selectionName: selectionName});
8+
};
9+
}
10+
11+
angular.module('app.search')
12+
.component('mlSelect', {
13+
templateUrl: 'app/search/ml-select.html',
14+
controller: MLSelectController,
15+
bindings: {
16+
label: '=',
17+
currentSelection: '=',
18+
selectionList: '=',
19+
onSelect: '&'
20+
}
21+
});
22+
23+
})();
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* jshint -W117, -W030 */
2+
(function () {
3+
'use strict';
4+
5+
describe('Component: ml-select', function () {
6+
7+
var elem, controller, snippet;
8+
9+
beforeEach(function() {
10+
bard.appModule('app.search');
11+
bard.inject('$compile', '$rootScope', '$templateCache', '$componentController');
12+
13+
$templateCache.put( 'app/search/ml-select.html',
14+
'<div class="ml-select"></div>'
15+
);
16+
});
17+
18+
beforeEach(function() {
19+
var $scope = $rootScope.$new();
20+
$scope.setSnippet = function(selectionName) {
21+
snippet = selectionName;
22+
};
23+
elem = angular.element('<ml-select on-select="setSnippet(selectionName)"></ml-select>');
24+
$compile(elem)($scope);
25+
$scope.$digest();
26+
var bindings = {onSelect: $scope.setSnippet};
27+
controller = $componentController('mlSelect', { $scope: $scope }, bindings);
28+
29+
// flush promises
30+
$rootScope.$apply();
31+
});
32+
33+
it('should compile', function() {
34+
expect(elem.children().hasClass('ml-select')).to.eq(true);
35+
});
36+
37+
it('should set snippet', function() {
38+
var type = 'xxx';
39+
controller.onSelect(type);
40+
expect(snippet).to.eq(type);
41+
});
42+
43+
});
44+
})();
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<div class="btn-group" uib-dropdown>
22
<button id="single-button" type="button" class="btn btn-sm btn-default" uib-dropdown-toggle>
3-
Snippet Size: <i>{{snippetType || 'compact'}}</i> <span class="caret"></span>
3+
{{$ctrl.label}}: <i>{{$ctrl.currentSelection || $ctrl.defaultValue}}</i> <span class="caret"></span>
44
</button>
55
<ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="single-button">
6-
<li role="menuitem" ng-repeat="snippet in snippets track by $index">
7-
<a href ng-click="$ctrl.setSnippetType(snippet)">{{snippet}}</a>
6+
<li role="menuitem" ng-repeat="selection in $ctrl.selectionList track by $index">
7+
<a href ng-click="$ctrl.select(selection)">{{selection}}</a>
88
</li>
99
</ul>
1010
</div>

app/templates/ui/app/search/ml-snippet.directive.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

app/templates/ui/app/search/ml-snippet.directive.spec.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

app/templates/ui/app/search/ml-snippet.module.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

app/templates/ui/app/search/search.controller.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* global MLSearchController */
2-
(function () {
2+
(function() {
33
'use strict';
44

55
angular.module('app.search')
@@ -22,5 +22,27 @@
2222
ctrl.mlSearch.setSnippet(type);
2323
ctrl.search();
2424
};
25+
26+
ctrl.setSort = function(type) {
27+
ctrl.mlSearch.setSort(type);
28+
ctrl.search();
29+
};
30+
31+
function listFromOperator(operatorArray, operatorType) {
32+
return (_.filter(
33+
operatorArray,
34+
function(val) {
35+
return val && val.state && val.state[0] && val.state[0][operatorType];
36+
}
37+
)[0] || { state: []}).state.map(function(state) {
38+
return state.name;
39+
});
40+
}
41+
42+
ctrl.mlSearch.getStoredOptions().then(function(data) {
43+
ctrl.sortList = listFromOperator(data.options.operator, 'sort-order');
44+
ctrl.snippetList = listFromOperator(data.options.operator, 'transform-results');
45+
});
46+
2547
}
2648
}());

app/templates/ui/app/search/search.controller.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
data: {
2626
results: results
2727
}
28+
}),
29+
queryConfig: $q.when({
30+
data: {
31+
options: {
32+
operator: []
33+
}
34+
}
2835
})
2936
});
3037

0 commit comments

Comments
 (0)