From 2155a5d635d0bffeb11956449b94a10c077016a1 Mon Sep 17 00:00:00 2001 From: Maarten Louage Date: Mon, 28 Apr 2025 11:01:50 +0000 Subject: [PATCH 1/2] (feat) modify global settings to support icons for socials and algemene voorwaarden link --- .vscode/launch.json | 15 +++ .../content-types/global-setting/schema.json | 106 ++++++++++-------- .../middlewares/global-setting-populate.js | 31 +++++ .../global-setting/routes/global-setting.js | 12 +- src/components/elements/social.json | 55 +++++---- types/generated/components.d.ts | 2 + types/generated/contentTypes.d.ts | 6 +- 7 files changed, 152 insertions(+), 75 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 src/api/global-setting/middlewares/global-setting-populate.js diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..d9fdb6e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node-terminal", + "name": "Run Script: develop", + "request": "launch", + "command": "yarn run develop", + "cwd": "${workspaceFolder}" + } + ] +} diff --git a/src/api/global-setting/content-types/global-setting/schema.json b/src/api/global-setting/content-types/global-setting/schema.json index d9eecf3..b68498c 100644 --- a/src/api/global-setting/content-types/global-setting/schema.json +++ b/src/api/global-setting/content-types/global-setting/schema.json @@ -1,46 +1,60 @@ -{ - "kind": "collectionType", - "collectionName": "global_settings", - "info": { - "singularName": "global-setting", - "pluralName": "global-settings", - "displayName": "Global Settings", - "description": "" - }, - "options": { - "draftAndPublish": true - }, - "pluginOptions": { - "i18n": { - "localized": true - } - }, - "attributes": { - "pages": { - "type": "relation", - "relation": "oneToMany", - "target": "api::page.page" - }, - "site": { - "pluginOptions": { - "i18n": { - "localized": true - } - }, - "type": "enumeration", - "enum": ["cloud", "dotnet"], - "default": "dotnet", - "required": true - }, - "Socials": { - "type": "component", - "repeatable": true, - "pluginOptions": { - "i18n": { - "localized": false - } - }, - "component": "elements.social" - } - } -} +{ + "kind": "collectionType", + "collectionName": "global_settings", + "info": { + "singularName": "global-setting", + "pluralName": "global-settings", + "displayName": "Global Settings", + "description": "" + }, + "options": { + "draftAndPublish": true + }, + "pluginOptions": { + "i18n": { + "localized": true + } + }, + "attributes": { + "pages": { + "type": "relation", + "relation": "oneToMany", + "target": "api::page.page" + }, + "site": { + "pluginOptions": { + "i18n": { + "localized": true + } + }, + "type": "enumeration", + "enum": [ + "cloud", + "dotnet" + ], + "default": "dotnet", + "required": true + }, + "socials": { + "type": "component", + "repeatable": true, + "pluginOptions": { + "i18n": { + "localized": false + } + }, + "component": "elements.social" + }, + "algemeneVoorwaarden": { + "type": "media", + "multiple": false, + "required": true, + "allowedTypes": [ + "images", + "files", + "videos", + "audios" + ] + } + } +} diff --git a/src/api/global-setting/middlewares/global-setting-populate.js b/src/api/global-setting/middlewares/global-setting-populate.js new file mode 100644 index 0000000..dd5a669 --- /dev/null +++ b/src/api/global-setting/middlewares/global-setting-populate.js @@ -0,0 +1,31 @@ +'use strict'; + +/** + * `global-setting-populate` middleware + */ + +const populate = { + pages: { + fields: ['title_website', 'slug'] + }, + algemeneVoorwaarden: { + fields: ['url'], + }, + socials: { + populate: { + icon: { + fields: ['url'], + }, + }, + } +} + + +module.exports = (config, { strapi }) => { + return async (ctx, next) => { + strapi.log.info('In global-setting-populate middleware.'); + ctx.query.populate = populate; + + await next(); + }; +}; diff --git a/src/api/global-setting/routes/global-setting.js b/src/api/global-setting/routes/global-setting.js index 75f29b4..f496e08 100644 --- a/src/api/global-setting/routes/global-setting.js +++ b/src/api/global-setting/routes/global-setting.js @@ -1,9 +1,11 @@ 'use strict'; -/** - * global-setting router - */ - const { createCoreRouter } = require('@strapi/strapi').factories; -module.exports = createCoreRouter('api::global-setting.global-setting'); +module.exports = createCoreRouter('api::global-setting.global-setting', { + config: { + find: { + middlewares: ['api::global-setting.global-setting-populate'], + }, + }, +}); diff --git a/src/components/elements/social.json b/src/components/elements/social.json index 756974c..ccf5b71 100644 --- a/src/components/elements/social.json +++ b/src/components/elements/social.json @@ -1,23 +1,32 @@ -{ - "collectionName": "components_elements_socials", - "info": { - "displayName": "Social", - "icon": "heart" - }, - "options": {}, - "attributes": { - "title": { - "type": "string", - "required": true - }, - "isEnabled": { - "type": "boolean", - "default": false, - "required": true - }, - "link": { - "type": "string", - "required": true - } - } -} +{ + "collectionName": "components_elements_socials", + "info": { + "displayName": "Social", + "icon": "heart", + "description": "" + }, + "options": {}, + "attributes": { + "title": { + "type": "string", + "required": true + }, + "isEnabled": { + "type": "boolean", + "default": false, + "required": true + }, + "link": { + "type": "string", + "required": true + }, + "icon": { + "allowedTypes": [ + "images" + ], + "type": "media", + "multiple": false, + "required": true + } + } +} diff --git a/types/generated/components.d.ts b/types/generated/components.d.ts index a209025..a82d266 100644 --- a/types/generated/components.d.ts +++ b/types/generated/components.d.ts @@ -56,10 +56,12 @@ export interface ElementsListItemWithIcon extends Struct.ComponentSchema { export interface ElementsSocial extends Struct.ComponentSchema { collectionName: 'components_elements_socials'; info: { + description: ''; displayName: 'Social'; icon: 'heart'; }; attributes: { + icon: Schema.Attribute.Media<'images'> & Schema.Attribute.Required; isEnabled: Schema.Attribute.Boolean & Schema.Attribute.Required & Schema.Attribute.DefaultTo; diff --git a/types/generated/contentTypes.d.ts b/types/generated/contentTypes.d.ts index acbff11..eaab4b6 100644 --- a/types/generated/contentTypes.d.ts +++ b/types/generated/contentTypes.d.ts @@ -553,6 +553,10 @@ export interface ApiGlobalSettingGlobalSetting }; }; attributes: { + algemeneVoorwaarden: Schema.Attribute.Media< + 'images' | 'files' | 'videos' | 'audios' + > & + Schema.Attribute.Required; createdAt: Schema.Attribute.DateTime; createdBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> & Schema.Attribute.Private; @@ -571,7 +575,7 @@ export interface ApiGlobalSettingGlobalSetting }; }> & Schema.Attribute.DefaultTo<'dotnet'>; - Socials: Schema.Attribute.Component<'elements.social', true> & + socials: Schema.Attribute.Component<'elements.social', true> & Schema.Attribute.SetPluginOptions<{ i18n: { localized: false; From f50d56ae22ca37d697253419ba6b9c1bacac3a59 Mon Sep 17 00:00:00 2001 From: Maarten Louage Date: Mon, 28 Apr 2025 11:34:16 +0000 Subject: [PATCH 2/2] (feat) add address in settings --- .../content-types/global-setting/schema.json | 12 ++++++++++++ types/generated/contentTypes.d.ts | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/api/global-setting/content-types/global-setting/schema.json b/src/api/global-setting/content-types/global-setting/schema.json index b68498c..c5549e9 100644 --- a/src/api/global-setting/content-types/global-setting/schema.json +++ b/src/api/global-setting/content-types/global-setting/schema.json @@ -55,6 +55,18 @@ "videos", "audios" ] + }, + "straat": { + "type": "string", + "required": true + }, + "postcode": { + "type": "string", + "required": true + }, + "gemeente": { + "type": "string", + "required": true } } } diff --git a/types/generated/contentTypes.d.ts b/types/generated/contentTypes.d.ts index eaab4b6..7af3f88 100644 --- a/types/generated/contentTypes.d.ts +++ b/types/generated/contentTypes.d.ts @@ -560,12 +560,14 @@ export interface ApiGlobalSettingGlobalSetting createdAt: Schema.Attribute.DateTime; createdBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> & Schema.Attribute.Private; + gemeente: Schema.Attribute.String & Schema.Attribute.Required; locale: Schema.Attribute.String; localizations: Schema.Attribute.Relation< 'oneToMany', 'api::global-setting.global-setting' >; pages: Schema.Attribute.Relation<'oneToMany', 'api::page.page'>; + postcode: Schema.Attribute.String & Schema.Attribute.Required; publishedAt: Schema.Attribute.DateTime; site: Schema.Attribute.Enumeration<['cloud', 'dotnet']> & Schema.Attribute.Required & @@ -581,6 +583,7 @@ export interface ApiGlobalSettingGlobalSetting localized: false; }; }>; + straat: Schema.Attribute.String & Schema.Attribute.Required; updatedAt: Schema.Attribute.DateTime; updatedBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> & Schema.Attribute.Private;