From ca07582e6e744f097023f673b1e54452df4ba1d3 Mon Sep 17 00:00:00 2001 From: hujambo-dunia Date: Wed, 29 Oct 2025 07:02:51 -0400 Subject: [PATCH 1/9] To Use page, adding Galaxy instance Tiers column along with Operational column --- gridsome.server.js | 107 ++++++++++++++++++++++++++++- src/composables/useTableSorting.js | 46 ++++++------- src/pages/Use.vue | 18 +++-- 3 files changed, 141 insertions(+), 30 deletions(-) diff --git a/gridsome.server.js b/gridsome.server.js index 2dccec80ca..375deb4aad 100644 --- a/gridsome.server.js +++ b/gridsome.server.js @@ -332,6 +332,34 @@ class nodeModifier { } return node; }, + Platform: function (node) { + node.designation = null; + + // Try to match platform URLs with designations + if (node.platforms && Array.isArray(node.platforms)) { + for (const platform of node.platforms) { + if (platform.url) { //platform_url + const url = platform.url.replace(/^https?:\/\//, ""); //platform_url + const designation = DESIGNATIONS_MAP.get(url); + if (designation) { + node.designation = designation; + break; + } + } + } + } + + // Also try matching against the main platform URL if it exists + if (!node.designation && node.url) { + const url = node.url.replace(/^https?:\/\//, ""); + const designation = DESIGNATIONS_MAP.get(url); + if (designation) { + node.designation = designation; + } + } + + return node; + }, }; } @@ -383,6 +411,58 @@ function parseNavbarItem(rawItem, pathPrefix) { return item; } +function loadDesignationsData() { + const designationsPath = path.join(__dirname, "content/usegalaxy/designations.csv"); + if (!fs.existsSync(designationsPath)) { + console.warn("Designations CSV file not found:", designationsPath); + return new Map(); + } + + const csvContent = fs.readFileSync(designationsPath, "utf8"); + const lines = csvContent.split("\n").filter(line => line.trim()); + const headers = lines[0].split(",").map(h => h.trim()); + const designationsMap = new Map(); + + for (let i = 1; i < lines.length; i++) { + const line = lines[i]; + if (!line.trim()) continue; + + // Parse CSV line, handling quoted values + const values = []; + let current = ""; + let inQuotes = false; + + for (let j = 0; j < line.length; j++) { + const char = line[j]; + if (char === '"') { + inQuotes = !inQuotes; + } else if (char === ',' && !inQuotes) { + values.push(current.trim()); + current = ""; + } else { + current += char; + } + } + values.push(current.trim()); + + if (values.length >= headers.length) { + const designation = {}; + headers.forEach((header, index) => { + designation[header.toLowerCase()] = values[index] || ""; + }); + + if (designation.url) { + const url = designation.url.replace(/^https?:\/\//, ""); + designationsMap.set(url, designation); + } + } + } + + return designationsMap; +} + +const DESIGNATIONS_MAP = loadDesignationsData(); + module.exports = function (api) { api.loadSource((actions) => { // Using the Data Store API: https://gridsome.org/docs/data-store-api/ @@ -426,7 +506,7 @@ module.exports = function (api) { }; } actions.addSchemaResolvers(schemas); - actions.addSchemaTypes( + actions.addSchemaTypes([ actions.schema.createObjectType({ name: "Dataset", interfaces: ["Node"], @@ -436,7 +516,30 @@ module.exports = function (api) { main_subsite: "String", }, }), - ); + actions.schema.createObjectType({ + name: "Platform", + interfaces: ["Node"], + extensions: { infer: true }, + fields: { + designation: { + type: "PlatformDesignation", + resolve: (obj) => obj.designation, + }, + }, + }), + actions.schema.createObjectType({ + name: "PlatformDesignation", + fields: { + operative: "String", + tier: "Int", + url: "String", + city: "String", + region: "String", + description: "String", + notes: "String", + }, + }), + ]); }); // Populate the derived fields. diff --git a/src/composables/useTableSorting.js b/src/composables/useTableSorting.js index a5edcfea06..89fbd25ddb 100644 --- a/src/composables/useTableSorting.js +++ b/src/composables/useTableSorting.js @@ -28,7 +28,7 @@ export function useTableSorting() { platform: platformSortHandler, title: titleSortHandler, summary: textSortHandler, - // tier: tierSortHandler, + tier: tierSortHandler, region: regionSortHandler, }; @@ -81,17 +81,17 @@ export function useTableSorting() { * @param {Object} bRow - Second row object * @returns {number} - Sort result (-1, 0, 1) */ - // const tierSortHandler = (aRow, bRow) => { - // // TODO refactor into another method - // const a = getTierValue(aRow); - // const b = getTierValue(bRow); + const tierSortHandler = (aRow, bRow) => { + // TODO refactor into another method + const a = getTierValue(aRow); + const b = getTierValue(bRow); - // if (a === null && b === null) return 0; - // if (a === null) return 1; - // if (b === null) return -1; + if (a === null && b === null) return 0; + if (a === null) return 1; + if (b === null) return -1; - // return a - b; - // }; + return a - b; + }; /** * Sort handler for region columns (handles string region values) @@ -128,17 +128,17 @@ export function useTableSorting() { * @param {Object} row - Row object * @returns {number|null} - Tier value for sorting */ - // const getTierValue = (row) => { - // if (row.designation && Array.isArray(row.designation) && row.designation.length > 0) { - // const tier = parseInt(row.designation[0].tier, 10); - // return isNaN(tier) ? null : tier; - // } - // if (row.designation && row.designation.tier) { - // const tier = parseInt(row.designation.tier, 10); - // return isNaN(tier) ? null : tier; - // } - // return null; - // }; + const getTierValue = (row) => { + if (row.designation && Array.isArray(row.designation) && row.designation.length > 0) { + const tier = parseInt(row.designation[0].tier, 10); + return isNaN(tier) ? null : tier; + } + if (row.designation && row.designation.tier) { + const tier = parseInt(row.designation.tier, 10); + return isNaN(tier) ? null : tier; + } + return null; + }; /** * Get the region value for sorting (returns string value or null) @@ -253,14 +253,14 @@ export function useTableSorting() { platformSortHandler, titleSortHandler, textSortHandler, - // tierSortHandler, + tierSortHandler, regionSortHandler, createSortableField, createSortableFields, getPlatformDisplayValue, - // getTierValue, + getTierValue, getRegionValue, compareStrings, getSortState, diff --git a/src/pages/Use.vue b/src/pages/Use.vue index bd490434c5..3faa72585c 100644 --- a/src/pages/Use.vue +++ b/src/pages/Use.vue @@ -104,12 +104,12 @@ - - + + -