/* * Server Info scripts. * * requires: * common_js.js * tajax.js */ var sinfo = {}; /** ======================================================================= * Logic behind a list of server infos. */ /** * Creates a sinfo.list instance. Takes a variable list of sinfo.controller * instances as arguments. */ sinfo.list = function() { // member fields this.servers = new Array(); for (var i = 0; i < arguments.length; i++) { if (arguments[i]) { this.servers.push(arguments[i]); } } }; sinfo.list.prototype.update = function() { for (var i = 0; i < this.servers.length; i++) { var si = this.servers[i]; if (si) { si.update(); } } }; sinfo.list.prototype.bodyShow = function() { js.debug("Showing bodies for " + this.servers.length + " servers"); for (var i = 0; i < this.servers.length; i++) { var si = this.servers[i]; js.debug("show body for [" + i + "]? " + si); if (si) { js.debug("showing body for [" + i + "]: " + si.view.title); si.view.bodyShow(); } } }; /* ========================================================================= * Standard factory for the controller / model / view */ /** * Creates the model & view during construction */ sinfo.createController = function(title, url, templateId) { if (! sinfo.__ids[title]) { sinfo.__ids[title] = 0; } sinfo.__ids[title] += 1; var id = title.replace(/\W/g, '_') + '_' + sinfo.__ids[title]; var model = new sinfo.model(id); var view = new sinfo.view(title, templateId); var controller = new sinfo.controller(url, model, view); return controller; }; sinfo.__ids = {}; /* ========================================================================= * Model: defines what's stored and referenced by the view and controller. */ /** * sinfo.model(String id) * * This object handles storing client-side data, and knows how to parse * the data from the server. * * @param id the identifier for the model, or null if you want one to be * generated for you. * @return new sinfo.model instance */ sinfo.model = js.Class(); sinfo.model.prototype.__init__ = function(id) { if (! id) { id = sinfo.__ids.length + 1; sinfo.__ids[id] = id; } // member fields this.index = sinfo.model.count++; this.id = id; // default data from server this.data = '<p><i>No data retrieved yet</i></p>'; this.lastUpdate = 'Never'; mvc.model.setup(this); mvc.model.setReadOnly(this, 'index', 'id'); }; /** * protected void _parse(String data) * * Parses the response from the server for proper storage in the model. * Default behavior stores the data as-is, and sets the lastUpdate to now. * * @param data the data from the server. */ sinfo.model.prototype._parse = function(response) { js.debug("+ start set sinfo model values"); if (response.error) { this.$data('<p><font color="red"><b>' + response.error + '</b></font></p>'); } else { this.$data(response.text); } this.$lastUpdate((new Date()).toString()); js.debug("+ end set sinfo model values"); }; /* ========================================================================= * controller - knows how to handle communication between the model and the * viewer */ /** * public sinfo.controller(String url, sinfo.model model, sinfo.view view) * * Creates the model & view during construction * * @param url URL to send the AJAX request. * @param model model storage object. * @param view view object. */ sinfo.controller = js.Class(); sinfo.controller.prototype.__init__ = function(url, model, view) { this.model = model; this.view = view; // constructed methods this.update = tajax.createUpdate(url, 'sinfo.controller.__update_cb'); view._setup(model, this); }; /** * public static void __update_cb(data, si) * * Static callback on server response. */ sinfo.controller.__update_cb = function(data, si) { si.model._parse(data); // don't need to call the view's update - the interceptors on the model // setters will do this for us. }; /* ========================================================================= * view - knows how to render the model to the screen, and tie it in to the * controller. * * This implementation is a rudimentary implementation of a view. It just * shows the contents of the server file. */ sinfo.view = js.Class(mvc.view); /** * public sinfo.view(String title, String templateId) * * Create a new sinfo.view instance. * * @param title the title of the form * @param templateId document ID of the template to base this instance from. * Defaults to 'serverinfo-base'. */ sinfo.view.prototype.__init__ = function(title, templateId) { this.title = title; if (! templateId) { templateId = 'serverinfo-base'; } this.templateId = templateId; this.model = null; this.controller = null; }; /** * void sinfo.view._setup(sinfo.model, sinfo.controller) * * Package-protected method to initialize the view after construction * of the controller and model. */ sinfo.view.prototype._setup = function(model, controller) { this.controller = controller; this.setModel(model); }; /** * public void sinfo.view.bodyShow() * * Performs initial rendering of the DHTML elements. Should only be called * within the body of the HTML. */ sinfo.view.prototype.bodyShow = function() { js.debug('inside view.bodyShow: ' + this.model.id); //document.writeln(js.msg(sinfo.messages.view_base_start, // this.model.id, this.title, this.model.lastUpdate)); document.writeln(js.msg(sinfo.messages.view_wrapper_start, this.model.id)); this.showTemplate(this.templateId); document.writeln(js.msg(sinfo.messages.view_wrapper_end)); }; sinfo.view.prototype.update_lastUpdate = function() { js.debug("update_lastUpdate for this: id = " + this.model.id); //js.debug('getElementById(' + this.model.id + '_updated) = ' + document.getElementById(this.model.id + '_updated')); d = document.getElementById(this.model.id + '_updated'); if (! d) { js.failure("Could not find doc id " + this.model.id + "_updated"); //return; } d.innerHTML = this.model.$lastUpdate(); }; sinfo.view.prototype.update_data = function() { js.debug("update_data for this: id = " + this.model.id); //js.debug('getElementById(' + this.model.id + '_data) = ' + document.getElementById(this.model.id + '_data')); var d = document.getElementById(this.model.id + '_data'); if (! d) { js.failure("Could not find doc id " + this.model.id + "_data"); return; } d.innerHTML = this.model.$data(); }; /* ========================================================================= * DEFAULT MESSAGES */ sinfo.messages = {}; sinfo.messages.language_code = "en"; sinfo.messages.language = "US English"; sinfo.messages.view_wrapper_start = "<div id='{1}' class='server-info'>"; sinfo.messages.view_wrapper_end = "</div>";
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 5925 | Matt Albrecht | Updates to the server status page | ||
#2 | 5816 | Matt Albrecht | Add / update the server status with a much better AJAX model. | ||
#1 | 5810 | Matt Albrecht |
New version of logDaemon that has better bug fixes. Also added server-status web page for a pure client-side AJAX app that pulls together different server-side statistics. |