Execute filter and implement filter clear/update
This commit is contained in:
parent
ca8adb33c7
commit
9a2d4a7f9f
|
@ -71,9 +71,20 @@ $all_accounts = $pg->fetch_all($sql_all, $cache);
|
|||
|
||||
if (isset($_GET['profile']) && trim($_GET['profile']) != '')
|
||||
{
|
||||
$q = strtolower(trim($_GET['profile']));
|
||||
if ($q === '<empty>') $q = '';
|
||||
$q = normalize_for_search($q);
|
||||
$q = trim($_GET['profile']);
|
||||
$q = base64_decode($q);
|
||||
$qt = null;
|
||||
if ($q === '<empty>') {
|
||||
$q = '';
|
||||
$qt = 'empty';
|
||||
} else if (preg_match('/^expr:.*/', $q)) {
|
||||
$q = trim(preg_replace('/^expr:/','',$q));
|
||||
$q = parse_search_expression($q);
|
||||
$qt = 'expr';
|
||||
} else {
|
||||
$q = normalize_for_search($q);
|
||||
$qt = 'simple';
|
||||
}
|
||||
|
||||
$ai = -1;
|
||||
foreach ($all_accounts as $account)
|
||||
|
|
5
base.php
5
base.php
|
@ -279,6 +279,11 @@ function normalize_for_search($str) {
|
|||
return trim(implode(' ', $newwords));
|
||||
}
|
||||
|
||||
function parse_search_expression($q) {
|
||||
var_dump($q);
|
||||
die;
|
||||
}
|
||||
|
||||
function content_cache__exists($key) {
|
||||
$cache_dir = $GLOBALS['appconf']['data_dir'].'/cache';
|
||||
if (!file_exists($cache_dir)) {
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
<br>
|
||||
<div class="input flex">
|
||||
<button class="btn center"
|
||||
onclick="window.view.instance.do.filter_users.execute()"
|
||||
><i class="fa fa-search fa-fw"></i>
|
||||
Execute</button>
|
||||
<div style="width:1em"></div>
|
||||
|
|
|
@ -34,6 +34,69 @@ window.view.instance = {
|
|||
});
|
||||
},
|
||||
},
|
||||
filter_users: {
|
||||
get_current_filter: function() {
|
||||
var data = {};
|
||||
var preset = E.element('#filters-current input[name="preset_name"]').value.trim();
|
||||
if (preset !== '' && preset.toLowerCase() !== 'undefined')
|
||||
data.preset_name = E.element('#filters-current input[name="preset_name"]').value;
|
||||
data.user_filter = E.element('#filters-current input[name=user_filter]:checked').value;
|
||||
var prof_stype = E.element("#filters-current input[name=profile_search_type]:checked").value;
|
||||
var profile = E.element("#filters-current textarea[name=profile]").value;
|
||||
if (prof_stype === 'empty')
|
||||
profile = '<empty>';
|
||||
else if (prof_stype === 'expr')
|
||||
profile = 'expr: '+profile;
|
||||
data.profile = btoa(profile);
|
||||
const obj_noavatar = E.element('*[name=no_avatar]:checked');
|
||||
if (obj_noavatar !== null)
|
||||
data.no_avatar = '';
|
||||
const obj_nostatuses = E.element('*[name=no_statuses]:checked');
|
||||
if (obj_nostatuses !== null)
|
||||
data.no_statuses = '';
|
||||
const obj_nofollows = E.element('*[name=no_follows]:checked');
|
||||
if (obj_nofollows !== null)
|
||||
data.no_follows = '';
|
||||
return data;
|
||||
},
|
||||
set_current_filter: function(data) {
|
||||
const _process = function(d) {
|
||||
if (d.preset_name === undefined)
|
||||
d.preset_name = 'Undefined';
|
||||
E.element('#filters-current input[name="preset_name"]').value = d.preset_name;
|
||||
E.element('#filters-current input[name=user_filter][value='+d.user_filter+']').click();
|
||||
d.profile = atob(d.profile);
|
||||
if (d.profile === '<empty>')
|
||||
E.element('#filters-current #profile-search-type-empty').click();
|
||||
else if (d.profile.startsWith('expr:')) {
|
||||
d.profile = d.profile.replace(/^expr:/,'').trim();
|
||||
E.element('#filters-current #profile-search-type-expr').click();
|
||||
E.element("#filters-current textarea[name=profile]").value = d.profile;
|
||||
}
|
||||
E.elements('#filters-current input[type=checkbox]').forEach(function(it){ it.checked = false });
|
||||
if (d.no_avatar !== undefined) E.element('#filters-current input[name=no_avatar]').click();
|
||||
if (d.no_statuses !== undefined) E.element('#filters-current input[name=no_statuses]').click();
|
||||
if (d.no_follows !== undefined) E.element('#filters-current input[name=no_follows]').click();
|
||||
console.log(d);
|
||||
};
|
||||
if (typeof data === 'object')
|
||||
_process(data);
|
||||
//else // TODO: load the filter by API
|
||||
},
|
||||
execute: function() {
|
||||
const btn = E.elemid('btncollapse-filters-current');
|
||||
if (btn.innerText.trim() === 'hide')
|
||||
btn.click();
|
||||
const data = window.view.instance.do.filter_users.get_current_filter();
|
||||
const hargs = get_hash_arguments();
|
||||
var payload = data;
|
||||
payload.instance = hargs.instance;
|
||||
payload = JSON_to_URLEncoded(payload);
|
||||
http.get(`api/v1/database/${hargs.software}/accounts/search?${payload}`, data, function(js) {
|
||||
console.log(js);
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
load: {
|
||||
new_accounts: function() {
|
||||
|
@ -64,20 +127,22 @@ window.view.instance = {
|
|||
E.element('#window-instance #container').innerHTML = html;
|
||||
E.elemid('profile-search-type-simple').onchange = function(e) {
|
||||
if (e.target.checked) {
|
||||
E.element('textarea[name="profile"]').setAttribute('placeholder', 'Input your text here');
|
||||
E.element('textarea[name="profile"]').removeAttribute('disabled');
|
||||
E.element('#filters-current textarea[name=profile]').setAttribute('placeholder', 'Input your text here');
|
||||
E.element('#filters-current textarea[name=profile]').removeAttribute('disabled');
|
||||
}
|
||||
};
|
||||
E.elemid('profile-search-type-expr').onchange = function(e) {
|
||||
if (e.target.checked) {
|
||||
E.element('textarea[name="profile"]').setAttribute('placeholder', '(words "apple banana" AND contains "i like apples") OR words "pineapple strawberry"');
|
||||
E.element('textarea[name="profile"]').removeAttribute('disabled');
|
||||
E.element('#filters-current textarea[name=profile]').setAttribute('placeholder',
|
||||
'(words "apple,banana" AND contains "i like apples") OR words "pineapple,strawberry"');
|
||||
E.element('#filters-current textarea[name=profile]').removeAttribute('disabled');
|
||||
}
|
||||
};
|
||||
E.elemid('profile-search-type-empty').onchange = function(e) {
|
||||
if (e.target.checked) {
|
||||
E.element('textarea[name="profile"]').setAttribute('placeholder', '<Profile content is empty>');
|
||||
E.element('textarea[name="profile"]').setAttribute('disabled', 'disabled');
|
||||
E.element('#filters-current textarea[name=profile]').setAttribute('placeholder', '<Profile content is empty>');
|
||||
E.element('#filters-current textarea[name=profile]').setAttribute('disabled', 'disabled');
|
||||
E.element("#filters-current textarea[name=profile]").value = '';
|
||||
}
|
||||
}
|
||||
E.custom.btncollapse_render();
|
||||
|
|
Loading…
Reference in New Issue