mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 04:57:59 +00:00
Added deadline for counting documents
Set a deadline for counting documents, and added a button to count documents if the deadline has been exceeded.
This commit is contained in:
parent
0e376866a7
commit
239af3590d
@ -7,7 +7,7 @@
|
||||
* Preserve state after switching to another tab (#56).
|
||||
* Find view: ask for confirmation before negligently deleting documents when the user has clicked the '-' button (#58).
|
||||
* Build script recreates the build output directory after it has been removed (#62).
|
||||
|
||||
* Set a deadline for counting documents, and added a button to count documents if the deadline has been exceeded.
|
||||
## [v0.2.2]
|
||||
|
||||
* Added Excel export format (#46).
|
||||
|
@ -10,7 +10,7 @@
|
||||
import applicationSettings from '$lib/stores/settings';
|
||||
import views from '$lib/stores/views';
|
||||
import { convertLooseJson, stringCouldBeID } from '$lib/strings';
|
||||
import { FindItems, RemoveItemById, UpdateFoundDocument } from '$wails/go/app/App';
|
||||
import { CountItems, FindItems, RemoveItemById, UpdateFoundDocument } from '$wails/go/app/App';
|
||||
import { EJSON } from 'bson';
|
||||
|
||||
export let collection;
|
||||
@ -26,11 +26,13 @@
|
||||
|
||||
let form = { ...defaults };
|
||||
let result = {};
|
||||
let countResult = {};
|
||||
let submittedForm = {};
|
||||
let queryField;
|
||||
let activePath = [];
|
||||
let objectViewerData;
|
||||
let querying = false;
|
||||
let counting = false;
|
||||
let objectViewerSuccessMessage = '';
|
||||
let viewsForCollection = {};
|
||||
|
||||
@ -71,6 +73,17 @@
|
||||
querying = false;
|
||||
}
|
||||
|
||||
async function countItems() {
|
||||
counting = true;
|
||||
countResult = await CountItems(
|
||||
collection.hostKey,
|
||||
collection.dbKey,
|
||||
collection.key,
|
||||
convertLooseJson(form.query) || defaults.query
|
||||
);
|
||||
counting = false;
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
if ($applicationSettings.autosubmitQuery) {
|
||||
await submitQuery();
|
||||
@ -290,11 +303,26 @@
|
||||
</div>
|
||||
|
||||
<div class="controls">
|
||||
<div>
|
||||
{#key result}
|
||||
<span class="flash-green">Results: {result.total || 0}</span>
|
||||
{/key}
|
||||
<div class="count">
|
||||
{#if counting}
|
||||
<span>Counting items…</span>
|
||||
{:else if countResult?.error}
|
||||
<span>{countResult.error}</span>
|
||||
{:else if countResult?.total === -1}
|
||||
<span>Something went wrong</span>
|
||||
{:else if countResult?.total}
|
||||
<!-- svelte-ignore a11y-invalid-attribute -->
|
||||
<a href="" on:click|preventDefault={countItems}>Results: {countResult.total}</a>
|
||||
{:else if result?.total === -1}
|
||||
<!-- svelte-ignore a11y-invalid-attribute -->
|
||||
<a href="" on:click|preventDefault={countItems}>Count items</a>
|
||||
{:else if result?.total}
|
||||
{#key result}
|
||||
<span class="flash-green">Results: {result.total || 0}</span>
|
||||
{/key}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="field inline">
|
||||
<select bind:value={collection.viewKey}>
|
||||
@ -388,4 +416,8 @@
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.count {
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
</style>
|
||||
|
2
frontend/wailsjs/go/app/App.d.ts
generated
vendored
2
frontend/wailsjs/go/app/App.d.ts
generated
vendored
@ -12,6 +12,8 @@ export function Aggregate(arg1:string,arg2:string,arg3:string,arg4:string,arg5:s
|
||||
|
||||
export function AskConfirmation(arg1:string):Promise<boolean>;
|
||||
|
||||
export function CountItems(arg1:string,arg2:string,arg3:string,arg4:string):Promise<app.CountItemsResult>;
|
||||
|
||||
export function CreateIndex(arg1:string,arg2:string,arg3:string,arg4:string):Promise<string>;
|
||||
|
||||
export function DropCollection(arg1:string,arg2:string,arg3:string):Promise<boolean>;
|
||||
|
4
frontend/wailsjs/go/app/App.js
generated
4
frontend/wailsjs/go/app/App.js
generated
@ -14,6 +14,10 @@ export function AskConfirmation(arg1) {
|
||||
return window['go']['app']['App']['AskConfirmation'](arg1);
|
||||
}
|
||||
|
||||
export function CountItems(arg1, arg2, arg3, arg4) {
|
||||
return window['go']['app']['App']['CountItems'](arg1, arg2, arg3, arg4);
|
||||
}
|
||||
|
||||
export function CreateIndex(arg1, arg2, arg3, arg4) {
|
||||
return window['go']['app']['App']['CreateIndex'](arg1, arg2, arg3, arg4);
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
@ -23,6 +25,11 @@ type FindItemsResult struct {
|
||||
ErrorDescription string `json:"errorDescription"`
|
||||
}
|
||||
|
||||
type CountItemsResult struct {
|
||||
Total int64 `json:"total"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) (result FindItemsResult) {
|
||||
var form Query
|
||||
|
||||
@ -75,12 +82,14 @@ func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) (result FindIt
|
||||
Sort: sort,
|
||||
}
|
||||
|
||||
total, err := client.Database(dbKey).Collection(collKey).CountDocuments(ctx, query, nil)
|
||||
if err != nil {
|
||||
ctx2, cancel := context.WithDeadline(ctx, time.Now().Add(time.Second))
|
||||
defer cancel()
|
||||
total, err := client.Database(dbKey).Collection(collKey).CountDocuments(ctx2, query, nil)
|
||||
if err == nil {
|
||||
result.Total = total
|
||||
} else {
|
||||
result.Total = -1
|
||||
runtime.LogWarningf(a.ctx, "Encountered an error while counting documents: %s", err.Error())
|
||||
result.ErrorTitle = "Error while counting documents"
|
||||
result.ErrorDescription = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
cur, err := client.Database(dbKey).Collection(collKey).Find(ctx, query, &opt)
|
||||
@ -102,7 +111,6 @@ func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) (result FindIt
|
||||
return
|
||||
}
|
||||
|
||||
result.Total = total
|
||||
result.Results = make([]string, 0)
|
||||
|
||||
for _, r := range results {
|
||||
@ -119,6 +127,34 @@ func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) (result FindIt
|
||||
return
|
||||
}
|
||||
|
||||
func (a *App) CountItems(hostKey, dbKey, collKey, query string) (result CountItemsResult) {
|
||||
var q bson.M
|
||||
err := bson.UnmarshalExtJSON([]byte(query), true, &q)
|
||||
if err != nil {
|
||||
runtime.LogInfof(a.ctx, "Invalid count query: %s", err.Error())
|
||||
result.Error = "Invalid query"
|
||||
return
|
||||
}
|
||||
|
||||
client, ctx, close, err := a.connectToHost(hostKey)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer close()
|
||||
|
||||
ctx, _ = context.WithDeadline(ctx, time.Now().Add(2*time.Minute))
|
||||
total, err := client.Database(dbKey).Collection(collKey).CountDocuments(ctx, q, nil)
|
||||
if err == nil {
|
||||
result.Total = total
|
||||
} else {
|
||||
result.Total = -1
|
||||
result.Error = err.Error()
|
||||
runtime.LogWarningf(a.ctx, "Encountered an error while counting documents: %s", err.Error())
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (a *App) UpdateFoundDocument(hostKey, dbKey, collKey, idJson, newDocJson string) bool {
|
||||
var id bson.M
|
||||
if err := bson.UnmarshalExtJSON([]byte(idJson), true, &id); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user