Skip to content

Commit

Permalink
feat(refact): migrated from _dev folder to resource folder for vue pr…
Browse files Browse the repository at this point in the history
…oject
  • Loading branch information
Dreimus committed Aug 30, 2024
1 parent 67439cf commit 525b0da
Show file tree
Hide file tree
Showing 170 changed files with 894 additions and 6,149 deletions.
5,853 changes: 0 additions & 5,853 deletions _dev/package-lock.json

This file was deleted.

23 changes: 0 additions & 23 deletions _dev/vite.config.js

This file was deleted.

16 changes: 0 additions & 16 deletions _dev/vite.config.prettyblocks.js

This file was deleted.

24 changes: 18 additions & 6 deletions config/routes.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
# routes.yml

prestasafe_prettyblocks_zone_list:
prettyblocks_admin_index:
path: /prettyblocks/admin
methods: [ GET ]
defaults:
_controller: PrestaSafe\PrettyBlocks\Controller\Admin\EditionController::indexAction

prettyblocks_zone_list:
path: /prettyblocks/api/zones
methods: [ GET ]
defaults:
_controller: 'prestasafe.prettyblocks.controller.zone_controller:listZones'
_controller: PrestaSafe\PrettyBlocks\Controller\Api\ZoneController:listZones

prestasafe_prettyblocks_zone_get:
prettyblocks_zone_get:
path: /prettyblocks/api/zones/{id}
methods: [ GET ]
defaults:
_controller: 'prestasafe.prettyblocks.controller.zone_controller:getZone'
_controller: PrestaSafe\PrettyBlocks\Controller\Api\ZoneController:getZone

prestasafe_prettyblocks_zone_update:
prettyblocks_zone_update:
path: /prettyblocks/api/zones/{id}
methods: [ PUT ]
defaults:
_controller: 'prestasafe.prettyblocks.controller.zone_controller:updateZone'
_controller: PrestaSafe\PrettyBlocks\Controller\Api\ZoneController:updateZone

prettyblocks_media_upload:
path: /prettyblocks/api/media/upload
methods: [ POST ]
defaults:
_controller: PrestaSafe\PrettyBlocks\Controller\Api\MediaController:uploadMedia
16 changes: 13 additions & 3 deletions config/services.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# config.yml

services:
default:
_defaults:
public: true
autoconfigure: true
autowire: true
Expand All @@ -20,18 +18,30 @@ services:
prestasafe.prettyblocks.repository.block_repository:
class: PrestaSafe\PrettyBlocks\Repository\BlockRepository
factory: [ '@doctrine', getRepository ]
arguments:
-
$persistentObject: PrestaSafe\PrettyBlocks\Entity\Block

prestasafe.prettyblocks.repository.component_repository:
class: PrestaSafe\PrettyBlocks\Repository\ComponentRepository
factory: [ '@doctrine', getRepository ]
arguments:
-
$persistentObject: PrestaSafe\PrettyBlocks\Entity\Component

prestasafe.prettyblocks.repository.primitive_field_repository:
class: PrestaSafe\PrettyBlocks\Repository\PrimitiveFieldRepository
factory: [ '@doctrine', getRepository ]
arguments:
-
$persistentObject: PrestaSafe\PrettyBlocks\Entity\PrimitiveField

prestasafe.prettyblocks.repository.zone_repository:
class: PrestaSafe\PrettyBlocks\Repository\ZoneRepository
factory: [ '@doctrine', getRepository ]
arguments:
-
$persistentObject: PrestaSafe\PrettyBlocks\Entity\Zone

# Service principal pour la gestion des zones
prestasafe.prettyblocks.service.zone_service:
Expand Down
21 changes: 6 additions & 15 deletions prettyblocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

use PrestaSafe\PrettyBlocks\Install\Installer;
use PrestaSafe\PrettyBlocks\Smarty\Plugin\ZonePlugin;
use PrestaShop\PrestaShop\Core\Module\WidgetInterface;

if (!defined('_PS_VERSION_')) {
Expand Down Expand Up @@ -66,13 +67,8 @@ public function isUsingNewTranslationSystem()

public function getContent()
{
$domain = Tools::getShopDomainSsl(true);
$symfonyUrl = $domain . Link::getUrlSmarty([
'entity' => 'sf',
'route' => 'admin_prettyblocks',
]);

return Tools::redirect($symfonyUrl);
$route = $this->get('router')->generate('prettyblocks_admin_index');
Tools::redirectAdmin($route);
}

private function loadDefault()
Expand Down Expand Up @@ -207,19 +203,14 @@ public function renderWidget($hookName = null, array $configuration = [])
}
}

public function registerBlockToZone($zone_name, $block_code)
{
return PrettyBlocksModel::registerBlockToZone($zone_name, $block_code);
}

