Skip to content

Commit

Permalink
Merge pull request #8270 from dmarcoux/bootstrap-status-messages
Browse files Browse the repository at this point in the history
Replace Bento views by Bootstrap views for Webui::MainController
  • Loading branch information
dmarcoux committed Sep 4, 2019
2 parents 7759d53 + 7249f9c commit 9ac40a2
Show file tree
Hide file tree
Showing 25 changed files with 74 additions and 237 deletions.
36 changes: 19 additions & 17 deletions src/api/app/controllers/webui/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@
class Webui::MainController < Webui::WebuiController
skip_before_action :check_anonymous, only: [:index]

def gather_busy
busy = []
archs = Architecture.where(available: 1).map(&:worker).uniq
archs.each do |arch|
starttime = Time.now.to_i - 168.to_i * 3600
rel = StatusHistory.where("time >= ? AND \`key\` = ?", starttime, 'building_' + arch)
values = rel.pluck(:time, :value).collect! { |time, value| [time.to_i, value.to_f] }
values = StatusHelper.resample(values, 400)
if busy.empty?
busy = values
elsif values.present?
busy = add_arrays(busy, values)
end
end
busy
end

def index
@status_messages = StatusMessage.alive.includes(:user).limit(4).to_a
@workerstatus = Rails.cache.fetch('workerstatus_hash', expires_in: 10.minutes) do
Expand All @@ -45,4 +28,23 @@ def index

switch_to_webui2
end

private

def gather_busy
busy = []
archs = Architecture.where(available: 1).map(&:worker).uniq
archs.each do |arch|
starttime = Time.now.to_i - 168.to_i * 3600
rel = StatusHistory.where("time >= ? AND \`key\` = ?", starttime, 'building_' + arch)
values = rel.pluck(:time, :value).collect! { |time, value| [time.to_i, value.to_f] }
values = StatusHelper.resample(values, 400)
if busy.empty?
busy = values
elsif values.present?
busy = add_arrays(busy, values)
end
end
busy
end
end
8 changes: 0 additions & 8 deletions src/api/app/controllers/webui/status_messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ class Webui::StatusMessagesController < Webui::WebuiController
# permissions.status_message_create
before_action :require_admin, only: [:destroy, :create]

def create_status_message_dialog
render_dialog
end

def create
# TODO: make use of permissions.status_message_create
status_message = StatusMessage.new(message: params[:message], severity: params[:severity], user: User.session!)
Expand All @@ -19,10 +15,6 @@ def create
redirect_to(controller: 'main', action: 'index')
end

def destroy_status_message_dialog
render_dialog
end

def destroy
status_message = StatusMessage.find(params[:id])

Expand Down
18 changes: 0 additions & 18 deletions src/api/app/views/webui/main/_latest_updates.haml

This file was deleted.

14 changes: 8 additions & 6 deletions src/api/app/views/webui/main/_sponsors.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
- unless CONFIG['sponsors'].nil? or CONFIG['sponsors'].empty?
- if CONFIG['sponsors'].present?
- sponsor = CONFIG['sponsors'].sample
.box.box-shadow.centered
%h2.box-header Sponsor
= link_to(sprite_tag(sponsor['icon']), sponsor['url'], { title: sponsor['name'] })
%p
%em= sponsor['description']
.card.mb-3
%h5.card-header Sponsor
.card-body.text-center
%figure.figure.mb-0
= link_to(sprite_tag(sponsor['icon'], class: 'figure-img img-fluid'), sponsor['url'], title: sponsor['name'])
%figcaption.figure-caption
= sponsor['description']
43 changes: 15 additions & 28 deletions src/api/app/views/webui/main/_status_messages.html.haml
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
- if @status_messages.present? || User.admin_session?
.box.box-shadow#messages
%h2.box-header
Announcements
\#{link_to('', news_feed_path(format: 'rss'), { class: 'alignright icons-feeds', title: 'RSS Feed' })}
- @status_messages.each do |msg|
.grid_4.news-sender
= user_with_realname_and_icon msg.user, short: true
wrote #{time_ago_in_words(msg.created_at)} ago
.clear
.grid_4.box.news-message
- if User.admin_session?
= link_to(sprite_tag('comment_delete', title: 'Remove status message'),
{ controller: 'status_messages', action: 'destroy_status_message_dialog', id: msg.id },
{ remote: true, class: 'delete-message' })
- case msg.severity.to_i
- when 3
= sprite_tag('exclamation', alt: 'Red')
- when 2
= sprite_tag('error', alt: 'Yellow')
- when 1
= sprite_tag('accept', alt: 'Green')
- else
= sprite_tag('information', alt: 'Information')
= render_as_markdown(msg.message)
.clear
.card.mb-3
.card-header.d-flex.justify-content-between
%h5
News
.float-right
= link_to(news_feed_path(format: 'rss'), title: 'RSS Feed') do
%i.fa.fa-rss
.list-group
- @status_messages.each do |message|
= render partial: 'status_message', locals: { message: message }
- if User.admin_session?
%p
= link_to(sprite_tag('comment_add') + content_tag(:span, 'Add new status message', id: "add-new-message"), { controller: 'status_messages', action: 'create_status_message_dialog' }, { remote: true })
.card-footer
= link_to('#', 'data-toggle': 'modal', 'data-target': '#status-message-modal') do
%i.fas.fa-plus-circle.text-primary
Add status message
= render partial: 'add_status_message_modal'
23 changes: 0 additions & 23 deletions src/api/app/views/webui/main/_systemstatus.html.haml

