From a833ddee4571308a91f689da92e035a14bff24b4 Mon Sep 17 00:00:00 2001 From: Adam Moore Date: Wed, 21 Feb 2024 05:19:46 +0000 Subject: [PATCH] Add the new build of the js file. --- dist/js/airtable-list-builder.js | 566 +++++++++++++++++++++++++++++++ 1 file changed, 566 insertions(+) create mode 100644 dist/js/airtable-list-builder.js diff --git a/dist/js/airtable-list-builder.js b/dist/js/airtable-list-builder.js new file mode 100644 index 0000000..9849305 --- /dev/null +++ b/dist/js/airtable-list-builder.js @@ -0,0 +1,566 @@ +/******/ (() => { // webpackBootstrap +var __webpack_exports__ = {}; +function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } +function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } +function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } +function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +(function ($, Drupal, drupalSettings) { + Drupal.behaviors.airtableListBuilder = { + attach: function attach(context, settings) { + // Get the content area + var $contentArea = $("#airtable-list"); + + // Grab the airtable variables. + var config = $contentArea.data('config'); + var configDefault = { + "gutter": 10, + "equalHeight": false + }; + config = _objectSpread(_objectSpread({}, configDefault), config); + for (filterKey in config.filters) { + // Set the default array of choices if choices are not provided for us. + if (!("choices" in config.filters[filterKey])) { + config.filters[filterKey].choices = []; + } + } + + // 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, + success: function success(data) { + $contentArea.find('#airtable-list-loader').remove(); + // Load the records. + var records = data.records; + if (records.length) { + for (recordIndex in records) { + for (fieldName in records[recordIndex].fields) { + if (fieldName.endsWith('_json') && records[recordIndex].fields[fieldName]) { + records[recordIndex].fields[stringToCSSClass(fieldName)] = JSON.parse(records[recordIndex].fields[fieldName]); + } else { + records[recordIndex].fields[stringToCSSClass(fieldName)] = records[recordIndex].fields[fieldName]; + } + } + } + var $recordWrapper = $('#airtable-list-record-wrapper'); + + // Process each record. + var _loop = function _loop() { + var record = records[recordIndex]; + var rowClasses = ''; + + // Process each field. + for (fieldKey in record.fields) { + // Process the filter choices if it's in the config + if (fieldKey in config.filters) { + if (Array.isArray(record.fields[fieldKey])) { + // Process Array + var _iterator2 = _createForOfIteratorHelper(record.fields[fieldKey]), + _step2; + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + item = _step2.value; + // See if the choice already exists. + var existingChoice = config.filters[fieldKey].choices.filter(function (row) { + return row.name === item; + }); + + // If the choice doesn't exist then add it to the list of choices. + if (!existingChoice.length) { + config.filters[fieldKey].choices.push({ + "key": stringToCSSClass(item), + "name": item + }); + } + + // Add to the list of classes for the row. + rowClasses += ' ' + stringToCSSClass(fieldKey) + '--' + stringToCSSClass(item); + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } else { + // See if the choice already exists. + var _existingChoice = config.filters[fieldKey].choices.filter(function (row) { + return row.name === record.fields[fieldKey]; + }); + + // If the choice doesn't exist then add it to the list of choices. + if (!_existingChoice.length) { + config.filters[fieldKey].choices.push({ + "key": stringToCSSClass(record.fields[fieldKey]), + "name": record.fields[fieldKey] + }); + } + + // Add to the list of classes for the row. + rowClasses += ' ' + stringToCSSClass(fieldKey) + '--' + stringToCSSClass(record.fields[fieldKey]); + } + } + } + + // Build the record html. + var recordTemplate = processTemplate(config, 'records', record.fields, record.fields); + + // Add rowClasses and add the record to the page. + recordTemplate = recordTemplate.replace('[rowClasses]', rowClasses); + $recordWrapper.append($(recordTemplate)); + }; + for (recordIndex in records) { + _loop(); + } + + // Pull the url parameters to use later. + var queryString = window.location.search; + var urlParams = new URLSearchParams(queryString); + var filters = {}; + // Add Filters on the page. + for (filterKey in config.filters) { + var _filter = config.filters[filterKey]; + // Build the select filter. + if (_filter.choices.length > 0) { + switch (_filter.templateID) { + case "filter-select": + var $filterSelect = $('select#airtable-list-' + filterKey); + // Build the options list. + var _iterator = _createForOfIteratorHelper(_filter.choices.sort(function (a, b) { + return a.name > b.name ? 1 : b.name > a.name ? -1 : 0; + })), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + choice = _step.value; + var $filterOption = $("