mirror of
https://github.com/getrebuild/rebuild.git
synced 2025-02-25 23:05:06 +08:00
__globalSearch done
This commit is contained in:
parent
19339722f4
commit
7c2462f3e5
5 changed files with 92 additions and 32 deletions
|
@ -18,19 +18,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
package com.rebuild.server.service.query;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import cn.devezhao.commons.CalendarUtils;
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Field;
|
||||
import cn.devezhao.persist4j.dialect.FieldType;
|
||||
import cn.devezhao.persist4j.dialect.Type;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
@ -42,12 +34,18 @@ import com.rebuild.server.metadata.entity.EasyMeta;
|
|||
import com.rebuild.server.service.bizz.UserHelper;
|
||||
import com.rebuild.server.service.bizz.privileges.Department;
|
||||
import com.rebuild.web.IllegalParameterException;
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import cn.devezhao.commons.CalendarUtils;
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Field;
|
||||
import cn.devezhao.persist4j.dialect.FieldType;
|
||||
import cn.devezhao.persist4j.dialect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 高级查询解析器
|
||||
|
@ -262,7 +260,7 @@ public class AdvFilterParser {
|
|||
value = parseValue(value, op, fieldMeta);
|
||||
}
|
||||
|
||||
// No value
|
||||
// No value for search
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ final User currentUser = Application.getUserStore().getUser(AppUtils.getRequestU
|
|||
</div>
|
||||
<div class="search-container">
|
||||
<input class="form-control form-control-sm search-input" type="text" name="search" maxlength="100" placeholder="搜索" />
|
||||
<div class="search-models animated fadeIn faster"></div>
|
||||
</div>
|
||||
<div class="rb-right-navbar">
|
||||
<ul class="nav navbar-nav float-right rb-user-nav">
|
||||
|
|
|
@ -2210,4 +2210,35 @@ form {
|
|||
height: 36px !important;
|
||||
line-height: 30px;
|
||||
padding: 3px 12px;
|
||||
}
|
||||
|
||||
.rb-top-header .search-container .search-models {
|
||||
position: absolute;
|
||||
min-width: 320px;
|
||||
max-width: 600px;
|
||||
padding: 15px;
|
||||
padding-top: 20px;
|
||||
box-shadow: 0 3px 0.3077rem rgba(0, 0, 0, .1);
|
||||
background: #fff;
|
||||
border-radius: 3px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.search-models a {
|
||||
background: #eee;
|
||||
color: #777;
|
||||
border-radius: 99px;
|
||||
padding: 4px 9px;
|
||||
max-width: 120px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.search-models a+a {
|
||||
margin-left: 6px;
|
||||
}
|
||||
|
||||
.search-models a:hover,
|
||||
.search-models a.active {
|
||||
background: #4285f4;
|
||||
color: #fff !important
|
||||
}
|
|
@ -103,7 +103,8 @@ class RbList extends React.Component {
|
|||
that.setState({ fields: fields }, () => scroller.perfectScrollbar('update'))
|
||||
}
|
||||
})
|
||||
this.fetchList()
|
||||
|
||||
this.fetchList(this.__buildQuick($('.input-search')))
|
||||
}
|
||||
componentDidUpdate() {
|
||||
let that = this
|
||||
|
@ -277,6 +278,16 @@ class RbList extends React.Component {
|
|||
this.lastFilter = null
|
||||
}
|
||||
}
|
||||
// @el - search element
|
||||
searchQuick(el) {
|
||||
this.search(this.__buildQuick(el))
|
||||
}
|
||||
__buildQuick(el) {
|
||||
let q = el.find('input').val()
|
||||
if (!q && !this.lastFilter) return null
|
||||
let filterExp = { entity: this.props.config.entity, type: 'QUICK', values: { 1: q }, qfields: el.data('qfields') }
|
||||
return filterExp
|
||||
}
|
||||
reload() {
|
||||
this.fetchList()
|
||||
}
|
||||
|
@ -478,17 +489,10 @@ const RbListPage = {
|
|||
$cleanMenu('.J_action')
|
||||
}
|
||||
|
||||
this.initQuickFilter(entity[0])
|
||||
},
|
||||
|
||||
initQuickFilter: function (e) {
|
||||
// Quick search
|
||||
let btn = $('.input-search .btn'),
|
||||
input = $('.input-search input')
|
||||
btn.click(() => {
|
||||
let q = $val(input)
|
||||
let filterExp = { entity: e, type: 'QUICK', values: { 1: q }, qfields: $('.input-search').data('qfields') }
|
||||
this._RbList.search(filterExp)
|
||||
})
|
||||
btn.click(() => this._RbList.searchQuick($('.input-search')))
|
||||
input.keydown((event) => { if (event.which === 13) btn.trigger('click') })
|
||||
},
|
||||
|
||||
|
@ -615,8 +619,10 @@ const AdvFilters = {
|
|||
|
||||
// Init
|
||||
$(document).ready(() => {
|
||||
let gs = $urlp('gs', location.hash)
|
||||
if (gs) $('.search-input, .input-search>input').val(gs)
|
||||
if (wpc.entity) {
|
||||
RbListPage.init(wpc.listConfig, wpc.entity, wpc.privileges)
|
||||
RbListPage.init(wpc.listConfig, wpc.entity, wpc.privileges, gs)
|
||||
if (!(wpc.advFilter === false)) AdvFilters.init('.adv-search', wpc.entity[0])
|
||||
}
|
||||
})
|
||||
|
|
|
@ -30,6 +30,8 @@ $(function () {
|
|||
__initNavs()
|
||||
}
|
||||
|
||||
setTimeout(__globalSearch, 1000)
|
||||
|
||||
if (rb.isAdminUser === true) {
|
||||
$('html').addClass('admin')
|
||||
if (rb.isAdminVerified !== true) $('.admin-verified').remove()
|
||||
|
@ -44,8 +46,6 @@ $(function () {
|
|||
$('.J_notifications-top').on('shown.bs.dropdown', __loadMessages)
|
||||
}
|
||||
|
||||
__globalSearch()
|
||||
|
||||
var bkeydown_times = 0
|
||||
$(document.body).keydown(function (e) {
|
||||
if (e.shiftKey) {
|
||||
|
@ -179,7 +179,31 @@ var __loadMessages = function () {
|
|||
|
||||
// Global search
|
||||
var __globalSearch = function () {
|
||||
$('.sidebar-elements li').each((idx, item) => {
|
||||
let id = $(item).attr('id')
|
||||
if (id && id.startsWith('nav_entity-')) {
|
||||
let $a = $(item).find('a')
|
||||
$('<a class="text-truncate" data-url="' + $a.attr('href') + '">' + $a.text() + '</a>').appendTo('.search-models')
|
||||
}
|
||||
})
|
||||
|
||||
let activeModel
|
||||
let aModels = $('.search-models a').click(function () {
|
||||
let s = $('.search-input').val()
|
||||
location.href = $(this).data('url') + '#gs=' + $encode(s)
|
||||
})
|
||||
if (aModels.length === 0) return
|
||||
activeModel = aModels.eq(0).addClass('active')
|
||||
|
||||
$(document).click((e) => {
|
||||
if ($(e.target).parents('.search-container').length === 0) $('.search-models').hide()
|
||||
})
|
||||
$('.search-container input').on('focus', (e) => {
|
||||
$('.search-models').show()
|
||||
}).on('keydown', (e) => {
|
||||
let s = $('.search-input').val()
|
||||
if (e.keyCode === 13 && s) location.href = activeModel.data('url') + '#gs=' + $encode(s)
|
||||
})
|
||||
}
|
||||
|
||||
// @mbg = .btn-group
|
||||
|
|
Loading…
Reference in a new issue