Skip to content

Commit

Permalink
Fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
rajakodings committed May 11, 2019
1 parent b3147ee commit c49c81b
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 77 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Additional Options available : <br/>
| ------------------ | ---------------- |
| <code>->maxLength(100);</code> | Set max length limit
| <code>->minLength(5);</code> | Set min length limit |
| <code>->strLimit(100);</code>| Set character limit |

Additional options example :
```php
Expand Down Expand Up @@ -160,6 +161,12 @@ Parameters available : <br/>
| $name | The input name (Optional) |
| $field_to_save | The field name if not same with the name (Optional) |

Additional options :

| Name | Description |
| --- | --- |
| <code>->strLimit($length);</code>|Set column limit characters|

## Select
**Example**
```php
Expand All @@ -181,6 +188,7 @@ Additional options available :
| --- | --- |
| <code>->options($array);</code> | The options of select |
| <code>->optionsFromTable($table, $key_field, $display_field, $SQLCondition = null);</code> | The options of select with table source |
| <code>->foreignKey($parent_select_name);</code> | To enable sub select|

Additional options example :
```php
Expand Down Expand Up @@ -368,6 +376,11 @@ Parameters available : <br/>
| $name | The input name (Optional) |
| $field_to_save | The field name if not same with the name (Optional) |

Additional options :

| Name | Description |
| --- | --- |
| <code>->strLimit($length);</code>|Set column limit characters|

# Additional Basic Options
| Name | Description |
Expand Down
69 changes: 11 additions & 58 deletions src/assets/css/main.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#table-module thead tr th {
border: 1px solid #cccccc;
}
#table-module tbody tr td {
border: 1px solid #cccccc;
}
.select2-container--default .select2-selection--single {border-radius: 0px !important; border: 1px solid #dddddd !important;}
.select2-container .select2-selection--single {height: 35px !important;}
.select2 {
width: 100%;
}
.select2-dropdown {z-index: 9999 !important}

.bootstrap-timepicker-minute,.bootstrap-timepicker-hour,.bootstrap-timepicker-meridian,.bootstrap-timepicker-second {
Expand All @@ -19,68 +30,10 @@

.datepicker{z-index:1151 !important;}

.sidebar-menu .treeview-menu>li>a {
padding:5px 5px 5px 25px;
}
.form-tab li a:hover {
background: #eeeeee !important;
}
.form-tab li a.selected {
background: #3c8dbc !important;
color:#ffffff !important;
}
.alert_floating {
bottom:10px;
right:10px;
position: fixed;
z-index:1001;
background: rgba(255, 140, 127, 0.7);
color:#222222;
font-weight: bold;
padding:20px 50px 20px 50px;
border-radius: 10px;
box-shadow: 0px 0px 5px #aaaaaa;
}

#table_dashboard {
font-size: 12px;
}

.dropdown-menu-action {
left: -130%;
}

.btn-group-action .btn-action {
cursor: default
}

#box-header-module {
box-shadow: 10px 10px 10px #dddddd;
}

.sub-module-tab li {
background: #F9F9F9;
cursor: pointer;
}

.sub-module-tab li.active {
background: #ffffff;
box-shadow: 0px -5px 10px #cccccc
}

.nav-tabs > li.active > a, .nav-tabs > li.active > a:focus, .nav-tabs > li.active > a:hover {
border: none;
}

.nav-tabs > li > a {
border: none;
}

.breadcrumb {
margin: 0 0 0 0;
padding: 0 0 0 0;
}

.form-group > label:first-child {
display: block
}
6 changes: 6 additions & 0 deletions src/types/date/asset.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<style>
.datepicker[readonly] {
cursor: pointer;
background: #fefefe;
}
</style>
2 changes: 1 addition & 1 deletion src/types/date/component.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<input type='text' title="{{ $column->getLabel() }}"
placeholder="{{ $column->getPlaceholder() }}"
{{ $column->getRequired()?'required':''}}
{{ $column->getReadonly()?'readonly':''}}
readonly
{{ $column->getDisabled()?'disabled':''}}
class='form-control datepicker'
name="{{ $column->getName() }}"
Expand Down
6 changes: 6 additions & 0 deletions src/types/datetime/asset.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<style>
.datetimepicker[readonly] {
cursor: pointer;
background: #fefefe;
}
</style>
5 changes: 5 additions & 0 deletions src/types/select/Route.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

cb()->routeGroupBackend(function () {
cb()->routePost("select-lookup",'\crocodicstudio\crudbooster\types\select\SelectController@postLookup');
});
20 changes: 19 additions & 1 deletion src/types/select/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,34 @@

use crocodicstudio\crudbooster\controllers\scaffolding\traits\DefaultOption;
use crocodicstudio\crudbooster\controllers\scaffolding\traits\Join;
use crocodicstudio\crudbooster\models\ColumnModel;
use crocodicstudio\crudbooster\types\select\SelectModel;
use Illuminate\Support\Facades\DB;

class Select
{
use DefaultOption, Join;

/**
* @param string $field_name
* @return $this
*/
public function foreignKey($field_name)
{
$data = columnSingleton()->getColumn($this->index);
/** @var SelectModel $data */
$data->setForeignKey($field_name);
columnSingleton()->setColumn($this->index, $data);

return $this;
}

/**
* @param $table string
* @param $key_field string
* @param $display_field string
* @param $SQLCondition string|callable
* @return $this
*/
public function optionsFromTable($table, $key_field, $display_field, $SQLCondition = null) {
$data = DB::table($table);
Expand All @@ -37,10 +53,12 @@ public function optionsFromTable($table, $key_field, $display_field, $SQLConditi
}
$data = columnSingleton()->getColumn($this->index);
/** @var $data SelectModel */
$data->setOptionsFromTable(["table"=>$table,"key_field"=>$key_field,"display_field"=>$display_field]);
$data->setOptionsFromTable(["table"=>$table,"key_field"=>$key_field,"display_field"=>$display_field,"sql_condition"=>$SQLCondition]);
columnSingleton()->setColumn($this->index, $data);

$this->options($options);

return $this;
}

public function options($data_options) {
Expand Down
37 changes: 37 additions & 0 deletions src/types/select/SelectController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Created by PhpStorm.
* User: User
* Date: 5/10/2019
* Time: 10:38 PM
*/

namespace crocodicstudio\crudbooster\types\select;

use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\DB;

class SelectController extends BaseController
{
public function postLookup() {
$foreignKey = decrypt(request('foreign_key'));
$foreignValue = request('foreign_value');
$table = decrypt(request('table'));
$sqlCondition = decrypt(request('sql_condition'));
if($foreignKey && $foreignValue && $table) {

$data = DB::table($table)
->where($foreignKey, $foreignValue);
if($sqlCondition) {
$data->whereRaw($sqlCondition);
}

$data = $data->get();

return response()->json(['status'=>true, 'data'=>$data]);

}else{
return response()->json(['status'=>false]);
}
}
}
21 changes: 20 additions & 1 deletion src/types/select/SelectModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@ class SelectModel extends ColumnModel

private $options;
private $options_from_table;
private $foreign_key;

/**
* @return mixed
*/
public function getForeignKey()
{
return $this->foreign_key;
}

/**
* @param mixed $foreign_key
*/
public function setForeignKey($foreign_key)
{
$this->foreign_key = $foreign_key;
}



/**
* @return mixed
Expand Down Expand Up @@ -45,7 +64,7 @@ public function getOptions()
/**
* @param mixed $options
*/
public function setOptions($options): void
public function setOptions($options)
{
$this->options = $options;
}
Expand Down
53 changes: 46 additions & 7 deletions src/types/select/component.blade.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,55 @@
@include("types::layout_header")
<?php /** @var \crocodicstudio\crudbooster\types\select\SelectModel $column */?>
<select style="width: 100%" class="form-control select2"
<select style="width: 100%" id="select-{{ $column->getName() }}" class="form-control select2"
{{ $column->getRequired()?'required':''}}
{{ $column->getReadonly()?'readonly':''}}
{{ $column->getDisabled()?'disabled':''}}
name="{{ $column->getName() }}" id="{{ $column->getName() }}">
<option value="">** Select a {{ $column->getLabel() }}</option>
<?php
$columnValue = old($column->getName())?:($column->getDefaultValue())?:$column->getValue();
?>
@foreach($column->getOptions() as $key=>$value)
<option {{ $columnValue==$key?'selected':'' }} value="{{ $key }}">{{ $value }}</option>
@endforeach
@if(!$column->getForeignKey())
<?php
$columnValue = old($column->getName())?:($column->getDefaultValue())?:$column->getValue();
?>
@foreach($column->getOptions() as $key=>$value)
<option {{ $columnValue==$key?'selected':'' }} value="{{ $key }}">{{ $value }}</option>
@endforeach
@endif
</select>

@if($column->getForeignKey())
@push('bottom')
<script>
$(function () {
let value = "{{ old($column->getName())?:($column->getDefaultValue())?:$column->getValue() }}";
$("#select-{{ $column->getForeignKey() }}").change(function () {
let foreign_value = $(this).val();
$.post("{{ cb()->getAdminUrl("select-lookup") }}",{
_token:"{{csrf_token()}}",
foreign_key:"{{ encrypt($column->getForeignKey()) }}",
foreign_value: foreign_value,
table:"{{ encrypt($column->getOptionsFromTable()['table']) }}",
sql_condition:"{{ encrypt($column->getOptionsFromTable()['sql_condition']) }}"
},function (resp) {
if(resp.status) {
var opt = "<option value=''>** Select a {{ $column->getLabel() }}</option>";
$.each(resp.data,function (i,obj) {
opt += "<option value='"+obj.{{ $column->getOptionsFromTable()['key_field'] }}+"'>"+obj.{{ $column->getOptionsFromTable()['display_field'] }}+"</option>";
})
$("#select-{{ $column->getName() }}").select2("val","");
$("#select-{{ $column->getName() }}").val("");
$("#select-{{ $column->getName() }}").html(opt);
if(value) {
$("#select-{{ $column->getName() }}").val(value);
$("#select-{{ $column->getName() }}").select2({
placeholder:"** Select a {{ $column->getLabel() }}"
})
}
}
})
}).trigger("change");
})
</script>
@endpush
@endif
@include("types::layout_footer")
14 changes: 14 additions & 0 deletions src/types/text/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,18 @@
class Hook extends TypesHook
{

/**
* @param $row
* @param $column TextModel
* @return string
*/
public function indexRender($row, $column)
{
$value = trim(strip_tags($row->{ $column->getField() }));
if($column->getLimit()) {
$value = Str::limit($value, $column->getLimit());
}
return $value;
}

}
10 changes: 10 additions & 0 deletions src/types/text/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ class Text
{
use DefaultOption, Join;

public function strLimit($length = 100) {
$data = columnSingleton()->getColumn($this->index);
/** @var WysiwygModel $data */
$data->setLimit($length);

columnSingleton()->setColumn($this->index, $data);

return $this;
}

public function maxLength($length) {
$model = columnSingleton()->getColumn($this->index);
/**
Expand Down
Loading

0 comments on commit c49c81b

Please sign in to comment.