Skip to content

Commit

Permalink
Merge pull request #145 from slovensko-digital/SD-2693/project-regist…
Browse files Browse the repository at this point in the history
…er-internal

SD-2693/project-register-internal
  • Loading branch information
celuchmarek authored Jun 24, 2024
2 parents c6c8e48 + e52e518 commit 3fb5c10
Show file tree
Hide file tree
Showing 72 changed files with 2,253 additions and 548 deletions.
5 changes: 5 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ REDFLAGS_FAQ_PAGE_ID=4410
REDFLAGS_STATS_PAGE_ID=8778

ROLLBAR_ACCESS_TOKEN=

GOOGLE_APPLICATION_CREDENTIALS=
GOOGLE_SHEET_ID=
GOOGLE_SHEET_EXPORT_ID=
GOOGLE_SHEET_SCRIPT_URL=
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ gem 'annotate'
gem 'rollbar'
gem 'oj'

# Use Google API gems
gem 'google-apis-docs_v1'
gem 'google-apis-drive_v3'
gem 'google-apis-sheets_v4'

group :development, :test do
gem 'dotenv-rails'
gem 'rspec-rails'
Expand Down
62 changes: 55 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ GEM
arel (8.0.0)
autoprefixer-rails (9.7.6)
execjs
base64 (0.2.0)
bindex (0.8.1)
bootstrap (4.0.0)
autoprefixer-rails (>= 6.0.3)
Expand Down Expand Up @@ -75,10 +76,11 @@ GEM
crack (0.4.3)
safe_yaml (~> 1.0.0)
crass (1.0.6)
declarative (0.0.20)
diff-lcs (1.3)
discourse_api (0.40.0)
faraday (~> 0.9)
faraday_middleware (~> 0.10)
discourse_api (1.1.0)
faraday (~> 1.0)
faraday_middleware (~> 1.0)
rack (>= 1.6)
docile (1.3.2)
dotenv (2.7.5)
Expand All @@ -93,17 +95,41 @@ GEM
factory_bot_rails (5.2.0)
factory_bot (~> 5.2.0)
railties (>= 4.2.0)
faraday (0.17.3)
faraday (1.0.1)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.14.0)
faraday (>= 0.7.4, < 1.0)
faraday_middleware (1.2.0)
faraday (~> 1.0)
ffi (1.12.2)
font-awesome-rails (4.7.0.5)
railties (>= 3.2, < 6.1)
foreman (0.87.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
google-apis-core (0.15.0)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 1.9)
httpclient (>= 2.8.1, < 3.a)
mini_mime (~> 1.0)
representable (~> 3.0)
retriable (>= 2.0, < 4.a)
rexml
google-apis-docs_v1 (0.27.0)
google-apis-core (>= 0.15.0, < 2.a)
google-apis-drive_v3 (0.51.0)
google-apis-core (>= 0.15.0, < 2.a)
google-apis-sheets_v4 (0.32.0)
google-apis-core (>= 0.15.0, < 2.a)
google-cloud-env (2.1.1)
faraday (>= 1.0, < 3.a)
googleauth (1.11.0)
faraday (>= 1.0, < 3.a)
google-cloud-env (~> 2.1)
jwt (>= 1.4, < 3.0)
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
hashdiff (1.0.1)
httpclient (2.8.3)
i18n (1.8.2)
concurrent-ruby (~> 1.0)
jbuilder (2.10.0)
Expand All @@ -113,6 +139,8 @@ GEM
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.3.0)
jwt (2.8.1)
base64
kaminari (1.2.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.1)
Expand All @@ -138,14 +166,16 @@ GEM
mini_mime (1.0.2)
mini_portile2 (2.7.1)
minitest (5.14.1)
multi_json (1.15.0)
multipart-post (2.1.1)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
nio4r (2.5.8)
nio4r (2.7.3)
nokogiri (1.13.1)
mini_portile2 (~> 2.7.0)
racc (~> 1.4)
oj (3.10.6)
os (1.1.4)
pg (0.21.0)
popper_js (1.16.0)
public_suffix (4.0.6)
Expand Down Expand Up @@ -190,6 +220,13 @@ GEM
rb-inotify (0.10.1)
ffi (~> 1.0)
regexp_parser (1.7.0)
representable (3.2.0)
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rexml (3.2.8)
strscan (>= 3.0.9)
rollbar (2.25.0)
rspec-core (3.9.2)
rspec-support (~> 3.9.3)
Expand Down Expand Up @@ -222,6 +259,11 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
signet (0.19.0)
addressable (~> 2.8)
faraday (>= 0.17.5, < 3.a)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
simplecov (0.17.1)
docile (~> 1.1)
json (>= 1.8, < 3)
Expand All @@ -243,14 +285,17 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
strscan (3.1.0)
thor (1.0.1)
thread_safe (0.3.6)
tilt (2.0.10)
trailblazer-option (0.1.2)
turbolinks (5.2.1)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
tzinfo (1.2.7)
thread_safe (~> 0.1)
uber (0.1.0)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
vcr (6.0.0)
Expand Down Expand Up @@ -284,6 +329,9 @@ DEPENDENCIES
factory_bot_rails
font-awesome-rails
foreman
google-apis-docs_v1
google-apis-drive_v3
google-apis-sheets_v4
jbuilder (~> 2.5)
jquery-rails
kaminari
Expand Down
19 changes: 19 additions & 0 deletions app/assets/javascripts/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,22 @@ $(document).on('ready turbolinks:load', function () {
$('[data-toggle="tooltip"]').tooltip();
$('.tag-tooltip').tooltip();
});

