Skip to content

Commit

Permalink
Added parts of syncing google drafts from metais PR
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasdrga committed Dec 9, 2024
1 parent 1a19cc6 commit 41c3041
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
3 changes: 2 additions & 1 deletion app/controllers/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def preview
@phase_revision = @phase.revisions.find_by(revision: @page.revisions.find_by(version: params['version']))
end
@ratings_by_type = @phase_revision.ratings.index_by(&:rating_type)

@project = @phase.project

else
if params['version'] == 'latest'
@phase_revision = @page.latest_revision
Expand Down
12 changes: 10 additions & 2 deletions app/jobs/sync_all_topics_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class SyncAllTopicsJob < ApplicationJob
queue_as :default

COLUMN_NAMES = ['Projekt', 'Projekt ID', 'Platforma', 'ID draft prípravy', 'ID prípravy', 'ID draft produktu', 'ID produktu'].freeze
COLUMN_NAMES = ['Projekt', 'Projekt ID', 'MetaIS', 'Platforma', 'ID draft prípravy', 'ID prípravy', 'ID draft produktu', 'ID produktu'].freeze

def perform(sync_all: true)
sheets_service = GoogleApiService.get_sheets_service
Expand All @@ -23,12 +23,20 @@ def find_indices(header_row)
def process_row(row, indices, sync_all)
project_name = row[indices["Projekt"]]
project_id = row[indices["Projekt ID"]]
project_metais_code = row[indices["MetaIS"]]
platform_link = row[indices["Platforma"]]
preparation_document_id = row[indices["ID draft prípravy"]]
preparation_page_id = row[indices["ID prípravy"]]
product_document_id = row[indices["ID draft produktu"]]
product_page_id = row[indices["ID produktu"]]


if project_metais_code.present?
project = Project.find_or_initialize_by(id: project_id)
project.metais_code = project_metais_code
project.save!
end

if sync_all
process_row_for_sync_all(project_name, project_id, platform_link, preparation_document_id, preparation_page_id, product_document_id, product_page_id)
else
Expand Down Expand Up @@ -64,4 +72,4 @@ def has_template_name?(document_id)
document_name = GoogleApiService.get_document(document_id)&.title
document_name == 'Kópia dokumentu RF-priprava-template' || document_name == 'Kópia dokumentu RF-produkt-template'
end
end
end
4 changes: 2 additions & 2 deletions app/jobs/sync_one_topic_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def process_row(row, indices, target_id)
product_page_id = row[indices["ID produktu"]]

if target_id == preparation_page_id.to_i
if platform_link != ''
if platform_link == 'Platforma link'
SyncTopicJob.perform_now(project_id, preparation_page_id)
else
enqueue_job_for_update("#{project_name} - Príprava", project_id, preparation_document_id, preparation_page_id, 'Prípravná fáza')
Expand All @@ -54,4 +54,4 @@ def has_template_name?(document_id)
document_name = GoogleApiService.get_document(document_id)&.title
document_name == 'Kópia dokumentu RF-priprava-template' || document_name == 'Kópia dokumentu RF-produkt-template'
end
end
end
1 change: 0 additions & 1 deletion app/views/admin/pages/preview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
</div>

<% if @phase.present? %>
<% @project = @phase_revision %>
<%= render file: 'phase_revision/show' %>
<% else %>
<% @page = @phase_revision %>
Expand Down
25 changes: 14 additions & 11 deletions spec/jobs/sync_all_topics_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@
[
[],
[],
['Projekt', 'Projekt ID', 'Platforma', 'ID draft prípravy', 'ID prípravy', 'ID draft produktu', 'ID produktu'],
['Projekt1', 'ABC1', '', 'ABC1', 'ABC1', 'ABC1', 'ABC1'],
['Projekt2', 'ABC2', '', 'ABC2', 'ABC2', 'ABC2', 'ABC2']
['Projekt', 'Projekt ID', 'MetaIS', 'Platforma', 'ID draft prípravy', 'ID prípravy', 'ID draft produktu', 'ID produktu'],
['Projekt1', 1, '', '', 'ABC1', 'ABC1', 'ABC1', 'ABC1'],
['Projekt2', 2, 'projekt_2741', '', 'ABC2', 'ABC2', 'ABC2', 'ABC2']
]
end

