Skip to content

Commit e8802af

Browse files
committed
Add mostly-search
1 parent 5fe9d6c commit e8802af

7 files changed

Lines changed: 559 additions & 41 deletions

File tree

‎elements.html‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,11 @@
5555
<!-- Nuxeo UI Elements -->
5656
<link rel="import" href="../nuxeo-ui-elements/nuxeo-icons.html">
5757
<link rel="import" href="../nuxeo-ui-elements/dataviz/nuxeo-document-distribution-chart.html">
58-
<link rel="import" href="../nuxeo-ui-elements/nuxeo-document-preview.html">
59-
<link rel="import" href="../nuxeo-ui-elements/nuxeo-aggregation/nuxeo-checkbox-aggregation.html">
60-
<link rel="import" href="../nuxeo-ui-elements/nuxeo-aggregation/nuxeo-dropdown-aggregation.html">
58+
<link rel="import" href="mostly-aggregation/mostly-checkbox-aggregation.html">
59+
<link rel="import" href="mostly-aggregation/mostly-dropdown-aggregation.html">
6160
<link rel="import" href="mostly-data-grid/mostly-data-grid.html">
6261
<link rel="import" href="mostly-data-list/mostly-data-list.html">
6362
<link rel="import" href="mostly-data-table/iron-data-table.html">
64-
<link rel="import" href="../nuxeo-ui-elements/nuxeo-document-permissions/nuxeo-document-permissions.html">
6563
<link rel="import" href="mostly-error.html">
6664
<link rel="import" href="../nuxeo-ui-elements/nuxeo-filter.html">
6765
<link rel="import" href="behaviors/mostly-filters-behavior.html">
@@ -70,8 +68,7 @@
7068
<link rel="import" href="mostly-layout.html">
7169
<link rel="import" href="behaviors/mostly-layout-behavior.html">
7270
<link rel="import" href="behaviors/mostly-page-provider-display-behavior.html">
73-
<link rel="import" href="../nuxeo-ui-elements/nuxeo-path-suggestion/nuxeo-path-suggestion.html">
74-
<link rel="import" href="../nuxeo-ui-elements/nuxeo-quick-filters/nuxeo-quick-filters.html">
71+
<link rel="import" href="mostly-quick-filters/mostly-quick-filters.html">
7572
<link rel="import" href="behaviors/mostly-routing-behavior.html">
7673
<link rel="import" href="../nuxeo-ui-elements/nuxeo-slots.html">
7774
<link rel="import" href="mostly-tree/mostly-tree.html">
@@ -83,7 +80,7 @@
8380
<link rel="import" href="../nuxeo-ui-elements/widgets/nuxeo-document-suggestion.html">
8481
<link rel="import" href="../nuxeo-ui-elements/widgets/nuxeo-file.html">
8582
<link rel="import" href="../nuxeo-ui-elements/widgets/nuxeo-operation-button.html">
86-
<link rel="import" href="../nuxeo-ui-elements/widgets/nuxeo-select.html">
83+
<link rel="import" href="widgets/mostly-select.html">
8784
<link rel="import" href="widgets/mostly-tag.html">
8885
<link rel="import" href="../nuxeo-ui-elements/widgets/nuxeo-date.html">
8986
<link rel="import" href="../nuxeo-ui-elements/widgets/nuxeo-input.html">
@@ -126,6 +123,7 @@
126123
<link rel="import" href="mostly-common/mostly-page-provider.html">
127124
<link rel="import" href="mostly-common/mostly-resource.html">
128125
<link rel="import" href="mostly-common/mostly-results.html">
126+
<link rel="import" href="mostly-common/mostly-search.html">
129127

130128
<!-- Application elements -->
131129
<link rel="import" href="mostly-app.html">
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<link rel="import" href="../../polymer/polymer.html">
2+
<link rel="import" href="../../paper-checkbox/paper-checkbox.html">
3+
<link rel="import" href="../behaviors/mostly-i18n-behavior.html">
4+
<link rel="import" href="../behaviors/mostly-aggregation-behavior.html">
5+
6+
<!--
7+
An element to interact with page provider aggregations as checkboxes.
8+
9+
<mostly-page-provider provider="default_search" auto
10+
aggregations="{{aggregations}}"
11+
params="[[params]]">
12+
</mostly-page-provider>
13+
14+
<mostly-checkbox-aggregation data="[[aggregations.dc_created_agg]]"
15+
value="{{params.dc_created_agg}}">
16+
</mostly-checkbox-aggregation>
17+
18+
@group Mostly UI
19+
@element mostly-checkbox-aggregation
20+
-->
21+
<dom-module id="mostly-checkbox-aggregation">
22+
<template>
23+
<style>
24+
paper-checkbox {
25+
--paper-checkbox-label-spacing: 10px;
26+
margin-bottom: 5px;
27+
}
28+
</style>
29+
30+
<div class="layout vertical">
31+
<template is="dom-repeat" items="{{buckets}}">
32+
<paper-checkbox noink checked="{{item.checked}}"
33+
on-change="_computeValues">
34+
[[_computeLabel(item)]] ([[item.docCount]])
35+
</paper-checkbox>
36+
</template>
37+
<template is="dom-if" if="[[_isEmpty]]">
38+
<label class="empty">[[i18n('checkboxAggregation.noResults')]]</label>
39+
</template>
40+
</div>
41+
42+
</template>
43+
<script>
44+
Polymer({
45+
is: 'mostly-checkbox-aggregation',
46+
behaviors: [Mostly.I18nBehavior, Mostly.AggregationBehavior]
47+
});
48+
</script>
49+
</dom-module>

