search and draggable
This commit is contained in:
parent
66097014a3
commit
93cee58cfb
@ -55,6 +55,11 @@
|
|||||||
width: 70px;
|
width: 70px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[type=checkbox] {
|
||||||
|
min-width: 50px;
|
||||||
|
width: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
min-width: 300px;
|
min-width: 300px;
|
||||||
}
|
}
|
||||||
@ -197,6 +202,8 @@
|
|||||||
<script src="{{ url_for('oshipka_bp.static', filename='js/lightbox.js') }}"></script>
|
<script src="{{ url_for('oshipka_bp.static', filename='js/lightbox.js') }}"></script>
|
||||||
<script src="{{ url_for('oshipka_bp.static', filename='js/chosen.js') }}"></script>
|
<script src="{{ url_for('oshipka_bp.static', filename='js/chosen.js') }}"></script>
|
||||||
<script src="{{ url_for('oshipka_bp.static', filename='js/datatables.js') }}"></script>
|
<script src="{{ url_for('oshipka_bp.static', filename='js/datatables.js') }}"></script>
|
||||||
|
<script src="{{ url_for('oshipka_bp.static', filename='js/fuse.js') }}"></script>
|
||||||
|
<script src="{{ url_for('oshipka_bp.static', filename='js/draggable.js') }}"></script>
|
||||||
<script src="{{ url_for('oshipka_bp.static', filename='js/oshipka.js') }}"></script>
|
<script src="{{ url_for('oshipka_bp.static', filename='js/oshipka.js') }}"></script>
|
||||||
{% block script %}
|
{% block script %}
|
||||||
<script>
|
<script>
|
||||||
|
7019
oshipka/webapp/static/js/draggable.js
Normal file
7019
oshipka/webapp/static/js/draggable.js
Normal file
File diff suppressed because it is too large
Load Diff
2162
oshipka/webapp/static/js/fuse.js
Normal file
2162
oshipka/webapp/static/js/fuse.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -13,3 +13,64 @@ function start_async_task(task_name, data, ondata) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createSearch(options) {
|
||||||
|
/**
|
||||||
|
* options:
|
||||||
|
* - searchElSel - element (usually input) that will be used to take query from
|
||||||
|
* - filterElSel - elements that will be shown/hidden depending on query match
|
||||||
|
* - filterElDataName - [default: searchable-content] the name of the data element that will contain the search document
|
||||||
|
* - resultsElSel - [default: false] results element to display instead of in-place
|
||||||
|
* - resultsElTitle - [default: <h3>Results</h3>] - title to show if there are results and there is resultsElSel
|
||||||
|
* - fuseOptions - options to pass to fuse search
|
||||||
|
* @type {*|string}
|
||||||
|
*/
|
||||||
|
let searchElSel = options.searchElSel || "#input-search";
|
||||||
|
let filterElSel = options.filterElSel || "#elements-to-filter-list";
|
||||||
|
let resultsElSel = options.resultsElSel || false;
|
||||||
|
let resultsElTitle = options.resultsElSel || "<h3>Results</h3>";
|
||||||
|
let filterElDataName = options.filterElDataName || "searchable-content";
|
||||||
|
let fuseOptions = options.fuseOptions || {
|
||||||
|
includeScore: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
let inputEl = $(searchElSel);
|
||||||
|
let elements = $(filterElSel);
|
||||||
|
let resultsEl = $(resultsElSel)
|
||||||
|
let documents = $.map(elements, function (el) {
|
||||||
|
return $(el).data(filterElDataName)
|
||||||
|
});
|
||||||
|
const fuse = new Fuse(documents, fuseOptions)
|
||||||
|
|
||||||
|
return {
|
||||||
|
search: function () {
|
||||||
|
let query = inputEl.val();
|
||||||
|
if (query === "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let results = fuse.search(query);
|
||||||
|
let showElIds = $.map(results, function (r) {
|
||||||
|
return r.refIndex
|
||||||
|
});
|
||||||
|
if (resultsEl) {
|
||||||
|
$(resultsEl).html(resultsElTitle);
|
||||||
|
$(elements).hide();
|
||||||
|
} else {
|
||||||
|
$(resultsEl).hide();
|
||||||
|
$.each($(elements), function (el) {
|
||||||
|
$(el).show();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$.each(elements, function (elId, el) {
|
||||||
|
if (showElIds.includes(elId)) {
|
||||||
|
$(el).show();
|
||||||
|
if (resultsEl) {
|
||||||
|
$(resultsEl).append($(el));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$(el).hide();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import importlib
|
import importlib
|
||||||
|
from copy import deepcopy, copy
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
import inflect
|
import inflect
|
||||||
@ -95,9 +96,9 @@ def _update_m_ns(vc, m_ns):
|
|||||||
|
|
||||||
def default_create_func(vc):
|
def default_create_func(vc):
|
||||||
m_ns = _filter_m_n(vc)
|
m_ns = _filter_m_n(vc)
|
||||||
instance = vc.model_view.model(**vc.serialized_args)
|
instance = vc.instances or vc.model_view.model(**vc.serialized_args)
|
||||||
vc.instance = instance
|
vc.instance = instance
|
||||||
vc.instances = [instance]
|
vc.instances = instance
|
||||||
_update_m_ns(vc, m_ns)
|
_update_m_ns(vc, m_ns)
|
||||||
db.session.add(instance)
|
db.session.add(instance)
|
||||||
|
|
||||||
@ -142,7 +143,7 @@ class ViewContext(object):
|
|||||||
jsonify_func=None, render_func=None, template_func=None, template_ctx_func=None,
|
jsonify_func=None, render_func=None, template_func=None, template_ctx_func=None,
|
||||||
should_redirect_no_instances_func=None,
|
should_redirect_no_instances_func=None,
|
||||||
should_redirect_at_end_func=None,
|
should_redirect_at_end_func=None,
|
||||||
json=False, **kwargs):
|
is_json=False, **kwargs):
|
||||||
self.args_get_func = args_get_func or default_get_args_func
|
self.args_get_func = args_get_func or default_get_args_func
|
||||||
self.args_process_func = args_process_func or default_none_func
|
self.args_process_func = args_process_func or default_none_func
|
||||||
self.filter_func = filter_func or default_none_func
|
self.filter_func = filter_func or default_none_func
|
||||||
@ -158,24 +159,24 @@ class ViewContext(object):
|
|||||||
self.template_func = template_func or default_none_func
|
self.template_func = template_func or default_none_func
|
||||||
self.template_ctx_func = template_ctx_func or default_none_func
|
self.template_ctx_func = template_ctx_func or default_none_func
|
||||||
self.should_redirect_at_end_func = should_redirect_at_end_func or default_none_func
|
self.should_redirect_at_end_func = should_redirect_at_end_func or default_none_func
|
||||||
self.json = json
|
self.is_json = is_json
|
||||||
|
|
||||||
self.serialized_args = {}
|
self.serialized_args = {}
|
||||||
self.url_args = {}
|
self.url_args = {}
|
||||||
self.instances = []
|
self.instances = []
|
||||||
self.should_execute = True
|
self.should_execute = True
|
||||||
self.should_redirect_at_end = True
|
self.should_redirect_at_end = not is_json
|
||||||
self.template = None
|
self.template = None
|
||||||
self.template_ctx = {}
|
self.template_ctx = {}
|
||||||
self.model_view = None
|
self.model_view = None
|
||||||
self.redirect_next = None
|
self.redirect_next = None
|
||||||
|
|
||||||
|
|
||||||
def create_view(model_view, view_context, is_json=False, **kwargs):
|
def create_view(model_view, view_context, **kwargs):
|
||||||
view_context.model_view = model_view
|
view_context.model_view = model_view
|
||||||
|
|
||||||
def return_json_or_template():
|
def return_json_or_template():
|
||||||
if is_json:
|
if view_context.is_json:
|
||||||
return view_context.jsonify_func(view_context)
|
return view_context.jsonify_func(view_context)
|
||||||
view_context.template_func(view_context)
|
view_context.template_func(view_context)
|
||||||
view_context.template_ctx_func(view_context)
|
view_context.template_ctx_func(view_context)
|
||||||
@ -196,7 +197,10 @@ def create_view(model_view, view_context, is_json=False, **kwargs):
|
|||||||
|
|
||||||
view_context.should_execute_func(view_context)
|
view_context.should_execute_func(view_context)
|
||||||
if not view_context.should_execute:
|
if not view_context.should_execute:
|
||||||
return view_context.redirect_func(view_context)
|
if view_context.is_json:
|
||||||
|
return view_context.jsonify_func(view_context)
|
||||||
|
else:
|
||||||
|
return view_context.redirect_func(view_context)
|
||||||
|
|
||||||
view_context.execute_func(view_context)
|
view_context.execute_func(view_context)
|
||||||
view_context.post_execute_func(view_context)
|
view_context.post_execute_func(view_context)
|
||||||
@ -235,7 +239,10 @@ class ModelView(object):
|
|||||||
view_func = url_args.pop('view_func')
|
view_func = url_args.pop('view_func')
|
||||||
self.app.add_url_rule(rule=url, endpoint=endpoint,
|
self.app.add_url_rule(rule=url, endpoint=endpoint,
|
||||||
view_func=view_func(self, **kwargs), **url_args)
|
view_func=view_func(self, **kwargs), **url_args)
|
||||||
kwargs['is_json'] = True
|
|
||||||
|
view_context_kwargs = copy(kwargs['view_context'].__dict__)
|
||||||
|
view_context_kwargs['is_json'] = True
|
||||||
|
kwargs['view_context'] = ViewContext(**view_context_kwargs)
|
||||||
self.app.add_url_rule(rule=api_url, endpoint=api_endpoint,
|
self.app.add_url_rule(rule=api_url, endpoint=api_endpoint,
|
||||||
view_func=view_func(self, **kwargs), **url_args)
|
view_func=view_func(self, **kwargs), **url_args)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user