From 8a559bb0f9e6fb96a16910feb448a3f0e672525c Mon Sep 17 00:00:00 2001 From: panabonic Date: Wed, 19 Jul 2023 13:03:15 +0300 Subject: [PATCH] minor fixes and updates --- app/Models/Registries/Entry.php | 5 +- app/Models/Registries/Registry.php | 6 +- app/Models/Registries/RegistryType.php | 2 +- .../Filters/Registries/EntryFilters.php | 8 ++ app/Services/Forms/Registries/EntryForms.php | 20 ++++- .../Forms/Registries/OperationForms.php | 75 ++----------------- .../Registries/EntryTransformer.php | 3 + .../Objects/ObjectTypeFieldsTableSeeder.php | 2 +- .../Objects/ObjectTypesTableSeeder.php | 7 +- 9 files changed, 51 insertions(+), 77 deletions(-) diff --git a/app/Models/Registries/Entry.php b/app/Models/Registries/Entry.php index 75622df..d7722ca 100644 --- a/app/Models/Registries/Entry.php +++ b/app/Models/Registries/Entry.php @@ -69,9 +69,8 @@ class Entry extends Model { if ($this->active_since) { $state = ($this->active_since <= now()) ? EntryState::ACTIVE : EntryState::AWAITING; if ($this->active_till && ($this->active_till <= now())) $state = EntryState::EXPIRED; - elseif ($this->suspended_since && ($this->suspended_since <= now())) { - - } + elseif ($this->cancelled_at && ($this->cancelled_at <= now())) $state = EntryState::CANCELLED; + elseif ($this->suspended_since && ($this->suspended_since <= now()) && (!$this->suspended_till || ($this->suspended_till > now()))) $state = EntryState::SUSPENDED; } return $state ? ['name' => $state, 'title' => EntryState::TITLES[$state] ?? null] : null; } diff --git a/app/Models/Registries/Registry.php b/app/Models/Registries/Registry.php index 163cf3c..3510e10 100644 --- a/app/Models/Registries/Registry.php +++ b/app/Models/Registries/Registry.php @@ -46,7 +46,11 @@ class Registry extends Model { public function getParsedTypeAttribute(): array { - return ['name' => $this->type, 'title' => RegistryType::TITLES[$this->type] ?? null, 'options' => RegistryType::OPTIONS[$this->type] ?? []]; + return ['name' => $this->type, 'title' => RegistryType::TITLES[$this->type] ?? null, 'options' => $this->options]; + } + + public function getOptionsAttribute(): array { + return RegistryType::OPTIONS[$this->type] ?? []; } diff --git a/app/Models/Registries/RegistryType.php b/app/Models/Registries/RegistryType.php index 0c0228e..45fb8d0 100644 --- a/app/Models/Registries/RegistryType.php +++ b/app/Models/Registries/RegistryType.php @@ -21,7 +21,7 @@ class RegistryType { public const OPTIONS = [ self::SIMPLE => [], - self::RULESET => ['categories' => true, 'operations' => true, 'states' => true], + self::RULESET => ['categories' => true, 'operations' => 'entry-operation-ruleset', 'states' => true], self::LABORATORIES => ['properties' => 'entry-properties-laboratory', 'states' => true], self::CERTIFIERS => ['properties' => 'entry-properties-certifier', 'states' => true], self::EXPERTS => ['categories' => true, 'properties' => 'entry-properties-expert', 'states' => true], diff --git a/app/Services/Filters/Registries/EntryFilters.php b/app/Services/Filters/Registries/EntryFilters.php index dae37a5..f1ae739 100644 --- a/app/Services/Filters/Registries/EntryFilters.php +++ b/app/Services/Filters/Registries/EntryFilters.php @@ -38,6 +38,14 @@ class EntryFilters extends FiltersService { ]; } + public function operationsFields(Collection $filters): array { + return []; + } + + public function propertiesFilters(Collection $filters): array { + return []; + } + public function getListings(Collection $filters): Fractal { return fractal(Dictionary::byName('listings')->first()->items, new DictionaryItemTransformer()); diff --git a/app/Services/Forms/Registries/EntryForms.php b/app/Services/Forms/Registries/EntryForms.php index 71517c7..93fadd2 100644 --- a/app/Services/Forms/Registries/EntryForms.php +++ b/app/Services/Forms/Registries/EntryForms.php @@ -68,7 +68,25 @@ class EntryForms extends FormsService { 'title' => 'Дата окончания действия', 'type' => FieldType::DATE, 'value' => ($v = $model->active_till ?? null) ? $v->toIso8601String() : null - ] + ], + [ + 'name' => 'suspended_since', + 'title' => 'Дата начала приостановки', + 'type' => FieldType::DATE, + 'value' => ($v = $model->suspended_since ?? null) ? $v->toIso8601String() : null + ], + [ + 'name' => 'suspended_till', + 'title' => 'Дата окончания приостановки', + 'type' => FieldType::DATE, + 'value' => ($v = $model->suspended_till ?? null) ? $v->toIso8601String() : null + ], + [ + 'name' => 'cancelled_at', + 'title' => 'Дата отмены', + 'type' => FieldType::DATE, + 'value' => ($v = $model->cancelled_at ?? null) ? $v->toIso8601String() : null + ], ]; return ['data' => $fields]; } diff --git a/app/Services/Forms/Registries/OperationForms.php b/app/Services/Forms/Registries/OperationForms.php index 18a1bea..69fc5f3 100644 --- a/app/Services/Forms/Registries/OperationForms.php +++ b/app/Services/Forms/Registries/OperationForms.php @@ -16,87 +16,24 @@ class OperationForms extends FormsService { public function form(?string $id = null, array $data = []): array { $model = NirObject::byUuid($id)->first(); + $entry = Entry::byUuid($data['entry'] ?? null)->firstOrFail(); $groups = [ - ['name' => 'common', 'fields' => $this->commonGroupFields($model)] + ['name' => 'common', 'fields' => $this->commonGroupFields($entry, $model)] ]; return ['title' => $this->formTitle($model), 'data' => $groups]; } - public function commonGroupFields(?NirObject $model): array { + public function commonGroupFields(Entry $entry, ?NirObject $model): array { + $objectTypeName = $entry->registry->options['operations'] ?? null; return $model ? fractal($model->groups->first()->fields, new ObjectPropertyTransformer($model))->toArray() : - fractal(ObjectType::byName('entry-operation')->first()->groups()->first()->fields, new FieldTransformer())->toArray(); - - /* - $fields = [ - [ - 'name' => 'type', - 'title' => 'Вид работы', - 'type' => FieldType::RELATION, - 'required' => true, - 'appearance' => 'radio', - 'options' => $this->getRelationItems(OperationType::TITLES), - 'value' => $this->getRelationValue(OperationType::TITLES, $model->type ?? null) - ], - [ - 'name' => 'order_name', - 'title' => 'Наименование приказа', - 'type' => FieldType::STRING, - 'required' => true, - 'value' => $model->order_name ?? null - ], - [ - 'name' => 'order_date', - 'title' => 'Дата приказа', - 'required' => true, - 'type' => FieldType::DATE, - 'value' => ($v = $model->order_date ?? null) ? $v->toIso8601String() : null - ], - [ - 'name' => 'order', - 'title' => 'Документ приказа', - 'type' => FieldType::DOCUMENT, - 'required' => true, - 'value' => ($order = $model->order ?? null) ? fractal($order, new AssetTransformer()) : null - ], - [ - 'name' => 'listing', - 'title' => 'Вхождение в перечень ПП', - 'type' => FieldType::RELATION, - 'multiple' => true, - 'appearance' => 'checkbox', - 'options' => fractal(Dictionary::byName('listings')->first()->items, new DictionaryItemTransformer()), - 'value' => null - ], - [ - 'name' => 'active_since', - 'title' => 'Дата начала действия', - 'type' => FieldType::DATE, - 'required' => true, - 'value' => ($v = $model->active_since ?? null) ? $v->toIso8601String() : null - ], - [ - 'name' => 'active_till', - 'title' => 'Дата окончания действия', - 'type' => FieldType::DATE, - 'value' => ($v = $model->active_till ?? null) ? $v->toIso8601String() : null - ], - [ - 'name' => 'developer', - 'title' => 'Разработчик', - 'type' => FieldType::STRING, - 'required' => true, - 'value' => $model->developer ?? null - ] - ]; - return ['data' => $fields]; - */ + fractal(ObjectType::byName($objectTypeName)->firstOrFail()->groups()->first()->fields, new FieldTransformer())->toArray(); } public function store(array $data): ?JsonResponse { $entry = Entry::byUuid($data['entry'] ?? null)->firstOrFail(); - $model = $entry->createObject('entry-operation', null, 'operations'); + $model = $entry->createObject($entry->registry->options['operations'] ?? null, null, 'operations'); $model->setValues($data); return fractal($model, new ObjectTransformer())->respond(); } diff --git a/app/Transformers/Registries/EntryTransformer.php b/app/Transformers/Registries/EntryTransformer.php index 51b455c..766f390 100644 --- a/app/Transformers/Registries/EntryTransformer.php +++ b/app/Transformers/Registries/EntryTransformer.php @@ -28,6 +28,9 @@ class EntryTransformer extends TransformerAbstract { 'state' => $model->state, 'active_since' => $model->active_since ? $model->active_since->toIso8601String() : null, 'active_till' => $model->active_till ? $model->active_till->toIso8601String() : null, + 'suspended_since' => $model->suspended_since ? $model->suspended_since->toIso8601String() : null, + 'suspended_till' => $model->suspended_till ? $model->suspended_till->toIso8601String() : null, + 'cancelled_at' => $model->cancelled_at ? $model->cancelled_at->toIso8601String() : null, 'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null, 'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null ]; diff --git a/database/seeders/Objects/ObjectTypeFieldsTableSeeder.php b/database/seeders/Objects/ObjectTypeFieldsTableSeeder.php index c806919..b9ba854 100644 --- a/database/seeders/Objects/ObjectTypeFieldsTableSeeder.php +++ b/database/seeders/Objects/ObjectTypeFieldsTableSeeder.php @@ -97,7 +97,7 @@ class ObjectTypeFieldsTableSeeder extends Seeder { ] ], - 'entry-operation' => [ + 'entry-operation-ruleset' => [ 'common' => [ 'fields' => ['operation-type', 'order-name', 'order-date', 'order-document', 'listings', 'active-since', 'active-till', 'developer'] ] diff --git a/database/seeders/Objects/ObjectTypesTableSeeder.php b/database/seeders/Objects/ObjectTypesTableSeeder.php index 881b0af..42eb712 100644 --- a/database/seeders/Objects/ObjectTypesTableSeeder.php +++ b/database/seeders/Objects/ObjectTypesTableSeeder.php @@ -78,7 +78,12 @@ class ObjectTypesTableSeeder extends Seeder { ], 'entry-operation' => [ - 'title' => 'Действие с записью в реестре' + 'title' => 'Действие с записью в реестре', + 'children' => [ + 'entry-operation-ruleset' => [ + 'title' => 'Действие со сводом правил' + ] + ] ] ];