added mind map for selection
This commit is contained in:
parent
e4655b5985
commit
3d65aaffbc
|
|
@ -704,23 +704,7 @@ class CurationsController < ApplicationController
|
||||||
end
|
end
|
||||||
sections = []
|
sections = []
|
||||||
sections = announcement.curation_post_sections.map do |section|
|
sections = announcement.curation_post_sections.map do |section|
|
||||||
if section.section_type == "universal_table"
|
section.get_frontend_object
|
||||||
{
|
|
||||||
"section" => section.title,
|
|
||||||
"entries" => section.get_table_entries_for_frontend,
|
|
||||||
"url_to_show" => "",
|
|
||||||
"text" => ""
|
|
||||||
}
|
|
||||||
elsif section.section_type == "text"
|
|
||||||
{
|
|
||||||
"section" => section.title,
|
|
||||||
"entries" => [],
|
|
||||||
"uid" => "",
|
|
||||||
"type" => section.section_type,
|
|
||||||
"url_to_show" => "",
|
|
||||||
"text" => section.text.html_safe
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
sections.compact!
|
sections.compact!
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ class CurationPost
|
||||||
include Slug
|
include Slug
|
||||||
require 'curation/cache'
|
require 'curation/cache'
|
||||||
include Curation::Cache
|
include Curation::Cache
|
||||||
SECTION_TYPES = ["text", "universal_table"]
|
|
||||||
attr_accessor :org_tag_ids,:org_category_id
|
attr_accessor :org_tag_ids,:org_category_id
|
||||||
def tags=(ids)
|
def tags=(ids)
|
||||||
self.org_tag_ids = self.tag_ids
|
self.org_tag_ids = self.tag_ids
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,9 @@ class CurationPostSection
|
||||||
field :text, localize: true
|
field :text, localize: true
|
||||||
field :universal_table
|
field :universal_table
|
||||||
field :table_entries
|
field :table_entries
|
||||||
|
field :mind_map_id
|
||||||
|
|
||||||
|
SECTION_TYPES = ["text", "universal_table", "mind_map"]
|
||||||
|
|
||||||
belongs_to :curation_post
|
belongs_to :curation_post
|
||||||
|
|
||||||
|
|
@ -42,4 +45,44 @@ class CurationPostSection
|
||||||
tids = self.table_entries.split(',')
|
tids = self.table_entries.split(',')
|
||||||
TableEntry.find(tids)
|
TableEntry.find(tids)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_frontend_object
|
||||||
|
case self.section_type
|
||||||
|
when "universal_table"
|
||||||
|
{
|
||||||
|
"section" => self.title,
|
||||||
|
"section_uid" => self.id.to_s[0..5],
|
||||||
|
"entries" => self.get_table_entries_for_frontend,
|
||||||
|
"url_to_show" => "",
|
||||||
|
"text" => "",
|
||||||
|
"mind_map_title" => "",
|
||||||
|
"mind_map_data" => ""
|
||||||
|
}
|
||||||
|
when "text"
|
||||||
|
{
|
||||||
|
"section" => self.title,
|
||||||
|
"section_uid" => self.id.to_s[0..5],
|
||||||
|
"entries" => [],
|
||||||
|
"uid" => "",
|
||||||
|
"type" => self.section_type,
|
||||||
|
"url_to_show" => "",
|
||||||
|
"text" => self.text.html_safe,
|
||||||
|
"mind_map_title" => "",
|
||||||
|
"mind_map_data" => ""
|
||||||
|
}
|
||||||
|
when "mind_map"
|
||||||
|
mm = MindMap.find(self.mind_map_id)
|
||||||
|
{
|
||||||
|
"section" => self.title,
|
||||||
|
"section_uid" => self.id.to_s[0..5],
|
||||||
|
"entries" => [],
|
||||||
|
"mind_map_title" => mm.title,
|
||||||
|
"mind_map_data" => mm.mind_map_data.to_json,
|
||||||
|
"uid" => "",
|
||||||
|
"type" => self.section_type,
|
||||||
|
"url_to_show" => "",
|
||||||
|
"text" => ""
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -745,6 +745,16 @@
|
||||||
var parent = $(this).parents(".curation_section");
|
var parent = $(this).parents(".curation_section");
|
||||||
parent.find(".section_type_text").hide();
|
parent.find(".section_type_text").hide();
|
||||||
parent.find(".section_type_ut").hide();
|
parent.find(".section_type_ut").hide();
|
||||||
|
parent.find(".section_type_mm").hide();
|
||||||
|
parent.find(".section_type_mm_mindmaps").hide();
|
||||||
|
if(parent.find(".section_type_text textarea").length > 0){
|
||||||
|
parent.find(".section_type_text textarea").each(function(index){
|
||||||
|
id = $(this).attr("id");
|
||||||
|
if(CKEDITOR.instances[id]){
|
||||||
|
CKEDITOR.instances[id].destroy(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
if($(this).val() == "text"){
|
if($(this).val() == "text"){
|
||||||
parent.find(".section_type_text").show();
|
parent.find(".section_type_text").show();
|
||||||
parent.find(".section_type_text textarea").each(function(index){
|
parent.find(".section_type_text textarea").each(function(index){
|
||||||
|
|
@ -753,12 +763,8 @@
|
||||||
});
|
});
|
||||||
}else if($(this).val() == "universal_table"){
|
}else if($(this).val() == "universal_table"){
|
||||||
parent.find(".section_type_ut").show();
|
parent.find(".section_type_ut").show();
|
||||||
if(parent.find(".section_type_text textarea").length > 0){
|
}else if($(this).val() == "mind_map"){
|
||||||
parent.find(".section_type_text textarea").each(function(index){
|
parent.find(".section_type_mm").show();
|
||||||
id = $(this).attr("id");
|
|
||||||
CKEDITOR.instances[id].destroy(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
<% if defined? UniversalTable %>
|
<% if defined? UniversalTable %>
|
||||||
|
|
@ -813,7 +819,6 @@
|
||||||
$('.select2').each(function () {
|
$('.select2').each(function () {
|
||||||
const data = $(this).data('value');
|
const data = $(this).data('value');
|
||||||
if (data) {
|
if (data) {
|
||||||
console.log($(this))
|
|
||||||
$(this).select2({
|
$(this).select2({
|
||||||
data: data,
|
data: data,
|
||||||
multiple: true,
|
multiple: true,
|
||||||
|
|
@ -821,6 +826,24 @@
|
||||||
}).val(data.map(i => i.id)).trigger('change');
|
}).val(data.map(i => i.id)).trigger('change');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// mind map
|
||||||
|
$(document).on('change', '.section_type_mm select.mind_map_select_ut', function(){
|
||||||
|
var tableid = $(this).val();
|
||||||
|
var parent = $(this).parents(".curation_section");
|
||||||
|
var select = parent.find(".section_type_mm_mindmaps select.mind_map_select");
|
||||||
|
$.ajax({
|
||||||
|
type: "get",
|
||||||
|
url: '/admin/universal_tables/get_mindmaps?table=' + tableid,
|
||||||
|
processData: false,
|
||||||
|
contentType: "json"
|
||||||
|
}).done(function(data){
|
||||||
|
select.html("");
|
||||||
|
$.each(data, function(index, item) {
|
||||||
|
select.append("<option value='"+ item.id +"'>" + item.title + "</option>");
|
||||||
|
});
|
||||||
|
parent.find(".section_type_mm_mindmaps").show();
|
||||||
|
})
|
||||||
|
})
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
$("#enable_sub_annc").click(function(){
|
$("#enable_sub_annc").click(function(){
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@
|
||||||
</span>
|
</span>
|
||||||
<span class="tab-content section_type">
|
<span class="tab-content section_type">
|
||||||
<span class="add-on"><%= t("curation.section_type") %></span>
|
<span class="add-on"><%= t("curation.section_type") %></span>
|
||||||
<%= f.select :section_type, CurationPost::SECTION_TYPES.map { |type| [t("curation.#{type}"), type] },
|
<%= f.select :section_type, CurationPostSection::SECTION_TYPES.map { |type| [t("curation.#{type}"), type] },
|
||||||
{ include_blank: t("curation.please_select"), selected: form_section_post.section_type },
|
{ include_blank: t("curation.please_select"), selected: form_section_post.section_type },
|
||||||
class: 'form-control' %>
|
class: 'form-control' %>
|
||||||
</span>
|
</span>
|
||||||
|
|
@ -74,6 +74,29 @@
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% if defined? UniversalTable %>
|
||||||
|
<span class="tab-content section_type_mm" style="<%= !form_section_post.new_record? && form_section_post.section_type == 'mind_map' ? '' : 'display:none' %>">
|
||||||
|
<span class="add-on"><%= t("curation.tables") %></span>
|
||||||
|
<%= f.select :universal_table, UTable.all.map { |table| [table.title, table.uid] },
|
||||||
|
{ include_blank: t("curation.please_select") },
|
||||||
|
class: 'form-control mind_map_select_ut' %>
|
||||||
|
</span>
|
||||||
|
<% if !form_section_post.new_record? && form_section_post.section_type == "mind_map" %>
|
||||||
|
<span class="tab-content section_type_mm_mindmaps">
|
||||||
|
<% maps = UTable.where(:uid => form_section_post.universal_table).first.mind_maps %>
|
||||||
|
<span class="add-on"><%= t("curation.mind_map") %></span>
|
||||||
|
<%= f.select :mind_map_id, maps.map { |m| [m.title, m.id.to_s] },
|
||||||
|
{ include_blank: t("curation.please_select"), selected: form_section_post.mind_map_id },
|
||||||
|
class: 'form-control mind_map_select' %>
|
||||||
|
</span>
|
||||||
|
<% else %>
|
||||||
|
<span class="tab-content section_type_mm_mindmaps" style="display:none">
|
||||||
|
<span class="add-on"><%= t("curation.mind_map") %></span>
|
||||||
|
<%= f.select :mind_map_id, [], {}, class: 'form-control mind_map_select' %>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<% if form_section_post.new_record? %>
|
<% if form_section_post.new_record? %>
|
||||||
<span class="delete_link add-on btn" title="<%= t(:delete_) %>">
|
<span class="delete_link add-on btn" title="<%= t(:delete_) %>">
|
||||||
<a class="icon-trash"></a>
|
<a class="icon-trash"></a>
|
||||||
|
|
@ -85,8 +108,4 @@
|
||||||
<%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
|
<%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
<%
|
<%
|
||||||
|
OrbitHelper.render_css_in_head(["mind_map/mindmap"])
|
||||||
params = OrbitHelper.params
|
params = OrbitHelper.params
|
||||||
page = @page || Page.where(url:params['url']).first
|
page = @page || Page.where(url:params['url']).first
|
||||||
@show_back_and_next_flag = 0
|
@show_back_and_next_flag = 0
|
||||||
|
|
@ -68,6 +69,9 @@
|
||||||
a.prev{
|
a.prev{
|
||||||
margin-right: 1em;
|
margin-right: 1em;
|
||||||
}
|
}
|
||||||
|
.section_mind_map .mind_map{
|
||||||
|
height:500px !important;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if @show_back_and_next_flag==1 %>
|
<% if @show_back_and_next_flag==1 %>
|
||||||
|
|
@ -211,3 +215,59 @@ $(".voice-player").on("click", function(){
|
||||||
return false;
|
return false;
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script type="module">
|
||||||
|
import '/assets/mind_map/utils/custom.overrides.js'
|
||||||
|
import '/assets/mind_map/jsmind/plugins/jsmind.draggable-node.js'
|
||||||
|
import { initJsmind, getJsmindData } from '/assets/mind_map/utils/custom.main.js'
|
||||||
|
import { INITIAL_MIND } from '/assets/mind_map/utils/custom.config.js'
|
||||||
|
let isEditable = false
|
||||||
|
let minds = []
|
||||||
|
const options = {
|
||||||
|
container: '',
|
||||||
|
editable: isEditable,
|
||||||
|
theme: 'primary',
|
||||||
|
mode: 'full',
|
||||||
|
tableUID: '',
|
||||||
|
text: {
|
||||||
|
addNode: "<%= t("universal_table.add_node") %>",
|
||||||
|
deleteNode: "<%= t("universal_table.delete_node") %>",
|
||||||
|
strokeColor: "<%= t("universal_table.stroke_color") %>",
|
||||||
|
bgColor: "<%= t("universal_table.bg_color") %>",
|
||||||
|
textColor: "<%= t("universal_table.text_color") %>"
|
||||||
|
},
|
||||||
|
view: {
|
||||||
|
engine: 'svg',
|
||||||
|
draggable: false,
|
||||||
|
node_overflow: 'wrap',
|
||||||
|
},
|
||||||
|
shortcut: {
|
||||||
|
mapping: {
|
||||||
|
addbrother: 2048 + 13,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll(".section_mind_map .mind_map_data").forEach(function (el) {
|
||||||
|
const dataText = el.querySelector(".data")?.textContent.trim();
|
||||||
|
if (!dataText) return;
|
||||||
|
|
||||||
|
const data = JSON.parse(dataText);
|
||||||
|
console.log("data", data);
|
||||||
|
|
||||||
|
const id = el.querySelector(".mind_map")?.id;
|
||||||
|
if (!id) return;
|
||||||
|
|
||||||
|
options.container = id;
|
||||||
|
console.log("options", options);
|
||||||
|
|
||||||
|
const mind = {
|
||||||
|
meta: {},
|
||||||
|
format: 'node_array',
|
||||||
|
data: data
|
||||||
|
};
|
||||||
|
|
||||||
|
minds.push(initJsmind(mind, options, isEditable));
|
||||||
|
});
|
||||||
|
console.log(minds)
|
||||||
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -214,4 +214,5 @@ en:
|
||||||
tables: Tables
|
tables: Tables
|
||||||
search_entries: Search Entries
|
search_entries: Search Entries
|
||||||
title: Title
|
title: Title
|
||||||
|
mind_map: Mind Map
|
||||||
|
|
||||||
|
|
@ -204,3 +204,4 @@ zh_tw:
|
||||||
tables: Tables
|
tables: Tables
|
||||||
search_entries: Search Entries
|
search_entries: Search Entries
|
||||||
title: Title
|
title: Title
|
||||||
|
mind_map: Mind Map
|
||||||
Loading…
Reference in New Issue