let(:indices) { { 'Projekt' => 0, 'Projekt ID' => 1, 'Platforma' => 2, 'ID draft prípravy' => 3, 'ID prípravy' => 4, 'ID draft produktu' => 5, 'ID produktu' => 6 } }
let(:indices) { { 'Projekt' => 0, 'Projekt ID' => 1, 'MetaIS' => 2,'Platforma' => 3, 'ID draft prípravy' => 4, 'ID prípravy' => 5, 'ID draft produktu' => 6, 'ID produktu' => 7 } }

before do
Project.create(id: 1)
Project.create(id: 2)

mock_document = instance_double("Google::Apis::DocsV1::Document")
allow(mock_document).to receive(:title).and_return("Dokument RF-priprava-template")
allow(GoogleApiService).to receive(:get_document).and_return(mock_document)
Expand All @@ -45,8 +48,8 @@
[],
[],
['Projekt'],
['Projekt1', 'ABC1', '', 'ABC1', 'ABC1', 'ABC1', 'ABC1'],
['Projekt2', 'ABC2', 'http://google.com', 'ABC2', 'ABC2', 'ABC2', 'ABC2']
['Projekt1', 1, '', 'ABC1', 'ABC1', 'ABC1', 'ABC1'],
['Projekt2', 2, 'projekt_2741', 'http://google.com', 'ABC2', 'ABC2', 'ABC2', 'ABC2']
]
end

Expand All @@ -61,7 +64,7 @@
[
[],
[],
['Projekt', 'Projekt ID', 'Platforma', 'ID draft prípravy', 'ID prípravy', 'ID draft produktu', 'ID produktu']
['Projekt', 'Projekt ID', 'MetaIS', 'Platforma', 'ID draft prípravy', 'ID prípravy', 'ID draft produktu', 'ID produktu']
]
end

Expand All @@ -76,9 +79,9 @@
[
[],
[],
['Projekt', 'Projekt ID', 'Platforma', 'ID draft prípravy', 'ID prípravy', 'ID draft produktu', 'ID produktu'],
['Projekt1', 'ABC1', '', 'ABC1', '', 'ABC1', ''],
['Projekt2', 'ABC2', 'http://google.com', 'ABC2', 'ABC2', 'ABC2', 'ABC2']
['Projekt', 'Projekt ID', 'MetaIS', 'Platforma', 'ID draft prípravy', 'ID prípravy', 'ID draft produktu', 'ID produktu'],
['Projekt1', 1, '', '', 'ABC1', '', 'ABC1', ''],
['Projekt2', 2, 'projekt_2741', 'http://google.com', 'ABC2', 'ABC2', 'ABC2', 'ABC2']
]
end

Expand All @@ -88,4 +91,4 @@
described_class.perform_now
end
end
end
end
2 changes: 1 addition & 1 deletion spec/jobs/sync_one_topic_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[],
['Projekt', 'Projekt ID', 'Platforma', 'ID draft prípravy', 'ID prípravy', 'ID draft produktu', 'ID produktu'],
['Projekt1', 'ABC1', '', 'ABC1', 'ABC1', 'ABC1', 'ABC1'],
['Projekt2', 'ABC2', 'http://google.com', 'ABC2', 'ABC2', 'ABC2', 'ABC2']
['Projekt2', 'ABC2', 'Platforma link', 'ABC2', 'ABC2', 'ABC2', 'ABC2']
]
end

Expand Down

0 comments on commit 41c3041

Please sign in to comment.