diff --git a/app/controllers/server/websites_controller.rb b/app/controllers/server/websites_controller.rb index 856ed06925a3da96d4103820a9965040a2b493a9..7ee0a9b20829620e9aed183e28459f30b67cfa3a 100644 --- a/app/controllers/server/websites_controller.rb +++ b/app/controllers/server/websites_controller.rb @@ -3,24 +3,13 @@ class Server::WebsitesController < Server::ApplicationController def index @websites = Communication::Website.all.ordered breadcrumb + add_breadcrumb Communication::Website.model_name.human(count: 2), server_websites_path end - def edit - @website = Communication::Website.find params[:id] - breadcrumb - add_breadcrumb @website - end - - def update + def refresh @website = Communication::Website.find params[:id] - @website.update_column :theme_version, params[:communication_website][:theme_version] + @website.get_current_theme_version! redirect_to server_websites_path end - protected - - def breadcrumb - super - add_breadcrumb Communication::Website.model_name.human(count: 2), server_websites_path - end end \ No newline at end of file diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index fbfb3ca4af288741bc2246c2cf88908ca8a2b28c..3fba5c493e1fe7f1fd7a8a8d0dbff1dad3107789 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -47,6 +47,7 @@ class Communication::Website < ApplicationRecord include WithProgramCategories include WithSpecialPages include WithStyle + include WithTheme enum git_provider: { github: 0, diff --git a/app/models/communication/website/with_style.rb b/app/models/communication/website/with_style.rb index 3d5172b77321c06f02baf1e992a2e370ebc53a0a..5eb1d00b28ea87c4f29aa9e1ffb0d7f32dffc58b 100644 --- a/app/models/communication/website/with_style.rb +++ b/app/models/communication/website/with_style.rb @@ -1,5 +1,5 @@ module Communication::Website::WithStyle - extend ActiveSupport::Concern + extend ActiveSupport::Concern def preview_style load_style if style_outdated? diff --git a/app/models/communication/website/with_theme.rb b/app/models/communication/website/with_theme.rb new file mode 100644 index 0000000000000000000000000000000000000000..ab6b6e332e5f85c4b80b9f9476ac7850718b0f33 --- /dev/null +++ b/app/models/communication/website/with_theme.rb @@ -0,0 +1,20 @@ +module Communication::Website::WithTheme + extend ActiveSupport::Concern + + def get_current_theme_version! + self.update_column :theme_version, current_theme_version + end + + def theme_version_url + return if url.blank? + "#{url}/osuny-theme-version" + end + + protected + + def current_theme_version + URI(theme_version_url).read + rescue + 'NA' + end +end \ No newline at end of file diff --git a/app/views/server/websites/edit.html.erb b/app/views/server/websites/edit.html.erb deleted file mode 100644 index bfa63d2db391e7360408b901898067caaec2109e..0000000000000000000000000000000000000000 --- a/app/views/server/websites/edit.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -<%= simple_form_for @website, url: server_website_path(@website) do |f| %> - <%= f.input :theme_version %> - <% content_for :action_bar_right do %> - <%= submit f %> - <% end %> -<% end %> \ No newline at end of file diff --git a/app/views/server/websites/index.html.erb b/app/views/server/websites/index.html.erb index 8576e5a665d1a48f1a4f14c8ac8b38c28e072d37..5995955a47cc2f074a3182a3cb58fd50c84e4761 100644 --- a/app/views/server/websites/index.html.erb +++ b/app/views/server/websites/index.html.erb @@ -11,20 +11,30 @@ <th><%= Communication::Website.human_attribute_name('in_production') %></th> <th><%= Communication::Website.human_attribute_name('theme_version') %></th> <th><%= University.model_name.human %></th> + <th></th> </tr> </thead> <tbody> <% @websites.each do |website| %> <tr> - <td><%= link_to website.name, edit_server_website_path(website) %></td> + <td> + <%= link_to website.name, edit_server_website_path(website) %> + </td> <td> <%= link_to website.url, website.url, target: :_blank if website.url.present? %> </td> - <td><%= t website.in_production %></td> <td> - <%= link_to website.theme_version, "#{website.url}/osuny-theme-version", target: :_blank if website.url.present? %> + <%= t website.in_production %> + </td> + <td> + <%= link_to website.theme_version, website.theme_version_url, target: :_blank if website.theme_version_url.present? %> + </td> + <td> + <%= link_to website.university, [:server, website.university] %> + </td> + <td> + <%= link_to "Sync version", refresh_server_website_path(website), method: :post, class: button_classes %> </td> - <td><%= link_to website.university, [:server, website.university] %></td> </tr> <% end %> </tbody> diff --git a/config/routes/server.rb b/config/routes/server.rb index 394797b297e66a17d1a60e96183e9301b2358de5..02c1e75ce39a8aed4bc722be545120b88291a08a 100644 --- a/config/routes/server.rb +++ b/config/routes/server.rb @@ -1,5 +1,11 @@ namespace :server do - resources :universities, :languages, :websites + resources :universities + resources :languages + resources :websites do + member do + post :refresh + end + end get 'blocks' => 'blocks#index', as: :blocks get 'blocks/:id' => 'blocks#show', as: :block post 'blocks/:id' => 'blocks#resave', as: :resave_block