Improve Templates (#183)
* Improve Templates * Fix test case * Update AI GenerateTemplate * update openai client and GPT completer * composer.lock * Update types and list json with script * Template changes * fix on draft template * Finish opnform templates --------- Co-authored-by: Forms Dev <chirag+new@notionforms.io> Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use Spatie\Sluggable\HasSlug;
|
||||
use Spatie\Sluggable\SlugOptions;
|
||||
use Stevebauman\Purify\Facades\Purify;
|
||||
@@ -16,14 +17,28 @@ class Template extends Model
|
||||
'name',
|
||||
'slug',
|
||||
'description',
|
||||
'short_description',
|
||||
'image_url',
|
||||
'structure',
|
||||
'questions',
|
||||
'publicly_listed',
|
||||
'industries',
|
||||
'types',
|
||||
'related_templates'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'structure' => 'array',
|
||||
'questions' => 'array',
|
||||
'industries' => 'array',
|
||||
'types' => 'array',
|
||||
'related_templates' => 'array',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $attributes = [
|
||||
'publicly_listed' => false,
|
||||
];
|
||||
|
||||
public function setDescriptionAttribute($value)
|
||||
@@ -32,6 +47,11 @@ class Template extends Model
|
||||
$this->attributes['description'] = Purify::clean($value);
|
||||
}
|
||||
|
||||
public function scopePubliclyListed($query)
|
||||
{
|
||||
return $this->where('publicly_listed', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Config/options
|
||||
*/
|
||||
@@ -42,4 +62,40 @@ class Template extends Model
|
||||
->generateSlugsFrom('name')
|
||||
->saveSlugsTo('slug');
|
||||
}
|
||||
|
||||
public function getTypes(): Collection
|
||||
{
|
||||
return self::getAllTypes()->filter(function ($type) {
|
||||
return in_array($type['slug'], $this->types);
|
||||
});
|
||||
}
|
||||
|
||||
public function getIndustries(): Collection
|
||||
{
|
||||
return self::getAllIndustries()->filter(function ($type) {
|
||||
return in_array($type['slug'], $this->industries);
|
||||
});
|
||||
}
|
||||
|
||||
public static function getAllTypes(): Collection
|
||||
{
|
||||
return collect(
|
||||
array_values(
|
||||
json_decode(
|
||||
file_get_contents(resource_path('data/forms/templates/types.json')),
|
||||
true)
|
||||
)
|
||||
)->values();
|
||||
}
|
||||
|
||||
public static function getAllIndustries(): Collection
|
||||
{
|
||||
return collect(
|
||||
array_values(
|
||||
json_decode(
|
||||
file_get_contents(resource_path('data/forms/templates/industries.json')),
|
||||
true)
|
||||
)
|
||||
)->values();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user