Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Troubleshooting: 20240910 #33

Merged
merged 20 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
674ce72
Use amazon s3 bucket to retrieve cache.
redndahead Feb 27, 2024
49ad540
Merge pull request #46 from gsb-library/RHW-55
redndahead Mar 2, 2024
1332457
Merge branch 'SU-SWS:main' into main
redndahead Mar 5, 2024
3176d74
RHW-54: Remove extraneous question mark when there are no parameters …
redndahead Mar 5, 2024
d1a731a
Merge pull request #47 from gsb-library/RHW-54
redndahead Mar 5, 2024
844eec9
RHW-59: Allow the header to be sticky up to medium height which is cu…
redndahead Mar 6, 2024
44984c5
Revert "RHW-59: Allow the header to be sticky up to medium height whi…
redndahead Mar 6, 2024
29557f4
RHW-59: Allow the header to be sticky up to medium height which is cu…
redndahead Mar 6, 2024
3da1e10
Merge pull request #48 from gsb-library/RHW-59
redndahead Mar 6, 2024
31325dc
RHW-60: Add h2 for screen readers.
redndahead Mar 7, 2024
eb2d0ba
Merge pull request #49 from gsb-library/RHW-60
redndahead Mar 7, 2024
e7bf4b4
Update airtable examples to latest version.
redndahead Mar 7, 2024
3729c3d
Make the page building more generic.
redndahead Mar 8, 2024
d5d07ac
Fix typos throwing an error on build.
redndahead Mar 8, 2024
6e61290
Need to save menu in a different call. Fix typo.
redndahead Mar 8, 2024
b577d4a
Training should be singular.
redndahead Mar 8, 2024
b0065f5
Merge pull request #50 from gsb-library/RHW-57
redndahead Mar 8, 2024
f730ad7
Style Airtable search box and filter dropdowns
cdchangr Mar 17, 2024
1687488
Create variables for filter dropdowns and search box
cdchangr Mar 19, 2024
df9727f
Merge pull request #51 from gsb-library/RHW-58
redndahead Mar 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/css/main.css

Large diffs are not rendered by default.

28 changes: 17 additions & 11 deletions dist/js/airtable-list-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
// Get the content area
var $contentArea = $("#airtable-list");

// Load settings configured in textarea
var textAreaConfig = "gsbResearchHubSubtheme" in drupalSettings ? drupalSettings.gsbResearchHubSubtheme : {};

