Skip to content

Commit

Permalink
Merge pull request #288 from lara-zeus/has-pro
Browse files Browse the repository at this point in the history
improvements on how to check if pro version installed
  • Loading branch information
atmonshi authored May 28, 2024
2 parents e0ef444 + b5f9bfc commit e2013e6
Show file tree
Hide file tree
Showing 27 changed files with 1,142 additions and 367 deletions.
1,238 changes: 935 additions & 303 deletions composer.lock

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions database/migrations/add_grade_to_field_response.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table(config('zeus-bolt.table-prefix').'field_responses', function (Blueprint $table) {
$table->integer('grade')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table(config('zeus-bolt.table-prefix').'field_responses', function (Blueprint $table) {
$table->dropColumn('grade');
});
}
};
32 changes: 32 additions & 0 deletions database/migrations/add_grade_to_response.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table(config('zeus-bolt.table-prefix').'responses', function (Blueprint $table) {
$table->integer('grades')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table(config('zeus-bolt.table-prefix').'responses', function (Blueprint $table) {
$table->dropColumn('grades');
});
}
};
9 changes: 7 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ parameters:
paths:
- src
- database

checkOctaneCompatibility: true
checkModelProperties: true
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false

ignoreErrors:
-
identifier: missingType.iterableValue
-
identifier: missingType.generics
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
@if($resp->field !== null)
<div class="py-2 text-ellipsis overflow-auto">
<p>{{ $resp->field->name ?? '' }}</p>
<p class="font-semibold mb-2">
{!! ( new $resp->field->type )->getResponse($resp->field, $resp) !!}
</p>

<div class="items-center flex justify-between">
<p class="font-semibold mb-2">
{!! ( new $resp->field->type )->getResponse($resp->field, $resp) !!}
</p>
@if($resp->form->extensions === 'LaraZeus\\BoltPro\\Extensions\\Grades')
<livewire:bolt-pro.grading :response="$resp" />
@endif
</div>

<hr/>
</div>
@endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
@if($resp->field !== null)
<div class="py-2 text-ellipsis overflow-auto">
<p>{{ $resp->field->name ?? '' }}</p>
<p class="font-semibold mb-2">
{!! ( new $resp->field->type )->getResponse($resp->field, $resp) !!}
</p>
<div class="items-center flex justify-between">
<p class="font-semibold mb-2">
{!! ( new $resp->field->type )->getResponse($resp->field, $resp) !!}
</p>
@if($resp->form->extensions === 'LaraZeus\\BoltPro\\Extensions\\Grades')
<livewire:bolt-pro.grading :response="$resp" />
@endif
</div>
<hr/>
</div>
@endif
Expand Down
2 changes: 2 additions & 0 deletions src/BoltServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ protected function getMigrations(): array
'alter_tables_constraints',
'add_compact_to_section',
'add_options_to_section',
'add_grade_to_response',
'add_grade_to_field_response',
];
}
}
44 changes: 15 additions & 29 deletions src/Concerns/Schemata.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Group;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Tabs;
use Filament\Forms\Components\Textarea;
Expand Down Expand Up @@ -102,14 +102,6 @@ public static function getMainFormSchema(): array
->tabs(static::getTabsSchema())
->columnSpan(2),

/*Section::make()
->columnSpan(2)
->schema([
Placeholder::make('section-title-placeholder')
->label(__('Sections'))
->helperText(__('sections are here to group the fields, and you can display it as pages from the Form options. if you have one section, it wont show in the form')),
]),*/