This file was deleted.

6 changes: 3 additions & 3 deletions src/api/app/views/webui/main/about.html.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- @pagetitle = "About"
%h2 About
- @pagetitle = 'About'
%h2= @pagetitle
%p
This is the web interface for the #{@configuration['title']}.
%p
Check the
%a{ href: "http://openbuildservice.org" } Open Build Service project page
%a{ href: 'http://openbuildservice.org' } Open Build Service project page
for details about the software behind it.
57 changes: 28 additions & 29 deletions src/api/app/views/webui/main/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
- @pagetitle = 'Welcome'
- @layouttype = 'custom'
.grid_11.alpha
.box.box-shadow
%h1.mainhead
Welcome to #{@configuration['title']}
= raw @configuration['description']
%br/
%ul#proceed-list
- if User.admin_session?
= proceed_link 'configure', 'Configuration', controller: 'configuration', action: 'index'
= proceed_link 'list', 'All Projects', controller: 'project'
= proceed_link 'system-search', 'Search', controller: 'search', action: 'index'
- else
= proceed_link 'start-here', 'Your Home', user_show_path(User.session!) if User.session
= proceed_link 'list', 'All Projects', controller: 'project'
= proceed_link 'system-search', 'Search', controller: 'search', action: 'index'
= proceed_link "document-new", 'New Project', controller: 'project', action: 'new', ns: User.session!.home_project_name if User.session
- unless @spider_bot
= proceed_link 'utilities-system-monitor', 'Status Monitor', controller: 'monitor', action: 'index'
= proceed_link 'drive-optical-32', 'New Image', image_templates_path
= render partial: 'systemstatus'
.grid_5.omega
- if !User.session and can_register
.box.box-shadow
%h2.box-header New here? Sign up!
= render partial: 'shared/sign_up'
= render partial: 'sponsors'
= render partial: 'status_messages'
= render partial: 'latest_updates' if (@latest_updates and ::Configuration.anonymous)

.row
.col-md-8.col-lg-7
.card.mb-3
.card-body
%h2
Welcome to #{@configuration['title']}
-# rubocop:disable Rails/OutputSafety
= raw @configuration['description']
-# rubocop:enable Rails/OutputSafety
.row.no-gutters.text-center#proceed-list
= render partial: 'proceed-list'
= render(partial: 'system_status', locals: { busy: @busy,
building_workers: @building_workers,
overall_workers: @overall_workers,
waiting_packages: @waiting_packages,
host_title: @configuration['title'],
system_stats: @system_stats })
.col-md-4.col-lg-5
- if !User.session && can_register
.card.mb-3
%h5.card-header New here? Sign up!
.card-body
= render partial: 'webui2/shared/sign_up', locals: { submit_btn_text: 'Sign Up' }
= render partial: 'sponsors'
- if @status_messages.present? || User.admin_session?
= render partial: 'status_messages'
= render(partial: 'latest_updates') if @latest_updates && ::Configuration.anonymous

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions src/api/app/views/webui2/webui/main/_sponsors.html.haml

This file was deleted.

16 changes: 0 additions & 16 deletions src/api/app/views/webui2/webui/main/_status_messages.html.haml

This file was deleted.

8 changes: 0 additions & 8 deletions src/api/app/views/webui2/webui/main/about.html.haml

This file was deleted.

29 changes: 0 additions & 29 deletions src/api/app/views/webui2/webui/main/index.html.haml

This file was deleted.

7 changes: 1 addition & 6 deletions src/api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ def self.public_or_about_path?(request)
get 'main/systemstatus' => :systemstatus
end

resources :status_messages, only: [:create, :destroy], controller: 'webui/status_messages' do
collection do
get 'create_status_message_dialog' => :create_status_message_dialog
get 'destroy_status_message_dialog' => :destroy_status_message_dialog
end
end
resources :status_messages, only: [:create, :destroy], controller: 'webui/status_messages'

controller 'webui/feeds' do
get 'main/news' => :news, constraints: ->(req) { req.format == :rss }, as: :news_feed
Expand Down
16 changes: 0 additions & 16 deletions src/api/spec/controllers/webui/status_messages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,4 @@
end
end
end

describe 'GET #create_status_message_dialog' do
before do
get :create_status_message_dialog, xhr: true
end

it { is_expected.to respond_with(:success) }
end

describe 'GET #destroy_status_message_dialog' do
before do
get :destroy_status_message_dialog, xhr: true
end

it { is_expected.to respond_with(:success) }
end
end

0 comments on commit 9ac40a2

Please sign in to comment.