mirror of
https://github.com/fluent/fluentd-ui.git
synced 2026-05-05 19:06:12 +02:00
Add polling alerts point on rails
This commit is contained in:
parent
63c5e97dbc
commit
488a0d8a59
@ -1,6 +1,7 @@
|
||||
(function(){
|
||||
"use strict";
|
||||
var POLLING_INTERVAL = 1 * 1000;
|
||||
var POLLING_INTERVAL = 3 * 1000;
|
||||
var POLLING_URL = "/polling/alerts";
|
||||
|
||||
$(function(){
|
||||
var alert = new Vue({
|
||||
@ -11,33 +12,30 @@
|
||||
|
||||
created: function(){
|
||||
var self = this;
|
||||
setInterval(function(){
|
||||
self.fetchData().then(function(alerts){
|
||||
var fetch = function(){
|
||||
self.fetchAlertsData().then(function(alerts){
|
||||
self.alerts = alerts;
|
||||
});
|
||||
}, POLLING_INTERVAL);
|
||||
};
|
||||
fetch();
|
||||
setInterval(fetch, POLLING_INTERVAL);
|
||||
},
|
||||
|
||||
computed: {
|
||||
alertsCount: {
|
||||
$get: function(){ return this.alerts.length; }
|
||||
},
|
||||
hasAlerts: {
|
||||
$get: function(){
|
||||
return this.alerts.length > 0;
|
||||
}
|
||||
$get: function(){ return this.alertsCount > 0; }
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
fetchData: function() {
|
||||
// TODO: fetch from Rails app
|
||||
fetchAlertsData: function() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
resolve([
|
||||
{
|
||||
"text": "dummy: " + (new Date).toString(),
|
||||
},
|
||||
{
|
||||
"text": "dummy: " + (Math.random()).toString(),
|
||||
},
|
||||
]);
|
||||
$.getJSON(POLLING_URL, function(data){
|
||||
resolve(data);
|
||||
}).fail(reject);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,3 +27,13 @@ label {
|
||||
#page-wrapper {
|
||||
padding-bottom: 2em;
|
||||
}
|
||||
|
||||
|
||||
// expand alert area width
|
||||
.navbar-top-links .dropdown-messages,
|
||||
.navbar-top-links .dropdown-tasks,
|
||||
.navbar-top-links .dropdown-alerts {
|
||||
// width: 310px;
|
||||
width: 400px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ class ApplicationController < ActionController::Base
|
||||
protect_from_forgery with: :exception
|
||||
helper_method :current_user
|
||||
helper_method :current_locale
|
||||
helper_method :installing_gem?, :installing_gems, :uninstalling_gem?, :uninstalling_gems
|
||||
before_action :login_required
|
||||
before_action :set_locale
|
||||
|
||||
@ -21,6 +22,26 @@ class ApplicationController < ActionController::Base
|
||||
I18n.locale
|
||||
end
|
||||
|
||||
def installing_gem?
|
||||
installing_gems.length > 0
|
||||
end
|
||||
|
||||
def installing_gems
|
||||
Plugin::WORKING.find_all do |data|
|
||||
data[:type] == :install && data[:state] == :running
|
||||
end.map{|data| data[:plugin]} || []
|
||||
end
|
||||
|
||||
def uninstalling_gem?
|
||||
uninstalling_gems.length > 0
|
||||
end
|
||||
|
||||
def uninstalling_gems
|
||||
Plugin::WORKING.find_all do |data|
|
||||
data[:type] == :uninstall && data[:state] == :running
|
||||
end.map{|data| data[:plugin]} || []
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_fluentd
|
||||
|
||||
20
app/controllers/polling_controller.rb
Normal file
20
app/controllers/polling_controller.rb
Normal file
@ -0,0 +1,20 @@
|
||||
class PollingController < ApplicationController
|
||||
def alerts
|
||||
alerts = []
|
||||
installing_gems.each do |plugin|
|
||||
target = plugin.gem_name.dup
|
||||
target << "(#{plugin.version})" if plugin.version
|
||||
alerts << {
|
||||
text: I18n.t('terms.installing', target: target)
|
||||
}
|
||||
end
|
||||
uninstalling_gems.each do |plugin|
|
||||
target = plugin.gem_name.dup
|
||||
target << "(#{plugin.version})" if plugin.version
|
||||
alerts << {
|
||||
text: I18n.t('terms.uninstalling', target: target)
|
||||
}
|
||||
end
|
||||
render json: alerts
|
||||
end
|
||||
end
|
||||
@ -5,26 +5,6 @@ module ApplicationHelper
|
||||
Plugin.gemfile_changed?
|
||||
end
|
||||
|
||||
def installing_gem?
|
||||
installing_gems.length > 0
|
||||
end
|
||||
|
||||
def installing_gems
|
||||
Plugin::WORKING.find_all do |data|
|
||||
data[:type] == :install && data[:state] == :running
|
||||
end.map{|data| data[:plugin]} || []
|
||||
end
|
||||
|
||||
def uninstalling_gem?
|
||||
uninstalling_gems.length > 0
|
||||
end
|
||||
|
||||
def uninstalling_gems
|
||||
Plugin::WORKING.find_all do |data|
|
||||
data[:type] == :uninstall && data[:state] == :running
|
||||
end.map{|data| data[:plugin]} || []
|
||||
end
|
||||
|
||||
def has_td_agent_system?
|
||||
File.exist?("/etc/init.d/td-agent")
|
||||
end
|
||||
|
||||
@ -24,6 +24,8 @@ en:
|
||||
new: New
|
||||
setup: "Setup %{target}"
|
||||
install_it: "Install %{target}"
|
||||
installing: "Installing: %{target}"
|
||||
uninstalling: "Uninstalling: %{target}"
|
||||
|
||||
plugins:
|
||||
common: &plugin_common
|
||||
|
||||
@ -24,6 +24,8 @@ ja:
|
||||
new: 新規作成
|
||||
setup: "%{target}をセットアップ"
|
||||
install_it: "%{target}をインストール"
|
||||
installing: "インストール中: %{target}"
|
||||
uninstalling: "アンインストール中: %{target}"
|
||||
|
||||
plugins:
|
||||
common: &plugin_common
|
||||
|
||||
@ -25,7 +25,12 @@ Rails.application.routes.draw do
|
||||
end
|
||||
end
|
||||
|
||||
resource :user, only: [:show, :edit, :update]
|
||||
|
||||
get "misc" => "misc#show"
|
||||
get "misc/information"
|
||||
resource :user, only: [:show, :edit, :update]
|
||||
|
||||
namespace :polling do
|
||||
get "alerts"
|
||||
end
|
||||
end
|
||||
|
||||
5
spec/controllers/polling_controller_spec.rb
Normal file
5
spec/controllers/polling_controller_spec.rb
Normal file
@ -0,0 +1,5 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe PollingController do
|
||||
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user