Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review: 1572-implement-changes-in-formbuilder #1598

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions app/Helpers/formbuilderhelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

use Illuminate\Support\Arr;

if (!function_exists('getCollapsableClass')) {
/**
* @param $element
* @param string $sourceForm
*
* @return string
*/
function getCollapsableClass($element, string $sourceForm): string
{
if (!isCollapsable($element)) {
return '';
}

return "collapsable $sourceForm";
}
}

if (!function_exists('isCollapsable')) {
/**
* @param $element
*
* @return bool
*/
function isCollapsable($element): bool
{
return Arr::get($element, 'is_collapsable', false);
}
}

if (!function_exists('getAddAdditionalButtonBorders')) {
/**
* @return string
*/
function getAddAdditionalButtonBorders(): string
{
return 'border-spring-50 border-x border-b w-full p-4';
}
}

if (!function_exists('getHelpTextDom')) {
function getHelpTextDom(string $label, string $helpText)
{
return '
<div>
<p class="help-button text-xs text-n-40 hover:text-spring-50 font-normal ml-1.5 cursor-pointer inline-block">
Help
</p>
<div class="help-button-content hidden">
<p class="font-bold text-bluecoral">' . htmlspecialchars($label) . '</p>
<div class="space-y-1.5">
' . htmlspecialchars($helpText) . '
</div>
</div>
</div>';
}
}

if (!function_exists('getHoverTextDom')) {
function getHoverTextDom(string $label, string $hoverText): string
{
return '
<div class="help ml-1.5 font-normal">
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 15 14" class="text-sm">
<path d="M7.385 4.667a1.1 1.1 0 0 0-.518.128c-.16.085-.295.209-.39.362l-.004.006-.003.007a.346.346 0 0 1-.093.105.438.438 0 0 1-.455.033.37.37 0 0 1-.113-.093.313.313 0 0 1-.06-.117.287.287 0 0 1-.005-.124l-.329-.058.329.058a.305.305 0 0 1 .049-.12l.004-.005.004-.006a1.75 1.75 0 0 1 .663-.615 1.92 1.92 0 0 1 2.092.176c.324.256.537.605.607.985.07.378-.005.77-.215 1.105-.211.337-.546.6-.952.737l-.227.076v.36a.31.31 0 0 1-.104.227.414.414 0 0 1-.28.106c-.11 0-.21-.04-.281-.106A.31.31 0 0 1 7 7.667V7a.31.31 0 0 1 .104-.227.414.414 0 0 1 .28-.106c.272 0 .536-.1.735-.285a.977.977 0 0 0 .317-.715.977.977 0 0 0-.317-.716 1.08 1.08 0 0 0-.734-.284Zm0 0V5v-.333Zm-.369 4.906.012-.021.009-.023a.16.16 0 0 1 .02-.037.736.736 0 0 1 .05-.06.391.391 0 0 1 .122-.074.433.433 0 0 1 .311 0l.12-.31-.12.31a.39.39 0 0 1 .127.079c.034.032.06.07.077.108a.3.3 0 0 1 .025.12v.015a.29.29 0 0 1-.02.118.263.263 0 0 1-.067.098l.227.244-.227-.244a.321.321 0 0 1-.116.068l-.01.003-.01.005a.386.386 0 0 1-.293 0l-.01-.005-.01-.003a.321.321 0 0 1-.117-.068l-.227.244.227-.244a.263.263 0 0 1-.067-.097l-.006-.015-.007-.015a.193.193 0 0 1-.022-.093V9.64a.51.51 0 0 1-.002-.057.078.078 0 0 1 .004-.01ZM3.572 1.74A7.245 7.245 0 0 1 7.385.667c.902 0 1.795.165 2.627.485.833.32 1.588.789 2.222 1.378a6.323 6.323 0 0 1 1.48 2.055c.341.766.517 1.587.517 2.415a6 6 0 0 1-1.147 3.51 6.76 6.76 0 0 1-3.072 2.338 7.362 7.362 0 0 1-3.968.363 7.033 7.033 0 0 1-3.51-1.741A6.201 6.201 0 0 1 .67 8.23a5.892 5.892 0 0 1 .387-3.645A6.467 6.467 0 0 1 3.572 1.74Zm.446 9.978a6.39 6.39 0 0 0 3.367.949c1.604 0 3.146-.592 4.288-1.652C12.815 9.955 13.46 8.511 13.46 7a5.4 5.4 0 0 0-1.03-3.158 6.007 6.007 0 0 0-2.729-2.08 6.488 6.488 0 0 0-3.498-.32 6.226 6.226 0 0 0-3.108 1.542 5.56 5.56 0 0 0-1.67 2.906 5.314 5.314 0 0 0 .348 3.287 5.773 5.773 0 0 0 2.244 2.54Z" fill="#68797E" stroke="#68797E" stroke-width=".667"></path>
</svg>
<div class="left-0 help__text w-72">
<p class="text-bluecoral mb-2 italic">IATI standard reference</p>
<span class="font-bold text-bluecoral">' . $label . '</span>
<p>' . $hoverText . '</p>
</div>
</div>';
}
}

