Skip to content

Commit

Permalink
sep data imports and exports
Browse files Browse the repository at this point in the history
  • Loading branch information
qinmingyuan committed Dec 5, 2023
1 parent ca0cda3 commit 57aca0f
Show file tree
Hide file tree
Showing 32 changed files with 220 additions and 94 deletions.
46 changes: 46 additions & 0 deletions app/controllers/datum/panel/data_exports_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Datum
class Panel::DataExportsController < Panel::BaseController
before_action :set_data_export, only: [:show, :edit, :update, :rebuild, :destroy]

def index
q_params = {}

@data_exports = DataExport.default_where(q_params).page(params[:page])
end

def sync
DataExport.sync
end

def rebuild
@data_export.rebuild!

redirect_back fallback_location: data_exports_url
end

def just_run
end

private
def set_data_export
@data_export = DataExport.find params[:id]
end

def data_export_params
result = params.fetch(:data_export, {}).permit(
:type,
:title,
:comment,
:data_table,
:export_excel,
:export_pdf,
parameters: [:column, :value] #todo key is original method of hash
)
_params = result['parameters']&.values&.map { |i| {i['column'] => i['value'] } }
_params = Array(_params).to_combine_h
result['parameters'] = _params
result
end

end
end
46 changes: 46 additions & 0 deletions app/controllers/datum/panel/data_imports_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Datum
class Panel::DataImportsController < Panel::BaseController
before_action :set_data_import, only: [:show, :edit, :update, :rebuild, :destroy]

def index
q_params = {}

@data_imports = DataImport.default_where(q_params).page(params[:page])
end

def sync
DataImport.sync
end

def rebuild
@data_import.rebuild!

redirect_back fallback_location: data_imports_url
end

def just_run
end

private
def set_data_import
@data_import = DataImport.find params[:id]
end

def data_import_params
result = params.fetch(:data_import, {}).permit(
:type,
:title,
:comment,
:data_table,
:export_excel,
:export_pdf,
parameters: [:column, :value] #todo key is original method of hash
)
_params = result['parameters']&.values&.map { |i| {i['column'] => i['value'] } }
_params = Array(_params).to_combine_h
result['parameters'] = _params
result
end

end
end
54 changes: 0 additions & 54 deletions app/controllers/datum/panel/data_lists_controller.rb

This file was deleted.

8 changes: 8 additions & 0 deletions app/controllers/datum/panel/home_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Datum
class Panel::HomeController < Panel::BaseController

def index
end

end
end
15 changes: 0 additions & 15 deletions app/models/datum/model/data_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,5 @@ def config_pdf
@config_pdf ||= export_pdf.to_s.safe_constantize
end

class_methods do
def sync
RailsExtend::Exports.exports.each do |klass|
r = Datum::DataExport.find_or_initialize_by(data_table: klass.to_s)
r.title = klass.name
r.save
end
RailsExtend::Exports.imports.each do |klass|
r = Datum::DataImport.find_or_initialize_by(data_table: klass.to_s)
r.title = klass.name
r.save
end
end
end

end
end
10 changes: 10 additions & 0 deletions app/models/datum/model/data_list/data_export.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
module Datum
module Model::DataList::DataExport
extend ActiveSupport::Concern

def just_run
end

class_methods do
def sync
RailsExtend::Exports.exports.each do |klass|
r = Datum::DataExport.find_or_initialize_by(data_table: klass.to_s)
r.title = klass.name
r.save
end
end
end

end
Expand Down
10 changes: 10 additions & 0 deletions app/models/datum/model/data_list/data_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,15 @@ def headers
export.columns.values.map(&->(i){ i[:header] })
end

class_methods do
def sync
RailsExtend::Exports.imports.each do |klass|
r = Datum::DataImport.find_or_initialize_by(data_table: klass.to_s)
r.title = klass.name
r.save
end
end
end

end
end
7 changes: 0 additions & 7 deletions app/views/datum/panel/base/_data_bar.html.erb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<%= f.select :type, options_for_select(Datum::DataList.options_i18n(:type), @data_list.type) %>
<%= f.text_field :title %>
<%= f.text_area :comment %>
<%= f.text_field :data_table %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<%= render 'data_bar' %>
<%= render 'index_bar' %>
<%= render 'index_actions' %>

