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:
parent
167c3bddb6
commit
ab1891be27
@ -4,12 +4,23 @@ let taskCounter = 0;
|
|||||||
|
|
||||||
export function startProgress(taskDescription = 'Loading…') {
|
export function startProgress(taskDescription = 'Loading…') {
|
||||||
const taskIndex = ++taskCounter;
|
const taskIndex = ++taskCounter;
|
||||||
StartProgressBar(taskIndex, taskDescription);
|
let started = false;
|
||||||
|
|
||||||
|
const debouncer = setTimeout(() => {
|
||||||
|
StartProgressBar(taskIndex, taskDescription);
|
||||||
|
started = true;
|
||||||
|
}, 150);
|
||||||
|
|
||||||
const task = {
|
const task = {
|
||||||
id: taskIndex,
|
id: taskIndex,
|
||||||
description: taskDescription,
|
description: taskDescription,
|
||||||
end: () => StopProgressBar(taskIndex),
|
|
||||||
|
end: () => {
|
||||||
|
clearTimeout(debouncer);
|
||||||
|
if (started) {
|
||||||
|
StopProgressBar(taskIndex);
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return task;
|
return task;
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
let queryToSave;
|
let queryToSave;
|
||||||
let showQueryChooser = false;
|
let showQueryChooser = false;
|
||||||
let exportInfo;
|
let exportInfo;
|
||||||
|
let querying = false;
|
||||||
|
|
||||||
$: viewsForCollection = views.forCollection(collection.hostKey, collection.dbKey, collection.key);
|
$: 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})` : ''};`;
|
$: 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;
|
$: activePage = (submittedForm.limit && submittedForm.skip && result?.results?.length) ? submittedForm.skip / submittedForm.limit : 0;
|
||||||
|
|
||||||
async function submitQuery() {
|
async function submitQuery() {
|
||||||
|
if (querying) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
querying = true;
|
||||||
const progress = startProgress('Performing query…');
|
const progress = startProgress('Performing query…');
|
||||||
activePath = [];
|
activePath = [];
|
||||||
const newResult = await FindItems(collection.hostKey, collection.dbKey, collection.key, JSON.stringify(form));
|
const newResult = await FindItems(collection.hostKey, collection.dbKey, collection.key, JSON.stringify(form));
|
||||||
|
|
||||||
if (newResult) {
|
if (newResult) {
|
||||||
newResult.results = newResult.results?.map(s => EJSON.parse(s, { relaxed: false }));
|
newResult.results = newResult.results?.map(s => EJSON.parse(s, { relaxed: false }));
|
||||||
result = newResult;
|
result = newResult;
|
||||||
submittedForm = deepClone(form);
|
submittedForm = deepClone(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.end();
|
progress.end();
|
||||||
resetFocus();
|
resetFocus();
|
||||||
|
querying = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refresh() {
|
async function refresh() {
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/ncruces/zenity"
|
"github.com/ncruces/zenity"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// @todo: this takes ~0.5 seconds. Improve?
|
||||||
func (u *UI) StartProgressBar(id uint, title string) {
|
func (u *UI) StartProgressBar(id uint, title string) {
|
||||||
if title == "" {
|
if title == "" {
|
||||||
// default title
|
// default title
|
||||||
@ -20,13 +21,13 @@ func (u *UI) StartProgressBar(id uint, title string) {
|
|||||||
|
|
||||||
func (u *UI) StopProgressBar(id uint) {
|
func (u *UI) StopProgressBar(id uint) {
|
||||||
for try := 0; try < 10; try++ {
|
for try := 0; try < 10; try++ {
|
||||||
p := u.progressBars[id]
|
if p := u.progressBars[id]; p != nil {
|
||||||
if p != nil {
|
|
||||||
p.Complete()
|
p.Complete()
|
||||||
p.Close()
|
p.Close()
|
||||||
p = nil
|
p = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
println("Progress dialog not found:", id, try)
|
println("Progress dialog not found:", id, try)
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user