if (!function_exists('getHelperTextDom')) {
function getHelperTextDom(string $helperText): string
{
/* Do not use <svg-vue icon='exclamation-warning'/> here */
return '
<div class="bg-eggshell flex space-x-2 my-2 p-4 items-center">
<svg class="elements-svg h-5" width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8.99935 4.79533C8.77834 4.79533 8.56638 4.88313 8.4101 5.03941C8.25382 5.19569 8.16602 5.40765 8.16602 5.62866V8.962C8.16602 9.18301 8.25382 9.39497 8.4101 9.55125C8.56638 9.70753 8.77834 9.79533 8.99935 9.79533C9.22037 9.79533 9.43233 9.70753 9.58861 9.55125C9.74489 9.39497 9.83269 9.18301 9.83269 8.962V5.62866C9.83269 5.40765 9.74489 5.19569 9.58861 5.03941C9.43233 4.88313 9.22037 4.79533 8.99935 4.79533ZM9.76602 11.9787C9.74778 11.9256 9.72256 11.8751 9.69102 11.8287L9.59102 11.7037C9.47383 11.588 9.32502 11.5097 9.16336 11.4786C9.00171 11.4474 8.83444 11.4648 8.68269 11.5287C8.5817 11.5709 8.48869 11.6301 8.40769 11.7037C8.33045 11.7815 8.26935 11.8739 8.22788 11.9754C8.18641 12.0769 8.16539 12.1857 8.16602 12.2953C8.16734 12.4042 8.18999 12.5118 8.23269 12.612C8.27011 12.7154 8.32982 12.8093 8.40759 12.8871C8.48536 12.9649 8.57927 13.0246 8.68269 13.062C8.78244 13.1061 8.89029 13.1289 8.99935 13.1289C9.10841 13.1289 9.21627 13.1061 9.31602 13.062C9.41943 13.0246 9.51335 12.9649 9.59111 12.8871C9.66888 12.8093 9.72859 12.7154 9.76602 12.612C9.80872 12.5118 9.83137 12.4042 9.83269 12.2953C9.83678 12.2398 9.83678 12.1841 9.83269 12.1287C9.81834 12.0755 9.79585 12.0249 9.76602 11.9787ZM8.99935 0.628662C7.35118 0.628662 5.74001 1.1174 4.3696 2.03308C2.99919 2.94876 1.93109 4.25025 1.30036 5.77297C0.669626 7.29568 0.504599 8.97124 0.826142 10.5877C1.14769 12.2043 1.94136 13.6891 3.1068 14.8546C4.27223 16.02 5.75709 16.8137 7.3736 17.1352C8.99011 17.4568 10.6657 17.2917 12.1884 16.661C13.7111 16.0303 15.0126 14.9622 15.9283 13.5917C16.8439 12.2213 17.3327 10.6102 17.3327 8.962C17.3327 7.86765 17.1171 6.78401 16.6983 5.77297C16.2796 4.76192 15.6657 3.84326 14.8919 3.06944C14.1181 2.29562 13.1994 1.68179 12.1884 1.263C11.1773 0.84421 10.0937 0.628662 8.99935 0.628662ZM8.99935 15.6287C7.68081 15.6287 6.39188 15.2377 5.29555 14.5051C4.19922 13.7726 3.34474 12.7314 2.84016 11.5132C2.33557 10.295 2.20355 8.9546 2.46078 7.66139C2.71802 6.36819 3.35296 5.1803 4.28531 4.24795C5.21766 3.3156 6.40554 2.68066 7.69875 2.42343C8.99196 2.16619 10.3324 2.29821 11.5506 2.8028C12.7687 3.30738 13.8099 4.16187 14.5425 5.25819C15.275 6.35452 15.666 7.64345 15.666 8.962C15.666 10.7301 14.9636 12.4258 13.7134 13.676C12.4632 14.9263 10.7675 15.6287 8.99935 15.6287Z" fill="#F4B784"/>
</svg>
<div class=" font-normal text-n-50 text-xs">' . $helperText . ' </div>
</div>';
}
}

