mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 13:07:58 +00:00
Started work on indexes
This commit is contained in:
parent
e85183b6f1
commit
f030c9fd3d
@ -59,7 +59,6 @@
|
||||
|
||||
function openJson(itemId) {
|
||||
const item = result?.results?.filter(i => i._id == itemId);
|
||||
console.log(item);
|
||||
json = JSON.stringify(item, undefined, 2);
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,43 @@
|
||||
<script>
|
||||
import CodeViewer from '../../../components/codeviewer.svelte';
|
||||
import ObjectGrid from '../../../components/objectgrid.svelte';
|
||||
import { GetIndexes } from '../../../../wailsjs/go/app/App';
|
||||
|
||||
export let collection;
|
||||
|
||||
const indexes = [];
|
||||
let indexes = [];
|
||||
let activeKey = '';
|
||||
let json = '';
|
||||
|
||||
function getIndexes() {}
|
||||
async function getIndexes() {
|
||||
const result = await GetIndexes(collection.hostKey, collection.dbKey, collection.key);
|
||||
if (result) {
|
||||
indexes = result;
|
||||
}
|
||||
}
|
||||
|
||||
function openJson(itemId) {
|
||||
const item = indexes?.filter(i => i.name == itemId);
|
||||
json = JSON.stringify(item, undefined, 2);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="buttons">
|
||||
<button class="btn" on:click={getIndexes}>Get indexes</button>
|
||||
<button class="btn danger" disabled={!indexes?.length}>Drop selected</button>
|
||||
<button class="btn">Create…</button>
|
||||
<div class="indexes">
|
||||
<div class="actions">
|
||||
<button class="btn" on:click={getIndexes}>Get indexes</button>
|
||||
<button class="btn danger" disabled={!indexes?.length || !activeKey}>Drop selected</button>
|
||||
<button class="btn">Create…</button>
|
||||
</div>
|
||||
|
||||
<ObjectGrid key="name" data={indexes} bind:activeKey on:trigger={e => openJson(e.detail)} />
|
||||
</div>
|
||||
|
||||
<CodeViewer bind:code={json} language="json" />
|
||||
|
||||
<style>
|
||||
.indexes {
|
||||
display: grid;
|
||||
gap: 0.5rem;
|
||||
grid-template: auto 1fr / 1fr;
|
||||
}
|
||||
</style>
|
||||
|
4
frontend/wailsjs/go/app/App.d.ts
vendored
4
frontend/wailsjs/go/app/App.d.ts
vendored
@ -1,13 +1,15 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
import {map[string]app} from '../models';
|
||||
import {primitive} from '../models';
|
||||
import {map[string]app} from '../models';
|
||||
import {app} from '../models';
|
||||
|
||||
export function DropCollection(arg1:string,arg2:string,arg3:string):Promise<boolean>;
|
||||
|
||||
export function DropDatabase(arg1:string,arg2:string):Promise<boolean>;
|
||||
|
||||
export function GetIndexes(arg1:string,arg2:string,arg3:string):Promise<Array<primitive.M>>;
|
||||
|
||||
export function Hosts():Promise<map[string]app.Host>;
|
||||
|
||||
export function OpenCollection(arg1:string,arg2:string,arg3:string):Promise<primitive.M>;
|
||||
|
@ -10,6 +10,10 @@ export function DropDatabase(arg1, arg2) {
|
||||
return window['go']['app']['App']['DropDatabase'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function GetIndexes(arg1, arg2, arg3) {
|
||||
return window['go']['app']['App']['GetIndexes'](arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
export function Hosts() {
|
||||
return window['go']['app']['App']['Hosts']();
|
||||
}
|
||||
|
42
internal/app/collection_indexes.go
Normal file
42
internal/app/collection_indexes.go
Normal file
@ -0,0 +1,42 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
func (a *App) GetIndexes(hostKey, dbKey, collKey string) []bson.M {
|
||||
client, ctx, close, err := a.connectToHost(hostKey)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return nil
|
||||
}
|
||||
defer close()
|
||||
|
||||
cur, err := client.Database(dbKey).Collection(collKey).Indexes().List(ctx)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Encountered an error while creating index cursor",
|
||||
Message: err.Error(),
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
var results []bson.M
|
||||
err = cur.All(ctx, &results)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Encountered an error while executing index cursor",
|
||||
Message: err.Error(),
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
Loading…
Reference in New Issue
Block a user