/**
* Hook dispatcher for registering smarty function
*/
public function hookActionDispatcher()
{
/* @deprecated {magic_zone} is deprecated since v1.1.0. Use {prettyblocks_zone} instead. */
$this->context->smarty->registerPlugin('function', 'magic_zone', [PrettyBlocks::class, 'renderZone']);
$this->context->smarty->registerPlugin('function', 'prettyblocks_zone', [PrettyBlocks::class, 'renderZone']);
$this->context->smarty->registerPlugin('function', 'prettyblocks_title', [PrettyBlocks::class, 'renderTitle']);
$this->context->smarty->registerPlugin('function', 'magic_zone', [ZonePlugin::class, 'renderZone']);
$this->context->smarty->registerPlugin('function', 'prettyblocks_zone', [ZonePlugin::class, 'renderZone']);
$this->context->smarty->registerPlugin('function', 'prettyblocks_title', [ZonePlugin::class, 'renderTitle']);
}
}
146 changes: 146 additions & 0 deletions src/Controller/Admin/EditionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php

declare(strict_types=1);

namespace PrestaSafe\PrettyBlocks\Controller\Admin;

use PrestaShop\PrestaShop\Adapter\LegacyContext;
use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Response;

class EditionController extends FrameworkBundleAdminController
{
public function indexAction(): Response
{
/** @var LegacyContext $context */
$context = $this->get('prestashop.adapter.legacy.context');

[$css, $js, $js_entry] = $this->getAssets($context);

$module = \Module::getInstanceByName('prettyblocks');

$link = new \Link();
$symfonyUrl = 'https://raviday_core.app.localhost/';
//$symfonyUrl = $this->get('router')->generate("prettyblocks_zone_get");

$shop_url = $context->getRootUrl();

$available_language_ids = $context->getAvailableLanguages();

return $this->render('@Modules/prettyblocks/templates/admin/index.html.twig', [
'base_url' => $link->getBaseLink(),
'favicon_url' => \Tools::getShopDomainSsl(true) . '/modules/' . $module->name . '/views/images/favicon.ico',
'module_name' => $module->displayName,
'shop_name' => $context->getContext()->shop->name,
'env' => [
'vitedev' => filter_var(getenv('PRETTYBLOCKS_VITE_DEV'), FILTER_VALIDATE_BOOLEAN) ?? false,
'PRETTYBLOCKS_VITE_HOST' => getenv('PRETTYBLOCKS_VITE_HOST') ? getenv('PRETTYBLOCKS_VITE_HOST') : 'http://localhost:3002/',
'iframe_sandbox' => getenv('PRETTYBLOCKS_IFRAME_SANDBOX') ? getenv('PRETTYBLOCKS_IFRAME_SANDBOX') : 'allow-same-origin allow-scripts allow-forms allow-popups allow-presentation allow-top-navigation allow-pointer-lock allow-popups-to-escape-sandbox allow-modals allow-top-navigation-by-user-activation',
],
'ajax_urls' => [
'simulate_home' => $symfonyUrl,
'search_by_ref' => $symfonyUrl,
'adminURL' => $context->getAdminBaseUrl(),
// 'update_ajax' => $updateAjax,
'sf' => $symfonyUrl,
'api' => $symfonyUrl,
'current_domain' => $shop_url,
'block_url' => $symfonyUrl,
'state' => $symfonyUrl,
'upload' => $symfonyUrl,
'collection' => $symfonyUrl,
// 'blocks_available' => $blockAvailableUrls,
// 'block_action_urls' => $blockUrl,
// 'theme_settings' => $settingsUrls,
'startup_url' => $symfonyUrl,
],
'trans_app' => [
'current_shop' => $this->trans('Shop in modification', 'Modules.Prettyblocks.Admin'),
'save' => $this->trans('Save', 'Modules.Prettyblocks.Admin'),
'add_new_element' => $this->trans('Add new element', 'Modules.Prettyblocks.Admin'),
'avalaible_elements' => $this->trans('Availables blocks', 'Modules.Prettyblocks.Admin'),
'close' => $this->trans('Close', 'Modules.Prettyblocks.Admin'),
'current_zone' => $this->trans('Current zone', 'Modules.Prettyblocks.Admin'),
'loading' => $this->trans('Loading', 'Modules.Prettyblocks.Admin'),
'default_settings' => $this->trans('Default settings', 'Modules.Prettyblocks.Admin'),
'choose_template' => $this->trans('Choose a template', 'Modules.Prettyblocks.Admin'),
'use_container' => $this->trans('Place the element in a column (container)', 'Modules.Prettyblocks.Admin'),
'bg_color' => $this->trans('Background color', 'Modules.Prettyblocks.Admin'),
'ex_color' => $this->trans('Add a color ex: #123456', 'Modules.Prettyblocks.Admin'),
'theme_settings' => $this->trans('Theme settings', 'Modules.Prettyblocks.Admin'),
'type_search_here' => $this->trans('Type your search here', 'Modules.Prettyblocks.Admin'),
'search_blocks' => $this->trans('Search blocks', 'Modules.Prettyblocks.Admin'),
'is_cached' => $this->trans('Enable cache', 'Modules.Prettyblocks.Admin'),
'paddings' => $this->trans('Paddings', 'Modules.Prettyblocks.Admin'),
'top' => $this->trans('Top', 'Modules.Prettyblocks.Admin'),
'right' => $this->trans('Right', 'Modules.Prettyblocks.Admin'),
'bottom' => $this->trans('Bottom', 'Modules.Prettyblocks.Admin'),
'left' => $this->trans('Left', 'Modules.Prettyblocks.Admin'),
'margins' => $this->trans('Margins', 'Modules.Prettyblocks.Admin'),
'use_custom_entry' => $this->trans('Use custom entries (px, rem etc..)', 'Modules.Prettyblocks.Admin'),
'auto_size_section' => $this->trans('Auto sizing', 'Modules.Prettyblocks.Admin'),
'paddings_section_help' => $this->trans('Padding is the space inside an element, between its content and its boundary', 'Modules.Prettyblocks.Admin'),
'margins_section_help' => $this->trans('Margin refers to the space outside an element, separating it from other elements', 'Modules.Prettyblocks.Admin'),
'force_full_width' => $this->trans('Stretch section to 100%', 'Modules.Prettyblocks.Admin'),
'position_updated' => $this->trans('Position updated successfully', 'Modules.Prettyblocks.Admin'),
'element_removed' => $this->trans('Element removed successfully', 'Modules.Prettyblocks.Admin'),
'element_added' => $this->trans('Element added successfully', 'Modules.Prettyblocks.Admin'),
'error_console' => $this->trans('An error occurred while processing your request', 'Modules.Prettyblocks.Admin'),
'duplicate_state_error' => $this->trans('An error occurred while duplicating the element', 'Modules.Prettyblocks.Admin'),
'get_pro' => $this->trans('Get Pro Blocks', 'Modules.Prettyblocks.Admin'),
],
'security_app' => [
'ajax_token' => \Configuration::getGlobalValue('_PRETTYBLOCKS_TOKEN_'),
'prettyblocks_version' => $module->version,
'available_language_ids' => $available_language_ids,
'tinymce_api_key' => 'no-api-key',
],
'prettyblocks' => [
'assets' => [
'css' => $css,
'js' => $js,
'entrypoint' => $js_entry,
],
],
]);
}

private function getAssets(LegacyContext $context): array
{
$filesystem = new Filesystem();
$path = '/modules/prettyblocks/src/Resources/public/';
$build_dir = _PS_ROOT_DIR_ . $path;
$build_dir_https = $context->getRootUrl() . ltrim($path, '/');
$js = [];
$css = [];
$js_entry = '';
if ($filesystem->exists($build_dir)) {
// load manifest.json
$manifest = $build_dir . 'manifest.json';

if (!$filesystem->exists($manifest)) {
throw new \Exception('manifest.json not exist');
}
$json = \Tools::file_get_contents($manifest);
$json = json_decode($json, true);

foreach ($json as $file) {
if (isset($file['file'])) {
if (isset($file['isEntry']) && $file['isEntry']) {
$js_entry = $build_dir_https . $file['file'];
} else {
$js[] = $build_dir_https . $file['file'];
}
}
if (isset($file['css'])) {
foreach ($file['css'] as $entry) {
$css[] = $build_dir_https . $entry;
}
}
}
}

return [$css, $js, $js_entry];
}
}
28 changes: 28 additions & 0 deletions src/Controller/Api/MediaController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace PrestaSafe\PrettyBlocks\Controller\Api;

