Skip to content

Commit

Permalink
dbconsole history
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuth committed Oct 7, 2022
1 parent ee4ba79 commit 00c46c7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ function LocalConfig() {
batch_prefix: "*",
},
dbconsole: {
mongocollection: 'paragraph'
mongocollection: 'paragraph',
history: []
},
groups: "none",
sort: "id",
Expand Down Expand Up @@ -70,7 +71,7 @@ function LocalConfig() {
},
};

return new Proxy(Object.assign({}, defaults, _load_config()), handler);
return new Proxy(Object.assign({save() {_save_config(this)}}, defaults, _load_config()), handler);
}

export default {
Expand Down
1 change: 1 addition & 0 deletions src/components/ContentView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ $forceUpdate();
<template v-for="tag in tags">
<a
v-if="tag != '...'"
:alt="tag"
:key="`${paragraph._id}-${Math.random()}-${tag}`"
:href="'/' + querystring_stringify({
groups: tag.match(/^\*/) ? 'none' : (tag.match(/^@/) ? 'group' : ''),
Expand Down
42 changes: 29 additions & 13 deletions src/views/DbConsole.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
@change="previewed = command.operation == 'count'"
></v-select>
<ParamInput
ref="editor"
:arg="{ name: 'Query', type: 'QUERY' }"
v-model="command.query"
@input="previewed = command.operation == 'count'"
Expand All @@ -22,7 +21,6 @@
@input="previewed = command.operation == 'count'"
/>
<ParamInput
ref="editor"
:arg="{ name: 'Parameters', type: 'QUERY' }"
v-model="command.operation_params"
@input="previewed = command.operation == 'count'"
Expand All @@ -36,6 +34,13 @@
<v-card-text>
<pre>{{ preview_text }}</pre>
</v-card-text>
<v-card-text>
{{ $t('history') }}
<v-row v-for="(h, index) in config.dbconsole.history" :key="index">
<v-col>{{ stringify_command(h) }}</v-col>
<v-col><v-button icon @click="replay(h)"><v-icon>mdi-replay</v-icon></v-button></v-col>
</v-row>
</v-card-text>
</v-card>
</template>

Expand All @@ -58,6 +63,7 @@ export default {
},
previewed: false,
preview_text: "",
config: api.config
};
},
methods: {
Expand All @@ -67,30 +73,40 @@ export default {
this.command.operation == "count" ? "" : this.command.operation_params,
});
},
stringify_command(data) {
return 'MongoCollection("' +
data.mongocollection +
'").query(' +
JSON.stringify(data.query, "", 2) +
")." +
data.operation +
"(" +
JSON.stringify(data.operation_params, "", 2) +
")";
},
preview() {
this.command.preview = true;
api.call("admin/db", this.get_command()).then((data) => {
data = data.result;
this.preview_text =
'MongoCollection("' +
data.mongocollection +
'").query(' +
JSON.stringify(data.query, "", 2) +
")." +
data.operation +
"(" +
JSON.stringify(data.operation_params, "", 2) +
")";
this.preview_text = this.stringify_command(data)
this.previewed = true;
});
},
execute() {
this.command.preview = false;
api.config.dbconsole = {mongocollection : this.command.mongocollection};
api.config.dbconsole.mongocollection = this.command.mongocollection;
if (!api.config.dbconsole.history) api.config.dbconsole.history = []
api.config.dbconsole.history.splice(0, 0, Object.assign({}, this.command));
if (api.config.dbconsole.history.length > 10) api.config.dbconsole.history = api.config.dbconsole.history.slice(0, 10)
api.config.save();
api.call("admin/db", this.get_command()).then((data) => {
this.preview_text += "\n\n" + JSON.stringify(data.result, "", 2);
});
},
replay(h) {
this.command = Object.assign({}, h);
this.execute();
}
},
mounted() {
api
Expand Down

0 comments on commit 00c46c7

Please sign in to comment.