#1645 refactor search panel
gitea/salix/dev This commit looks good Details

This commit is contained in:
Bernat 2019-08-29 08:32:46 +02:00
parent 6daabed202
commit b656db3a84
5 changed files with 16 additions and 5 deletions

View File

@ -11,6 +11,7 @@ describe('Item summary path', () => {
it('should search for an item', async() => {
const result = await nightmare
.clearInput(selectors.itemsIndex.searchItemInput)
.write(selectors.itemsIndex.searchItemInput, 'Ranged weapon longbow 2m')
.waitToClick(selectors.itemsIndex.searchButton)
.waitForNumberOfElements(selectors.itemsIndex.searchResult, 1)

View File

@ -11,6 +11,7 @@ describe('Item Create/Clone path', () => {
it(`should search for the item Infinity Gauntlet to confirm it isn't created yet`, async() => {
const result = await nightmare
.clearInput(selectors.itemsIndex.searchItemInput)
.write(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet')
.waitToClick(selectors.itemsIndex.searchButton)
.waitForNumberOfElements(selectors.itemsIndex.searchResult, 0)
@ -95,6 +96,7 @@ describe('Item Create/Clone path', () => {
it(`should search for the item Infinity Gauntlet`, async() => {
const result = await nightmare
.clearInput(selectors.itemsIndex.searchItemInput)
.write(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet')
.waitToClick(selectors.itemsIndex.searchButton)
.waitForNumberOfElements(selectors.itemsIndex.searchResult, 1)
@ -117,6 +119,7 @@ describe('Item Create/Clone path', () => {
it('should search for the item Infinity Gauntlet and find two', async() => {
const result = await nightmare
.waitToClick(selectors.itemTags.goToItemIndexButton)
.clearInput(selectors.itemsIndex.searchItemInput)
.write(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet')
.waitToClick(selectors.itemsIndex.searchButton)
.waitForNumberOfElements(selectors.itemsIndex.searchResult, 2)

View File

@ -29,6 +29,7 @@ describe('Item regularize path', () => {
it('should search for the item', async() => {
const resultCount = await nightmare
.clearInput(selectors.itemsIndex.searchItemInput)
.write(selectors.itemsIndex.searchItemInput, 'Ranged weapon pistol 9mm')
.waitToClick(selectors.itemsIndex.searchButton)
.waitForNumberOfElements(selectors.itemsIndex.searchResult, 1)
@ -134,6 +135,7 @@ describe('Item regularize path', () => {
it('should search for the item once again', async() => {
const resultCount = await nightmare
.clearInput(selectors.itemsIndex.searchItemInput)
.write(selectors.itemsIndex.searchItemInput, 'Ranged weapon pistol 9mm')
.waitToClick(selectors.itemsIndex.searchButton)
.waitForNumberOfElements(selectors.itemsIndex.searchResult, 1)

View File

@ -28,7 +28,6 @@ export default class Controller extends Component {
() => this.onStateChange());
this._filter = null;
this.searchString = '';
this.autoLoad = false;
}
@ -58,6 +57,10 @@ export default class Controller extends Component {
this.doSearch();
}
get shownFilter() {
return this._filter != null ? this._filter : this.suggestedFilter;
}
openPanel(event) {
if (event.defaultPrevented) return;
event.preventDefault();
@ -65,7 +68,8 @@ export default class Controller extends Component {
this.$panelScope = this.$.$new();
this.$panel = this.$compile(`<${this.panel}/>`)(this.$panelScope);
let panel = this.$panel.isolateScope().$ctrl;
panel.filter = this._filter;
if (this.shownFilter)
panel.filter = JSON.parse(JSON.stringify(this.shownFilter));
panel.onSubmit = filter => this.onPanelSubmit(filter);
this.$.popover.parent = this.element;
@ -94,13 +98,12 @@ export default class Controller extends Component {
}
doSearch() {
let filter = this._filter;
this.searchString = this.getStringFromObject(this.shownFilter);
let filter = this._filter;
if (filter == null && this.autoload)
filter = {};
this.searchString = this.getStringFromObject(filter);
if (this.onSearch)
this.onSearch({$params: filter});
@ -214,6 +217,7 @@ ngModule.component('vnSearchbar', {
template: require('./searchbar.html'),
bindings: {
filter: '<?',
suggestedFilter: '<?',
onSearch: '&?',
panel: '@',
model: '<?',

View File

@ -15,6 +15,7 @@
panel="vn-item-search-panel"
on-search="$ctrl.onSearch($params)"
info="Search items by id, name or barcode"
suggested-filter="{isActive: true}"
vn-focus>
</vn-searchbar>
<vn-icon-menu