use PrestaSafe\PrettyBlocks\Service\ZoneService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class MediaController extends AbstractController
{
public function upload(Request $request, ZoneService $zoneService): JsonResponse
{
$zone = $request->get('zone');
$file = $request->files->get('file');

if (!$zone || !$file) {
return new JsonResponse(['error' => 'Invalid request'], 400);
}

$zoneService->upload($zone, $file);

return new JsonResponse(['success' => true]);
}

}
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion _dev/index.html → src/Resources/editor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<title>PrettyBlocks Editor</title>
</head>
<body>
<div id="app"></div>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions _dev/package.json → src/Resources/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
"private": true,
"version": "1.0.0",
"scripts": {
"dev": "vite --port 3002",
"dev": "vite --port 3002 --host 0.0.0.0",
"build": "vite build",
"watch": "vite build --watch --mode development",
"preview": "vite preview",
"watch-iframe": "vite build --watch --config vite.config.prettyblocks.js",
"test": "jest"
},
"dependencies": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import Button from "./Button.vue";
import Iframe from "../scripts/iframe";
import { contextShop } from "../store/currentBlock";
// let iframe = new Iframe(ajax_urls.startup_url, 1, 1)
let iframe = new Iframe();
let iframe = new Iframe(ajax_urls.startup_url, 1, 1)
//let iframe = new Iframe();
defineProps({
src: String,
});
Expand Down Expand Up @@ -85,7 +85,7 @@ let showLoader = computed(() => {
watch(iframe.loader);
let filteredURL = computed(() => {
// return iframe.updateFilteredURL(iframe.current_url.value);
return iframe.updateFilteredURL(iframe.current_url.value);
});
watch(iframe.current_url, () => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 525b0da

Please sign in to comment.