Skip to content
Snippets Groups Projects
Unverified Commit 5f387b71 authored by Pierre-André Boissinot's avatar Pierre-André Boissinot Committed by GitHub
Browse files

Merge pull request #1622 from noesya/server_locales

Ajustements de la partie Server
parents 2323d066 3d751a27
No related branches found
No related tags found
No related merge requests found
Showing
with 162 additions and 67 deletions
......@@ -25,7 +25,7 @@ window.osuny.websites.batchSyncThemes = {
window.addEventListener('DOMContentLoaded', function () {
'use strict';
if (document.body.classList.contains('websites-manage_versions')) {
if (document.body.classList.contains('websites-index')) {
window.osuny.websites.batchSyncThemes.init();
}
});
class Server::BlocksController < Server::ApplicationController
before_action :load_template, except: [:index]
def index
@templates = Communication::Block.template_kinds.keys
@templates = Kaminari.paginate_array(Communication::Block.template_kinds.keys.sort_by { |k| t("enums.communication.block.template_kind.#{k}") }).page(params[:page])
breadcrumb
end
def show
@blocks = @blocks.page(params[:page])
breadcrumb
add_breadcrumb t("enums.communication.block.template_kind.#{@template}")
end
def resave
@blocks.find_each &:save
redirect_to server_block_path(@template), notice: "#{@blocks.count} blocks saved"
@blocks.find_each(&:save)
redirect_back fallback_location: server_block_path(@template), notice: t('server_admin.blocks.blocks_saved', count: @blocks.count)
end
protected
......@@ -27,4 +29,5 @@ class Server::BlocksController < Server::ApplicationController
super
add_breadcrumb Communication::Block.model_name.human(count: 2), server_blocks_path
end
end
class Server::DashboardController < Server::ApplicationController
def index
@parts = [
{
title: "#{University.count} #{University.model_name.human(count: 2).downcase}",
title: "#{University.count} #{University.model_name.human(count: University.count).downcase}",
path: server_universities_path
},
{
title: "#{Communication::Website.count} #{Communication::Website.model_name.human(count: 2).downcase}",
title: "#{Communication::Website.count} #{Communication::Website.model_name.human(count: Communication::Website.count).downcase}",
path: server_websites_path
}
]
@websites = Communication::Website.updatable_theme.ordered
@websites = Communication::Website.for_older_theme_version(Osuny::ThemeInfo.get_current_version).ordered
breadcrumb
end
end
class Server::EmergencyMessagesController < Server::ApplicationController
load_and_authorize_resource
def index
@emergency_messages = @emergency_messages.reorder(created_at: :desc)
@emergency_messages = @emergency_messages.ordered.page(params[:page])
breadcrumb
end
......
class Server::LanguagesController < Server::ApplicationController
load_and_authorize_resource
def index
@languages = @languages.ordered.page(params[:page])
breadcrumb
end
......@@ -59,4 +61,5 @@ class Server::LanguagesController < Server::ApplicationController
def language_params
params.require(:language).permit(:name, :iso_code, :summernote_locale)
end
end
class Server::UniversitiesController < Server::ApplicationController
load_and_authorize_resource
def index
@universities = @universities.ordered
@universities = @universities.ordered.page(params[:page])
breadcrumb
end
......@@ -67,4 +68,5 @@ class Server::UniversitiesController < Server::ApplicationController
:is_really_a_university
)
end
end
class Server::WebsitesController < Server::ApplicationController
before_action :load_websites, only: [:index, :manage_versions, :clean_and_rebuild_all_websites]
before_action :load_website, except: [:index, :manage_versions, :clean_and_rebuild_all_websites]
before_action :load_websites, only: [:index, :clean_and_rebuild_all_websites]
before_action :load_website, except: [:index, :clean_and_rebuild_all_websites]
has_scope :for_theme_version
has_scope :for_production
......@@ -9,21 +10,15 @@ class Server::WebsitesController < Server::ApplicationController
has_scope :for_updatable_theme
def index
@websites = @websites.ordered.page(params[:page]).per(100)
breadcrumb
end
def manage_versions
@websites = @websites.with_repository.with_url
load_filters
breadcrumb
add_breadcrumb "Gestion des versions"
end
def clean_and_rebuild_all_websites
@websites.find_each do |website|
website.clean_and_rebuild
end
redirect_back(fallback_location: manage_versions_server_websites_path, notice: t('server_admin.websites.clean_and_rebuild_all_websites_notice'))
redirect_back(fallback_location: server_websites_path, notice: t('server_admin.websites.clean_and_rebuild_all_websites_notice'))
end
def sync_theme_version
......@@ -36,7 +31,11 @@ class Server::WebsitesController < Server::ApplicationController
def show
breadcrumb
add_breadcrumb @website
end
def edit
breadcrumb
add_breadcrumb t('edit')
end
def update
......@@ -50,6 +49,9 @@ class Server::WebsitesController < Server::ApplicationController
def breadcrumb
super
add_breadcrumb Communication::Website.model_name.human(count: 2), server_websites_path
if @website
add_breadcrumb @website, server_website_path(@website)
end
end
def load_websites
......@@ -59,4 +61,5 @@ class Server::WebsitesController < Server::ApplicationController
def load_website
@website = Communication::Website.find params[:id]
end
end
......@@ -88,7 +88,6 @@ class Communication::Website < ApplicationRecord
scope :ordered, -> { order(:name) }
scope :in_production, -> { where(in_production: true) }
scope :for_production, -> (production) { where(in_production: production) }
scope :for_theme_version, -> (version) { where(theme_version: version) }
scope :for_search_term, -> (term) {
where("
unaccent(communication_websites.name) ILIKE unaccent(:term) OR
......@@ -96,15 +95,8 @@ class Communication::Website < ApplicationRecord
", term: "%#{sanitize_sql_like(term)}%")
}
scope :for_update, -> (autoupdate) { where(autoupdate_theme: autoupdate) }
scope :for_updatable_theme, -> (status) { updatable_theme if status == 'true' }
scope :with_repository, -> { where.not(repository: [nil, '']) }
scope :with_url, -> { where.not(url: [nil, '']) }
scope :with_access_token, -> { where.not(access_token: [nil, '']) }
scope :updatable_theme, -> {
with_repository.
with_url.
with_access_token
}
def to_s
"#{name}"
......
......@@ -7,6 +7,9 @@ module Communication::Website::WithGitRepository
dependent: :destroy
after_save :destroy_obsolete_git_files, if: :should_clean_on_git?
scope :with_repository, -> { where.not(repository: [nil, '']) }
end
def git_repository
......
......@@ -5,6 +5,11 @@ module Communication::Website::WithTheme
scope :with_automatic_update, -> { where(autoupdate_theme: true) }
scope :with_manual_update, -> { where(autoupdate_theme: false) }
scope :for_theme_version, -> (version) { where(theme_version: version) }
scope :for_older_theme_version, -> (version) { where.not(theme_version: version) }
scope :for_updatable_theme, -> (status) { updatable_theme if status == 'true' }
scope :updatable_theme, -> { with_repository.with_url.with_access_token }
def self.autoupdate_websites
Communication::Website.with_automatic_update.find_each do |website|
website.update_theme_version
......@@ -21,6 +26,10 @@ module Communication::Website::WithTheme
"#{url}/osuny-theme-version"
end
def theme_updatable?
repository.present? && url.present? && access_token.present?
end
protected
def current_theme_version
......
......@@ -28,6 +28,8 @@ class EmergencyMessage < ApplicationRecord
validates :name, :subject_fr, :subject_en, :content_fr, :content_en, presence: true
scope :ordered, -> { order(created_at: :desc) }
def deliver!
users_fr = target.where(language_id: Language.find_by(iso_code: 'fr').id)
users_fr.each do |user|
......
......@@ -5,7 +5,7 @@ module University::WithInvoice
before_save :denormalize_invoice_date
scope :contributing, -> { where.not(contribution_amount: [nil, 0.0]) }
scope :contributing, -> { where.not(contribution_amount: [nil, 0.0, '', 0]) }
def invoice_proximity
if next_invoice_in_days < 30
......
......@@ -3,19 +3,53 @@ module Filters
def initialize(user)
super
add_search
add_for_theme_version
add_for_update
add_for_updatable_theme
end
private
def add_for_theme_version
add :for_theme_version,
::Communication::Website.all.pluck(:theme_version).uniq.sort,
'Filtrer par version du thème'
add :for_production,
[{ to_s: I18n.t('true'), id: 'true' }, { to_s: I18n.t('false'), id: 'false' }],
'Filtrer par état de production'
I18n.t(
'filters.attributes.element',
element: I18n.t('server_admin.websites.theme_version').downcase
)
add :for_production,
[
{ to_s: I18n.t('true'), id: 'true' },
{ to_s: I18n.t('false'), id: 'false' }
],
I18n.t(
'filters.attributes.element',
element: I18n.t('server_admin.websites.production_status').downcase
)
end
def add_for_update
add :for_update,
[{ to_s: 'Automatique', id: 'true' }, { to_s: 'Manuelle', id: 'false' }],
'Filtrer par mode de mise à jour'
add :for_updatable_theme,
[{ to_s: 'Mise à jour automatique possible', id: 'true' }],
'Filtrer par capacité de mise à jour automatique'
[
{ to_s: I18n.t('server_admin.websites.autoupdate_theme.true'), id: 'true' },
{ to_s: I18n.t('server_admin.websites.autoupdate_theme.false'), id: 'false' }
],
I18n.t(
'filters.attributes.element',
element: I18n.t('server_admin.websites.update_mode').downcase
)
end
def add_for_updatable_theme
add :for_updatable_theme,
[
{ to_s: I18n.t('server_admin.websites.updatable_theme_filter.value'), id: 'true' }
],
I18n.t(
'filters.attributes.element',
element: I18n.t('server_admin.websites.updatable_theme_filter.element').downcase
)
end
end
end
......@@ -124,7 +124,7 @@ class Git::Providers::Github < Git::Providers::Abstract
end
def current_theme_sha
@current_theme_sha ||= client.branch(ENV["GITHUB_WEBSITE_THEME_REPOSITORY"], ENV["GITHUB_WEBSITE_THEME_BRANCH"])[:commit][:sha]
@current_theme_sha ||= Osuny::ThemeInfo.get_current_sha
end
def tree_item_at_path(path)
......
class Osuny::ThemeInfo
def self.get_current_version
@last_version ||= client.releases(ENV["GITHUB_WEBSITE_THEME_REPOSITORY"]).first[:tag_name]
end
def self.get_current_sha
@current_theme_sha ||= client.branch(ENV["GITHUB_WEBSITE_THEME_REPOSITORY"], ENV["GITHUB_WEBSITE_THEME_BRANCH"])[:commit][:sha]
end
private
def self.client
@client ||= Octokit::Client.new access_token: ENV["GITHUB_ACCESS_TOKEN"]
end
end
......@@ -4,8 +4,8 @@
<table class="<%= table_classes %>">
<thead>
<tr>
<th><%= Communication::Block.human_attribute_name('name') %></th>
<th><%= Communication::Block.human_attribute_name('quantity') %></th>
<th><%= t('server_admin.blocks.title') %></th>
<th><%= t('server_admin.blocks.quantity') %></th>
</tr>
</thead>
<tbody>
......@@ -18,3 +18,5 @@
</tbody>
</table>
</div>
<%= paginate @templates, theme: 'bootstrap-5' %>
\ No newline at end of file
......@@ -4,43 +4,60 @@
<table class="<%= table_classes %>">
<thead>
<tr>
<th><%= Communication::Block.human_attribute_name('name') %></th>
<th><%= Communication::Block.human_attribute_name('about') %></th>
<th><%= Communication::Block.human_attribute_name('data') %></th>
<th><%= Communication::Block.human_attribute_name('university') %></th>
<th><%= Communication::Block.human_attribute_name('url') %></th>
<th><%= t('server_admin.blocks.title') %></th>
<th><%= t('server_admin.blocks.about') %></th>
<th><%= t('server_admin.blocks.data') %></th>
<th><%= University.model_name.human %></th>
<th><%= t('server_admin.blocks.url') %></th>
</tr>
</thead>
<tbody>
<% @blocks.each do |block| %>
<% next if block.about.nil?%>
<% url = "#{block.about.university.url }#{edit_admin_communication_block_path(block)}" %>
<tr>
<td>
<%= truncate "#{block}" %><br>
<small><%= block.id %></small>
</td>
<td>
<%= truncate "#{block.about}" %>
<span class="badge bg-dark">
<%= block.about.class.model_name.human %>
</span>
<% if block.about.present? %>
<%= truncate "#{block.about}" %>
<span class="badge bg-dark">
<%= block.about.class.model_name.human %>
</span>
<% end %>
</td>
<td class="pe-3" width="600">
<%= link_to t('server_admin.blocks.see'),
"#collpase-#{block.id}",
class: 'btn btn-xs btn-light',
role: 'button',
'data-bs-toggle': 'collapse',
'aria-expanded': 'false',
'aria-controls': "collpase-#{block.id}" %>
<div class="collapse" id="collpase-<%= block.id %>">
<textarea rows="10" class="form-control"><%= block.data %></textarea>
</div>
</td>
<td>
<%= link_to block.university, [:server, block.university] %>
</td>
<td>
<textarea rows="1" class="form-control"><%= block.data %></textarea>
<% url = "#{block.university.url }#{edit_admin_communication_block_path(block)}" %>
<%= link_to t('server_admin.blocks.open'),
url,
target: :_blank %>
</td>
<td><%= block.about.university %></td>
<td><%= link_to 'Open',
url,
target: :_blank %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<%= paginate @blocks, theme: 'bootstrap-5' %>
<% content_for :action_bar_right do %>
<%= link_to t('resave'),
<%= link_to t('server_admin.blocks.resave'),
resave_server_block_path(@template),
method: :post,
class: button_classes %>
......
......@@ -4,12 +4,14 @@
<% @parts.each do |part| %>
<div class="col-md-6 d-flex">
<%= osuny_panel part[:title] do %>
<%= link_to 'Voir la liste', part[:path], class: 'btn btn-sm btn-primary stretched-link' %>
<%= link_to t('server_admin.see_list'), part[:path], class: 'btn btn-sm btn-primary stretched-link' %>
<% end %>
</div>
<% end %>
</div>
<%= osuny_panel 'Monitoring' do %>
<%= render 'server/websites/list', websites: @websites %>
<% end %>
<% if @websites.any? %>
<%= osuny_panel t('server_admin.websites.outdated') do %>
<%= render 'server/websites/list', websites: @websites %>
<% end %>
<% end %>
\ No newline at end of file
......@@ -14,15 +14,15 @@
<% @emergency_messages.each do |emergency_message| %>
<tr>
<td><%= link_to emergency_message, [:server, emergency_message] %></td>
<td><%= l emergency_message.delivered_at if emergency_message.delivered? %></td>
<td><%= l(emergency_message.delivered_at) if emergency_message.delivered? %></td>
<td class="text-end">
<div class="btn-group" role="group">
<% unless emergency_message.delivered? %>
<%= link_to t('edit'),
edit_server_emergency_message_path(emergency_message),
[:edit, :server, emergency_message],
class: button_classes %>
<%= link_to t('delete'),
server_emergency_message_path(emergency_message),
[:server, emergency_message],
method: :delete,
data: { confirm: t('please_confirm') },
class: button_classes_danger %>
......@@ -35,6 +35,9 @@
</table>
</div>
<%= paginate @emergency_messages, theme: 'bootstrap-5' %>
<% content_for :action_bar_right do %>
<%= link_to t('create'), new_server_emergency_message_path, class: button_classes %>
<% end %>
......@@ -46,9 +46,9 @@
<% content_for :action_bar_right do %>
<% unless @emergency_message.delivered? %>
<%= link_to t('edit'), edit_server_emergency_message_path(@emergency_message), class: button_classes %>
<%= link_to t('edit'), [:edit, :server, @emergency_message], class: button_classes %>
<%= link_to t('server_admin.emergency_messages.deliver'),
deliver_server_emergency_message_path(@emergency_message),
[:deliver, :server, @emergency_message],
method: :post,
data: { confirm: t('please_confirm') },
class: button_classes %>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment