]> _ Git - cubist_cms-back.git/commitdiff
wip #5700 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 27 Jan 2023 18:05:07 +0000 (19:05 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 27 Jan 2023 18:05:07 +0000 (19:05 +0100)
src/app/Magic/Models/ExternalServer.php
src/resources/views/fields/external_path.blade.php

index 8f58a7f0d6c279a3549d36ce4aedf28e0847711f..d123bfec3b22d5c1be175cdfa04d43e005e3b7d0 100644 (file)
@@ -34,21 +34,29 @@ class ExternalServer extends CubistMagicAbstractModel implements IServer
         $this->addField('username', Text::class, __('Nom d\'utilisateur'), ['when' => ['protocol' => $this->getUsernameProtocols()]]);
         $this->addField('password', Password::class, __('Mot de passe'), ['when' => ['protocol' => $this->getPasswordProtocols()]]);
         $this->addField('base_path', Text::class, __('Chemin de base'), ['default' => '/']);
-        $this->addField('base_url', URL::class, __('URL de base'), ['default' => 'https://']);
+        $this->addField('base_url', URL::class, __('URL de base'), ['default' => 'https://', 'column' => true]);
     }
 
     public static function getAllServers()
     {
-
         if (null === static::$_servers) {
             static::$_servers = [];
             foreach (static::where('created_ok', '1')->get() as $server) {
-                static::$_servers[$server->id] = ['name' => $server->name, 'base_url' => $server->base_url];
+                static::$_servers[$server->id] = static::_getOneServer($server);
             }
         }
         return static::$_servers;
     }
 
+    /**
+     * @param $server static
+     * @return void
+     */
+    protected static function _getOneServer($server)
+    {
+        return ['name' => $server->name, 'base_url' => $server->base_url ?: $server->base_path];
+    }
+
     protected function getProtocols()
     {
         return ['FTP' => __('FTP non sécurisé'), 'FTPS' => __('FTP sécurisé explicite sur TLS'), 'FTPES' => __('FTP sécurisé implicite sur TLS'), 'SFTP' => 'SFTP'];
@@ -81,10 +89,9 @@ class ExternalServer extends CubistMagicAbstractModel implements IServer
 
 
     /**
-     * @param $protocol
      * @return Driver
      */
-    public function getTransferDriver($protocol)
+    public function getTransferDriver()
     {
         if (in_array($this->getProtocol(), $this->getFTPProtocols())) {
             return new FTP($this);
index c9f6afa8249911d40c972df8c09e98da212c6e3a..99aa3f77a4aa85d5e345104eacb3d4ecf1bf3aa7 100644 (file)
@@ -43,8 +43,8 @@ $servers = $serversClass::getAllServers();
         <label>{!! __('Chemin') !!}</label>
         <div class="input-group">
             <div class="input-group-prepend"><span class="input-group-text prefix"></span></div>
-            <input @include('crud::fields.inc.attributes')
-                   value="{{ $value['path'] }}"
+            <input data-class="external_path_server_path" @include('crud::fields.inc.attributes')
+            value="{{ $value['path'] }}"
                    type="text"
                    name="{{ $field['name'] }}[path]"
             ></div>
@@ -104,10 +104,23 @@ $servers = $serversClass::getAllServers();
 
     @push('crud_fields_scripts')
         <script>
+            function liveslugify(text) {
+                return text
+                    .toString()// Cast to string (optional)
+                    .replace(/\/+/g,'fwdslash')
+                    .normalize('NFKD')            // The normalize() using NFKD method returns the Unicode Normalization Form of a given string.
+                    .replace(/\s+/g, '-')         // Replace spaces with -
+                    .replace(/[^\w\-]+/g, '')     // Remove all non-word chars
+                    .replace(/\_/g, '-')           // Replace _ with -
+                    .replace(/\-\-+/g, '-')       // Replace multiple - with single -
+                    //.replace(/\-$/g, '')         // Remove trailing -
+                    .replace(/fwdslash/g,'/');
+            }
+
             $(function () {
                 function updateServer(s) {
                     var prefix = $(s).find('option[value="' + $(s).val() + '"]').data('prefix');
-                    console.log($(s).val(), prefix,(s).find('option[value="' + $(s).val() + '"]'));
+                    console.log($(s).val(), prefix, (s).find('option[value="' + $(s).val() + '"]'));
                     $(s).closest('.external_path__wrapper').find('.prefix').text(prefix);
                 }
 
@@ -115,6 +128,10 @@ $servers = $serversClass::getAllServers();
                     updateServer($(this));
                 });
 
+                $(document).on('keyup keydown', '[data-class="external_path_server_path"]', function () {
+                    $(this).val(liveslugify($(this).val()));
+                });
+
                 $('[data-class="external_path_server_select"]').each(function () {
                     updateServer($(this));
                 });