if (!function_exists('getCollapsableButtonDom')) {
function getCollapsableButtonDom(): string
{
/* Do not use <svg-vue icon='arrow-down'/> here */
return '
<btton class="collapsable-button">
<svg viewBox="0 0 20 20" class="h-6 text-n-50 rotate-180" xmlns="http://www.w3.org/2000/svg">
<path d="M14.1671 7.64076C14.0109 7.48556 13.7997 7.39844 13.5796 7.39844C13.3594 7.39844 13.1482 7.48556 12.9921 7.64076L10.0004 10.5908L7.0504 7.64076C6.89427 7.48556 6.68306 7.39844 6.4629 7.39844C6.24275 7.39844 6.03154 7.48556 5.8754 7.64076C5.7973 7.71823 5.7353 7.8104 5.693 7.91195C5.65069 8.0135 5.62891 8.12242 5.62891 8.23243C5.62891 8.34244 5.65069 8.45136 5.693 8.55291C5.7353 8.65446 5.7973 8.74663 5.8754 8.8241L9.40874 12.3574C9.48621 12.4355 9.57837 12.4975 9.67992 12.5398C9.78147 12.5821 9.89039 12.6039 10.0004 12.6039C10.1104 12.6039 10.2193 12.5821 10.3209 12.5398C10.4224 12.4975 10.5146 12.4355 10.5921 12.3574L14.1671 8.8241C14.2452 8.74663 14.3072 8.65446 14.3495 8.55291C14.3918 8.45136 14.4136 8.34244 14.4136 8.23243C14.4136 8.12242 14.3918 8.0135 14.3495 7.91195C14.3072 7.8104 14.2452 7.71823 14.1671 7.64076Z" fill="currentColor"/>
</svg>
</btton>';
}
}
if (!function_exists('getOptionalTextDom')) {
function getOptionalTextDom(): string
{
/* Do not use <svg-vue icon='single-dot'/> here */
return '
<span class="text-n-40 optional-text flex items-center font-light">
<svg width="16" height="18" viewBox="0 0 16 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M6 9C6 9.49596 6.19702 9.9716 6.54771 10.3223C6.8984 10.673 7.37405 10.87 7.87 10.87C8.36595 10.87 8.8416 10.673 9.19229 10.3223C9.54298 9.9716 9.74 9.49596 9.74 9C9.74 8.50405 9.54298 8.02841 9.19229 7.67772C8.8416 7.32702 8.36595 7.13 7.87 7.13C7.37405 7.13 6.8984 7.32702 6.54771 7.67772C6.19702 8.02841 6 8.50405 6 9Z" fill="#68797E"/>
</svg>
<span>Optional</span>
</span>';
}
}
45 changes: 1 addition & 44 deletions app/Helpers/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ function getTimestampFromOrganizationXml(string $publisherId, App\IATI\Models\Or
*/
function generateAddAdditionalLabel(string $parentElement, string $elementName): string
{
$elementName = str_replace('_', '', $elementName);
$elementName = str_replace('_', ' ', $elementName);

if ($parentElement === 'reporting_org' && $elementName === 'narrative') {
$elementName = 'name';
Expand Down Expand Up @@ -1380,46 +1380,3 @@ function trimStringValueInArray($array): array
}, $array);
}
}

