namespace App\Models;
use App\Fields\Webflow\WebflowImages;
+use App\Fields\Webflow\WebflowTexts;
use App\Http\Controllers\Admin\Operations\Tools\StaticSiteUploader;
use App\Http\Controllers\Admin\Operations\Tools\WebflowOperation;
use App\Jobs\WebflowPublish;
use Cubist\Backpack\Magic\Fields\BunchOfFieldsMultiple;
use Cubist\Backpack\Magic\Fields\Code;
use Cubist\Backpack\Magic\Fields\Hidden;
-use Cubist\Backpack\Magic\Fields\KeyValueBunchOfFieldsMultiple;
use Cubist\Backpack\Magic\Fields\SelectFromArray;
use Cubist\Backpack\Magic\Fields\Table;
use Cubist\Backpack\Magic\Fields\Text;
use Cubist\Util\CommandLine;
use Cubist\Util\Files\Files;
use Cubist\Util\Json;
+use Illuminate\Contracts\Cache\Lock;
use Illuminate\Support\Facades\Cache;
// __('!! Outils')
$this->addField('upload', SelectFromArray::class, __('Uploader sur'), ['translatable' => false, 'options' => $sites, 'tab' => __('Paramètres')]);
$this->addField('js', Code::class, __('Javascript complémentaire'), ['translatable' => false, 'language' => 'js', 'tab' => __('Code'), 'hint' => __('Code ajouté à toutes les pages')]);
$this->addField('css', Code::class, __('CSS complémentaire'), ['translatable' => false, 'language' => 'css', 'tab' => __('Code'), 'hint' => __('Code ajouté à toutes les pages')]);
- $this->addField('texts', KeyValueBunchOfFieldsMultiple::class, '', ['tab' => __('Textes'), 'edit_label' => '%url | %seo_title', 'allows_add' => false, 'allows_delete' => false, 'allows_clone' => false, 'allows_reorder' => false, 'bunch' => WebflowText::class, 'translatable' => true]);
+ $this->addField('texts', WebflowTexts::class, '', ['tab' => __('Textes'), 'translatable' => true,'hint'=>__('Modifier un texte ici ne produira aucun changement sur webflow')]);
$this->addField('images', WebflowImages::class, '', ['tab' => __('Images'), 'translatable' => true]);
$this->addField('seo', BunchOfFieldsMultiple::class, '', ['translatable' => true, 'edit_label' => '%url | %seo_title', 'allows_add' => false, 'allows_delete' => false, 'allows_clone' => false, 'allows_reorder' => false, 'bunch' => SEOPage::class, 'tab' => __('SEO')]);
$this->addField('api', Hidden::class);
return true;
}
- protected function refreshFormDataFromAPI()
+ protected function getLock(): Lock
{
- Webflow::clearCache();
- $this->api = Webflow::getEditableData($this->webflow);
+ return Cache::lock('webflow_api_refresh_' . $this->id);
+ }
- $mainLocale = $this->getMainLocale();
- $seo = Json::decode($this->seo, true);
- $seo[$mainLocale] = $this->api['seo'];
- foreach ($this->getLocalesCodes() as $locale) {
- if ($locale === $mainLocale) {
- continue;
- }
- if (!isset($seo[$locale])) {
- $seo[$locale] = [];
- }
- foreach ($seo[$mainLocale] as $s) {
- $seo[$locale][] = $s;
+ protected function refreshFormDataFromAPI()
+ {
+ $lock = $this->getLock();
+ try {
+ $lock->block(360);
+
+ Webflow::clearCache();
+ $this->api = Webflow::getEditableData($this->webflow);
+
+ $mainLocale = $this->getMainLocale();
+
+ $props = ['seo'/*, 'texts', 'images'*/];
+ foreach ($props as $prop) {
+ $data = Json::decode($this->$prop, Json::TYPE_ARRAY);
+ $data[$mainLocale] = $this->api[$prop];
+ foreach ($this->getLocalesCodes() as $locale) {
+ if ($locale === $mainLocale) {
+ continue;
+ }
+ if (!isset($data[$locale])) {
+ $data[$locale] = [];
+ }
+ foreach ($data[$mainLocale] as $d) {
+ $data[$locale][] = $d;
+ }
+ }
+ $this->setTranslations($prop, $data);
}
- }
- $this->setTranslations('seo', $seo);
- $this->saveQuietly();
+ $this->saveQuietly();
+ } catch (LockTimeoutException $e) {
+
+ } finally {
+ $lock?->release();
+ }
}
/**
public function onRetrieved(): bool
{
- $locales = $this->locales_domains;
- if (is_string($locales)) {
- $locales = json_decode($locales, true);
+
+ $lock = $this->getLock();
+ try {
+ $lock->block(1200);
+
+ $locales = $this->locales_domains;
+ if (is_string($locales)) {
+ $locales = json_decode($locales, true);
+ }
+ Cache::put('webflow_' . $this->id . '_locales', $locales);
+
+ } catch (LockTimeoutException $e) {
+
+ } finally {
+ $lock?->release();
}
- Cache::put('webflow_' . $this->id . '_locales', $locales);
+
return parent::onRetrieved();
}
+@php
+ $value=old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? '[]';
+ $translations=\Cubist\Util\Json::decode($value,\Cubist\Util\Json::TYPE_ARRAY)??[];
+ $texts=\Cubist\Util\Json::decode($crud->entry->api,\Cubist\Util\Json::TYPE_ARRAY)['texts'];
+ foreach ($translations as $key=>$trans) {
+ $t=base64_decode($key);
+ if(!isset($texts[$t])){
+ $texts[$t]=['occurences'=>0,'key'=>$key];
+ }
+ }
+@endphp
+
+@include('crud::fields.inc.wrapper_start')
+<label>{!! $field['label'] !!}</label>
+@include('crud::fields.inc.translatable_icon')
+
+@foreach($texts as $text=>$details)
+ <label>{{$text}}</label>
+ <textarea rows="{{ceil(mb_strlen($text)/150)}}" name="{{ $field['name'] }}[{{$details['key']}}]" @include('crud::fields.inc.attributes')>
+ {{$translations[$details['key']]??''}}
+ </textarea>
+
+ @if (isset($field['hint']))
+ <p class="help-block">{{__(':nb occurences',['nb'=>$details['occurences']])}}</p>
+ @endif
+@endforeach
+{{-- HINT --}}
+
+@include('crud::fields.inc.wrapper_end')