Repeater::make('sections')
->hiddenLabel()
->schema(static::getSectionsSchema())
Expand All @@ -118,9 +110,12 @@ public static function getMainFormSchema(): array
->addActionLabel(__('Add Section'))
->cloneable()
->collapsible()
//->collapsed(fn (string $operation) => $operation === 'edit')
->collapsed(fn (string $operation) => $operation === 'edit')
->minItems(1)
->extraItemActions([
// @phpstan-ignore-next-line
Bolt::hasPro() ? \LaraZeus\BoltPro\Actions\SectionMarkAction::make('marks') : null,

Action::make('options')
->label(__('section options'))
->slideOver()
Expand Down Expand Up @@ -159,8 +154,6 @@ public static function getTabsSchema(): array
->columns()
->schema([
TextInput::make('name')
//->hint(__('Translatable'))
//->hintIcon('heroicon-s-language')
->required()
->maxLength(255)
->live(onBlur: true)
Expand Down Expand Up @@ -216,13 +209,9 @@ public static function getTabsSchema(): array
->label(__('Text & Details'))
->schema([
Textarea::make('description')
//->hint(__('Translatable'))
//->hintIcon('heroicon-s-language')
->label(__('Form Description'))
->helperText(__('shown under the title of the form and used in SEO')),
RichEditor::make('details')
//->hint(__('Translatable'))
//->hintIcon('heroicon-s-language')
->label(__('Form Details'))
->helperText(__('a highlighted section above the form, to show some instructions or more details')),
RichEditor::make('options.confirmation-message')
Expand All @@ -234,7 +223,6 @@ public static function getTabsSchema(): array
->label(__('Display & Access'))
->columns()
->schema([

Grid::make()
->columnSpan(1)
->columns(1)
Expand Down Expand Up @@ -313,6 +301,7 @@ public static function getTabsSchema(): array
Select::make('extensions')
->label(__('Extensions'))
->preload()
->live()
->options(function () {
// @phpstan-ignore-next-line
return collect(BoltPlugin::get()->getExtensions())
Expand All @@ -328,7 +317,7 @@ public static function getTabsSchema(): array

Tabs\Tab::make('design')
->label(__('Design'))
->visible(class_exists(\LaraZeus\BoltPro\BoltProServiceProvider::class) && config('zeus-bolt.allow_design'))
->visible(Bolt::hasPro() && config('zeus-bolt.allow_design'))
->schema([
ViewField::make('options.primary_color')
->hiddenLabel()
Expand Down Expand Up @@ -367,8 +356,6 @@ public static function getSectionsSchema(): array
Hidden::make('options.visibility.values'),
TextInput::make('name')
->columnSpanFull()
//->hint(__('Translatable'))
//->hintIcon('heroicon-s-language')
->required()
->lazy()
->label(__('Section Name')),
Expand All @@ -381,7 +368,7 @@ public static function getSectionsSchema(): array
->cloneable()
->minItems(1)
->collapsible()
//->collapsed(fn (string $operation) => $operation === 'edit')
->collapsed(fn (string $operation) => $operation === 'edit')
->grid([
'default' => 1,
'md' => 2,
Expand All @@ -392,6 +379,9 @@ public static function getSectionsSchema(): array
->itemLabel(fn (array $state): ?string => $state['name'] ?? null)
->addActionLabel(__('Add field'))
->extraItemActions([
// @phpstan-ignore-next-line
Bolt::hasPro() ? \LaraZeus\BoltPro\Actions\FieldMarkAction::make('marks') : null,

Action::make('fields options')
->slideOver()
->color('warning')
Expand All @@ -404,7 +394,7 @@ public static function getSectionsSchema(): array
array $arguments,
Repeater $component
) => $component->getItemState($arguments['item']))
->form(function (Get $get, array $arguments) {
->form(function (Get $get, array $arguments, Repeater $component) {
$allSections = self::getVisibleFields($get('../../sections'), $arguments);

return [
Expand All @@ -416,12 +406,12 @@ public static function getSectionsSchema(): array
'lg' => 2,
])
->label(__('Field Options'))
->schema(function (Get $get) use ($allSections) {
->schema(function (Get $get) use ($allSections, $component, $arguments) {
$class = $get('type');
if (class_exists($class)) {
$newClass = (new $class);
if ($newClass->hasOptions()) {
return $newClass->getOptions($allSections);
return $newClass->getOptions($allSections, $component->getState()[$arguments['item']]);
}
}

Expand Down Expand Up @@ -453,17 +443,13 @@ public static function getFieldsSchema(): array
return [
Hidden::make('description'),
TextInput::make('name')
//->hint(__('Translatable'))
//->hintIcon('heroicon-s-language')
->required()
->lazy()
->label(__('Field Name')),
Select::make('type')
->required()
->searchable()
->preload()
//->options(Bolt::availableFields()->pluck('title', 'class'))

/*->getSearchResultsUsing(function (string $search) {
$users = Bolt::availableFields()->where('title', 'like', "%{$search}%");
Expand All @@ -483,7 +469,7 @@ public static function getFieldsSchema(): array
->live()
->default('\LaraZeus\Bolt\Fields\Classes\TextInput')
->label(__('Field Type')),
Grid::make()
Group::make()
->columns([
'default' => 1,
'lg' => 2,
Expand Down
13 changes: 11 additions & 2 deletions src/Facades/Bolt.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ public static function availableFields(): Collection
$fields = $fields->merge($appFields);
}

if (class_exists(\LaraZeus\BoltPro\BoltProServiceProvider::class)) {
$boltProFields = Collectors::collectClasses(base_path('vendor/lara-zeus/bolt-pro/src/Fields'), 'LaraZeus\\BoltPro\\Fields\\');
if (static::hasPro()) {
$boltProFields = Collectors::collectClasses(
base_path('vendor/lara-zeus/bolt-pro/src/Fields'),
'LaraZeus\\BoltPro\\Fields\\'
);

if ($boltProFields->isNotEmpty()) {
$fields = $fields->merge($boltProFields);
}
Expand Down Expand Up @@ -102,4 +106,9 @@ public static function isJson(string $string): bool

return true;
}

public static function hasPro(): bool
{
return class_exists(\LaraZeus\BoltPro\BoltProServiceProvider::class);
}
}
8 changes: 7 additions & 1 deletion src/Fields/Classes/CheckboxList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use LaraZeus\Accordion\Forms\Accordion;
use LaraZeus\Accordion\Forms\Accordions;
use LaraZeus\Bolt\Facades\Bolt;
use LaraZeus\Bolt\Fields\FieldsContract;
use LaraZeus\Bolt\Models\Field;
use LaraZeus\Bolt\Models\FieldResponse;
Expand All @@ -29,10 +30,11 @@ public function description(): string
return __('checkbox items from data source');
}

public static function getOptions(?array $sections = null): array
public static function getOptions(?array $sections = null, ?array $field = null): array
{
return [
self::dataSource(),

Accordions::make('check-list-options')
->accordions([
Accordion::make('general-options')
Expand All @@ -45,13 +47,17 @@ public static function getOptions(?array $sections = null): array
]),
self::hintOptions(),
self::visibility($sections),
// @phpstan-ignore-next-line
Bolt::hasPro() ? \LaraZeus\BoltPro\Facades\GradeOptions::schema($field) : null,
]),
];
}

public static function getOptionsHidden(): array
{
return [
// @phpstan-ignore-next-line
Bolt::hasPro() ? \LaraZeus\BoltPro\Facades\GradeOptions::hidden() : null,
self::hiddenDataSource(),
self::hiddenVisibility(),
self::hiddenHtmlID(),
Expand Down
7 changes: 6 additions & 1 deletion src/Fields/Classes/DatePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use LaraZeus\Accordion\Forms\Accordion;
use LaraZeus\Accordion\Forms\Accordions;
use LaraZeus\Bolt\Facades\Bolt;
use LaraZeus\Bolt\Fields\FieldsContract;

class DatePicker extends FieldsContract
Expand All @@ -27,7 +28,7 @@ public function description(): string
return __('full date picker');
}

public static function getOptions(?array $sections = null): array
public static function getOptions(?array $sections = null, ?array $field = null): array
{
return [
Accordions::make('check-list-options')
Expand All @@ -42,13 +43,17 @@ public static function getOptions(?array $sections = null): array
]),
self::hintOptions(),
self::visibility($sections),
// @phpstan-ignore-next-line
Bolt::hasPro() ? \LaraZeus\BoltPro\Facades\GradeOptions::schema($field) : null,
]),
];
}

public static function getOptionsHidden(): array
{
return [
// @phpstan-ignore-next-line
Bolt::hasPro() ? \LaraZeus\BoltPro\Facades\GradeOptions::hidden() : null,
self::hiddenHtmlID(),
self::hiddenHintOptions(),
self::hiddenRequired(),
Expand Down
Loading

0 comments on commit e2013e6

Please sign in to comment.