// Grab the airtable variables.
var config = $contentArea.data('config');
var templateConfig = $contentArea.data('config');
var configDefault = {
"gutter": 10,
"equalHeight": false
};
config = _objectSpread(_objectSpread({}, configDefault), config);
config = _objectSpread(_objectSpread(_objectSpread({}, configDefault), templateConfig), textAreaConfig);
for (filterKey in config.filters) {
// Set the default array of choices if choices are not provided for us.
if (!("choices" in config.filters[filterKey])) {
Expand All @@ -32,15 +35,12 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
// Load the airtable data
$.ajax({
type: "GET",
beforeSend: function beforeSend(xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + settings.gsbResearchHubSubtheme.snaplogicToken);
},
dataType: "json",
url: settings.gsbResearchHubSubtheme.snaplogicURL + "/GSB/rh-airtable_proxy_cache/output?airtable_table=" + config.table + "&airtable_view=" + config.view,
url: "https://gsbrh-airtable-cache.s3.us-west-2.amazonaws.com/airtable-proxy-cache-" + config.table + "-" + config.view + ".json",
success: function success(data) {
$contentArea.find('#airtable-list-loader').remove();
// Load the records.
var records = data.records;
var records = data.data.records;
if (records.length) {
for (recordIndex in records) {
for (fieldName in records[recordIndex].fields) {
Expand Down Expand Up @@ -270,7 +270,14 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
}

// Set the browser url.
window.history.replaceState(null, null, '?' + urlParamaters.toString());
var params = urlParamaters.toString();
// If there are no parameters set then reset the url to no parameters.
// Otherwise set it to the given filters.
if (params === '') {
window.history.replaceState(null, null, window.location.pathname);
} else {
window.history.replaceState(null, null, '?' + params);
}

// combine filters
var filterValue = buildFilters(filters);
Expand Down Expand Up @@ -349,7 +356,6 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
// Apply the data to the template.
function processTemplate(config, templateKey, data, allData) {
var template = $('template#airtable-list-' + stringToCSSClass(templateKey) + '-template').html();
var settings = drupalSettings.gsbResearchHubSubtheme;
if (template) {
// Pull all of the tokens from the template.
var tokens = [];
Expand Down Expand Up @@ -409,8 +415,8 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
if ("format" in config && token in config.format) {
// Pull in any additional config passed in from the text area.
var additionalConfig = [];
if ("arrayFormatConfig" in settings && token in settings.arrayFormatConfig) {
additionalConfig = settings.arrayFormatConfig[token];
if ("arrayFormatConfig" in config && token in config.arrayFormatConfig) {
additionalConfig = config.arrayFormatConfig[token];
}
content = formatString(config.format[token].type, config.format[token].options, content, additionalConfig);
}
Expand Down
22 changes: 1 addition & 21 deletions gsb_research_hub_subtheme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,9 @@ function gsb_research_hub_subtheme_preprocess_paragraph(&$variables) {
if (!is_null($jsonConfig) && isset($jsonConfig['type']) && $jsonConfig['type'] == 'airtable') {
$variables['#attached']['library'][] = 'gsb_research_hub_subtheme/airtable-list-builder';

$sl_env_conf = [
'dev' => [
'snaplogicURL' => 'https://snaplogic-dev.stanford.edu/api/1/rest/feed-master/queue/StanfordDev',
'snaplogicToken' => 'iQ7GGRoNRcGi8iZf28xSgDgaDDUslteL',
],
'test' => [
'snaplogicURL' => 'https://snaplogic-uat.stanford.edu/api/1/rest/feed-master/queue/StanfordUAT',
'snaplogicToken' => 'J4G3SZC0cFVVZLr93TAJtm8Lnj6Jkuop',
],
'prod' => [
'snaplogicURL' => 'https://snaplogic.stanford.edu/api/1/rest/feed-master/queue/StanfordProd',
'snaplogicToken' => '0mdOOeXqOuQdFUxwt9ngJ3KSlxh7v1z2',
],
];

$sl_env = theme_get_setting('gsb_research_hub_subtheme_sl_env', 'gsb_research_hub_subtheme');

$jsVars = is_null($sl_env) ? $sl_env_conf['prod'] : $sl_env_conf[$sl_env];
if (isset($jsonConfig['variables'])) {
$jsVars = array_merge($jsonConfig['variables'], $jsVars);
$variables['#attached']['drupalSettings']['gsbResearchHubSubtheme'] = $jsonConfig['variables'];
}

$variables['#attached']['drupalSettings']['gsbResearchHubSubtheme'] = $jsVars;
}
}
}
Expand Down
87 changes: 41 additions & 46 deletions set-default-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,90 +11,85 @@
\Drupal\menu_link_content\Entity\MenuLinkContent::create(["title" => "Submenu link", "link" => ["uri" => "https://google.com"], "menu_name" => "main", "parent" => "menu_link_field:node_field_menulink_e18a741f-7d86-492a-a02f-7ca73989ca13_und", "expanded" => TRUE, "weight" => 0])->save();


/********************
** Airtable Items **
********************/
$at_menu = \Drupal\menu_link_content\Entity\MenuLinkContent::create(["title" => "Airtable", "link" => ["uri" => "internal:/"], "menu_name" => "main", "parent" => "", "expanded" => TRUE, "weight" => 0]);
$at_menu->save();
$at_menu_id = "menu_link_content:" . $at_menu->uuid();
$airtable_pages = [
/*********************
** Pages to Create **
*********************/
$parent_menu_links = array('main' => '');
$pages = [
[
'title' => 'Service Catalog',
'wysiwyg_text' => '{"type":"airtable","view": "service_catalog"}',
'menu_parent' => $at_menu_id,
],
[
'title' => 'Past Trainings & Workshops',
'wysiwyg_text' => '{"type":"airtable","view": "training_past"}',
'menu_parent' => $at_menu_id,
'title' => 'Services',
'wysiwyg_text' => 'Services Placeholder',
'menu_parent' => 'main',
],
[
'title' => 'Upcoming Trainings & Workshops',
'wysiwyg_text' => '{"type":"airtable","view": "training_upcoming"}',
'menu_parent' => $at_menu_id,
'title' => 'Service Catalog',
'wysiwyg_text' => '{"type":"airtable","view": "service_catalog","variables": {"arrayFormatConfig": {"core-service": {"classMap":{"Artificial Intelligence": "darc","Computationally Intensive Research": "darc","Data Acquisition and Governance": "dag","Data Analytics": "darc","Data Onboarding and Storage": "darc","Human Subjects Research": "blab","Library Research Collections": "library","Publication Support": "library","Research Comms": "ro","Research Operations": "ro","Research Planning": "library"}}}}}',
'menu_parent' => 'Services',
],
[
'title' => 'All Training',
'wysiwyg_text' => '{"type":"airtable","view": "training"}',
'menu_parent' => '',
],
'title' => 'Training & Workshops',
'wysiwyg_text' => '{"type":"airtable","view": "training","variables": {"arrayFormatConfig": {"categories": {"classMap":{"Research Data Sources": "library","Library Resources": "library","Data Stewardship": "dag","Data Licensing": "dag tag","Data Onboarding and Storage": "darc","Data Analytics": "darc","Artificial Intelligence": "darc","Research Computing": "darc","Human Subjects Research": "blab","Survey Methodology": "blab","Publication Support": "library","Research Grants": "ro"}}}}}',
'menu_parent' => 'main',
]
];


foreach ($airtable_pages as $page) {
// Create Service Catalog Node
$at_node = \Drupal::entityTypeManager()->getStorage("node")->create([
// Build all the pages.
foreach ($pages as $page) {
// Create Node
$node = \Drupal::entityTypeManager()->getStorage("node")->create([
"type" => "stanford_page",
"title" => $page['title'],
]);
$at_node->save();
$node->save();

// Create layout for paragraph for Service Catalog.
$at_paragraph_layout = \Drupal::entityTypeManager()->getStorage("paragraph")->create([
// Create layout for paragraph.
$paragraph_layout = \Drupal::entityTypeManager()->getStorage("paragraph")->create([
"type" => "stanford_layout",
"parent_id" => $at_node->id(),
"parent_id" => $node->id(),
"parent_type" => "node",
"parent_field_name" => "su_page_components",
]);

$at_paragraph_layout->setBehaviorSettings("layout_paragraphs", [
$paragraph_layout->setBehaviorSettings("layout_paragraphs", [
"layout" => "layout_paragraphs_1_column",
"config" => [
"label" => ""
],
"parent_uuid" => "",
"region" => ""
]);
$at_paragraph_layout->save();
$paragraph_layout->save();

// Create paragraph for Service Catalog
$at_paragraph = \Drupal::entityTypeManager()->getStorage("paragraph")->create([
// Create paragraph.
$paragraph = \Drupal::entityTypeManager()->getStorage("paragraph")->create([
"type" => "stanford_wysiwyg",
"parent_id" => $at_node->id(),
"parent_id" => $node->id(),
"parent_type" => "node",
"parent_field_name" => "su_page_components",
"su_wysiwyg_text" => $page['wysiwyg_text'],
]);

$at_paragraph->setBehaviorSettings("layout_paragraphs", [
"parent_uuid" => $at_paragraph_layout->uuid(),
$paragraph->setBehaviorSettings("layout_paragraphs", [
"parent_uuid" => $paragraph_layout->uuid(),
"region" => "main"
]);
$at_paragraph->save();
$paragraph->save();

// Add paragraph to service catalog node.
$at_node->su_page_components = [
// Add paragraph to node.
$node->su_page_components = [
[
"target_id" => $at_paragraph_layout->id(),
"target_revision_id" => $at_paragraph_layout->getRevisionId()
"target_id" => $paragraph_layout->id(),
"target_revision_id" => $paragraph_layout->getRevisionId()
],
[
"target_id" => $at_paragraph->id(),
"target_revision_id" => $at_paragraph->getRevisionId()
"target_id" => $paragraph->id(),
"target_revision_id" => $paragraph->getRevisionId()
]
];
$at_node->save();
$node->save();

// Set Menu
\Drupal\menu_link_content\Entity\MenuLinkContent::create(["title" => $page['title'], "link" => ["uri" => "internal:/node/" . $at_node->id()], "menu_name" => "main", "parent" => $page['menu_parent'], "expanded" => TRUE, "weight" => 0])->save();
$menu = \Drupal\menu_link_content\Entity\MenuLinkContent::create(["title" => $page['title'], "link" => ["uri" => "internal:/node/" . $node->id()], "menu_name" => "main", "parent" => $parent_menu_links[$page['menu_parent']], "expanded" => TRUE, "weight" => 0]);
$menu->save();
$parent_menu_links[$page['title']] = "menu_link_content:" . $menu->uuid();
}
31 changes: 20 additions & 11 deletions src/js/airtable-list-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
// Get the content area
var $contentArea = $("#airtable-list");

// Load settings configured in textarea
var textAreaConfig = ("gsbResearchHubSubtheme" in drupalSettings) ? drupalSettings.gsbResearchHubSubtheme : {};

// Grab the airtable variables.
let config = $contentArea.data('config');
let templateConfig = $contentArea.data('config');

var configDefault = {
"gutter": 10,
"equalHeight": false
}
config = {
...configDefault,
...config
...templateConfig,
...textAreaConfig
}

for (filterKey in config.filters) {
Expand All @@ -27,15 +31,12 @@
// Load the airtable data
$.ajax({
type: "GET",
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + settings.gsbResearchHubSubtheme.snaplogicToken);
},
dataType: "json",
url: settings.gsbResearchHubSubtheme.snaplogicURL + "/GSB/rh-airtable_proxy_cache/output?airtable_table=" + config.table + "&airtable_view=" + config.view,
url: "https://gsbrh-airtable-cache.s3.us-west-2.amazonaws.com/airtable-proxy-cache-" + config.table + "-" + config.view + ".json",
success: function(data) {
$contentArea.find('#airtable-list-loader').remove();
// Load the records.
let records = data.records;
let records = data.data.records;
if (records.length) {
for (recordIndex in records) {
for (fieldName in records[recordIndex].fields) {
Expand Down Expand Up @@ -253,7 +254,15 @@
}

// Set the browser url.
window.history.replaceState(null, null,'?' + urlParamaters.toString());
let params = urlParamaters.toString();
// If there are no parameters set then reset the url to no parameters.
// Otherwise set it to the given filters.
if (params === '') {
window.history.replaceState(null, null, window.location.pathname);
}
else {
window.history.replaceState(null, null,'?' + params);
}

// combine filters
let filterValue = buildFilters(filters);
Expand Down Expand Up @@ -338,7 +347,7 @@
// Apply the data to the template.
function processTemplate(config, templateKey, data, allData) {
var template = $('template#airtable-list-' + stringToCSSClass(templateKey) + '-template').html();
var settings = drupalSettings.gsbResearchHubSubtheme;

if (template) {
// Pull all of the tokens from the template.
var tokens = [];
Expand Down Expand Up @@ -382,8 +391,8 @@

// Pull in any additional config passed in from the text area.
var additionalConfig = [];
if ("arrayFormatConfig" in settings && token in settings.arrayFormatConfig) {
additionalConfig = settings.arrayFormatConfig[token];
if ("arrayFormatConfig" in config && token in config.arrayFormatConfig) {
additionalConfig = config.arrayFormatConfig[token];
}
content = formatString(config.format[token].type, config.format[token].options, content, additionalConfig);
}
Expand Down
2 changes: 1 addition & 1 deletion src/scss/components/masthead/_wrapper.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@charset "UTF-8";

@media (min-height: $su-screen-lg) {
@media (min-height: $su-screen-md) {
.su-masthead {
position: sticky;
top: 0;
Expand Down
Loading
Loading