if (!function_exists('getCollapsableClass')) {
/**
* @param $element
* @param string $sourceForm
*
* @return string
*/
function getCollapsableClass($element, string $sourceForm): string
{
if (!isCollapsable($element)) {
return '';
}

// $elementName = Arr::get($element, 'name', '');

return "collapsable $sourceForm";
}
}

if (!function_exists('isCollapsable')) {
/**
* @param $element
*
* @return bool
*/
function isCollapsable($element): bool
{
return Arr::get($element, 'is_collapsable', false);
}
}

if (!function_exists('canAddMore')) {
/**
* @param $element
*
* @return bool
*/
function canAddMore($element): bool
{
return Arr::get($element, 'add_more', false) || Arr::get($element, 'add_more_attributes', false);
}
}
34 changes: 28 additions & 6 deletions app/Http/Controllers/Admin/Activity/BudgetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use App\Http\Requests\Activity\Budget\BudgetRequest;
use App\IATI\Services\Activity\ActivityService;
use App\IATI\Services\Activity\BudgetService;
use App\IATI\Traits\EditFormTrait;
use Exception;
use Illuminate\Contracts\View\View;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
Expand All @@ -18,6 +20,8 @@
*/
class BudgetController extends Controller
{
use EditFormTrait;

/**
* @var BudgetService
*/
Expand Down Expand Up @@ -54,17 +58,35 @@ public function edit(int $id): View|RedirectResponse
$activity = $this->activityService->getActivity($id);

$deprecationStatusMap = Arr::get($activity->deprecation_status_map, 'budget', []);
$form = $this->budgetService->formGenerator($id, $activity->default_field_values ?? [], deprecationStatusMap: $deprecationStatusMap);
$form = $this->budgetService->formGenerator(
id : $id,
activityDefaultFieldValues: $activity->default_field_values ?? [],
deprecationStatusMap : $deprecationStatusMap
);

$hasData = (bool) Arr::get($activity, 'budget', false);
$formHeader = $this->getFormHeader(
hasData : $hasData,
elementName: 'budget',
parentTitle: Arr::get($activity, 'title.0.narrative', 'Untitled')
);
$breadCrumbInfo = $this->basicBreadCrumbInfo($activity, 'budget');

$data = [
'title' => $element['label'],
'name' => 'budget',
'title' => $element['label'],
'name' => 'budget',
'form_header' => $formHeader,
'bread_crumb_info' => $breadCrumbInfo,
];

return view('admin.activity.budget.edit', compact('form', 'activity', 'data'));
} catch (\Exception $e) {
} catch (Exception $e) {
logger()->error($e->getMessage());

return redirect()->route('admin.activity.show', $id)->with('error', 'Error has occurred while opening budget form.');
return redirect()->route('admin.activity.show', $id)->with(
'error',
'Error has occurred while opening budget form.'
);
}
}

Expand All @@ -86,7 +108,7 @@ public function update(BudgetRequest $request, $id): JsonResponse|RedirectRespon
}

return redirect()->route('admin.activity.show', $id)->with('success', 'Budget updated successfully.');
} catch (\Exception $e) {
} catch (Exception $e) {
logger()->error($e->getMessage());

return redirect()->route('admin.activity.show', $id)->with('error', 'Error has occurred while updating budget.');
Expand Down
32 changes: 26 additions & 6 deletions app/Http/Controllers/Admin/Activity/CapitalSpendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use App\Http\Controllers\Controller;
use App\Http\Requests\Activity\CapitalSpend\CapitalSpendRequest;
use App\IATI\Services\Activity\CapitalSpendService;
use App\IATI\Traits\EditFormTrait;
use Exception;
use Illuminate\Contracts\View\View;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
Expand All @@ -17,6 +19,7 @@
*/
class CapitalSpendController extends Controller
{
use EditFormTrait;
/**
* @var CapitalSpendService
*/
Expand Down Expand Up @@ -45,17 +48,34 @@ public function edit(int $id): View|RedirectResponse
$element = getElementSchema('capital_spend');
$activity = $this->capitalSpendService->getActivityData($id);
$deprecationStatusMap = Arr::get($activity->deprecation_status_map, 'capital_spend', []);
$form = $this->capitalSpendService->formGenerator($id, deprecationStatusMap: $deprecationStatusMap);
$form = $this->capitalSpendService->formGenerator(
id : $id,
deprecationStatusMap: $deprecationStatusMap
);

$hasData = (bool) Arr::get($activity, 'capital_spend', false);
$formHeader = $this->getFormHeader(
hasData : $hasData,
elementName: 'capital_spend',
parentTitle: Arr::get($activity, 'title.0.narrative', 'Untitled')
);
$breadCrumbInfo = $this->basicBreadCrumbInfo($activity, 'capital_spend');

$data = [
'title' => $element['label'],
'name' => 'capital_spend',
'title' => $element['label'],
'name' => 'capital_spend',
'form_header' => $formHeader,
'bread_crumb_info' => $breadCrumbInfo,
];

return view('admin.activity.capitalSpend.edit', compact('form', 'activity', 'data'));
} catch (\Exception $e) {
} catch (Exception $e) {
logger()->error($e->getMessage());

return redirect()->route('admin.activity.show', $id)->with('error', 'Error has occurred while rendering activity capital-spend form.');
return redirect()->route('admin.activity.show', $id)->with(
'error',
'Error has occurred while rendering activity capital-spend form.'
);
}
}

