Skip to content

Commit

Permalink
Merge pull request #270 from AuScope/dev-sample
Browse files Browse the repository at this point in the history
Dev sample
  • Loading branch information
bmotevalli authored Aug 6, 2024
2 parents a17dcdb + 061050f commit b70f279
Show file tree
Hide file tree
Showing 36 changed files with 1,897 additions and 775 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,31 @@ ckan.module('datatable-module', function ($, _) {
});
},
setupTable: function (preview_data) {
console.log(preview_data)
var authorsData = preview_data.authors;
var resourcesData = preview_data.related_resources;
var samplesData = preview_data.samples;
var fundersData = preview_data.funders;

sampleExcludedColumns = ["owner_org", "notes", "location_data", "location_choice", "related_resources_urls", "author_emails"];
sampleExcludedColumns = ["owner_org", "notes", "location_data", "location_choice", "related_resources_urls", "author_emails", "private", "type","sample_repository_contact_email"];
sampleJsonColumns = ['author', 'related_resource', 'funder'];
sampleJsonColumnsTitle = ['author_name', 'related_resource_title', 'funder_name'];
var sampleColumnOrder = [
'status', 'log' , 'sample_number', 'description', 'user_keywords', 'sample_type', 'parent_sample', 'method',
'acquisition_start_date', 'acquisition_end_date', 'depth_from', 'depth_to',
'supplementation_information', 'credit', 'commodities', 'locality', 'point_latitude',
'point_longitude', 'elevation', 'epsg_code', 'sample_repository_contact_name',
, 'author_emails', 'related_resources_urls', 'project_ids'
];
this.setupDataTable('#authorsTable', authorsData);
this.setupDataTable('#fundersTable', fundersData);
this.setupDataTable('#resourcesTable', resourcesData);
this.setupDataTable('#samplesTable', samplesData, true, sampleExcludedColumns, sampleJsonColumns, sampleJsonColumnsTitle);
this.setupDataTable('#samplesTable', samplesData, true, sampleExcludedColumns, sampleJsonColumns, sampleJsonColumnsTitle,sampleColumnOrder);
$('.collapsible-header').click(function () {
$(this).next('.collapsible-content').slideToggle();
});
},

