mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 13:07:58 +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).
|
* 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).
|
* 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).
|
* 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]
|
## [v0.2.2]
|
||||||
|
|
||||||
* Added Excel export format (#46).
|
* Added Excel export format (#46).
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
import applicationSettings from '$lib/stores/settings';
|
import applicationSettings from '$lib/stores/settings';
|
||||||
import views from '$lib/stores/views';
|
import views from '$lib/stores/views';
|
||||||
import { convertLooseJson, stringCouldBeID } from '$lib/strings';
|
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';
|
import { EJSON } from 'bson';
|
||||||
|
|
||||||
export let collection;
|
export let collection;
|
||||||
@ -26,11 +26,13 @@
|
|||||||
|
|
||||||
let form = { ...defaults };
|
let form = { ...defaults };
|
||||||
let result = {};
|
let result = {};
|
||||||
|
let countResult = {};
|
||||||
let submittedForm = {};
|
let submittedForm = {};
|
||||||
let queryField;
|
let queryField;
|
||||||
let activePath = [];
|
let activePath = [];
|
||||||
let objectViewerData;
|
let objectViewerData;
|
||||||
let querying = false;
|
let querying = false;
|
||||||
|
let counting = false;
|
||||||
let objectViewerSuccessMessage = '';
|
let objectViewerSuccessMessage = '';
|
||||||
let viewsForCollection = {};
|
let viewsForCollection = {};
|
||||||
|
|
||||||
@ -71,6 +73,17 @@
|
|||||||
querying = false;
|
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() {
|
async function refresh() {
|
||||||
if ($applicationSettings.autosubmitQuery) {
|
if ($applicationSettings.autosubmitQuery) {
|
||||||
await submitQuery();
|
await submitQuery();
|
||||||
@ -290,11 +303,26 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<div>
|
<div class="count">
|
||||||
{#key result}
|
{#if counting}
|
||||||
<span class="flash-green">Results: {result.total || 0}</span>
|
<span>Counting items…</span>
|
||||||
{/key}
|
{: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>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="field inline">
|
<label class="field inline">
|
||||||
<select bind:value={collection.viewKey}>
|
<select bind:value={collection.viewKey}>
|
||||||
@ -388,4 +416,8 @@
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.count {
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
</style>
|
</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 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 CreateIndex(arg1:string,arg2:string,arg3:string,arg4:string):Promise<string>;
|
||||||
|
|
||||||
export function DropCollection(arg1:string,arg2:string,arg3:string):Promise<boolean>;
|
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);
|
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) {
|
export function CreateIndex(arg1, arg2, arg3, arg4) {
|
||||||
return window['go']['app']['App']['CreateIndex'](arg1, arg2, arg3, arg4);
|
return window['go']['app']['App']['CreateIndex'](arg1, arg2, arg3, arg4);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
@ -23,6 +25,11 @@ type FindItemsResult struct {
|
|||||||
ErrorDescription string `json:"errorDescription"`
|
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) {
|
func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) (result FindItemsResult) {
|
||||||
var form Query
|
var form Query
|
||||||
|
|
||||||
@ -75,12 +82,14 @@ func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) (result FindIt
|
|||||||
Sort: sort,
|
Sort: sort,
|
||||||
}
|
}
|
||||||
|
|
||||||
total, err := client.Database(dbKey).Collection(collKey).CountDocuments(ctx, query, nil)
|
ctx2, cancel := context.WithDeadline(ctx, time.Now().Add(time.Second))
|
||||||
if err != nil {
|
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())
|
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)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Total = total
|
|
||||||
result.Results = make([]string, 0)
|
result.Results = make([]string, 0)
|
||||||
|
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
@ -119,6 +127,34 @@ func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) (result FindIt
|
|||||||
return
|
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 {
|
func (a *App) UpdateFoundDocument(hostKey, dbKey, collKey, idJson, newDocJson string) bool {
|
||||||
var id bson.M
|
var id bson.M
|
||||||
if err := bson.UnmarshalExtJSON([]byte(idJson), true, &id); err != nil {
|
if err := bson.UnmarshalExtJSON([]byte(idJson), true, &id); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user