auto-refresh data when updated
Should be evident when the name of the filter has been changed
This commit is contained in:
parent
eedd53aba4
commit
3e2723d58b
1 changed files with 120 additions and 110 deletions
|
@ -148,13 +148,15 @@ class Search {
|
||||||
show().then(() => {
|
show().then(() => {
|
||||||
if (((typeof options).includes(`obj`) && options) ? options[`auto sync`] : false) {
|
if (((typeof options).includes(`obj`) && options) ? options[`auto sync`] : false) {
|
||||||
// Set the refresh function.
|
// Set the refresh function.
|
||||||
let item = this[source[`name`]][`selected`];
|
let EXISTING_DATA = {};
|
||||||
|
EXISTING_DATA[`item`] = this[source[`name`]][`selected`];
|
||||||
|
EXISTING_DATA[`criteria`] = this[source[`name`]][`criteria`];
|
||||||
|
|
||||||
this[source[`name`]][`scripts`][`refresh`] = () => {
|
this[source[`name`]][`scripts`][`refresh`] = () => {
|
||||||
wait((this[`state`][`read/write`] ? this[`state`][`read/write`] >= 0 : true)).then(
|
wait((this[`state`][`read/write`] ? this[`state`][`read/write`] >= 0 : true)).then(
|
||||||
() => {
|
() => {
|
||||||
if (this[source][`selected`] == item) {
|
if (this[source[`name`]][`selected`] == EXISTING_DATA[`item`] || EXISTING_DATA[`criteria`] == this[source[`name`]][`criteria`]) {
|
||||||
show()
|
show();
|
||||||
} else if (this[source[`name`]][`scripts`][`background`][`refresh`]) {
|
} else if (this[source[`name`]][`scripts`][`background`][`refresh`]) {
|
||||||
this[source[`name`]][`scripts`][`background`][`refresh`].cancel();
|
this[source[`name`]][`scripts`][`background`][`refresh`].cancel();
|
||||||
};
|
};
|
||||||
|
@ -162,7 +164,7 @@ class Search {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
this[source[`name`]][`scripts`][`background`][`refresh`] = new background(() => {this[source[`name`]][`scripts`][`refresh`]});
|
this[source[`name`]][`scripts`][`background`][`refresh`] = new background(() => {this[source[`name`]][`scripts`][`refresh`]()});
|
||||||
};
|
};
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
logging.error(err);
|
logging.error(err);
|
||||||
|
@ -231,27 +233,27 @@ class Search {
|
||||||
const gui_output = () => {
|
const gui_output = () => {
|
||||||
// Prepare the elements we will need.
|
// Prepare the elements we will need.
|
||||||
if (this[source][`elements`][`results list`] ? this[source][`elements`][`results list`].length : false) {
|
if (this[source][`elements`][`results list`] ? this[source][`elements`][`results list`].length : false) {
|
||||||
|
/*
|
||||||
|
Add the selected state.
|
||||||
|
*/
|
||||||
|
const select = (element) => {
|
||||||
|
if (element) {
|
||||||
|
// Remove all active classes.
|
||||||
|
(element).parentElement.querySelectorAll(`li:has(a)`).forEach((ELEMENT) => {
|
||||||
|
ELEMENT.classList.remove(`active`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add the active.
|
||||||
|
element.classList.add(`active`);
|
||||||
|
|
||||||
|
return (element);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const design = () => {
|
const design = () => {
|
||||||
// Prepare the access keys.
|
// Prepare the access keys.
|
||||||
let ACCESS_KEYS = {"top": ["1", "2", "3", "4", "5", "6", "7", "8", "9"], "nav": ["<", ">"]};
|
let ACCESS_KEYS = {"top": ["1", "2", "3", "4", "5", "6", "7", "8", "9"], "nav": ["<", ">"]};
|
||||||
|
|
||||||
/*
|
|
||||||
Add the selected state.
|
|
||||||
*/
|
|
||||||
const select = (element) => {
|
|
||||||
if (element) {
|
|
||||||
// Remove all active classes.
|
|
||||||
(element.parentElement).parentElement.querySelectorAll(`li`).forEach((ELEMENT) => {
|
|
||||||
ELEMENT.classList.remove(`active`);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add the active.
|
|
||||||
element.parentElement.classList.add(`active`);
|
|
||||||
|
|
||||||
return (element);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Add the access keys (shortcut).
|
Add the access keys (shortcut).
|
||||||
|
|
||||||
|
@ -312,13 +314,16 @@ class Search {
|
||||||
// Add the action.
|
// Add the action.
|
||||||
ELEMENTS_RESULT[`title`].addEventListener(`click`, () => {
|
ELEMENTS_RESULT[`title`].addEventListener(`click`, () => {
|
||||||
// Set the visual state.
|
// Set the visual state.
|
||||||
select(ELEMENTS_RESULT[`title`]);
|
select(ELEMENTS_RESULT[`container`]);
|
||||||
shortcut(RESULT, ELEMENTS_RESULT[`title`], `execute`);
|
shortcut(RESULT, ELEMENTS_RESULT[`title`], `execute`);
|
||||||
|
|
||||||
// Pick the data.
|
// Pick the data.
|
||||||
this.pick(source, RESULT, data[RESULT]);
|
this.pick(source, RESULT, data[RESULT]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add the real linked data name temporarily.
|
||||||
|
ELEMENTS_RESULT[`container`][`linked`] = RESULT;
|
||||||
|
|
||||||
// Add the shortcut.
|
// Add the shortcut.
|
||||||
ELEMENTS_RESULT[`title`] = shortcut(RESULT, ELEMENTS_RESULT[`title`], `config`);
|
ELEMENTS_RESULT[`title`] = shortcut(RESULT, ELEMENTS_RESULT[`title`], `config`);
|
||||||
|
|
||||||
|
@ -338,6 +343,11 @@ class Search {
|
||||||
(TEMPLATE.length)
|
(TEMPLATE.length)
|
||||||
? TEMPLATE.forEach((ELEMENT) => {
|
? TEMPLATE.forEach((ELEMENT) => {
|
||||||
ELEMENT_TARGET.appendChild(ELEMENT);
|
ELEMENT_TARGET.appendChild(ELEMENT);
|
||||||
|
|
||||||
|
// Preselect the item.
|
||||||
|
if (ELEMENT[`linked`] == nested.dictionary.get(this, [source, `selected`])) {
|
||||||
|
select(ELEMENT);
|
||||||
|
};
|
||||||
})
|
})
|
||||||
: this.pick(source, null);
|
: this.pick(source, null);
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue