From 9dafd0db163df4d7e4e074a514519325a81b9219 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Tue, 9 Jun 2015 19:01:53 +0200 Subject: [PATCH] feature #3748: Add template log panel --- .../public/app/tabs/vms-tab/panels/log.js | 88 +++++++++++++++++++ .../app/tabs/vms-tab/panels/log/panelId.js | 3 + 2 files changed, 91 insertions(+) create mode 100644 src/sunstone/public/app/tabs/vms-tab/panels/log.js create mode 100644 src/sunstone/public/app/tabs/vms-tab/panels/log/panelId.js diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/log.js b/src/sunstone/public/app/tabs/vms-tab/panels/log.js new file mode 100644 index 0000000000..6c516fdf30 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/panels/log.js @@ -0,0 +1,88 @@ +define(function(require) { + /* + DEPENDENCIES + */ + + var Locale = require('utils/locale'); + var Notifier = require('utils/notifier'); + var OpenNebulaVM = require('opennebula/vm'); + + /* + CONSTANTS + */ + + var TAB_ID = require('../tabId'); + var PANEL_ID = require('./log/panelId'); + var RESOURCE = "VM" + var XML_ROOT = "VM" + + /* + CONSTRUCTOR + */ + + function Panel(info) { + this.panelId = PANEL_ID; + this.title = Locale.tr("Log"); + this.icon = "fa-file-text"; + + this.element = info[XML_ROOT]; + + return this; + }; + + Panel.PANEL_ID = PANEL_ID; + Panel.prototype.html = _html; + Panel.prototype.setup = _setup; + Panel.prototype.onShow = _onShow; + + return Panel; + + /* + FUNCTION DEFINITIONS + */ + + function _html() { + return '
' + + '
' + + '
' + + '' + + '' + + '' + + '
' + + '
' + + '
'; + } + + function _setup(context) { + } + + function _onShow(context) { + var that = this; + OpenNebulaVM.log({ + data: {id: that.element.ID}, + success: function(req, response) { + var log_lines = response['vm_log'].split("\n"); + var colored_log = ''; + for (var i = 0; i < log_lines.length; i++) { + var line = log_lines[i]; + if (line.match(/\[E\]/)) { + line = '' + line + ''; + } + colored_log += line + "
"; + } + + $('.vm_log_container', context).html( + '
' + + '
' + + colored_log + + '
' + + '
') + + }, + error: function(request, error_json) { + $('.vm_log_container', context).html(''); + Notifier.onError(request, error_json); + } + }); + } +}); diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/log/panelId.js b/src/sunstone/public/app/tabs/vms-tab/panels/log/panelId.js new file mode 100644 index 0000000000..a4f629ac33 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/panels/log/panelId.js @@ -0,0 +1,3 @@ +define(function(require){ + return 'vm_log_tab'; +}); \ No newline at end of file