1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-18 13:07:58 +00:00

Improvements to progress dialogs

This commit is contained in:
Romein van Buren 2023-05-27 17:52:51 +02:00
parent 167c3bddb6
commit ab1891be27
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
3 changed files with 25 additions and 4 deletions

View File

@ -4,12 +4,23 @@ let taskCounter = 0;
export function startProgress(taskDescription = 'Loading…') {
const taskIndex = ++taskCounter;
StartProgressBar(taskIndex, taskDescription);
let started = false;
const debouncer = setTimeout(() => {
StartProgressBar(taskIndex, taskDescription);
started = true;
}, 150);
const task = {
id: taskIndex,
description: taskDescription,
end: () => StopProgressBar(taskIndex),
end: () => {
clearTimeout(debouncer);
if (started) {
StopProgressBar(taskIndex);
}
},
};
return task;

View File

@ -35,6 +35,7 @@
let queryToSave;
let showQueryChooser = false;
let exportInfo;
let querying = false;
$: viewsForCollection = views.forCollection(collection.hostKey, collection.dbKey, collection.key);
$: code = `db.${collection.key}.find(${form.query || '{}'}${form.fields && form.fields !== '{}' ? `, ${form.fields}` : ''}).sort(${form.sort})${form.skip ? `.skip(${form.skip})` : ''}${form.limit ? `.limit(${form.limit})` : ''};`;
@ -42,16 +43,24 @@
$: activePage = (submittedForm.limit && submittedForm.skip && result?.results?.length) ? submittedForm.skip / submittedForm.limit : 0;
async function submitQuery() {
if (querying) {
return;
}
querying = true;
const progress = startProgress('Performing query…');
activePath = [];
const newResult = await FindItems(collection.hostKey, collection.dbKey, collection.key, JSON.stringify(form));
if (newResult) {
newResult.results = newResult.results?.map(s => EJSON.parse(s, { relaxed: false }));
result = newResult;
submittedForm = deepClone(form);
}
progress.end();
resetFocus();
querying = false;
}
async function refresh() {

View File

@ -6,6 +6,7 @@ import (
"github.com/ncruces/zenity"
)
// @todo: this takes ~0.5 seconds. Improve?
func (u *UI) StartProgressBar(id uint, title string) {
if title == "" {
// default title
@ -20,13 +21,13 @@ func (u *UI) StartProgressBar(id uint, title string) {
func (u *UI) StopProgressBar(id uint) {
for try := 0; try < 10; try++ {
p := u.progressBars[id]
if p != nil {
if p := u.progressBars[id]; p != nil {
p.Complete()
p.Close()
p = nil
return
}
println("Progress dialog not found:", id, try)
time.Sleep(100 * time.Millisecond)
}