‎mostly-common/mostly-search.html‎

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
<link rel="import" href="../../polymer/polymer.html">
2+
<link rel="import" href="mostly-resource.html">
3+
4+
<!--
5+
`mostly-search` allows managing saved searches on a Nuxeo server.
6+
7+
<mostly-search></mostly-search>
8+
9+
Example - Get all saved searches accessible by the current user:
10+
11+
<mostly-search auto searches="{{searches}}"></mostly-search>
12+
13+
Example - Get a saved search by id:
14+
15+
<mostly-search auto search-id="[[id]]" search="{{search}}"></mostly-search>
16+
17+
Example - Execute a saved search:
18+
19+
<mostly-search auto search-id="[[id]]" results="{{results}}"></mostly-search>
20+
21+
You can trigger a method explicitly by calling `get`, `post`, `put`, `remove` or `execute on the
22+
element.
23+
24+
@group Mostly Elements
25+
@element mostly-search
26+
-->
27+
28+
<dom-module id="mostly-search">
29+
<template>
30+
<style>
31+
:host {
32+
display: none;
33+
}
34+
</style>
35+
36+
<mostly-resource id="resource" connection-id="[[connectionId]]" method="[[method]]"
37+
path="[[path]]" data="[[data]]" headers="[[headers]]" params="[[params]]">
38+
</mostly-resource>
39+
40+
</template>
41+
<script>
42+
Polymer({
43+
is: 'mostly-search',
44+
45+
properties: {
46+
47+
/**
48+
* Id of a saved search to be used on requests.
49+
*/
50+
searchId: {
51+
type: String,
52+
value: ''
53+
},
54+
55+
/**
56+
* Body to be used on POST/PUT requests.
57+
*/
58+
data: Object,
59+
60+
/**
61+
* A single saved search as a result of a GET request with a given id.
62+
*/
63+
search: {
64+
type: Object,
65+
notify: true
66+
},
67+
68+
/**
69+
* Saved searches accessible by the current user.
70+
* Result of a GET request when an id is not specified.
71+
*/
72+
searches: {
73+
type: Array,
74+
notify: true
75+
},
76+
77+
/**
78+
* Results when executing a given saved search.
79+
*/
80+
results: {
81+
type: Array,
82+
notify: true
83+
},
84+
85+
/**
86+
* Computed path of the search endpoint to use.
87+
*/
88+
path: {
89+
type: String,
90+
computed: '_computePath(auto, searchId)'
91+
},
92+
93+
/**
94+
* Search parameters.
95+
*/
96+
params: {
97+
type: Object
98+
},
99+
100+
/**
101+
* The id of a mostly-connection to use.
102+
*/
103+
connectionId: String,
104+
105+
/**
106+
* If true, automatically execute the search request.
107+
*/
108+
auto: {
109+
type: Boolean,
110+
value: false,
111+
observer: '_autoChanged'
112+
},
113+
114+
/**
115+
* The HTTP method to use ('GET', 'POST', 'PUT', or 'DELETE'). Default is 'GET'
116+
*/
117+
method: {
118+
type: String,
119+
value: 'get'
120+
},
121+
122+
/**
123+
* The headers of the request.
124+
*/
125+
headers: Object,
126+
127+
/**
128+
* The delay in milliseconds to debounce the auto fetch call.
129+
*/
130+
autoDelay: {
131+
type: Number,
132+
value: 300
133+
},
134+
135+
/**
136+
* True while requests are in flight.
137+
*/
138+
loading: {
139+
type: Boolean,
140+
notify: true,
141+
readOnly: true
142+
}
143+
},
144+
145+
/**
146+
* Gets the list of saved searches or the current search search if `search-id` is set.
147+
*/
148+
get: function() {
149+
this.method = 'get';
150+
return this.$.resource.execute().then((response) => {
151+
if (this.searchId) {
152+
this.search = response;
153+
} else {
154+
this.searches = response.data;
155+
}
156+
return response;
157+
});
158+
},
159+
160+
/**
161+
* Saves the search.
162+
*/
163+
post: function() {
164+
this.method = 'post';
165+
return this.$.resource.execute();
166+
},
167+
168+
/**
169+
* Updates the saved search.
170+
*/
171+
put: function() {
172+
this.method = 'put';
173+
return this.$.resource.execute();
174+
},
175+
176+
/**
177+
* Deletes the saved search.
178+
*/
179+
remove: function() {
180+
this.method = 'delete';
181+
return this.$.resource.execute();
182+
},
183+
184+
/**
185+
* Executes the saved search.
186+
*/
187+
execute: function() {
188+
if (this.searchId) {
189+
this.method = 'get';
190+
this.$.resource.path += '/execute';
191+
this.$.resource.execute().then((response) => {
192+
this.results = response.data;
193+
});
194+
}
195+
},
196+
197+
_computePath: function() {
198+
var path = '/search/saved';
199+
if (this.searchId) {
200+
path += '/' + this.searchId;
201+
}
202+
return path;
203+
},
204+
205+
_autoChanged: function() {
206+
if (this.auto && this.path) {
207+
this.debounce('_auto', () => {
208+
this.get().then(() => {
209+
this.execute();
210+
});
211+
}, this.autoDelay);
212+
}
213+
},
214+
215+
ready: function() {
216+
this.$.resource.addEventListener('loading-changed', () => {
217+
this._setLoading(this.$.resource.loading);
218+
});
219+
}
220+
});
221+
</script>
222+
</dom-module>

‎mostly-data-table/iron-data-table.html‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,23 @@
6464
</mostly-data-table-column>
6565
<mostly-data-table-column filter-by="dc_modified_agg" flex="50" sort-by="updatedAt">
6666
<template is="header">
67-
<nuxeo-dropdown-aggregation
67+
<mostly-dropdown-aggregation
6868
placeholder="Modified"
6969
data="[[aggregations.dc_modified_agg]]"
7070
value="{{column.filterValue}}" multiple>
71-
</nuxeo-dropdown-aggregation>
71+
</mostly-dropdown-aggregation>
7272
</template>
7373
<template>
7474
[[item.updatedAt]]
7575
</template>
7676
</mostly-data-table-column>
7777
<mostly-data-table-column filter-by="dc_creator_agg" flex="50">
7878
<template is="header">
79-
<nuxeo-dropdown-aggregation
79+
<mostly-dropdown-aggregation
8080
placeholder="Author"
8181
data="[[aggregations.dc_creator_agg]]"
8282
value="{{column.filterValue}}" multiple>
83-
</nuxeo-dropdown-aggregation>
83+
</mostly-dropdown-aggregation>
8484
</template>
8585
<template>
8686
<span class="tag user">[[item.creator]]</span>

0 commit comments

Comments
 (0)