activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1439017 - in /activemq/activemq-apollo/trunk/apollo-web/src/main: scala/org/apache/activemq/apollo/web/ scala/org/apache/activemq/apollo/web/resources/ webapp/console/ webapp/console/js/
Date Sun, 27 Jan 2013 04:14:00 GMT
Author: chirino
Date: Sun Jan 27 04:14:00 2013
New Revision: 1439017

URL: http://svn.apache.org/viewvc?rev=1439017&view=rev
Log:
Add a configuration tab to the console view.

Modified:
    activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/JerseyServlet.scala
    activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/ConfigurationResource.scala
    activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/console/index.html
    activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/console/js/app.js

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/JerseyServlet.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/JerseyServlet.scala?rev=1439017&r1=1439016&r2=1439017&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/JerseyServlet.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/JerseyServlet.scala
Sun Jan 27 04:14:00 2013
@@ -43,7 +43,6 @@ class JerseyServlet extends ServletConta
     settings.put("com.sun.jersey.config.feature.ImplicitViewables", "true")
     settings.put("com.sun.jersey.config.property.MediaTypeMappings", """
         html : text/html,
-        xml : application/xml,
         json : application/json
         """)
 

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/ConfigurationResource.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/ConfigurationResource.scala?rev=1439017&r1=1439016&r2=1439017&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/ConfigurationResource.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/ConfigurationResource.scala
Sun Jan 27 04:14:00 2013
@@ -134,7 +134,8 @@ class ConfigurationResource extends Reso
   }
 
   @POST
-  @Consumes(Array(WILDCARD))
+  @Produces(Array(APPLICATION_OCTET_STREAM))
+  @Consumes(Array(APPLICATION_OCTET_STREAM))
   @Path("/files/{name}")
   @ApiOperation(value = "Updates the contents of the configuration file.")
   def put(@PathParam("name") name:String, config:Array[Byte]):Unit = {
@@ -143,7 +144,7 @@ class ConfigurationResource extends Reso
       result(NOT_FOUND)
     }
     file.write_bytes(config)
