Skip to content

Commit

Permalink
optimize theme parts
Browse files Browse the repository at this point in the history
  • Loading branch information
A1Gard committed Dec 22, 2024
1 parent 5edcdb1 commit 89f80a5
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/makePart.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function handle()
}
DOC;

file_put_contents($folderPath . '/' . $part . '.blade.php', "<section class='{$part}'></section>");
file_put_contents($folderPath . '/' . $part . '.blade.php', str_replace('THEME_PART_NAME',$part,'<section class="THEME_PART_NAME live-setting" data-live="{{$data->area_name.\'_\'.$data->part}}" ></section>'));
file_put_contents($folderPath . '/' . $part . '.js', '');
file_put_contents($folderPath . '/' . $part . '.json', json_encode($detail,JSON_PRETTY_PRINT));
file_put_contents($folderPath . '/' . ucfirst($part) . '.php', $handler);
Expand Down
18 changes: 18 additions & 0 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\Category;
use App\Models\Area;
use App\Models\Part;
use App\Models\Post;
use App\Models\Menu;
use App\Models\Product;
use App\Models\Rate;
Expand Down Expand Up @@ -902,6 +903,23 @@ function getProductsQueryBySetting($key, $limit = 10)
}
return $q->orderBy($data[1], $data[2])->limit($limit)->get();
}
/**
* get posts by setting key
* @param $key
* @param integer $limit
* @return \App\Models\Post[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Post_C
*/
function getPostsQueryBySetting($key, $limit = 10)
{
$data = explode(',', getSetting($key) ?? '1,id,DESC');
if ($data[0] == 0) {
$q = Post::where('status', 1);
}else{
$q = Group::where('id', $data[0])->first()
->posts()->where('status', 1);
}
return $q->orderBy($data[1], $data[2])->limit($limit)->get();
}

