Skip to content

Commit 9504a8c

Browse files
committed
Stop search view from messing iwht browser history
Fixes #195 Browser back button functions as expected. Will go live in v2.0.3.
1 parent fbe3534 commit 9504a8c

File tree

5 files changed

+60
-21
lines changed

5 files changed

+60
-21
lines changed

gui/app/components/search/search-view.js

+31-8
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,43 @@ export default Component.extend({
1717
searchSvc: service('search'),
1818
results: A([]),
1919
validSearch: true,
20+
keywords: '' ,
21+
matchFilter: null,
2022

21-
init() {
23+
// init() {
24+
// this._super(...arguments);
25+
// },
26+
27+
didReceiveAttrs() {
28+
this._super(...arguments);
29+
this.set('keywords', this.get('filter'));
30+
this.set('matchFilter', this.get('matchFilter'));
31+
this.fetch();
32+
console.log('receive a');
33+
},
34+
35+
didReceiveAttrs() {
2236
this._super(...arguments);
37+
// this.set('keywords', this.get('filter'));
38+
this.set('matchFilter', this.get('matchFilter'));
2339
this.fetch();
40+
console.log('update a');
2441
},
2542

43+
// didUpdateAttrs() {
44+
// this._super(...arguments);
45+
// this.fetch();
46+
// console.log('update a');
47+
// },
48+
2649
fetch() {
2750
let payload = {
28-
keywords: this.get('filter'),
29-
doc: this.get('matchDoc'),
30-
attachment: this.get('matchFile'),
31-
tag: this.get('matchTag'),
32-
content: this.get('matchContent'),
33-
slog: this.get('slog')
51+
keywords: this.get('keywords'),
52+
doc: this.get('matchFilter.matchDoc'),
53+
attachment: this.get('matchFilter.matchFile'),
54+
tag: this.get('matchFilter.matchTag'),
55+
content: this.get('matchFilter.matchContent'),
56+
slog: this.get('matchFilter.slog')
3457
};
3558

3659
payload.keywords = payload.keywords.trim();
@@ -51,7 +74,7 @@ export default Component.extend({
5174

5275
actions: {
5376
onSearch() {
54-
if (this.get('filter').trim().length < 3) {
77+
if (this.get('keywords').trim().length < 3) {
5578
this.set('validSearch', false);
5679
return;
5780
}

gui/app/pods/search/controller.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ import Controller from '@ember/controller';
1414

1515
export default Controller.extend({
1616
appMeta: service(),
17-
1817
queryParams: ['filter', 'matchDoc', 'matchContent', 'matchTag', 'matchFile', 'slog'],
1918
filter: '',
2019
matchDoc: true,
2120
matchContent: true,
2221
matchTag: true,
2322
matchFile: true,
24-
slog: false,
23+
slog: false
2524
});

gui/app/pods/search/route.js

+21
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@ import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-rout
1313
import Route from '@ember/routing/route';
1414

1515
export default Route.extend(AuthenticatedRouteMixin, {
16+
matchFilter: null,
17+
18+
beforeModel(transition) {
19+
let matchFilter = {
20+
matchDoc: is.undefined(transition.to.queryParams.matchDoc) ? true : (transition.to.queryParams.matchDoc == 'true'),
21+
matchContent: is.undefined(transition.to.queryParams.matchContent) ? true : (transition.to.queryParams.matchContent == 'true'),
22+
matchTag: is.undefined(transition.to.queryParams.matchTag) ? true : (transition.to.queryParams.matchTag == 'true'),
23+
matchFile: is.undefined(transition.to.queryParams.matchFile) ? true : (transition.to.queryParams.matchFile == 'true'),
24+
slog: is.undefined(transition.to.queryParams.slog) ? false : (transition.to.queryParams.slog === 'true'),
25+
};
26+
27+
this.set('matchFilter', matchFilter);
28+
},
29+
30+
setupController: function (controller, model) {
31+
this._super(controller, model);
32+
33+
controller.set('model', model);
34+
controller.set('matchFilter', this.get('matchFilter'));
35+
},
36+
1637
activate() {
1738
this.get('browser').setTitle('Search');
1839
}

gui/app/pods/search/template.hbs

+5-9
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
<div class="title">Match Filter</div>
66
<div class="list">
77
<div class="item">
8-
{{input id="search-1" type="checkbox" checked=matchDoc}}
8+
{{input id="search-1" type="checkbox" checked=matchFilter.matchDoc}}
99
<label for="search-1" class="name">Document name</label>
1010
</div>
1111
<div class="item">
12-
{{input id="search-2" type="checkbox" checked=matchContent}}
12+
{{input id="search-2" type="checkbox" checked=matchFilter.matchContent}}
1313
<label for="search-2" class="name">Document content</label>
1414
</div>
1515
<div class="item">
16-
{{input id="search-3" type="checkbox" checked=matchTag}}
16+
{{input id="search-3" type="checkbox" checked=matchFilter.matchTag}}
1717
<label for="search-3" class="name">Tag name</label>
1818
</div>
1919
<div class="item">
20-
{{input id="search-4" type="checkbox" checked=matchFile}}
20+
{{input id="search-4" type="checkbox" checked=matchFilter.matchFile}}
2121
<label for="search-4" class="name">Attachment name</label>
2222
</div>
2323
</div>
@@ -69,9 +69,5 @@
6969

7070
{{search/search-view
7171
filter=filter
72-
matchDoc=matchDoc
73-
matchContent=matchContent
74-
matchTag=matchTag
75-
matchFile=matchFile
76-
slog=slog}}
72+
matchFilter=matchFilter}}
7773
{{/layout/master-content}}

gui/app/templates/components/search/search-view.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<div class="view-search">
22
<form onsubmit={{action "onSearch"}} class="form-inline">
33
<div class="form-group">
4-
{{focus-input type="text" value=filter class="form-control mr-3 search-box" placeholder="keywords, tags"}}
4+
{{focus-input type="text" value=keywords class="form-control mr-3 search-box" placeholder="keywords, tags"}}
55
</div>
66
<div class="form-group">
77
{{ui/ui-button color=constants.Color.Green light=true label=constants.Label.Search onClick=(action "onSearch")}}
88
</div>
99
</form>
1010
{{#if validSearch}}
11-
{{search/search-results results=results keywords=filter}}
11+
{{search/search-results results=results keywords=keywords}}
1212
{{else}}
1313
{{ui/ui-spacer size=300}}
1414
<p class="color-red-700">Your search query is too short</p>

0 commit comments

Comments
 (0)