-    result(strip_resolve("."))
+    result(OK)
   }
 
   @POST

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/console/index.html
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/console/index.html?rev=1439017&r1=1439016&r2=1439017&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/console/index.html (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/console/index.html Sun Jan 27
04:14:00 2013
@@ -504,6 +504,27 @@
         </div>
       </div>
       {{/if}}
+      {{#if App.MainController.is_configuration_selected}}
+      <div class="row">
+        <div class="span12" style="padding-bottom:1em">
+          {{view Ember.Select
+                 class="nomargin"
+                 contentBinding="App.ConfigurationController.files"
+                 valueBinding="App.ConfigurationController.selected"
+          }}
+          {{#if App.ConfigurationController.modified}}
+          <button class="btn btn-small" {{action "save" target="App.ConfigurationController"
on="click"}}><i class="icon-save"></i> Save</button>
+          <button class="btn btn-small" {{action "refresh_selected" target="App.ConfigurationController"
on="click"}}><i class="icon-undo"></i> Revert</button>
+          {{/if}}
+        </div>
+      </div>
+      <div class="row">
+        {{view App.AceView
+            class="span12"
+            modeBinding="App.ConfigurationController.selected_ace_mode"
+            codeBinding="App.ConfigurationController.buffer"}}
+      </div>
+      {{/if}}
     </div>
     {{/unless}}
     </script>
@@ -519,6 +540,8 @@
 </footer>
 
 <script src="js/jquery-1.7.2.min.js"></script>
+<script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript"
charset="utf-8"></script>
+<!--<script src="js/ace/ace.js" type="text/javascript" charset="utf-8"></script>-->
 <!--<script src="js/excanvas.min.js"></script>-->
 <!--<script src="js/jquery.flot.js"></script>-->
 <!--<script src="js/jquery.flot.pie.js"></script>-->

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/console/js/app.js
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/console/js/app.js?rev=1439017&r1=1439016&r2=1439017&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/console/js/app.js (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/console/js/app.js Sun Jan 27
04:14:00 2013
@@ -75,11 +75,22 @@ Ember.Handlebars.registerHelper('memory'
   return Ember.Handlebars.helpers.bind(property, options);
 });
 
+$(window).resize(function() {
+ App.set("window_size", {
+  height:$(window).height(),
+  width:$(window).width(),
+ })
+});
+
 App = Em.Application.create({
+  window_size:{
+    height:$(window).height(),
+    width:$(window).width(),
+  },
   ready: function() {
     setInterval(function() {
       if( App.LoginController.get('is_logged_in') ) {
-//        App.auto_refresh();
+        App.auto_refresh();
       }
     }, 2000);
     this._super();
@@ -91,6 +102,7 @@ App = Em.Application.create({
     App.BrokerController.auto_refresh();
     App.VirtualHostController.auto_refresh();
     App.ConnectorController.auto_refresh();
+    App.ConfigurationController.auto_refresh();
     Ember.run(function(){
       $(".tooltip-link").tooltip();
     });
@@ -100,6 +112,7 @@ App = Em.Application.create({
     App.BrokerController.refresh();
     App.VirtualHostController.refresh();
     App.ConnectorController.refresh();
+    App.ConfigurationController.refresh();
   },
 
   default_error_handler:function(xhr, status, thrown) {
@@ -151,7 +164,7 @@ function date_to_string(v) {
 }
 
 App.MainController = Em.Controller.create({
-  tabs:["Virtual Hosts","Connectors","Operating Environment"],
+  tabs:["Virtual Hosts","Connectors","Operating Environment","Configuration"],
   selected_tab:"Virtual Hosts",
   is_virtual_hosts_selected:function() {
     return this.get("selected_tab") == "Virtual Hosts"
@@ -162,6 +175,9 @@ App.MainController = Em.Controller.creat
   is_operating_environment_selected:function() {
     return this.get("selected_tab") == "Operating Environment"
   }.property("selected_tab"),
+  is_configuration_selected:function() {
+    return this.get("selected_tab") == "Configuration"
+  }.property("selected_tab"),
 });
 
 App.LoginController = Em.Controller.create({
@@ -693,6 +709,212 @@ App.MessagesController = Ember. ArrayCon
 
 });
 
+App.ConfigurationController = Ember.Controller.create({
+
+  offline:false,
+  files:[],
+  selected:"apollo.xml",
+  actual_selected:"apollo.xml",
+  buffer:null,
+  original:null,
+  buffers:{},
+
+  selected_ace_mode: function(){
+    var selected = this.get("actual_selected");
+    var re = /(?:\.([^.]+))?$/;
+    var mode = re.exec(selected)[1] || "text"
+    if( mode == "pem" || mode == "p12" || mode == "properties" ||
+        mode=="config" || mode == "keystore" || mode=="txt" ) {
+      mode = "text";
+    }
+    return mode;
+  }.property("actual_selected"),
+
+  modified: function() {
+    return this.get("original") != this.get("buffer");
+  }.property("original", "buffer"),
+
+  is_modified: function() {
+    return this.get("original") != this.get("buffer");
+  },
+
+  auto_refresh: function() {
+    if( App.MainController.get("is_configuration_selected")) {
+      this.refresh();
+    }
+    if(App.ConfigurationController.get("buffer")==null ) {
+      this.refresh_selected();
+    }
+  },
+
+  refresh: function() {
+    App.ajax("GET", "/broker/config/files", function(json) {
+      App.ConfigurationController.set("files", json);
+    });
+  },
+
+  refresh_selected: function() {
+    var self = this;
+    var selected = this.get("actual_selected");
+    this.ajax("GET", "/broker/config/files/"+selected, function(buffer) {
+      self.set("original", buffer);
+      self.set("buffer", buffer);
+    }, function(error, a, b, c){
+      self.set("original", null);
+      self.set("buffer", null);
+    });
+  },
+
+  ajax:function(type, path, success, error, data) {
+    $.ajax({
+      type: type,
+      url: "../api/json"+path,
+      headers: {
+        AuthPrompt:'false',
+      },
+      headers: {
+        "Accept":"application/octet-stream",
+      },
+      dataType: 'text',
+      success: function(data, textStatus, jqXHR){
+        App.BrokerController.set("offline", false);
+        if( success ) {
+          success(data, textStatus, jqXHR)
+        }
+      },
+      error: error,
+      data:data,
+      processData:false,
+      contentType:"application/octet-stream",
+    });
+  },
+
+  on_selected_change:function() {
+    var self = this;
+    var actual_selected = this.get("actual_selected");
+    var selected = this.get("selected");
+    if( actual_selected == selected ) {
+      return;
+    }
+    if( !this.is_modified() ) {
+      this.set("actual_selected", selected);
+    } else {
+      Bootstrap.ModalPane.popup({
+        heading: "Are you sure?",
+        message: "Switching files will cause you to loose the current edits you have made
to the current file.",
+        primary: "OK",
+        secondary: "Cancel",
+        showBackdrop: true,
+        callback: function(opts, event) {
+          if (opts.primary) {
+            self.set("actual_selected", selected);
+          } else {
+            self.set("selected", actual_selected);
+          }
+        }
+      });
+    }
+  }.observes("selected"),
+
+  on_actual_selected_change:function() {
+    this.refresh_selected();
+  }.observes("actual_selected"),
+
+  save: function() {
+    var self = this;
+    var selected = this.get("actual_selected");
+    this.ajax("POST", "/broker/config/files/"+selected, function(buffer) {
+      self.set("original", buffer);
+      Bootstrap.AlertMessage.create({
+        type:"info",
+        message:"File "+selected+" saved."
+      }).appendTo("#notifications")
+    }, function(error, a, b, c){
+      Bootstrap.AlertMessage.create({
+        type:"warning",
+        message:"File "+selected+" could not be saved: "+a
+      }).appendTo("#notifications")
+    }, this.get("buffer"));
+  },
+
+});
+
+App.AceView = Ember.View.extend({
+
+  editor: null,
+  mode:"xml",
+  onModeChange:function(){
+    var editor = this.get("editor")
+    var mode = this.get("mode")
+    if( editor!=null ) {
+      editor.getSession().setMode("ace/mode/"+mode);
+    }
+  }.observes('editor', 'mode'),
+
+  theme:"monokai",
+  onThemeChange:function(){
+    var editor = this.get("editor")
+    var theme = "ace/theme/"+this.get("theme")
+    if( editor!=null ) {
+      editor.setTheme(theme);
+    }
+  }.observes('editor', 'theme'),
+
+  didInsertElement: function() {
+    var self = this;
+    var id = this.$().attr('id');
+    var editor = ace.edit(id);
+
+    editor.renderer.setShowPrintMargin(true);
+    editor.renderer.setShowGutter(true);
+    var session = editor.getSession();
+    session.setUseSoftTabs(true);
+    session.setTabSize(2);
+    session.on('change', function (e) {
+      self.onEditorTextChange(session, e);
+    });
+    this.set('editor', editor);
+  },
+
+  onStyleChange: function() {
+    var editor = this.get('editor');
+    if( editor!=null ) {
+      var div = this.$()
+      div.css("height", $(window).height()-(div.offset().top+40));
+      editor.resize();
+    }
+  }.observes('editor', 'App.window_size'),
+
+  onViewChange: function() {
+    if( this._updating )
+      return;
+    var editor = this.get('editor');
+    var code = this.get('code');
+    this._updating = true
+    if (editor && code && code !== this._codeFromEditor) {
+      this._codeFromUpdate = code;
+      editor.setValue(code);
+    }
+    this._updating = false
+  }.observes('code', 'editor'),
+
+  onEditorTextChange: function(session, e) {
+    if( this._updating )
+      return;
+    var self = this;
+    var code = session.getValue();
+    if (code !== self._codeFromUpdate) {
+      this._updating = true;
+      this._codeFromEditor = code;
+        console.log("Setting: ["+code+"]");
+        self.set('code', code);
+        console.log("Done");
+      this._updating = false;
+    }
+  }
+});
+
+
 Ember.View.create({
   templateName: 'notifications',
 }).appendTo("#notifications");



Mime
View raw message