$(document).ready(function(){
$('[data-toggle="collapse"]').on('click', function() {
$(this).find('.collapsed,.expanded').toggleClass('d-none');
});
});

document.addEventListener("turbolinks:load", function() {
document.addEventListener("turbolinks:load", function() {
if (!window.printCalled && window.location.pathname.endsWith("/pdf")) {
window.printCalled = true;
window.print();
}
});

document.addEventListener("turbolinks:before-render", function() {
window.printCalled = false;
});
});
34 changes: 21 additions & 13 deletions app/controllers/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,67 @@ class Admin::PagesController < AdminController
before_action :load_page, only: [:show, :preview, :publish, :unpublish, :sync_one]

def index
@pages = Page.order(id: :desc).page(params[:page])
@projects = @pages.map { |page| Project.find_by(page: page) }
@pages = Page.includes(phase: :project).order(id: :desc)
@projects = @pages.map { |page| page.phase.project }.uniq
end

def show
@revisions = @page.revisions.order(version: :desc).page(params[:page])
@project = Project.find_by(page: @page)
@project = @page.phase.project
end

def preview
@project = Project.find_by(page: @page)
@phase = @page.phase

if @project.present?
if params['version'] == 'latest'
@revision = ProjectRevision.find_by!(revision: @page.latest_revision)
@phase_revision = @phase.revisions.find_by!(revision: @page.latest_revision)
else
@revision = ProjectRevision.joins(:project, :revision).find_by!(projects: { page: @page }, revisions: { version: params['version'] })
@phase_revision = @phase.revisions.find_by!(revision: @page.revisions.where(version: params['version']))
end

@ratings_by_type = @revision.ratings.index_by(&:rating_type)
@ratings_by_type = @phase.revisions.ratings.index_by(&:rating_type)
else
if params['version'] == 'latest'
@revision = @page.latest_revision
@phase_revision = PhaseRevision.find_by(revision: @page.latest_revision)
else
@revision = @page.revisions.find_by!(version: params['version'])
@phase_revision = PhaseRevision.joins(:revision)
.find_by(revisions: { version: params['version'] })
end
end
end

def publish
if params['version'] == 'latest'
@page.update!(published_revision: @page.latest_revision)
revision = @page.latest_revision
@page.update!(published_revision: revision)
else
@page.update!(published_revision: @page.revisions.find_by!(version: params['version']))
revision = @page.revisions.find_by!(version: params['version'])
@page.update!(published_revision: revision)
end

@page.publish_and_enqueue_jobs(revision)

redirect_back fallback_location: { action: :index }
end

def unpublish
revision_id = @page.published_revision.id if @page.published_revision.present?

@page.update!(published_revision: nil)
@page.unpublish_and_enqueue_jobs(revision_id)

redirect_back fallback_location: { action: :index }
end

def sync
SyncCategoryTopicsJob.perform_later(ENV.fetch('REDFLAGS_CATEGORY_SLUG'))
SyncAllTopicsJob.perform_later

