Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[ADD] added remove functionality.

  • Loading branch information...
commit 9d6a0a407d65978eb6ef8c1ef707e81368e02dca 1 parent e156c04
@bagwanpankaj authored
View
32 lib/humongous/application.rb
@@ -1,4 +1,4 @@
-# require './monkey_patch'
+require './monkey_patch'
module Humongous
MonkeyPatch.activate!
@@ -188,14 +188,44 @@ def from_bson( options )
post "/database" do
@connection.db(params["database_name"]).create_collection("test");
+ content_type :json
{ :status => "OK", :created => true, :name => params["database_name"] }.to_json
end
post "/database/:database_name/collection" do
@connection.db(params["database_name"]).create_collection(params[:collection_name]);
+ content_type :json
{ :status => "OK", :created => true, :name => params["collection_name"] }.to_json
end
+ delete "/database/:database_name/collection/:collection_name/remove" do
+ selector = {}
+ opts = {}
+ query = Crack::JSON.parse(params[:remove_query])
+ selector = selector.merge(query) if !!query
+ @database = @connection.db(params["database_name"])
+ @collection = @database.collection(params["collection_name"])
+ content_type :json
+ { :removed => @collection.remove( selector, opts ), :status => "OK" }.to_json
+ end
+
+ end
+
+ #gem version
+ def self.version #:nodoc
+ "Humongous::VERSION"
+ end
+
+ def self.description
+ %Q{
+ Humongous: A Ruby way to browse and maintain mongo instance. Using HTML5.
+ This is beta version, So there is long way to go, but still you can enjoy its
+ simplistic design.
+ }
+ end
+
+ def self.summary
+ %Q{An standalone Mongo Browser for Ruby. Just run and forget.}
end
end
View
2  lib/humongous/public/javascripts/application.js
@@ -39,7 +39,7 @@ $(document).ready(function(){
app.helpers.yielder( app.html.query_browser, {} );
e.preventDefault();
} );
- $( '.yielder form' ).live( 'submit', function( e ){
+ $( '.yielder form.find_form' ).live( 'submit', function( e ){
var db = app.storage.get("database"), coll = app.storage.get("collection")
if(db && !coll){
alert("Please choose a collection first.")
View
113 lib/humongous/public/javascripts/bootstrap-alerts.js
@@ -0,0 +1,113 @@
+/* ==========================================================
+ * bootstrap-alerts.js v1.4.0
+ * http://twitter.github.com/bootstrap/javascript.html#alerts
+ * ==========================================================
+ * Copyright 2011 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ========================================================== */
+
+
+!function( $ ){
+
+ "use strict"
+
+ /* CSS TRANSITION SUPPORT (https://gist.github.com/373874)
+ * ======================================================= */
+
+ var transitionEnd
+
+ $(document).ready(function () {
+
+ $.support.transition = (function () {
+ var thisBody = document.body || document.documentElement
+ , thisStyle = thisBody.style
+ , support = thisStyle.transition !== undefined || thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.MsTransition !== undefined || thisStyle.OTransition !== undefined
+ return support
+ })()
+
+ // set CSS transition event type
+ if ( $.support.transition ) {
+ transitionEnd = "TransitionEnd"
+ if ( $.browser.webkit ) {
+ transitionEnd = "webkitTransitionEnd"
+ } else if ( $.browser.mozilla ) {
+ transitionEnd = "transitionend"
+ } else if ( $.browser.opera ) {
+ transitionEnd = "oTransitionEnd"
+ }
+ }
+
+ })
+
+ /* ALERT CLASS DEFINITION
+ * ====================== */
+
+ var Alert = function ( content, options ) {
+ this.settings = $.extend({}, $.fn.alert.defaults, options)
+ this.$element = $(content)
+ .delegate(this.settings.selector, 'click', this.close)
+ }
+
+ Alert.prototype = {
+
+ close: function (e) {
+ var $element = $(this).parent('.alert-message')
+
+ e && e.preventDefault()
+ $element.removeClass('in')
+
+ function removeElement () {
+ $element.remove()
+ }
+
+ $.support.transition && $element.hasClass('fade') ?
+ $element.bind(transitionEnd, removeElement) :
+ removeElement()
+ }
+
+ }
+
+
+ /* ALERT PLUGIN DEFINITION
+ * ======================= */
+
+ $.fn.alert = function ( options ) {
+
+ if ( options === true ) {
+ return this.data('alert')
+ }
+
+ return this.each(function () {
+ var $this = $(this)
+
+ if ( typeof options == 'string' ) {
+ return $this.data('alert')[options]()
+ }
+
+ $(this).data('alert', new Alert( this, options ))
+
+ })
+ }
+
+ $.fn.alert.defaults = {
+ selector: '.close'
+ }
+
+ $(document).ready(function () {
+ new Alert($('body'), {
+ selector: '.alert-message[data-alert] .close'
+ })
+ })
+
+}( window.jQuery || window.ender );
View
135 lib/humongous/public/javascripts/query_browser.js
@@ -7,41 +7,8 @@ app.html.query_browser = {
this.clear();
return(
{ tag: "DIV", cls: "query_browser", children: [
- { tag: "FORM", children:
- [
- { tag: "FIELDSET", children: [
- // this._get_legend(),
- { tag: "DIV", cls: "input_row", children: [
- { tag: "DIV", cls: "query_form", children: [
- { tag: "LABEL", "for": "query", text: "Query" },
- { tag: "INPUT", type: "text", placeholder: "Find All", id: "query", size: "41", name: "query" }
- ] },
- { tag: "DIV", cls: "sort_form", children: [
- { tag: "LABEL", "for": "sort", text: "Sort" },
- { tag: "INPUT", type: "text", placeholder: "[\"name\", \"asc\"]", id: "sort", name: "sort" }
- ] },
- { tag: "DIV", cls: "clear" }
- ] },
- // { tag: "DIV", cls: "clear" },
- { tag: "DIV", cls: "input_row", children: [
- { tag: "DIV", cls: "fields_form", children: [
- { tag: "LABEL", "for": "fields", text: "Fields" },
- { tag: "INPUT", type: "text", placeholder: "field1, field2", id: "fields", size: "30", name: "fields" }
- ] },
- { tag: "DIV", cls: "skip_form", children: [
- { tag: "LABEL", "for": "skip", text: "Skip" },
- { tag: "INPUT", type: "text", placeholder: "0", id: "skip", size: "5", name: "skip", value: "0", cls: 'number' }
- ] },
- { tag: "DIV", cls: "limit_form", children: [
- { tag: "LABEL", "for": "limit", text: "Limit" },
- { tag: "INPUT", type: "text", placeholder: "10", id: "limit", size: "5", name: "limit", value: "10", cls: 'number' }
- ] },
- { tag: "INPUT", type: 'submit', cls: "submit_btn btn", value: "Search" },
- { tag: "DIV", cls: "clear" }
- ] }
- ] }
- ]
- },
+ this._query_pills(),
+ { tag: "DIV", cls: "query_form_container", child: app.query_forms["find_form"] },
{ tag: "DIV", cls: "query_result" },
{ tag: "DIV", id: "object_modal", "style": "display: none; ", cls: "modal hide fade", children: [
{ tag: "DIV", cls: "modal-header", children: [
@@ -77,6 +44,23 @@ app.html.query_browser = {
$('#object_modal').modal('toggle');
}
})
+ },
+ _query_pills: function(){
+ return(
+ { tag: "UL", cls: "pills", children: [
+ { tag: "LI", cls: "active", child: { tag: "A", href: "#", text: "Find", show: "find_form" }, onClick: this._pills_click_handler },
+ { tag: "LI", child: { tag: "A", href: "#", text: "Remove", show: "remove_form" }, onClick: this._pills_click_handler },
+ { tag: "LI", child: { tag: "A", href: "#", text: "Insert", show: "insert_form" }, onClick: this._pills_click_handler },
+ { tag: "LI", child: { tag: "A", href: "#", text: "MapReduce", show: "mapreduce_form" }, onClick: this._pills_click_handler },
+ ]}
+ )
+ },
+ _pills_click_handler: function(e){
+ var click_container = $(e.target);
+ $( click_container ).parent().siblings().removeClass( "active" );
+ $( click_container ).parent().addClass( "active" );
+ $(".query_form_container").children().remove();
+ $( app.query_forms[click_container.attr("show")] ).appendTo(".query_form_container")
}
};
app.html.build_results = {
@@ -185,4 +169,83 @@ app.html.template.select_field = app.merge( app.html.template.abstract_field, {
};
return res;
}
-} );
+} );
+app.query_forms = {
+ find_form: { tag: "FORM", cls: "find_form", children:
+ [
+ { tag: "FIELDSET", children: [
+ // this._get_legend(),
+ { tag: "DIV", cls: "input_row", children: [
+ { tag: "DIV", cls: "query_form", children: [
+ { tag: "LABEL", "for": "query", text: "Query" },
+ { tag: "INPUT", type: "text", placeholder: "Find All", id: "query", size: "41", name: "query" }
+ ] },
+ { tag: "DIV", cls: "sort_form", children: [
+ { tag: "LABEL", "for": "sort", text: "Sort" },
+ { tag: "INPUT", type: "text", placeholder: "[\"name\", \"asc\"]", id: "sort", name: "sort" }
+ ] },
+ { tag: "DIV", cls: "clear" }
+ ] },
+ // { tag: "DIV", cls: "clear" },
+ { tag: "DIV", cls: "input_row", children: [
+ { tag: "DIV", cls: "fields_form", children: [
+ { tag: "LABEL", "for": "fields", text: "Fields" },
+ { tag: "INPUT", type: "text", placeholder: "field1, field2", id: "fields", size: "30", name: "fields" }
+ ] },
+ { tag: "DIV", cls: "skip_form", children: [
+ { tag: "LABEL", "for": "skip", text: "Skip" },
+ { tag: "INPUT", type: "text", placeholder: "0", id: "skip", size: "5", name: "skip", value: "0", cls: 'number' }
+ ] },
+ { tag: "DIV", cls: "limit_form", children: [
+ { tag: "LABEL", "for": "limit", text: "Limit" },
+ { tag: "INPUT", type: "text", placeholder: "10", id: "limit", size: "5", name: "limit", value: "10", cls: 'number' }
+ ] },
+ { tag: "INPUT", type: 'submit', cls: "submit_btn btn", value: "Search" },
+ { tag: "DIV", cls: "clear" }
+ ] }
+ ] }
+ ]
+ },
+ remove_form: { tag: "FORM", cls: "remove_form", action: "/database/" + app.storage.get("database") + "/collection/" + app.storage.get("collection") + "/remove", method: "DELETE", child: {
+ tag: "FIELDSET", children: [
+ { tag: "DIV", cls: "input_row", children: [
+ { tag: "DIV", cls: "query_form", children: [
+ { tag: "LABEL", "for": "remove_query", text: "Query", style: "margin: 0 10px 0" },
+ { tag: "TEXTAREA", style: "height: 50px; width: 300px", placeholder: "{}", id: "remove_query", name: "remove_query" }
+ ] },
+ { tag: "INPUT", type: 'submit', cls: "submit_btn btn", value: "Remove", onClick: this._remove_submit },
+ { tag: "DIV", cls: "clear" }
+ ] }
+ ]
+ }, onSubmit: function(e){
+ e.preventDefault();
+ app.ax({
+ url: $(this).attr("action"),
+ data: $(this).serialize(),
+ type: $(this).attr("method"),
+ success: function( data ){
+ console.log(data);
+ if(data.removed){
+ var alert = { tag: "DIV", cls: "alert-message success fade in", "data-alert": "true", children: [
+ { tag: "A", cls: "close", href: "#", text: "x" },
+ { tag: "P", text: "Query ran successfully." }
+ ] };
+ }else{
+ var alert = { tag: "DIV", cls: "alert-message error fade in", "data-alert": "true", children: [
+ { tag: "A", cls: "close", href: "#", text: "x" },
+ { tag: "P", text: "Query has thrown error. Please check again." }
+ ] };
+ }
+ $( ".query_result" ).children().remove();
+ $( alert ).appendTo( '.query_result' );
+ }
+ })
+ }
+ },
+ insert_form: {
+ tag: "DIV", cls: "insert_form", text: "insert_form"
+ },
+ mapreduce_form: {
+ tag: "DIV", cls: "mapreduce_form", text: "mapreduce_form"
+ },
+}
View
1  lib/humongous/views/index.erb
@@ -24,6 +24,7 @@
<script type='text/javascript' src='/javascripts/jquery.min.js'></script>
<script type='text/javascript' src='/javascripts/jquery.nohtml.js'></script>
<script type='text/javascript' src='/javascripts/bootstrap-modal.js'></script>
+ <script type='text/javascript' src='/javascripts/bootstrap-alerts.js'></script>
<script type='text/javascript' src='/javascripts/core.js'></script>
<script type='text/javascript' src='/javascripts/storage.js'></script>
Please sign in to comment.
Something went wrong with that request. Please try again.