diff --git a/src/api.js b/src/api.js index cfee0b7..793a614 100644 --- a/src/api.js +++ b/src/api.js @@ -28,7 +28,8 @@ function LocalConfig() { batch_prefix: "*", }, dbconsole: { - mongocollection: 'paragraph' + mongocollection: 'paragraph', + history: [] }, groups: "none", sort: "id", @@ -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 { diff --git a/src/components/ContentView.vue b/src/components/ContentView.vue index cbdc55c..a91b069 100644 --- a/src/components/ContentView.vue +++ b/src/components/ContentView.vue @@ -55,6 +55,7 @@ $forceUpdate(); @@ -58,6 +63,7 @@ export default { }, previewed: false, preview_text: "", + config: api.config }; }, methods: { @@ -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