add correct returns to sortable search matches

also cleaned up code style

rancher/rancher#18288
This commit is contained in:
Westly Wright 2019-02-22 15:39:30 -07:00
parent 7537421efc
commit 4f0ad7ecbe
No known key found for this signature in database
GPG Key ID: 4FAB3D8673DC54A3
2 changed files with 94 additions and 83 deletions

View File

@ -33,6 +33,7 @@ function toggleInput(node, on) {
}
}
}
export function matches(fields, token, item) {
let tokenMayBeIp = /^[0-9a-f\.:]+$/i.test(token);
@ -66,8 +67,8 @@ export function matches(fields, token, item) {
if ( val === token ) {
return true;
}
break;
return false;
case 'ip':
if ( tokenMayBeIp ) {
let re = new RegExp(`(?:^|\.)${ token }(?:\.|$)`);
@ -76,18 +77,20 @@ export function matches(fields, token, item) {
return true;
}
}
break;
return false;
case 'prefix':
if ( val.indexOf(token) === 0) {
return true;
}
break;
return false;
default:
if ( val.indexOf(token) >= 0) {
return true;
}
return false;
}
}
}
@ -136,7 +139,8 @@ export default Component.extend(Sortable, StickyHeader, {
init() {
this._super(...arguments);
this.set('selectedNodes', []);
set(this, 'selectedNodes', []);
if (get(this, 'bulkActions')) {
this.actionsChanged();
}
@ -184,7 +188,9 @@ export default Component.extend(Sortable, StickyHeader, {
ref,
items: [obj]
};
map[group] = entry;
ary.push(entry);
}
if ( get(this, 'selectedNodes').includes(obj) ) {
@ -199,7 +205,6 @@ export default Component.extend(Sortable, StickyHeader, {
},
didReceiveAttrs() {
this._super(...arguments);
if (get(this, 'isVisible')) {
this.triggerResize();
}
@ -207,11 +212,12 @@ export default Component.extend(Sortable, StickyHeader, {
actions: {
clearSearch() {
this.set('searchText', '');
set(this, 'searchText', '');
},
executeBulkAction(name, e) {
e.preventDefault();
let handler = get(this, 'bulkActionHandler');
let nodes = get(this, 'selectedNodes');
@ -270,12 +276,12 @@ export default Component.extend(Sortable, StickyHeader, {
if ( get(this, 'page') > 1 && from > last) {
let page = Math.ceil(last / perPage);
this.set('page', page);
set(this, 'page', page);
}
}),
sortKeyChanged: observer('sortBy', function() {
this.set('page', 1);
set(this, 'page', 1);
}),
actionsChanged: observer('selectedNodes.@each._availableActions', 'pagedContent.@each._availableActions', function() {
@ -288,6 +294,7 @@ export default Component.extend(Sortable, StickyHeader, {
if ( !nodes.length ) {
disableAll = true;
let firstNode = get(this, 'pagedContent.firstObject');
if ( firstNode ) {
@ -307,6 +314,7 @@ export default Component.extend(Sortable, StickyHeader, {
if ( !obj ) {
obj = $().extend(true, {}, act);// eslint-disable-line
map[act.action] = obj;
}
@ -326,6 +334,7 @@ export default Component.extend(Sortable, StickyHeader, {
if ( !obj ) {
obj = $().extend(true, {}, act); // eslint-disable-line
map[act.action] = obj;
}
@ -350,7 +359,7 @@ export default Component.extend(Sortable, StickyHeader, {
});
}
this.set('availableActions', out);
set(this, 'availableActions', out);
}),
searchInPlace: computed('search', 'searchToWormhole', function() {
return get(this, 'search') && !get(this, 'searchToWormhole');
@ -435,6 +444,7 @@ export default Component.extend(Sortable, StickyHeader, {
if ( searchText.length ) {
subMatches = {};
let searchTokens = searchText.split(/\s*[, ]\s*/);
for ( let i = out.length - 1 ; i >= 0 ; i-- ) {
@ -453,6 +463,7 @@ export default Component.extend(Sortable, StickyHeader, {
if ( token && matches(searchFields, token, row) !== expect ) {
mainFound = false;
break;
}
}
@ -474,6 +485,7 @@ export default Component.extend(Sortable, StickyHeader, {
if ( matches(subFields, token, subRows[k]) !== expect ) {
subFound = false;
break;
}
}
@ -492,7 +504,7 @@ export default Component.extend(Sortable, StickyHeader, {
}
}
this.set('subMatches', subMatches);
set(this, 'subMatches', subMatches);
return out;
}),
@ -530,7 +542,7 @@ export default Component.extend(Sortable, StickyHeader, {
},
set(key, value) {
var content = this.get('pagedContent').filterBy('canBulkRemove');
var content = get(this, 'pagedContent').filterBy('canBulkRemove');
if ( value ) {
this.toggleMulti(content, []);
@ -625,7 +637,7 @@ export default Component.extend(Sortable, StickyHeader, {
this.toggleMulti([node], content);
}
this.set('prevNode', node);
set(this, 'prevNode', node);
},
nodesBetween(a, b) {
@ -635,7 +647,6 @@ export default Component.extend(Sortable, StickyHeader, {
if ( key ) {
// Grouped has 2 levels to look through
let grouped = get(this, 'groupedContent');
let from = this.groupIdx(a);
let to = this.groupIdx(b);

View File

@ -1,4 +1,4 @@
<table class="fixed grid sortable-table {{if internalBulkActions 'has-actions'}} {{if groupByKey 'bordered'}} {{if subRows 'has-sub-rows bordered'}} {{tableClassNames}}">
<table class="fixed grid sortable-table {{if internalBulkActions "has-actions"}} {{if groupByKey "bordered"}} {{if subRows "has-sub-rows bordered"}} {{tableClassNames}}">
<thead>
<tr class="fixed-header-placeholder">
{{#if internalBulkActions}}
@ -17,7 +17,7 @@
<div class="bulk-actions pull-left">
{{#each availableActions as |action index|}}
{{#if action.enabled}}
<a class="btn btn-sm bg-primary" href="#" onclick={{action 'executeBulkAction' action.action}} tabindex={{index}}>
<a class="btn btn-sm bg-primary" href="#" onclick={{action "executeBulkAction" action.action}} tabindex={{index}}>
{{t action.label}}
<i class="{{action.icon}}"></i>
</a>
@ -37,7 +37,7 @@
<div class="pull-left">
{{#if leftActions}}
<div class="vertical-middle pr-20">
{{yield this 'left-actions'}}
{{yield this "left-actions"}}
</div>
{{/if}}
</div>
@ -46,11 +46,11 @@
{{#if search}}
<div class="vertical-middle">
{{#ember-wormhole to=searchToWormhole renderInPlace=(not searchToWormhole)}}
<div class="{{unless searchToWormhole 'pull-right'}} search-group input-group">
{{input value=searchText aria-title=(t 'generic.search') type="search" class="input-sm pull-right" placeholder=(t 'generic.search')}}
<div class="{{unless searchToWormhole "pull-right"}} search-group input-group">
{{input value=searchText aria-title=(t "generic.search") type="search" class="input-sm pull-right" placeholder=(t "generic.search")}}
{{#if searchText}}
<span class="input-group-btn">
<button class="btn bg-transparent text-info pl-10 pr-10" {{action 'clearSearch'}}><i class="icon icon-close"/></button>
<button class="btn bg-transparent text-info pl-10 pr-10" {{action "clearSearch"}}><i class="icon icon-close"/></button>
</span>
{{/if}}
</div>
@ -60,7 +60,7 @@
{{#if rightActions}}
<div class="vertical-middle pl-20">
{{yield this 'right-actions'}}
{{yield this "right-actions"}}
</div>
{{/if}}
</div>
@ -89,7 +89,7 @@
</thead>
{{#if prefix}}
<tbody>
{{yield this 'prefix'}}
{{yield this "prefix"}}
</tbody>
{{/if}}
@ -97,33 +97,33 @@
{{#if extraGroups.length}}
{{#each extraGroups as |group|}}
<tbody class="group">
{{yield this 'group' group}}
{{yield this 'norows'}}
{{yield this "group" group}}
{{yield this "norows"}}
</tbody>
{{/each}}
{{/if}}
{{#each groupedContent as |group|}}
<tbody class="group">
{{yield this 'group' group}}
{{yield this "group" group}}
{{#each group.items as |row|}}
{{yield this 'row' row dt (array-includes childFilterNodes row.id)}}
{{yield this "row" row dt (array-includes childFilterNodes row.id)}}
{{/each}}
</tbody>
{{else}}
{{yield this (if arranged.length 'nomatch' 'norows')}}
{{yield this (if arranged.length "nomatch" "norows")}}
{{/each}}
{{else}}
<tbody>
{{#each pagedContent as |row|}}
{{yield this 'row' row dt (array-includes childFilterNodes row.id)}}
{{yield this "row" row dt (array-includes childFilterNodes row.id)}}
{{else}}
{{yield this (if arranged.length 'nomatch' 'norows')}}
{{yield this (if arranged.length "nomatch" "norows")}}
{{/each}}
</tbody>
{{/if}}
{{#if suffix}}
{{yield this 'suffix'}}
{{yield this "suffix"}}
{{/if}}
</table>