/**
* get group's posts by setting key
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/setting-field.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class="form-control @error('status') is-invalid @enderror">
</span>
<searchable-select
@error($setting->key) :err="true" @enderror
:items='@json($groups)'
:items='@json($groupz)'
title-field="name"
value-field="id"
xlang="{{config('app.locale')}}"
Expand Down
11 changes: 10 additions & 1 deletion resources/views/segments/posts/PostsSlider/PostsSlider.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
</h1>

</div>

<div id="posts-slider-container">

<div id="posts-slider">

@foreach( getGroupPostsBySetting($data->area_name.'_'.$data->part.'_group',10) as $post )

@foreach( getPostsQueryBySetting($data->area_name.'_'.$data->part.'_query',10) as $post )
<div class="item slider-content">
<div class="post-slider">

Expand All @@ -23,5 +25,12 @@
</div>
@endforeach
</div>

</div>
<div id="pst-nxt" class="sld-btn">
<i class="ri-arrow-right-line"></i>
</div>
<div id="pst-prv" class="sld-btn">
<i class="ri-arrow-left-line"></i>
</div>
</section>
37 changes: 28 additions & 9 deletions resources/views/segments/posts/PostsSlider/PostsSlider.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {tns} from "tiny-slider/src/tiny-slider";

var postsSlider ;
var postsSlider;

document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('#posts-slider')?.forEach(function (el) {
if (el.classList.contains('.tns-slider')){
if (el.classList.contains('.tns-slider')) {
console.log('ignore');
return 'ignore';
}
Expand All @@ -17,20 +17,24 @@ document.addEventListener('DOMContentLoaded', () => {
mouseDrag: true,
autoplayTimeout: 5000,
gutter: 10,
responsive:{
560:{
responsive: {
560: {
items: 2,
edgePadding: 30,
},
768:{
items: 4,
768: {
items: 3,
edgePadding: 40,
},
1000:{
items: 5,
1000: {
items: 4,
edgePadding: 50,
},
1400:{
1400: {
items: 5,
edgePadding: 60,
},
1700: {
items: 6,
edgePadding: 60,
},
Expand All @@ -40,4 +44,19 @@ document.addEventListener('DOMContentLoaded', () => {
});
});

document.querySelector('#pst-nxt')?.addEventListener('click',function () {
if (document.documentElement.getAttribute('dir') === 'rtl'){
postsSlider.goTo('prev');
}else{
postsSlider.goTo('next');
}
});
document.querySelector('#pst-prv')?.addEventListener('click',function () {
if (document.documentElement.getAttribute('dir') !== 'rtl'){
postsSlider.goTo('prev');
}else{
postsSlider.goTo('next');
}
});

});
23 changes: 13 additions & 10 deletions resources/views/segments/posts/PostsSlider/PostsSlider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,30 @@ class PostsSlider
{
public static function onAdd(Part $part = null)
{

$setting = new Setting();
$setting->section = 'theme';
$setting->key = $part->area_name . '_' . $part->part.'_title';
$setting->value = 'Lorem ipsum dolor sit amet';
$setting->type = 'TEXT';
$setting->size = 12;
$setting->title = $part->area_name . ' ' . $part->part .' title';
$setting->key = $part->area_name . '_' . $part->part.'_query';
$setting->value = Group::first()->id.',id,DESC';
$setting->size = 6;
$setting->type = 'POST_QUERY';
$setting->title = $part->area_name . ' ' . $part->part. ' query';
$setting->save();


$setting = new Setting();
$setting->section = 'theme';
$setting->key = $part->area_name . '_' . $part->part.'_group';
$setting->value = Group::first()->id;
$setting->key = $part->area_name . '_' . $part->part.'_title';
$setting->value = 'Lorem ipsum dolor sit amet';
$setting->type = 'TEXT';
$setting->size = 6;
$setting->type = 'GROUP';
// $setting->data = json_encode(['xmin' => 2, 'xmax' => 90]);
$setting->title = $part->area_name . ' ' . $part->part. ' group';
$setting->title = $part->area_name . ' ' . $part->part .' title';
$setting->save();





$setting = new Setting();
$setting->section = 'theme';
$setting->key = $part->area_name . '_' . $part->part.'_color';
Expand Down
48 changes: 48 additions & 0 deletions resources/views/segments/posts/PostsSlider/PostsSlider.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
padding: 3rem 0;
background: var(--post-slider-color);
color: var(--xshop-diff);
position: relative;

h1{
font-size: 30px;
Expand Down Expand Up @@ -31,10 +32,13 @@
background: linear-gradient(-90deg, var(--post-slider-color) 20%, rgba(0,0,0,0) 100%);

}


}
.post-slider{
border-radius: var(--xshop-border-radius);
position: relative;
margin-bottom: 1rem;
img{
width: 100%;
height: 35vh;
Expand Down Expand Up @@ -64,4 +68,48 @@
}

}

.tns-nav{
position: absolute;
display: flex !important;
width: 200px;
left: 50%;
height: 50px;
bottom: -2rem;
transform: translateX(-50%);

align-items: center;
justify-content: center;
button{
display: inline-block;
margin: 7px;
width: 10px;
height: 10px;
border-radius: var(--xshop-border-radius);
background: #ffffff;
border: 0;
}

.tns-nav-active{

background: var(--xshop-secondary);
}
}

.sld-btn{
position: absolute;
top: 47%;
cursor: pointer;
z-index: 55;
i{
font-size: 35px;
}
}

#pst-nxt{
right: 45px;
}
#pst-prv{
left: 45px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
<div class="row">
@foreach(\App\Models\Product::where('status',1)->orderByDesc('id')->limit(4)->get() as $product)
<div class="col-lg-3 col-md-6">
@include(\App\Models\Area::where('name','product-grid')->first()->defPart(),compact('product'))
<div class="product-item">
@include(\App\Models\Area::where('name','product-grid')->first()->defPart(),compact('product'))
</div>
</div>
@endforeach
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<section class='ProductsSlider'>
<section class='ProductsSlider live-setting' data-live='{{$data->area_name.'_'.$data->part}}' >
<div class="{{gfx()['container']}}">
<h1>
{{getSetting($part->area_name . '_' . $part->part.'_title')}}
Expand Down

0 comments on commit 89f80a5

Please sign in to comment.