ekosistem dan framework
This commit is contained in:
@@ -65,30 +65,42 @@ class FormBasisData extends Model
|
||||
return $this->belongsTo(KolomBasisData::class, 'kolom_id');
|
||||
}
|
||||
|
||||
public function renderHtml(string $state, $errors = null, $optionsFK = null, $values = null): string
|
||||
public function renderHtml(string $state, $errors = null, $optionsFK = null, $values = null, $framework = 'bootstrap'): string
|
||||
{
|
||||
return match ($this->tipe) {
|
||||
LayoutForm::COLUMN => '<div class="col-'.($this->column_width ?? 3).' mb-4 form-control-validation">'
|
||||
.$this->childHtml($state, $errors, $optionsFK, $values).'</div>',
|
||||
LayoutForm::VALUE => $this->value($state, $errors, $optionsFK, $values),
|
||||
LayoutForm::SECTION => '<h6 class="mb-3">'.$this->section_label.'</h6>',
|
||||
LayoutForm::ROW => '<div class="row">'.$this->childHtml($state, $errors, $optionsFK, $values).'</div>',
|
||||
LayoutForm::HR_LINE => '<hr/>',
|
||||
default => ''
|
||||
};
|
||||
if ($framework == 'tailwind') {
|
||||
return match ($this->tipe) {
|
||||
LayoutForm::COLUMN => '<div className="space-y-2 form-control-validation">'
|
||||
.$this->childHtml($state, $errors, $optionsFK, $values, $framework).'</div>',
|
||||
LayoutForm::VALUE => $this->value($state, $errors, $optionsFK, $values, $framework),
|
||||
LayoutForm::SECTION => '<h3 className="font-semibold text-lg text-slate-900">'.$this->section_label.'</h3>',
|
||||
LayoutForm::ROW => '<div className="grid grid-cols-1 gap-5">'.$this->childHtml($state, $errors, $optionsFK, $values, $framework).'</div>',
|
||||
LayoutForm::HR_LINE => '<hr/>',
|
||||
default => ''
|
||||
};
|
||||
} else {
|
||||
return match ($this->tipe) {
|
||||
LayoutForm::COLUMN => '<div class="col-'.($this->column_width ?? 3).' mb-4 form-control-validation">'
|
||||
.$this->childHtml($state, $errors, $optionsFK, $values, $framework).'</div>',
|
||||
LayoutForm::VALUE => $this->value($state, $errors, $optionsFK, $values, $framework),
|
||||
LayoutForm::SECTION => '<h6 class="mb-3">'.$this->section_label.'</h6>',
|
||||
LayoutForm::ROW => '<div class="row">'.$this->childHtml($state, $errors, $optionsFK, $values, $framework).'</div>',
|
||||
LayoutForm::HR_LINE => '<hr/>',
|
||||
default => ''
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function childHtml(string $state, $errors = null, $optionsFK = null, $values = null): string
|
||||
private function childHtml(string $state, $errors = null, $optionsFK = null, $values = null, $framework = 'bootstrap'): string
|
||||
{
|
||||
$html = '';
|
||||
foreach ($this->form as $form) {
|
||||
$html .= $form->renderHtml($state, $errors, $optionsFK, $values);
|
||||
$html .= $form->renderHtml($state, $errors, $optionsFK, $values, $framework);
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function value(string $state, $errors = null, $optionsFK = null, $values = null): string
|
||||
private function value(string $state, $errors = null, $optionsFK = null, $values = null, $framework = 'bootstrap'): string
|
||||
{
|
||||
$html = '';
|
||||
if ($this->kolom) {
|
||||
@@ -97,92 +109,227 @@ class FormBasisData extends Model
|
||||
$value = $values ? $values->where('kolom_id', $k->id)->first() : null;
|
||||
$oldValue = old($k->kolom);
|
||||
|
||||
$html .= '<label class="form-label" for="value-data-kolom_name">kolom_required'.$this->kolom->label;
|
||||
$html .= '</label>';
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Label htmlFor="label" className="text-sm font-medium text-slate-700">kolom_required'.$this->kolom->label;
|
||||
$html .= '</Label>';
|
||||
} else {
|
||||
$html .= '<label class="form-label" for="value-data-kolom_name">kolom_required'.$this->kolom->label;
|
||||
$html .= '</label>';
|
||||
}
|
||||
|
||||
if($k->tipe == 'varchar') {
|
||||
$html .= '<input type="text" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
} else {
|
||||
$html .= '<input type="text" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
}
|
||||
}
|
||||
elseif($k->tipe == 'text') {
|
||||
$html .= '<textarea class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name">kolom_value</textarea>';
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Textarea className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name">kolom_value</Textarea>';
|
||||
} else {
|
||||
$html .= '<textarea class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name">kolom_value</textarea>';
|
||||
}
|
||||
}
|
||||
elseif($k->tipe == 'integer') {
|
||||
$html .= '<input type="number" class="form-control" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" step="1" value="kolom_value" />';
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input type="number" className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" step="1" value="kolom_value" />';
|
||||
} else {
|
||||
$html .= '<input type="number" class="form-control" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" step="1" value="kolom_value" />';
|
||||
}
|
||||
}
|
||||
elseif($k->tipe == 'float') {
|
||||
$html .= '<input type="number" class="form-control kolom_error" id="add-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" step="any" />';
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" step="any" />';
|
||||
} else {
|
||||
$html .= '<input type="number" class="form-control kolom_error" id="add-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" step="any" />';
|
||||
}
|
||||
}
|
||||
elseif($k->tipe == 'date') {
|
||||
$html .= '<input type="date" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input type="date" className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
} else {
|
||||
$html .= '<input type="date" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
}
|
||||
}
|
||||
elseif($k->tipe == 'datetime'){
|
||||
$html .= '<input type="datetime-local" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input type="datetime-local" className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
} else {
|
||||
$html .= '<input type="datetime-local" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
}
|
||||
}
|
||||
elseif($k->tipe == 'boolean') {
|
||||
if ($state == 'preview' || $state == 'view') {
|
||||
$html .= '<input type="text" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input type="text" className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
} else {
|
||||
$html .= '<input type="text" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
}
|
||||
} elseif ($state == 'add') {
|
||||
$html .= '<select class="form-select tipe-boolean kolom_error id="value-data-kolom_name" name="kolom_name">
|
||||
<option value="1" '. (old($k->kolom) == 1 ? 'selected' : '') .'>Ya</option>
|
||||
<option value="0" '. (old($k->kolom) == 0 ? 'selected' : '') .'>Tidak</option>
|
||||
</select>';
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Select value="kolom_value">
|
||||
<SelectTrigger className="border-slate-200 focus:ring-emerald-500 rounded-xl h-11 bg-white text-left">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent className="rounded-xl">
|
||||
<SelectItem value="1" className="rounded-lg">Ya</SelectItem>
|
||||
<SelectItem value="0" className="rounded-lg">Tidak</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>';
|
||||
} else {
|
||||
$html .= '<select class="form-select tipe-boolean kolom_error" id="value-data-kolom_name" name="kolom_name">
|
||||
<option value="1" '. (old($k->kolom) == 1 ? 'selected' : '') .'>Ya</option>
|
||||
<option value="0" '. (old($k->kolom) == 0 ? 'selected' : '') .'>Tidak</option>
|
||||
</select>';
|
||||
}
|
||||
} elseif ($state == 'edit') {
|
||||
$html .= '<select class="form-select tipe-boolean kolom_error id="value-data-kolom_name" name="kolom_name">
|
||||
<option value="1" '. ((old($k->kolom) ?? (($value ? $value['value_'.$k->tipe] : null) ?? null) == 1) ? 'selected' : '') .'>Ya</option>
|
||||
<option value="0" '. ((old($k->kolom) ?? (($value ? $value['value_'.$k->tipe] : null) ?? null) == 0) ? 'selected' : '') .'>Tidak</option>
|
||||
</select>';
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Select value="kolom_value">
|
||||
<SelectTrigger className="border-slate-200 focus:ring-emerald-500 rounded-xl h-11 bg-white text-left">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent className="rounded-xl">
|
||||
<SelectItem value="1" className="rounded-lg">Ya</SelectItem>
|
||||
<SelectItem value="0" className="rounded-lg">Tidak</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>';
|
||||
} else {
|
||||
$html .= '<select class="form-select tipe-boolean kolom_error" id="value-data-kolom_name" name="kolom_name">
|
||||
<option value="1" '. ((old($k->kolom) ?? (($value ? $value['value_'.$k->tipe] : null) ?? null) == 1) ? 'selected' : '') .'>Ya</option>
|
||||
<option value="0" '. ((old($k->kolom) ?? (($value ? $value['value_'.$k->tipe] : null) ?? null) == 0) ? 'selected' : '') .'>Tidak</option>
|
||||
</select>';
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($k->tipe == 'foreign_key') {
|
||||
if ($state == 'preview' || $state == 'view') {
|
||||
$html .= '<input type="text" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input type="text" className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
} else {
|
||||
$html .= '<input type="text" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
}
|
||||
} elseif ($state == 'add') {
|
||||
$html .= '<select class="form-select tipe-boolean kolom_error id="value-data-kolom_name" name="kolom_name">';
|
||||
if ($optionsFK && $optionsFK->where('kolom_id', $k->id)->first() != null) {
|
||||
foreach ($optionsFK->where('kolom_id', $k->id)->first()['options'] as $option) {
|
||||
$html .= '<option value="'.$option->value.'" '.(old($k->kolom) == $option->value ? 'selected' : '').'>'.$option->label.'</option>';
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Select value="kolom_value" id="value-data-kolom_name" name="kolom_name" className="form-select tipe-foreign_key kolom_error">
|
||||
<SelectTrigger className="border-slate-200 focus:ring-emerald-500 rounded-xl h-11 bg-white text-left">
|
||||
<SelectValue />
|
||||
</SelectTrigger>';
|
||||
if ($optionsFK && $optionsFK->where('kolom_id', $k->id)->first() != null) {
|
||||
foreach ($optionsFK->where('kolom_id', $k->id)->first()['options'] as $option) {
|
||||
$html .= '<SelectContent className="rounded-xl">
|
||||
<SelectItem value="'.$option->value.'" className="rounded-lg">'.$option->label.'</SelectItem>
|
||||
</SelectContent>';
|
||||
}
|
||||
}
|
||||
$html .= '</Select>';
|
||||
} else {
|
||||
$html .= '<select class="form-select tipe-foreign_key kolom_error" id="value-data-kolom_name" name="kolom_name">';
|
||||
if ($optionsFK && $optionsFK->where('kolom_id', $k->id)->first() != null) {
|
||||
foreach ($optionsFK->where('kolom_id', $k->id)->first()['options'] as $option) {
|
||||
$html .= '<option value="'.$option->value.'" '.(old($k->kolom) == $option->value ? 'selected' : '').'>'.$option->label.'</option>';
|
||||
}
|
||||
}
|
||||
$html .= '</select>';
|
||||
}
|
||||
$html .= '</select>';
|
||||
} elseif ($state == 'edit') {
|
||||
$html .= '<select class="form-select tipe-boolean kolom_error id="value-data-kolom_name" name="kolom_name">';
|
||||
if ($optionsFK && $optionsFK->where('kolom_id', $k->id)->first() != null) {
|
||||
foreach ($optionsFK->where('kolom_id', $k->id)->first()['options'] as $option) {
|
||||
$html .= '<option value="'.$option->value.'" '.(old($k->kolom) ?? ($value ? $value['value_relasi'] : null) == $option->value ? 'selected' : '').'>'.$option->label.'</option>';
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Select value="kolom_value" id="value-data-kolom_name" name="kolom_name" className="form-select tipe-foreign_key kolom_error">
|
||||
<SelectTrigger className="border-slate-200 focus:ring-emerald-500 rounded-xl h-11 bg-white text-left">
|
||||
<SelectValue />
|
||||
</SelectTrigger>';
|
||||
if ($optionsFK && $optionsFK->where('kolom_id', $k->id)->first() != null) {
|
||||
foreach ($optionsFK->where('kolom_id', $k->id)->first()['options'] as $option) {
|
||||
$html .= '<SelectContent className="rounded-xl">
|
||||
<SelectItem value="'.$option->value.'" className="rounded-lg" '.(old($k->kolom) ?? ($value ? ($value['value_relasi'] == $option->value) : null) ? 'selected' : '') .'>'.$option->label.'</SelectItem>
|
||||
</SelectContent>';
|
||||
}
|
||||
}
|
||||
$html .= '</Select>';
|
||||
} else {
|
||||
$html .= '<select class="form-select tipe-foreign_key kolom_error" id="value-data-kolom_name" name="kolom_name">';
|
||||
if ($optionsFK && $optionsFK->where('kolom_id', $k->id)->first() != null) {
|
||||
foreach ($optionsFK->where('kolom_id', $k->id)->first()['options'] as $option) {
|
||||
$html .= '<option value="'.$option->value.'" '.(old($k->kolom) ?? ($value ? $value['value_relasi'] : null) == $option->value ? 'selected' : '').'>'.$option->label.'</option>';
|
||||
}
|
||||
}
|
||||
$html .= '</select>';
|
||||
}
|
||||
$html .= '</select>';
|
||||
}
|
||||
}
|
||||
elseif($k->tipe == 'enum') {
|
||||
if ($state == 'preview' || $state == 'view') {
|
||||
$html .= '<input type="text" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input type="text" className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
} else {
|
||||
$html .= '<input type="text" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
}
|
||||
} elseif ($state == 'add') {
|
||||
$html .= '<select class="form-select tipe-boolean kolom_error id="value-data-kolom_name" name="kolom_name">';
|
||||
foreach($k->enum_opsi as $opsi) {
|
||||
$html .= '<option value="' .$opsi['value']. '" ' .(old($k->kolom) == $opsi['value'] ? 'selected' : ''). '>' .$opsi['label']. '</option>';
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Select value="kolom_value" id="value-data-kolom_name" name="kolom_name" className="form-select tipe-enum kolom_error">
|
||||
<SelectTrigger className="border-slate-200 focus:ring-emerald-500 rounded-xl h-11 bg-white text-left">
|
||||
<SelectValue />
|
||||
</SelectTrigger>';
|
||||
foreach($k->enum_opsi as $opsi) {
|
||||
$html .= '<SelectContent className="rounded-xl">
|
||||
<SelectItem value="'.$opsi['value'].'" className="rounded-lg">'.$opsi['label'].'</SelectItem>
|
||||
</SelectContent>';
|
||||
}
|
||||
$html .= '</Select>';
|
||||
} else {
|
||||
$html .= '<select class="form-select tipe-enum kolom_error" id="value-data-kolom_name" name="kolom_name">';
|
||||
foreach($k->enum_opsi as $opsi) {
|
||||
$html .= '<option value="' .$opsi['value']. '" ' .(old($k->kolom) == $opsi['value'] ? 'selected' : ''). '>' .$opsi['label']. '</option>';
|
||||
}
|
||||
$html .= '</select>';
|
||||
}
|
||||
$html .= '</select>';
|
||||
} elseif ($state == 'edit') {
|
||||
$html .= '<select class="form-select tipe-boolean kolom_error id="value-data-kolom_name" name="kolom_name">';
|
||||
foreach($k->enum_opsi as $opsi) {
|
||||
$html .= '<option value="' .$opsi['value']. '" ' .(old($k->kolom) ?? ($value ? $value['value_'.$k->tipe] : null) == $opsi['value'] ? 'selected' : ''). '>' .$opsi['label']. '</option>';
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Select value="kolom_value" id="value-data-kolom_name" name="kolom_name" className="form-select tipe-enum kolom_error">
|
||||
<SelectTrigger className="border-slate-200 focus:ring-emerald-500 rounded-xl h-11 bg-white text-left">
|
||||
<SelectValue />
|
||||
</SelectTrigger>';
|
||||
foreach($k->enum_opsi as $opsi) {
|
||||
$html .= '<SelectContent className="rounded-xl">
|
||||
<SelectItem value="'.$opsi['value'].'" className="rounded-lg">'.$opsi['label'].'</SelectItem>
|
||||
</SelectContent>';
|
||||
}
|
||||
$html .= '</Select>';
|
||||
} else {
|
||||
$html .= '<select class="form-select tipe-enum kolom_error" id="value-data-kolom_name" name="kolom_name">';
|
||||
foreach($k->enum_opsi as $opsi) {
|
||||
$html .= '<option value="' .$opsi['value']. '" ' .(old($k->kolom) ?? ($value ? $value['value_'.$k->tipe] : null) == $opsi['value'] ? 'selected' : ''). '>' .$opsi['label']. '</option>';
|
||||
}
|
||||
$html .= '</select>';
|
||||
}
|
||||
$html .= '</select>';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$html .= '<input type="text" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
if ($framework == 'tailwind') {
|
||||
$html .= '<Input type="text" className="form-control kolom_error h-11" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
} else {
|
||||
$html .= '<input type="text" class="form-control kolom_error" id="value-data-kolom_name" readonly
|
||||
name="kolom_name" value="kolom_value" />';
|
||||
}
|
||||
}
|
||||
|
||||
$errorClass = $errors && $errors->has($k->kolom)
|
||||
|
||||
Reference in New Issue
Block a user