Skip to content

Commit

Permalink
Fix issue with semantic linking visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
NTaherifar committed Jun 26, 2024
1 parent 0a88406 commit 3ef4808
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ this.ckan.module('jstree-view-module', function (jquery) {
var id = this.el.attr('data-id');
var title = this.el.attr('data-title');

var truncatedTitle = self.truncateText(title, 20);

var data = [{
"text": title,
"text": truncatedTitle,
"id": id,
"state": {
"opened": true
}
},
"a_attr": { "title": title }

}];

$('#tree').jstree({
Expand Down Expand Up @@ -46,6 +50,7 @@ this.ckan.module('jstree-view-module', function (jquery) {

$('#tree').on("dblclick", ".jstree-anchor", function (e) {
var href = $(this).attr('href');
console.log(href);
if (href) {
e.preventDefault();
window.location.href = href;
Expand Down Expand Up @@ -84,7 +89,8 @@ this.ckan.module('jstree-view-module', function (jquery) {
createChildProcessor: function (packageId) {
var childrenCount;
var checkedChildren = [];

var self = this;

function verifyChild(child) {
$.ajax({
url: '/api/3/action/package_show',
Expand All @@ -107,6 +113,8 @@ this.ckan.module('jstree-view-module', function (jquery) {
if (--childrenCount === 0) {
if (checkedChildren.length > 0) {
checkedChildren.forEach(function (validChild) {
validChild.a_attr = Object.assign({}, validChild.a_attr, { "title": validChild.text });
validChild.text = self.truncateText(validChild.text, 20);
$('#tree').jstree(true).create_node(packageId, validChild, "last");
$('#tree').jstree(true).open_node(packageId);
});
Expand All @@ -129,6 +137,15 @@ this.ckan.module('jstree-view-module', function (jquery) {
});
}
};
},

truncateText: function (text, maxLength) {
if (text.length <= maxLength) {
return text;
}
var startText = text.slice(0, Math.ceil(maxLength / 2));
var endText = text.slice(-Math.floor(maxLength / 2));
return startText + '...' + endText;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
this.ckan.module('parent-sample-selector-module', function ($, _) {
return {
initialize: function () {
this.textInputElement = $('#field-parent-name');
this.inputElement = $('#field-parent');
this.initializeSelect2();
this.prepopulateSelect2();
Expand All @@ -10,57 +9,62 @@ this.ckan.module('parent-sample-selector-module', function ($, _) {
initializeSelect2: function () {
var self = this;
this.org_id = this.options.group;
console.log(self.org_id);
this.inputElement.select2({
placeholder: "Select Parent of Sample",
minimumInputLength: 0,
ajax: {
url: '/api/3/action/package_search',
url: '/api/3/action/organization_show',
type: 'GET',
dataType: 'json',
quietMillis: 500,
data: function (term, page) {
data: function (params) {
self.searchTerm = params || '';
return {
q: term,
include_private: true,
fq: 'owner_org:' + self.org_id // filter query for organization id
id: self.org_id,
include_datasets: 'true'
};
},
results: function (data, page) {
processResults: function (data) {
if (!data.success) {
return { results: [] };
}
var searchTerm = self.searchTerm.toLowerCase();
var filteredResults = data.result.packages.filter(function (item) {
return item.title.toLowerCase().includes(searchTerm);
});
return {
results: data.result.results.map(function (item) {
results: filteredResults.map(function (item) {
return { id: item.id, text: item.title };
})
};
},
cache: true
},
formatResult: function (item) { return item.text; },
formatSelection: function (item) { return item.text; },
templateResult: function (item) { return item.text; },
templateSelection: function (item) { return item.text; },
dropdownCssClass: "bigdrop",
escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
}).on("change", function (e) {
self.updateDependentFields();
});
},
updateDependentFields: function () {
var self = this;

var selectedData = self.inputElement.select2('data');
if (selectedData) {
self.textInputElement.val(selectedData.text);
}
escapeMarkup: function (m) { return m; }
})
},

prepopulateSelect2: function () {
var self = this;
var existingId = this.inputElement.val();
var existingText = this.textInputElement.val(); // Assuming you store the selected text in data attribute

if (existingId && existingText) {
var dataForSelect2 = { id: existingId, text: existingText };
self.inputElement.select2('data', dataForSelect2, true);
if (existingId) {
$.ajax({
url: '/api/3/action/package_show',
data: { id: existingId },
type: 'GET',
dataType: 'json',
success: function (data) {
if (data.success && data.result) {
var item = data.result;
var dataForSelect2 = new Option(item.title, item.id, true, true);
self.inputElement.select2('data', dataForSelect2, true);
}
}
});
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ dataset_fields:
help_text: Select the parent sample from existing samples.
groupBy: About Sample

- field_name: parent-name
form_snippet: hidden_field.html
display_snippet: null
groupBy: About Sample

- field_name: author
label: Authors
preset: composite_repeating
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,11 @@ <h2 class="module-heading"><i class="fa fa-sitemap"></i> Sample Family</h2>
<div data-module="jstree-view-module" data-id="{{ pkg.id }}" data-title="{{ pkg.title }}">
<div id="tree"></div>
</div>

</div>
{% endblock %}

<style>
#tree .jstree-anchor {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: inline-block;
max-width: calc(100% - 24px);
vertical-align: middle;
box-sizing: border-box;
}

#tree .jstree-node {
.tree-item {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
Expand All @@ -29,35 +18,51 @@ <h2 class="module-heading"><i class="fa fa-sitemap"></i> Sample Family</h2>
box-sizing: border-box;
}

#tree .jstree-wholerow {
display: none;
}


.jstree-wholerow-ul {
position: relative;
display: inline-block;
width: 100%;
padding-top: 10px;
}

#tree .jstree-ocl {
margin-right: 0px;
}

.jstree-ocl::before {
content: "\f0da";
font-family: "FontAwesome";
font-weight: 900;
font-style: normal;

}

.jstree-open>.jstree-ocl::before {
.jstree-open > .jstree-ocl::before {
content: "\f0d7";
font-family: "FontAwesome";
font-weight: 900;
font-style: normal;
}

.tooltip {
position: relative;
display: inline-block;
}

.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -60px;
opacity: 0;
transition: opacity 0.3s;
}

.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
</style>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div
data-module="parent-sample-selector-module"
{% if data.get('organization', {}).get('id') %}
data-module-group="{{ data['organization']['id'] }}"
data-module="parent-sample-selector-module"
{% if data.get('owner_org') %}
data-module-group="{{ data['owner_org'] }}"
{% else %}
data-module-group="{{ data['group'] }}"
{% endif %}
data-module-group="{{ data['group_id'] }}"
{% endif %}

class="form-group" id="parent">

<label class="form-label" for="field-parent">Parent Sample</label>
Expand Down

0 comments on commit 3ef4808

Please sign in to comment.