mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 21:17:59 +00:00
Started work on remove feature
This commit is contained in:
parent
92ec231c48
commit
6d7f35775c
@ -1,24 +1,43 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import { RemoveItems } from '../../../../wailsjs/go/app/App';
|
||||||
import CodeExample from '../../../components/code-example.svelte';
|
import CodeExample from '../../../components/code-example.svelte';
|
||||||
|
|
||||||
export let collection;
|
export let collection;
|
||||||
|
|
||||||
let remove = '';
|
let json = '';
|
||||||
$: code = `db.${collection.key}.remove(${remove});`;
|
let many = true;
|
||||||
|
let result = undefined;
|
||||||
|
$: code = `db.${collection.key}.remove(${json});`;
|
||||||
|
|
||||||
function performRemove() {}
|
async function removeItems() {
|
||||||
|
result = await RemoveItems(collection.hostKey, collection.dbKey, collection.key, json, many);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form on:submit|preventDefault={performRemove}>
|
<form on:submit|preventDefault={removeItems}>
|
||||||
<CodeExample {code} />
|
<div class="options">
|
||||||
|
<CodeExample {code} />
|
||||||
|
<label class="field">
|
||||||
|
<span class="label">Many</span>
|
||||||
|
<span class="checkbox">
|
||||||
|
<input type="checkbox" bind:checked={many} />
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<label class="field">
|
<label class="field">
|
||||||
<textarea cols="30" rows="10" bind:value={remove} placeholder={'{}'} class="code"></textarea>
|
<textarea cols="30" rows="10" bind:value={json} placeholder={'{}'} class="code"></textarea>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<div></div>
|
<div>
|
||||||
<button type="submit" class="btn" disabled={!remove}>Remove</button>
|
{#key result}
|
||||||
|
{#if typeof result === 'number'}
|
||||||
|
<span class="flash-green">Removed {result} item{result === 1 ? '' : 's'}</span>
|
||||||
|
{/if}
|
||||||
|
{/key}
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn">Remove</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
@ -29,6 +48,12 @@
|
|||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.options {
|
||||||
|
display: grid;
|
||||||
|
gap: 0.5rem;
|
||||||
|
grid-template: 1fr / 1fr auto;
|
||||||
|
}
|
||||||
|
|
||||||
.flex {
|
.flex {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
@ -61,6 +61,8 @@ button {
|
|||||||
/* Inputs */
|
/* Inputs */
|
||||||
input {
|
input {
|
||||||
font: inherit;
|
font: inherit;
|
||||||
|
}
|
||||||
|
input:not([type="checkbox"]) {
|
||||||
min-width: 100px;
|
min-width: 100px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,7 @@ p strong {
|
|||||||
border-right: none;
|
border-right: none;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
background-color: #fff;
|
||||||
}
|
}
|
||||||
.field .label {
|
.field .label {
|
||||||
background-color: #eee;
|
background-color: #eee;
|
||||||
@ -85,6 +86,10 @@ p strong {
|
|||||||
background-color: rgba(255, 80, 80, 0.3);
|
background-color: rgba(255, 80, 80, 0.3);
|
||||||
border-color: rgb(255, 80, 80);
|
border-color: rgb(255, 80, 80);
|
||||||
}
|
}
|
||||||
|
.field > span.checkbox {
|
||||||
|
text-align: center;
|
||||||
|
min-width: 75px;
|
||||||
|
}
|
||||||
|
|
||||||
.btn {
|
.btn {
|
||||||
background-color: #00008b;
|
background-color: #00008b;
|
||||||
|
2
frontend/wailsjs/go/app/App.d.ts
vendored
2
frontend/wailsjs/go/app/App.d.ts
vendored
@ -21,3 +21,5 @@ export function OpenCollection(arg1:string,arg2:string,arg3:string):Promise<prim
|
|||||||
export function OpenConnection(arg1:string):Promise<Array<string>>;
|
export function OpenConnection(arg1:string):Promise<Array<string>>;
|
||||||
|
|
||||||
export function OpenDatabase(arg1:string,arg2:string):Promise<Array<string>>;
|
export function OpenDatabase(arg1:string,arg2:string):Promise<Array<string>>;
|
||||||
|
|
||||||
|
export function RemoveItems(arg1:string,arg2:string,arg3:string,arg4:string,arg5:boolean):Promise<number>;
|
||||||
|
@ -37,3 +37,7 @@ export function OpenConnection(arg1) {
|
|||||||
export function OpenDatabase(arg1, arg2) {
|
export function OpenDatabase(arg1, arg2) {
|
||||||
return window['go']['app']['App']['OpenDatabase'](arg1, arg2);
|
return window['go']['app']['App']['OpenDatabase'](arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function RemoveItems(arg1, arg2, arg3, arg4, arg5) {
|
||||||
|
return window['go']['app']['App']['RemoveItems'](arg1, arg2, arg3, arg4, arg5);
|
||||||
|
}
|
||||||
|
69
internal/app/collection_remove.go
Normal file
69
internal/app/collection_remove.go
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (a *App) RemoveItems(hostKey, dbKey, collKey, jsonData string, many bool) int64 {
|
||||||
|
var filter bson.M
|
||||||
|
var err error
|
||||||
|
jsonData = strings.TrimSpace(jsonData)
|
||||||
|
|
||||||
|
if len(jsonData) == 0 {
|
||||||
|
sure, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
|
Title: "Confirm",
|
||||||
|
Message: "Are you sure you want to drop all items in " + collKey + "?",
|
||||||
|
Buttons: []string{"Yes", "No"},
|
||||||
|
DefaultButton: "Yes",
|
||||||
|
CancelButton: "No",
|
||||||
|
})
|
||||||
|
if sure != "Yes" {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = json.Unmarshal([]byte(jsonData), &filter)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
|
Type: runtime.ErrorDialog,
|
||||||
|
Title: "Couldn't parse JSON",
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
defer close()
|
||||||
|
|
||||||
|
var res *mongo.DeleteResult
|
||||||
|
|
||||||
|
if many {
|
||||||
|
res, err = client.Database(dbKey).Collection(collKey).DeleteMany(ctx, filter)
|
||||||
|
} else {
|
||||||
|
res, err = client.Database(dbKey).Collection(collKey).DeleteOne(ctx, filter)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
|
Type: runtime.ErrorDialog,
|
||||||
|
Title: "Encountered an error while performing query",
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.DeletedCount
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user