Skip to content

Commit

Permalink
Make template responsive
Browse files Browse the repository at this point in the history
  • Loading branch information
SmarterVision committed Jan 22, 2021
1 parent a2f8707 commit 5273716
Show file tree
Hide file tree
Showing 50 changed files with 259 additions and 324 deletions.
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +0,0 @@
Laravel Generator
==============================

[![Total Downloads](https://poser.pugx.org/infyomlabs/laravel-generator/downloads)](https://packagist.org/packages/infyomlabs/laravel-generator)
[![Monthly Downloads](https://poser.pugx.org/infyomlabs/laravel-generator/d/monthly)](https://packagist.org/packages/infyomlabs/laravel-generator)
[![Daily Downloads](https://poser.pugx.org/infyomlabs/laravel-generator/d/daily)](https://packagist.org/packages/infyomlabs/laravel-generator)
[![Latest Stable Version](https://poser.pugx.org/infyomlabs/laravel-generator/v/stable)](https://packagist.org/packages/infyomlabs/laravel-generator)
[![Latest Unstable Version](https://poser.pugx.org/infyomlabs/laravel-generator/v/unstable)](https://packagist.org/packages/infyomlabs/laravel-generator)
[![License](https://poser.pugx.org/infyomlabs/laravel-generator/license)](https://packagist.org/packages/infyomlabs/laravel-generator)

Documentation is located [here](http://labs.infyom.com/laravelgenerator)
3 changes: 2 additions & 1 deletion src/Commands/Publish/VueJsLayoutPublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace InfyOm\Generator\Commands\Publish;

use InfyOm\Generator\Utils\FileUtil;
use Illuminate\Support\Str;

class VueJsLayoutPublishCommand extends PublishBaseCommand
{
Expand Down Expand Up @@ -35,7 +36,7 @@ class VueJsLayoutPublishCommand extends PublishBaseCommand
public function handle()
{
$version = $this->getApplication()->getVersion();
if (str_contains($version, '5.1')) {
if (Str::contains($version, '5.1')) {
$this->laravelVersion = '5.1';
} else {
$this->laravelVersion = '5.2';
Expand Down
8 changes: 4 additions & 4 deletions src/Common/BaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace InfyOm\Generator\Common;

use Exception;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Log;

abstract class BaseRepository extends \Prettus\Repository\Eloquent\BaseRepository
Expand Down Expand Up @@ -54,11 +55,10 @@ public function updateRelations($model, $attributes)
$methodClass = get_class($model->$key($key));
switch ($methodClass) {
case 'Illuminate\Database\Eloquent\Relations\BelongsToMany':
$new_values = array_get($attributes, $key, []);
$new_values = Arr::get($attributes, $key, []);
if (array_search('', $new_values) !== false) {
unset($new_values[array_search('', $new_values)]);
}
Log::info(array_values($new_values));
// if(count(array_values($new_values)) === 0){
// $pivot = $model->$key()->detach(array_values($new_values));
// }else{
Expand All @@ -71,7 +71,7 @@ public function updateRelations($model, $attributes)
break;
case 'Illuminate\Database\Eloquent\Relations\BelongsTo':
$model_key = $model->$key()->getQualifiedForeignKey();
$new_value = array_get($attributes, $key, null);
$new_value = Arr::get($attributes, $key, null);
$new_value = $new_value == '' ? null : $new_value;
$model->$model_key = $new_value;
break;
Expand All @@ -80,7 +80,7 @@ public function updateRelations($model, $attributes)
case 'Illuminate\Database\Eloquent\Relations\HasOneOrMany':
break;
case 'Illuminate\Database\Eloquent\Relations\HasMany':
$new_values = array_get($attributes, $key, []);
$new_values = Arr::get($attributes, $key, []);
if (array_search('', $new_values) !== false) {
unset($new_values[array_search('', $new_values)]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Common/GeneratorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ public function prepareModelNames()
$this->mDashedPlural = str_replace('_', '-', Str::snake($this->mSnakePlural));
$this->mSlash = str_replace('_', '/', Str::snake($this->mSnake));
$this->mSlashPlural = str_replace('_', '/', Str::snake($this->mSnakePlural));
$this->mHuman = title_case(str_replace('_', ' ', Str::snake($this->mSnake)));
$this->mHumanPlural = title_case(str_replace('_', ' ', Str::snake($this->mSnakePlural)));
$this->mHuman = Str::title(str_replace('_', ' ', Str::snake($this->mSnake)));
$this->mHumanPlural = Str::title(str_replace('_', ' ', Str::snake($this->mSnakePlural)));
}

public function prepareOptions(CommandData &$commandData)
Expand Down
11 changes: 6 additions & 5 deletions src/Common/GeneratorFieldRelation.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace InfyOm\Generator\Common;
use Illuminate\Support\Str;

class GeneratorFieldRelation
{
Expand All @@ -24,27 +25,27 @@ public function getRelationFunctionText()
$modelName = $this->inputs[0];
switch ($this->type) {
case '1t1':
$functionName = camel_case($modelName);
$functionName = Str::camel($modelName);
$relation = 'hasOne';
$relationClass = 'HasOne';
break;
case '1tm':
$functionName = camel_case(str_plural($modelName));
$functionName = Str::camel(Str::plural($modelName));
$relation = 'hasMany';
$relationClass = 'HasMany';
break;
case 'mt1':
$functionName = camel_case($modelName);
$functionName = Str::camel($modelName);
$relation = 'belongsTo';
$relationClass = 'BelongsTo';
break;
case 'mtm':
$functionName = camel_case(str_plural($modelName));
$functionName = Str::camel(Str::plural($modelName));
$relation = 'belongsToMany';
$relationClass = 'BelongsToMany';
break;
case 'hmt':
$functionName = camel_case(str_plural($modelName));
$functionName = Str::camel(Str::plural($modelName));
$relation = 'hasManyThrough';
$relationClass = 'HasManyThrough';
break;
Expand Down
7 changes: 4 additions & 3 deletions src/Generators/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace InfyOm\Generator\Generators;

use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use InfyOm\Generator\Common\CommandData;
use InfyOm\Generator\Common\GeneratorFieldRelation;
use InfyOm\Generator\Utils\FileUtil;
Expand Down Expand Up @@ -192,12 +193,12 @@ private function getPHPDocType($db_type, $relation = null)
return 'string';
case '1t1':
case 'mt1':
return '\\'.$this->commandData->config->nsModel.'\\'.$relation->inputs[0].' '.camel_case($relation->inputs[0]);
return '\\'.$this->commandData->config->nsModel.'\\'.$relation->inputs[0].' '.Str::camel($relation->inputs[0]);
case '1tm':
return '\Illuminate\Database\Eloquent\Collection'.' '.$relation->inputs[0];
case 'mtm':
case 'hmt':
return '\Illuminate\Database\Eloquent\Collection'.' '.camel_case($relation->inputs[0]);
return '\Illuminate\Database\Eloquent\Collection'.' '.Str::camel($relation->inputs[0]);
default:
return $db_type;
}
Expand Down Expand Up @@ -231,7 +232,7 @@ private function generateRequiredFields()

foreach ($this->commandData->fields as $field) {
if (!empty($field->validations)) {
if (str_contains($field->validations, 'required')) {
if (Str::contains($field->validations, 'required')) {
$requiredFields[] = $field->name;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Generators/Scaffold/ViewGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private function getTransArray($string = ''){
}
return $result;
}

private function getLangArray(){
$mSnake = $this->commandData->config->mSnake;
$lang = [
Expand All @@ -231,7 +231,7 @@ private function getLangArray(){
$mSnake."_create" => $this->getTransArray('Create '.$this->commandData->config->mHuman),
];
foreach ($this->commandData->fields as $field) {
$title = preg_replace('/-|_/',' ',title_case($field->name));
$title = preg_replace('/-|_/',' ',Str::title($field->name));
if($field->inIndex || $field->inForm){
$lang[$mSnake.'_'.$field->name] = $this->getTransArray($title);
}
Expand All @@ -246,7 +246,7 @@ private function getLangArray(){
private function generateFields()
{
$this->htmlFields = [];
$startSeparator = '<div style="flex: 50%;max-width: 50%;padding: 0 4px;" class="column">';
$startSeparator = '<div class="d-flex flex-column col-sm-12 col-md-6">';
$endSeparator = '</div>';

foreach ($this->commandData->fields as $field) {
Expand Down Expand Up @@ -362,7 +362,7 @@ public function generateCustomField($fields)
$this->htmlFields = [];
// $this->commandData = new CommandData($this->commandData, CommandData::$COMMAND_TYPE_API_SCAFFOLD);
// $this->commandData->commandType = CommandData::$COMMAND_TYPE_API_SCAFFOLD;
$startSeparator = '<div style="flex: 50%;max-width: 50%;padding: 0 4px;" class="column">';
$startSeparator = '<div class="d-flex flex-column col-sm-12 col-md-6">';
$endSeparator = '</div>';

foreach ($fields as $field) {
Expand Down
9 changes: 5 additions & 4 deletions src/Utils/HTMLFieldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace InfyOm\Generator\Utils;

use InfyOm\Generator\Common\GeneratorField;
use Illuminate\Support\Str;

class HTMLFieldGenerator
{
Expand All @@ -29,15 +30,15 @@ public static function generateHTML(GeneratorField $field, $templateType)
} else {
$fieldTemplate = get_template('scaffold.fields.select', $templateType);
}
if (starts_with($field->htmlValues[0], '$')) {
if (Str::startsWith($field->htmlValues[0], '$')) {
$fieldTemplate = str_replace(
'$INPUT_ARR$',
$field->htmlValues[0],
$fieldTemplate
);
$fieldTemplate = str_replace(
'$INPUT_ARR_SELECTED$',
str_plural($field->htmlValues[0]) . 'Selected',
Str::plural($field->htmlValues[0]) . 'Selected',
$fieldTemplate
);
} else {
Expand Down Expand Up @@ -105,15 +106,15 @@ public static function generateCustomFieldHTML(GeneratorField $field, $templateT
} else {
$fieldTemplate = get_template('scaffold.custom_fields.select', $templateType);
}
if (starts_with($field->htmlValues[0], '$')) {
if (Str::startsWith($field->htmlValues[0], '$')) {
$fieldTemplate = str_replace(
'$INPUT_ARR$',
$field->htmlValues[0],
$fieldTemplate
);
$fieldTemplate = str_replace(
'$INPUT_ARR_SELECTED$',
str_plural($field->htmlValues[0]) . 'Selected',
Str::plural($field->htmlValues[0]) . 'Selected',
$fieldTemplate
);
} else {
Expand Down
7 changes: 4 additions & 3 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
use Illuminate\Support\Str;

if (!function_exists('infy_tab')) {
/**
Expand Down Expand Up @@ -230,7 +231,7 @@ function fill_template_with_field_data($variables, $fieldVariables, $template, $
*/
function model_name_from_table_name($tableName)
{
return ucfirst(camel_case(str_singular($tableName)));
return ucfirst(Str::camel(str_singular($tableName)));
}
}
if (!function_exists('get_relation')) {
Expand Down Expand Up @@ -282,8 +283,8 @@ function fill_add_repositories_template($fieldNames, $templateData, $templateTyp
$addRepositoryTemplate = get_template('scaffold.controller.repository_attr', $templateType);

$addRepositoryTemplate = fill_template([
'$RELATION_MODEL$' => studly_case($modelName),
'$RELATION_MODEL_SNAKE$' => snake_case($modelName)
'$RELATION_MODEL$' => Str::studly($modelName),
'$RELATION_MODEL_SNAKE$' => Str::snake($modelName)
], $addRepositoryTemplate);

$addRepositoryTemplate = preg_split('/#{3}/', $addRepositoryTemplate);
Expand Down
3 changes: 1 addition & 2 deletions templates/api/controller/api_controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use InfyOm\Generator\Criteria\LimitOffsetCriteria;
use Prettus\Repository\Criteria\RequestCriteria;
use Illuminate\Support\Facades\Response;
use Prettus\Repository\Exceptions\RepositoryException;
use Flash;

$DOC_CONTROLLER$
class $MODEL_NAME$APIController extends Controller
Expand All @@ -31,7 +30,7 @@ class $MODEL_NAME$APIController extends Controller
$this->$MODEL_NAME_CAMEL$Repository->pushCriteria(new RequestCriteria($request));
$this->$MODEL_NAME_CAMEL$Repository->pushCriteria(new LimitOffsetCriteria($request));
} catch (RepositoryException $e) {
Flash::error($e->getMessage());
return $this->sendError($e->getMessage());
}
$$MODEL_NAME_PLURAL_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->all();

Expand Down
13 changes: 1 addition & 12 deletions templates/scaffold/auth/login.stub
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,5 @@
<script src="{{asset('plugins/jquery/jquery.min.js')}}"></script>
<!-- Bootstrap 4 -->
<script src="{{asset('plugins/bootstrap/js/bootstrap.bundle.min.js')}}"></script>
<!-- iCheck -->
<script src="{{asset('plugins/iCheck/icheck.min.js')}}"></script>
<script>
$(function () {
$('.icheck input').iCheck({
checkboxClass: 'icheckbox_flat-blue',
radioClass : 'iradio_flat-blue',
increaseArea : '20%' // optional
})
})
</script>
</body>
</html>
</html>
11 changes: 0 additions & 11 deletions templates/scaffold/auth/register.stub
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,6 @@
<script src="{{asset('plugins/jquery/jquery.min.js')}}"></script>
<!-- Bootstrap 4 -->
<script src="{{asset('plugins/bootstrap/js/bootstrap.bundle.min.js')}}"></script>
<!-- iCheck -->
<script src="{{asset('plugins/iCheck/icheck.min.js')}}"></script>
<script>
$(function () {
$('.icheck input').iCheck({
checkboxClass: 'icheckbox_flat-blue',
radioClass : 'iradio_flat-blue',
increaseArea : '20%' // optional
})
})
</script>
</body>
</html>

Expand Down
13 changes: 5 additions & 8 deletions templates/scaffold/custom_fields/boolean.stub
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<!-- 'Boolean $FIELD_NAME_TITLE$ Field' -->
<div class="form-group row ">
{!! Form::label('$FIELD_NAME$', trans("lang.$MODEL_NAME_SNAKE$_$FIELD_NAME$"),['class' => 'col-3 control-label text-right']) !!}
<div class="checkbox icheck">
<label class="col-9 ml-2 form-check-inline">
{!! Form::hidden('$FIELD_NAME$', 0) !!}
{!! Form::checkbox('$FIELD_NAME$', 1, $FIELD_VALUE$) !!}
</label>
</div>
<div class="form-group align-items-baseline d-flex flex-column flex-md-row">
{!! Form::label('$FIELD_NAME$', trans("lang.$MODEL_NAME_SNAKE$_$FIELD_NAME$"),['class' => 'col-md-3 control-label text-md-right mx-1']) !!} {!! Form::hidden('$FIELD_NAME$', 0, ['id'=>"hidden_$FIELD_NAME$"]) !!}
<div class="col-md-9 icheck-{{setting('theme_color')}}">
{!! Form::checkbox('$FIELD_NAME$', 1, null) !!} <label for="$FIELD_NAME$"></label>
</div>
</div>
15 changes: 6 additions & 9 deletions templates/scaffold/custom_fields/checkbox.stub
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<!-- $FIELD_NAME_TITLE$ Field -->
<div class="form-group row ">
{!! Form::label('$FIELD_NAME$', trans("lang.$MODEL_NAME_SNAKE$_$FIELD_NAME$"),['class' => 'col-3 control-label text-right']) !!}
<div class="checkbox icheck">
<label class="w-100 ml-2 form-check-inline">
{!! Form::hidden('$FIELD_NAME$', false) !!}
{!! Form::checkbox('$FIELD_NAME$', '$CHECKBOX_VALUE$', $FIELD_VALUE$) !!} <span class="ml-2">$CHECKBOX_VALUE$</span>
</label>
</div>
</div>
<div class="form-group align-items-baseline d-flex flex-column flex-md-row">
{!! Form::label('$FIELD_NAME$', trans("lang.$MODEL_NAME_SNAKE$_$FIELD_NAME$"),['class' => 'col-md-3 control-label text-md-right mx-1']) !!} {!! Form::hidden('$FIELD_NAME$', 0, ['id'=>"hidden_$FIELD_NAME$"]) !!}
<div class="col-md-9 icheck-{{setting('theme_color')}}">
{!! Form::checkbox('$FIELD_NAME$', 1, null) !!} <label for="$FIELD_NAME$"></label>
</div>
</div>
6 changes: 3 additions & 3 deletions templates/scaffold/custom_fields/checkbox_group.stub
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- $FIELD_NAME_TITLE$ Field -->
<div class="form-group row ">
{!! Form::label('$FIELD_NAME$', trans("lang.$MODEL_NAME_SNAKE$_$FIELD_NAME$"),['class' => 'col-3 control-label text-right']) !!}
<div class="form-group align-items-baseline d-flex flex-column flex-md-row">
{!! Form::label('$FIELD_NAME$', trans("lang.$MODEL_NAME_SNAKE$_$FIELD_NAME$"),['class' => 'col-md-3 control-label text-md-right mx-1']) !!}
$CHECKBOXES$
</div>
</div>
8 changes: 4 additions & 4 deletions templates/scaffold/custom_fields/date.stub
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!-- $FIELD_NAME_TITLE$ Field -->
<div class="form-group row ">
{!! Form::label('$FIELD_NAME$', trans("lang.$MODEL_NAME_SNAKE$_$FIELD_NAME$"), ['class' => 'col-3 control-label text-right']) !!}
<div class="col-9">
<div class="form-group align-items-baseline d-flex flex-column flex-md-row">
{!! Form::label('$FIELD_NAME$', trans("lang.$MODEL_NAME_SNAKE$_$FIELD_NAME$"), ['class' => 'col-md-3 control-label text-md-right mx-1']) !!}
<div class="col-md-9">
{!! Form::date('$FIELD_NAME$', $FIELD_VALUE$, [$REQUIRED$$DISABLED$'class' => 'form-control','placeholder'=> trans("lang.$MODEL_NAME_SNAKE$_$FIELD_NAME$_placeholder") ]) !!}
<div class="form-text text-muted">
{{ trans("lang.$MODEL_NAME_SNAKE$_$FIELD_NAME$_help") }}
</div>
</div>
</div>
</div>
8 changes: 4 additions & 4 deletions templates/scaffold/custom_fields/email.stub
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!-- $FIELD_NAME_TITLE$ Field -->
<div class="form-group row ">
{!! Form::label('$FIELD_NAME$', trans("lang.$MODEL_NAME_SNAKE$_$FIELD_NAME$"), ['class' => 'col-3 control-label text-right']) !!}
<div class="col-9">
<div class="form-group align-items-baseline d-flex flex-column flex-md-row">
{!! Form::label('$FIELD_NAME$', trans("lang.$MODEL_NAME_SNAKE$_$FIELD_NAME$"), ['class' => 'col-md-3 control-label text-md-right mx-1']) !!}
<div class="col-md-9">
{!! Form::email('$FIELD_NAME$', $FIELD_VALUE$, [$REQUIRED$$DISABLED$'class' => 'form-control','placeholder'=> trans("lang.$MODEL_NAME_SNAKE$_$FIELD_NAME$_placeholder") ]) !!}
<div class="form-text text-muted">
{{ trans("lang.$MODEL_NAME_SNAKE$_$FIELD_NAME$_help") }}
</div>
</div>
</div>
</div>
Loading

0 comments on commit 5273716

Please sign in to comment.