setupDataTable: function (selector, data, addStyle = false, excludedColumns = [], jsonColumns = [], jsonColumnsTitle = []) {
setupDataTable: function (selector, data, addStyle = false, excludedColumns = [], jsonColumns = [], jsonColumnsTitle = [], columnOrder = []) {
var self = this;
if (data && data.length > 0) {
var columns = Object.keys(data[0]).filter(function (key) {
Expand All @@ -43,6 +49,16 @@ ckan.module('datatable-module', function ($, _) {
return { title: key.charAt(0).toUpperCase() + key.slice(1), data: key };
});

if (columnOrder.length > 0) {
columns = columnOrder.map(function (key) {
return columns.find(function (col) {
return col.data === key;
});
}).filter(function (col) {
return col !== undefined;
});
}

var columnDefs = columns.map(function (column, index) {
if (jsonColumns.includes(column.data)) {
var jsonColumnIndex = jsonColumns.indexOf(column.data);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
this.ckan.module('facet-select-module', function ($, _) {
return {
initialize: function () {
this.inputElements = this.el.find('.facet-select');
this.title = this.el.data('title');
if (this.inputElements.length > 0) {
this.initializeSelect2();
} else {
setTimeout(this.initialize.bind(this), 500);
}
},

initializeSelect2: function () {
var self = this;
this.inputElements.each(function () {
var $element = $(this);
$element.select2({
placeholder: "Select " + self.title,
allowClear: true,
width: 'resolve'
}).on("change", function (e) {
self.updateQueryString($element);
});
});
},

updateQueryString: function ($element) {
var selectedValues = $element.val();
var url = new URL(window.location.href);
var params = new URLSearchParams(url.search);
params.delete($element.attr('name'));

if (selectedValues) {
selectedValues.forEach(function (value) {
params.append($element.attr('name'), value);
});
}

url.search = params.toString();
window.history.pushState({}, '', url.toString());

// Hide the select2 container and show loading indicator
$element.select2('destroy');
this.el.find('.loading-indicator').show();
$element.hide();

// Delay the page reload to ensure the loading indicator is visible
setTimeout(function () {
window.location.reload();
}, 500);
}
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ 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 truncatedTitle = self.truncateText(title, 20);

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

"a_attr": { "title": title}
}];

$('#tree').jstree({
Expand All @@ -43,22 +42,26 @@ this.ckan.module('jstree-view-module', function (jquery) {
}
}
}).on("select_node.jstree", function (e, data) {
if (data.node.children.length === 0) {
if (data.node.children.length === 0 && data.node.type !== "leaf") {
self.fetchChildren(data.node.id);
}
});

$('#tree').on("dblclick", ".jstree-anchor", function (e) {
var href = $(this).attr('href');
console.log(href);
if (href) {
e.preventDefault();
window.location.href = href;
}).on("click", ".jstree-anchor", function (e) {
e.preventDefault(); // Prevent default behavior

var node = $('#tree').jstree(true).get_node(this.id.replace('_anchor', ''));
console.log( node)
if (node && (node.children.length > 0 || node.type === "leaf")) {
console.log("link");
var href = $(this).attr("href");
if (href) {
window.location.href = href; // Explicitly navigate to the link
}
} else {
e.preventDefault(); // Prevent navigation if the node is not clickable
}
});

self.fetchChildren(id);

self.fetchChildren(id);
},

fetchChildren: function (packageId) {
Expand Down Expand Up @@ -90,7 +93,7 @@ this.ckan.module('jstree-view-module', function (jquery) {
var childrenCount;
var checkedChildren = [];
var self = this;

function verifyChild(child) {
$.ajax({
url: '/api/3/action/package_show',
Expand All @@ -113,8 +116,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);
validChild.a_attr = Object.assign({}, validChild.a_attr, { "title": validChild.text, "href": "/dataset/" + validChild.id.toLowerCase(), "class": "clickable-node" });
validChild.text = self.truncateText(validChild.text, 20);
$('#tree').jstree(true).create_node(packageId, validChild, "last");
$('#tree').jstree(true).open_node(packageId);
});
Expand All @@ -132,13 +135,13 @@ this.ckan.module('jstree-view-module', function (jquery) {
verifyChild({
"text": childData.object,
"id": childData.object,
"a_attr": { href: "/dataset/" + childData.object.toLowerCase(), target: "_blank" }
"a_attr": { href: "/dataset/" + childData.object.toLowerCase(), "class": "clickable-node" }
});
});
}
};
},

truncateText: function (text, maxLength) {
if (text.length <= maxLength) {
return text;
Expand All @@ -148,5 +151,4 @@ this.ckan.module('jstree-view-module', function (jquery) {
return startText + '...' + endText;
}
}

});
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ igsn_theme-js:
- js/datatable-module.js
- js/jstree-view-module.js
- js/parent-sample-selector-module.js
- js/facet-select-module.js
- js/igsn_theme.js
extra:
preload:
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ msgstr "Extras"
#: ckan/templates/snippets/context/dataset.html:17 ckan/views/dataset.py:299
#: ckan/views/group.py:308 ckan/views/home.py:74
msgid "Tags"
msgstr "Tags"
msgstr "Keywords"

#: ckan/logic/converters.py:91 ckan/logic/converters.py:107
#, python-format
msgid "Tag vocabulary \"%s\" does not exist"
msgstr "Tag vocabulary \"%s\" does not exist"
msgstr "Keywords vocabulary \"%s\" does not exist"

#: ckan/logic/converters.py:141 ckan/logic/converters.py:168
#: ckan/logic/converters.py:195 ckan/logic/validators.py:196
Expand Down Expand Up @@ -418,12 +418,12 @@ msgstr "Group name already exists in database"
#: ckan/logic/validators.py:436
#, python-format
msgid "Tag \"%s\" length is less than minimum %s"
msgstr "Tag \"%s\" length is less than minimum %s"
msgstr "Keywords \"%s\" length is less than minimum %s"

#: ckan/logic/validators.py:440
#, python-format
msgid "Tag \"%s\" length is more than maximum %i"
msgstr "Tag \"%s\" length is more than maximum %i"
msgstr "Keywords \"%s\" length is more than maximum %i"

#: ckan/logic/validators.py:449
#, python-format
Expand All @@ -435,7 +435,7 @@ msgstr ""
#: ckan/logic/validators.py:459
#, python-format
msgid "Tag \"%s\" must not be uppercase"
msgstr "Tag \"%s\" must not be uppercase"
msgstr "Keywords \"%s\" must not be uppercase"

#: ckan/logic/validators.py:570
msgid "User names must be strings"
Expand Down Expand Up @@ -489,21 +489,21 @@ msgstr "Cannot change value of key from %s to %s. This key is read-only"

#: ckan/logic/validators.py:696
msgid "Tag vocabulary was not found."
msgstr "Tag vocabulary was not found."
msgstr "Keywords vocabulary was not found."

#: ckan/logic/validators.py:711
#, python-format
msgid "Tag %s does not belong to vocabulary %s"
msgstr "Tag %s does not belong to vocabulary %s"
msgstr "Keywords %s does not belong to vocabulary %s"

#: ckan/logic/validators.py:721
msgid "No tag name"
msgstr "No tag name"
msgstr "No Keywords name"

#: ckan/logic/validators.py:734
#, python-format
msgid "Tag %s already belongs to vocabulary %s"
msgstr "Tag %s already belongs to vocabulary %s"
msgstr "Keywords %s already belongs to vocabulary %s"

#: ckan/logic/validators.py:758
msgid "Please provide a valid URL"
Expand Down Expand Up @@ -676,7 +676,7 @@ msgstr "Could not find vocabulary \"%s\""
#: ckan/logic/action/delete.py:641
#, python-format
msgid "Could not find tag \"%s\""
msgstr "Could not find tag \"%s\""
msgstr "Could not find Keywords \"%s\""

#: ckan/logic/action/delete.py:656 ckan/logic/action/delete.py:660
msgid "You must be logged in to unfollow something."
Expand Down Expand Up @@ -1405,7 +1405,7 @@ msgstr ""

#: ckan/templates/admin/config.html:19
msgid "Site Tag Line"
msgstr "Site Tag Line"
msgstr "Site Keywords Line"

#: ckan/templates/admin/config.html:24 ckan/templates/macros/autoform.html:62
msgid "Site logo"
Expand Down Expand Up @@ -2020,7 +2020,7 @@ msgstr "Search samples"

#: ckan/templates/home/snippets/search.html:17
msgid "Popular tags"
msgstr "Popular tags"
msgstr "Popular Keywords"

#: ckan/templates/home/snippets/stats.html:5
msgid "{0} statistics"
Expand Down Expand Up @@ -2245,7 +2245,7 @@ msgid ""
" performed while public or private datasets belong to this organization."
msgstr ""
"Are you sure you want to delete this Collection? Note*: Deleting cannot be"
" performed while public or private samples belong to this organization."
" performed while public or private samples belong to this collection."

#: ckan/templates/organization/snippets/organization_form.html:43
msgid "Save Organization"
Expand Down Expand Up @@ -4054,7 +4054,7 @@ msgstr ""

#: ckanext/activity/templates/snippets/activities/added_tag.html:6
msgid "{actor} added the tag {tag} to the dataset {dataset}"
msgstr "{actor} added the tag {tag} to the sample {dataset}"
msgstr "{actor} added the Keywords {tag} to the sample {dataset}"

#: ckanext/activity/templates/snippets/activities/changed_group.html:6
msgid "{actor} updated the group {group}"
Expand Down Expand Up @@ -4135,7 +4135,7 @@ msgstr "{actor} signed up"

#: ckanext/activity/templates/snippets/activities/removed_tag.html:6
msgid "{actor} removed the tag {tag} from the dataset {dataset}"
msgstr "{actor} removed the tag {tag} from the sample {dataset}"
msgstr "{actor} removed the Keywords {tag} from the sample {dataset}"

#: ckanext/activity/templates/snippets/changes/author.html:5
msgid "Set author of {pkg_link} to {new_author} (previously {old_author})"
Expand Down Expand Up @@ -5119,11 +5119,11 @@ msgstr "No groups"
#: ckanext/stats/templates/ckanext/stats/index.html:114
#: ckanext/stats/templates/ckanext/stats/index.html:168
msgid "Top Tags"
msgstr "Top Tags"
msgstr "Top Keywords"

#: ckanext/stats/templates/ckanext/stats/index.html:118
msgid "Tag Name"
msgstr "Tag Name"
msgstr "Keywords Name"

#: ckanext/stats/templates/ckanext/stats/index.html:119
#: ckanext/stats/templates/ckanext/stats/index.html:143
Expand Down
Loading

0 comments on commit b70f279

Please sign in to comment.