<%= render layout: 'index_table' do %>
<%= render partial: 'index_tbody', layout: 'index_tr', collection: @data_lists, as: :model %>
<%= render partial: 'index_tbody', layout: 'index_tr', collection: @data_exports, as: :model %>
<% end %>
4 changes: 4 additions & 0 deletions app/views/datum/panel/data_imports/_button.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= button_to({ action: 'sync', **params.permit(:type) }, class: 'button is-small is-link') do %>
<i class="fa-solid fa-plus"></i>
<span class="pl-1"><%= t('.sync.title') %></span>
<% end %>
5 changes: 5 additions & 0 deletions app/views/datum/panel/data_imports/_edit_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= form_with model: @data_list, scope: :data_list, url: { action: 'update' } do |f| %>
<%= render partial: 'form', locals: { f: f } %>
<%= render partial: 'com/extra/item', locals: { model: @data_list, f: f } %>
<%= f.submit %>
<% end %>
5 changes: 5 additions & 0 deletions app/views/datum/panel/data_imports/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= f.text_field :title %>
<%= f.text_area :comment %>
<%= f.text_field :data_table %>
<%= f.text_field :export_excel %>
<%= f.text_field :export_pdf %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<td><%= link_to model.title, { controller: 'table_lists', data_list_id: model.id } %></td>
<td><%= model.comment %></td>
<td><%= model.data_table %></td>
<td><%= model.export_excel %></td>
<td><%= model.export_pdf %></td>
<td><%= simple_format_hash(model.parameters) %></td>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<th><%= Datum::DataList.human_attribute_name(:title) %></th>
<th><%= Datum::DataList.human_attribute_name(:comment) %></th>
<th><%= Datum::DataList.human_attribute_name(:data_table) %></th>
<th colspan="2">Export</th>
<th><%= Datum::DataList.human_attribute_name(:parameters) %></th>
18 changes: 18 additions & 0 deletions app/views/datum/panel/data_imports/_index/_index_tr.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<% if !defined?(rails_role_user) || rails_role_user.has_role?(controller_path: 'datum/panel/data_lists', action_name: 'read', id: model.id) %>
<tr id="tr_<%= model.id %>" data-controller="show" data-action="mouseenter->show#show mouseleave->show#hide">
<%= yield %>
<td>
<div data-show-target="item" style="visibility: hidden">
<%= button_to({ action: 'rebuild', id: model.id }, method: :patch, aria: { label: t('.rebuild'), turbo_confirm: t('.confirm') }, class: 'button is-small is-rounded is-light') do %>
<i class="fa-solid fa-recycle has-text-warning"></i>
<% end %>
<%= button_to({ action: 'edit', id: model.id }, aria: { label: t('.edit.title') }, class: 'button is-small is-rounded is-light') do %>
<i class="fa-solid fa-pencil has-text-link"></i>
<% end %>
<%= button_to({ action: 'destroy', id: model.id }, method: :delete, aria: { label: t('.destroy.title') }, data: { turbo_confirm: t('.confirm') }, class: 'button is-small is-rounded is-light') do %>
<i class="fa-solid fa-trash has-text-danger"></i>
<% end %>
</div>
</td>
</tr>
<% end %>
Empty file.
6 changes: 6 additions & 0 deletions app/views/datum/panel/data_imports/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= render 'index_bar' %>
<%= render 'index_actions' %>

<%= render layout: 'index_table' do %>
<%= render partial: 'index_tbody', layout: 'index_tr', collection: @data_imports, as: :model %>
<% end %>
31 changes: 31 additions & 0 deletions app/views/datum/panel/data_imports/reportable.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<ul class="breadcrumb">
<li><%= link_to 'back', :back %></li>
</ul>

<div class="page-header">
<h1>Table lists</h1>
<%= link_to 'combine', combine_report_list_path(@report_list) %>
</div>



<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th colspan="3"></th>
</tr>
</thead>

<tbody>
<% @table_lists.each do |table_list| %>
<tr>
<td><%= table_list.id %></td>
<td><%= link_to 'Download Csv', report_list_table_list_path(@report_list, table_list, format: 'csv') %></td>
<td><%= link_to 'Download Pdf', report_list_table_list_path(@report_list, table_list, format: 'pdf') %></td>
<td><%= link_to 'destroy', report_list_table_list_path(@report_list, table_list), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

7 changes: 0 additions & 7 deletions app/views/datum/panel/data_records/_tabs.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/datum/panel/data_records/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= render 'tabs' %>
<%= render 'index_bar' %>
<%= render 'index_actions' %>

<%= render layout: 'index_table' do %>
Expand Down
Empty file.
5 changes: 3 additions & 2 deletions app/views/panel/_data_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<span><%= t('datum.panel.title') %></span>
<i class="fa-solid fa-fw dropdown"></i>
</a>
<div class="menu-list" data-empty-target="content">
<%= link_to t('datum.panel.data_lists.index.title'), { controller: 'datum/panel/data_lists' }, data: { turbo_frame: 'body', action: 'menu#enter' }, class: active_helper(controllers: 'data_lists', active: 'is-active') %>
<div data-empty-target="content" class="menu-list">
<%= link_to t('datum.panel.data_exports.index.title'), { controller: 'datum/panel/data_exports' }, data: { turbo_frame: 'body', action: 'menu#enter' }, class: active_helper(controllers: 'data_exports', active: 'is-active') %>
<%= link_to t('datum.panel.data_imports.index.title'), { controller: 'datum/panel/data_imports' }, data: { turbo_frame: 'body', action: 'menu#enter' }, class: active_helper(controllers: 'data_imports', active: 'is-active') %>
<%= link_to t('datum.panel.data_records.index.title'), { controller: 'datum/panel/data_records' }, data: { turbo_frame: 'body', action: 'menu#enter' }, class: active_helper(controllers: 'data_records', active: 'is-active') %>
</div>
</div>
9 changes: 7 additions & 2 deletions config/locales/en.controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ en:
datum:
panel:
title: Reports
data_lists:
data_exports:
index:
title: Reports
title: Exports
sync:
title: Sync
data_imports:
index:
title: Imports
sync:
title: Sync
data_records:
Expand Down
11 changes: 8 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,26 @@
end
end
namespace :panel, defaults: { namespace: 'panel' } do
root 'home#index'
resources :data_exports do
collection do
post :sync
end
member do
put :update_publish
patch :rebuild
end
end
resources :data_imports do
collection do
post :sync
end
member do
patch :rebuild
match :template, via: [:get, :post]
end
end
resources :data_lists, only: [] do
collection do
post :sync
end
resources :table_lists do
collection do
get :direct
Expand Down

0 comments on commit 57aca0f

Please sign in to comment.