Expand All @@ -77,7 +97,7 @@ public function update($id, CapitalSpendRequest $request): JsonResponse|Redirect
}

return redirect()->route('admin.activity.show', $id)->with('success', 'Activity capital-spend updated successfully.');
} catch (\Exception $e) {
} catch (Exception $e) {
logger()->error($e->getMessage());

return redirect()->route('admin.activity.show', $id)->with('error', 'Error has occurred while updating activity capital-spend.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use App\Http\Controllers\Controller;
use App\Http\Requests\Activity\CollaborationType\CollaborationTypeRequest;
use App\IATI\Services\Activity\CollaborationTypeService;
use App\IATI\Traits\EditFormTrait;
use Exception;
use Illuminate\Contracts\View\View;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
Expand All @@ -17,6 +19,8 @@
*/
class CollaborationTypeController extends Controller
{
use EditFormTrait;

/**
* @var CollaborationTypeService
*/
Expand Down Expand Up @@ -45,17 +49,36 @@ public function edit(int $id): View|RedirectResponse
$element = getElementSchema('collaboration_type');
$activity = $this->collaborationTypeService->getActivityData($id);
$deprecationStatusMap = Arr::get($activity->deprecation_status_map, 'collaboration_type', []);
$form = $this->collaborationTypeService->formGenerator($id, $activity->default_field_values ?? [], deprecationStatusMap: $deprecationStatusMap);
$form = $this->collaborationTypeService->formGenerator(
id : $id,
activityDefaultFieldValues: $activity->default_field_values ?? [],
deprecationStatusMap : $deprecationStatusMap
);

$hasData = (bool) Arr::get($activity, 'collaboration_type', false);
$formHeader = $this->getFormHeader(
hasData : $hasData,
elementName: 'collaboration_type',
parentTitle: Arr::get($activity, 'title.0.narrative', 'Untitled')
);
$breadCrumbInfo = $this->basicBreadCrumbInfo($activity, 'collaboration_type');

$data = [
'title' => $element['label'],
'name' => 'collaboration_type',
'title' => $element['label'],
'name' => 'collaboration_type',
'form_header' => $formHeader,
'bread_crumb_info' => $breadCrumbInfo,

];

return view('admin.activity.collaborationType.edit', compact('form', 'activity', 'data'));
} catch (\Exception $e) {
} catch (Exception $e) {
logger()->error($e->getMessage());

return redirect()->route('admin.activity.show', $id)->with('error', 'Error has occurred while rendering activity collaboration-type form.');
return redirect()->route('admin.activity.show', $id)->with(
'error',
'Error has occurred while rendering activity collaboration-type form.'
);
}
}

Expand All @@ -77,7 +100,7 @@ public function update(CollaborationTypeRequest $request, $id): JsonResponse|Red
}

return redirect()->route('admin.activity.show', $id)->with('success', 'Activity collaboration-type updated successfully.');
} catch (\Exception $e) {
} catch (Exception $e) {
logger()->error($e->getMessage());

return redirect()->route('admin.activity.show', $id)->with('error', 'Error has occurred while updating activity collaboration type.');
Expand Down
Loading