redirect_back fallback_location: { action: :index }
end

def sync_one
SyncTopicJob.perform_later(@page.id)
SyncOneTopicJob.perform_later(@page.id)

redirect_back fallback_location: { action: :index }
end
Expand Down
11 changes: 1 addition & 10 deletions app/controllers/admin/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
class Admin::ProjectsController < AdminController
before_action :load_project, only: [:update]

def update
@project.update!(project_params)
redirect_to admin_page_path(@project.page)
end
before_action :load_project

private

def load_project
@project = Project.find(params[:id])
end

def project_params
params.require(:project).permit(:category)
end
end
43 changes: 43 additions & 0 deletions app/controllers/phase_revision_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class PhaseRevisionController < ApplicationController
def show
@project = Project.find_by!(id: params[:project_id])
@phase_revision = PhaseRevision.find_published_revision(@project.id, params[:revision_type])

if @phase_revision
@revision = @phase_revision.revision
@ratings_by_type = @phase_revision.ratings.index_by(&:rating_type)
@metadata.og.title = @revision.title
@metadata.og.description = 'Kolaboratívne hodnotenie projektu metodikou Red Flags.'

render :show
end
end

def pdf
@project = Project.find_by!(id: params[:project_id])
@phase_revision = PhaseRevision.find_published_revision(@project.id, params[:revision_type])

if @phase_revision
@revision = @phase_revision.revision
@ratings_by_type = @phase_revision.ratings.index_by(&:rating_type)
@metadata.og.title = @revision.title
@metadata.og.description = 'Kolaboratívne hodnotenie projektu metodikou Red Flags.'

render layout: "no_header_footer"
end
end

def show_history
@project = Project.find_by!(id: params[:project_id])
@phase_revision = PhaseRevision.find_revision_history(@project.id, params[:revision_type], params[:version])

if @phase_revision
@revision = @phase_revision.revision
@ratings_by_type = @phase_revision.ratings.index_by(&:rating_type)
@metadata.og.title = @revision.title
@metadata.og.description = 'Kolaboratívne hodnotenie projektu metodikou Red Flags.'

render :show
end
end
end
10 changes: 1 addition & 9 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
class ProjectsController < ApplicationController
def show
@project = Project.find(params[:id]).published_revision
@ratings_by_type = @project.ratings.index_by(&:rating_type)
@metadata.og.title = @project.title
@metadata.og.description = 'Kolaboratívne hodnotenie projektu metodikou Red Flags.'
end

def index
@selected_tag = params[:tag]
@projects = Project.published
@projects = @projects.with_tag(params[:tag]) if ProjectsHelper::ALLOWED_TAGS.keys.include?(params[:tag])
@projects = @projects.map { |p| p.published_revision }.sort_by(&:aggregated_rating)
@projects = Project.filtered_projects(@selected_tag, params[:sort])
end
end
6 changes: 3 additions & 3 deletions app/controllers/static_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class StaticController < ApplicationController
def index
top_projects = Project.published.joins(:published_revision).limit(5)
top_project_revisions = PhaseRevision.where(published: true).joins(:revision).limit(5)

@good_projects = top_projects.good.order('redflags_count ASC, total_score::float / maximum_score DESC').map(&:published_revision)
@bad_projects = top_projects.bad.order('redflags_count DESC, total_score::float / maximum_score ASC').map(&:published_revision)
@good_projects = top_project_revisions.where('phase_revisions.redflags_count = ?', 0).order('phase_revisions.total_score::float / phase_revisions.maximum_score DESC')
@bad_projects = top_project_revisions.order('phase_revisions.redflags_count DESC, phase_revisions.total_score::float / phase_revisions.maximum_score ASC')
end

def about
Expand Down
9 changes: 6 additions & 3 deletions app/helpers/previews_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ def page_preview?(page)
end

def revision_preview?(revision)
return true unless Project.exists?(page: revision.page)
project_revision = ProjectRevision.where(revision: revision).first
project_revision && !project_revision.total_score_percentage.nan?
return true unless revision.phase_revision&.phase&.project.present?

phase_revision = revision.phase_revision
return false if phase_revision.nil?

phase_revision.total_score.present? && !phase_revision.total_score_percentage.nan?
end
end
Loading

0 comments on commit 3fb5c10

Please sign in to comment.