mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 21:17:59 +00:00
Drop active item in find.svelte
This commit is contained in:
parent
a153858730
commit
3d97f3b92f
@ -1,5 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
import { FindItems } from '../../../../wailsjs/go/app/App';
|
import { FindItems, RemoveItemById } from '../../../../wailsjs/go/app/App';
|
||||||
import CodeExample from '../../../components/code-example.svelte';
|
import CodeExample from '../../../components/code-example.svelte';
|
||||||
import { input } from '../../../actions';
|
import { input } from '../../../actions';
|
||||||
import ObjectGrid from '../../../components/objectgrid.svelte';
|
import ObjectGrid from '../../../components/objectgrid.svelte';
|
||||||
@ -20,7 +20,7 @@
|
|||||||
let result = {};
|
let result = {};
|
||||||
let submittedForm = {};
|
let submittedForm = {};
|
||||||
let queryField;
|
let queryField;
|
||||||
let activePath = '';
|
let activePath = [];
|
||||||
let objectViewerData;
|
let objectViewerData;
|
||||||
$: 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})` : ''};`;
|
||||||
|
|
||||||
@ -46,8 +46,14 @@
|
|||||||
submitQuery();
|
submitQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove() {
|
async function removeActive() {
|
||||||
// todo
|
if (!activePath[0]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const ok = await RemoveItemById(collection.hostKey, collection.dbKey, collection.key, activePath[0]);
|
||||||
|
if (ok) {
|
||||||
|
await submitQuery();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetFocus() {
|
function resetFocus() {
|
||||||
@ -116,7 +122,7 @@
|
|||||||
{/key}
|
{/key}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button class="btn danger" on:click={remove} disabled={!activePath?.length}>
|
<button class="btn danger" on:click={removeActive} disabled={!activePath?.length}>
|
||||||
<Icon name="-" />
|
<Icon name="-" />
|
||||||
</button>
|
</button>
|
||||||
<button class="btn" on:click={prev} disabled={!submittedForm.limit || (submittedForm.skip <= 0) || !result?.results?.length}>
|
<button class="btn" on:click={prev} disabled={!submittedForm.limit || (submittedForm.skip <= 0) || !result?.results?.length}>
|
||||||
|
2
frontend/wailsjs/go/app/App.d.ts
vendored
2
frontend/wailsjs/go/app/App.d.ts
vendored
@ -28,6 +28,8 @@ export function OpenDatabase(arg1:string,arg2:string):Promise<Array<string>>;
|
|||||||
|
|
||||||
export function RemoveHost(arg1:string):Promise<void>;
|
export function RemoveHost(arg1:string):Promise<void>;
|
||||||
|
|
||||||
|
export function RemoveItemById(arg1:string,arg2:string,arg3:string,arg4:string):Promise<boolean>;
|
||||||
|
|
||||||
export function RemoveItems(arg1:string,arg2:string,arg3:string,arg4:string,arg5:boolean):Promise<number>;
|
export function RemoveItems(arg1:string,arg2:string,arg3:string,arg4:string,arg5:boolean):Promise<number>;
|
||||||
|
|
||||||
export function UpdateItems(arg1:string,arg2:string,arg3:string,arg4:string):Promise<number>;
|
export function UpdateItems(arg1:string,arg2:string,arg3:string,arg4:string):Promise<number>;
|
||||||
|
@ -50,6 +50,10 @@ export function RemoveHost(arg1) {
|
|||||||
return window['go']['app']['App']['RemoveHost'](arg1);
|
return window['go']['app']['App']['RemoveHost'](arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function RemoveItemById(arg1, arg2, arg3, arg4) {
|
||||||
|
return window['go']['app']['App']['RemoveItemById'](arg1, arg2, arg3, arg4);
|
||||||
|
}
|
||||||
|
|
||||||
export function RemoveItems(arg1, arg2, arg3, arg4, arg5) {
|
export function RemoveItems(arg1, arg2, arg3, arg4, arg5) {
|
||||||
return window['go']['app']['App']['RemoveItems'](arg1, arg2, arg3, arg4, arg5);
|
return window['go']['app']['App']['RemoveItems'](arg1, arg2, arg3, arg4, arg5);
|
||||||
}
|
}
|
||||||
|
@ -67,3 +67,28 @@ func (a *App) RemoveItems(hostKey, dbKey, collKey, jsonData string, many bool) i
|
|||||||
|
|
||||||
return res.DeletedCount
|
return res.DeletedCount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) RemoveItemById(hostKey, dbKey, collKey, itemId string) bool {
|
||||||
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
defer close()
|
||||||
|
|
||||||
|
filter := bson.M{"_id": itemId}
|
||||||
|
err = client.Database(dbKey).Collection(collKey).FindOneAndDelete(ctx, filter).Err()
|
||||||
|
|
||||||
|
if err != nil && err != mongo.ErrNoDocuments {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
|
Type: runtime.ErrorDialog,
|
||||||
|
Title: "Encountered an error while performing query",
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user