Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
Template
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Modulus
Services
Template
Commits
c9ffddc9
Commit
c9ffddc9
authored
May 05, 2020
by
Sylvain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mise à jour des templates
parent
3f13fbf2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
165 additions
and
236 deletions
+165
-236
README.md
README.md
+2
-2
src/Compose/Template1Bt4.php
src/Compose/Template1Bt4.php
+3
-2
src/Compose/Template3Bt4.php
src/Compose/Template3Bt4.php
+1
-1
src/Compose/Template4Bt4.php
src/Compose/Template4Bt4.php
+159
-231
No files found.
README.md
View file @
c9ffddc9
# Modulus Service
Field
# Modulus Service
Template
A helper to generate HTML
form field
s in Bootstrap very easily
A helper to generate HTML
back-office list
s in Bootstrap very easily
## Required
-
Composer
...
...
src/Compose/Template1Bt4.php
View file @
c9ffddc9
...
...
@@ -2,8 +2,9 @@
namespace
Goldenscarab\Modulus\Service\Template\Compose
;
use
Illuminate\Support\
Facades\Request
;
use
Illuminate\Support\
Str
;
use
\Illuminate\Support\HtmlString
;
use
Illuminate\Support\Facades\Request
;
class
Template1Bt4
...
...
@@ -64,7 +65,7 @@ class Template1Bt4
$render
=
vsprintf
(
$template
,
[
empty
(
$this
->
table_id
)
?
'table-'
.
str_
slug
(
$this
->
route_prefix
)
:
$this
->
table_id
,
empty
(
$this
->
table_id
)
?
'table-'
.
Str
::
slug
(
$this
->
route_prefix
)
:
$this
->
table_id
,
trim
(
'table table-sm table-hover table-striped '
.
$this
->
table_class
),
$this
->
renderIndent
(
$this
->
renderListHead
(),
3
),
$this
->
renderIndent
(
$this
->
renderListBody
(),
2
),
...
...
src/Compose/Template3Bt4.php
View file @
c9ffddc9
...
...
@@ -54,7 +54,7 @@ class Template3Bt4
$render
=
vsprintf
(
$template
,
[
empty
(
$this
->
table_id
)
?
'table-'
.
str_
slug
(
$this
->
route_prefix
)
:
$this
->
table_id
,
empty
(
$this
->
table_id
)
?
'table-'
.
Str
::
slug
(
$this
->
route_prefix
)
:
$this
->
table_id
,
trim
(
'table table-sm table-hover table-striped '
.
$this
->
table_class
),
$this
->
renderIndent
(
$this
->
renderListHead
(),
3
),
$this
->
renderIndent
(
$this
->
renderListBody
(),
2
),
...
...
src/Compose/Template4Bt4.php
View file @
c9ffddc9
...
...
@@ -2,17 +2,17 @@
namespace
Goldenscarab\Modulus\Service\Template\Compose
;
use
Illuminate\Support\Arr
;
use
Illuminate\Support\Str
;
use
\Illuminate\Support\HtmlString
;
use
Illuminate\Support\Facades\Request
;
use
Goldenscarab\Modulus\Helpers\Dynamik
;
use
Goldenscarab\Modulus\Helpers\Bootstrap4
;
class
Template4Bt4
{
private
$route_prefix
;
private
$route_param
;
private
$table_id
;
private
$table_class
;
...
...
@@ -27,12 +27,157 @@ class Template4Bt4
private
$_columns
;
public
function
__construct
(
$attrs
=
[])
{
$this
->
setAttrs
(
$attrs
);
}
public
function
renderAction
(
$data
,
$source
)
:
string
{
$render
=
''
;
$data
=
$this
->
replaceDefaultsAction
(
$data
);
$data
=
$this
->
removeWithoutPermission
(
$data
);
$dynamik
=
new
Dynamik
(
$source
);
$action_data
=
$dynamik
->
dynamikize
(
$data
);
if
(
Arr
::
has
(
$action_data
,
'dropdown'
))
{
$render
=
Bootstrap4
::
renderAButtonDropDown
(
$action_data
);
}
else
if
(
Arr
::
has
(
$action_data
,
'button'
))
{
$render
=
Bootstrap4
::
renderAButton
(
data_get
(
$action_data
,
'button'
,
[]));
}
return
$render
;
}
/**
* Replacement des tag de valeur par défaut par une action associée
*
* @param array $datas
* @return array
*/
private
function
replaceDefaultsAction
(
array
$datas
)
{
$datas_default
=
[];
$models_action
=
array
(
'[READ]'
=>
[
'label'
=>
'<i class="fa fa-eye mr-2"></i>'
.
__
(
'Consulter'
),
'permission'
=>
$this
->
can_prefix
.
'-read'
,
'href'
=>
[
'url'
=>
[
'route'
=>
$this
->
route_prefix
.
'.read'
,
'args'
=>
[
':id'
,
[
'callback'
=>
[
'function'
=>
'current_query_to_string()'
]]]
]],
],
'[CREATE]'
=>
[
'label'
=>
'<i class="fa fa-plus mr-2"></i>'
.
__
(
'Ajouter'
),
'permission'
=>
$this
->
can_prefix
.
'-create'
,
'href'
=>
[
'url'
=>
[
'route'
=>
$this
->
route_prefix
.
'.create'
,
'args'
=>
[
':id'
,
[
'callback'
=>
[
'function'
=>
'current_query_to_string()'
]]]
]],
],
'[UPDATE]'
=>
[
'label'
=>
'<i class="fa fa-pencil-square-o mr-2"></i>'
.
__
(
'Modifier'
),
'permission'
=>
$this
->
can_prefix
.
'-update'
,
'href'
=>
[
'url'
=>
[
'route'
=>
$this
->
route_prefix
.
'.update'
,
'args'
=>
[
':id'
,
[
'callback'
=>
[
'function'
=>
'current_query_to_string()'
]]]
]],
],
'[DUPLICATE]'
=>
[
'label'
=>
'<i class="fa fa-clone mr-2"></i>'
.
__
(
'Dupliquer'
),
'permission'
=>
$this
->
can_prefix
.
'-create'
,
'href'
=>
[
'url'
=>
[
'route'
=>
$this
->
route_prefix
.
'.duplicate'
,
'args'
=>
[
':id'
,
[
'callback'
=>
[
'function'
=>
'current_query_to_string()'
]]]
]],
],
'[DELETE]'
=>
[
'label'
=>
'<i class="fa fa-trash mr-2"></i>'
.
__
(
'Supprimer'
),
'permission'
=>
$this
->
can_prefix
.
'-delete'
,
'href'
=>
'#'
,
'class'
=>
'confirm text-danger'
,
'data-href'
=>
[
'url'
=>
[
'route'
=>
$this
->
route_prefix
.
'.delete'
,
'args'
=>
[
':id'
,
[
'callback'
=>
[
'function'
=>
'current_query_to_string()'
]]]
]],
],
'[EXPORT]'
=>
[
'label'
=>
'<i class="fa fa-file-excel-o mr-2"></i>'
.
__
(
'Exporter'
),
'permission'
=>
$this
->
can_prefix
.
'-read'
,
'href'
=>
[
'url'
=>
[
'route'
=>
$this
->
route_prefix
.
'.export'
,
'args'
=>
[[
'callback'
=>
[
'function'
=>
'current_query_to_string()'
]]]
]],
],
'[TRUNCATE]'
=>
[
'label'
=>
'<i class="fa fa-times mr-2"></i>'
.
__
(
'Tout supprimer'
),
'permission'
=>
$this
->
can_prefix
.
'-delete'
,
'href'
=>
'#'
,
'class'
=>
'confirm'
,
'data-href'
=>
[
'url'
=>
[
'route'
=>
$this
->
route_prefix
.
'.truncate'
,
'args'
=>
[[
'callback'
=>
[
'function'
=>
'current_query_to_string()'
]]]
]],
],
'[RESET-POSITION]'
=>
[
'label'
=>
'<i class="fa fa-list-ol mr-2"></i>'
.
__
(
'Reset position'
),
'permission'
=>
$this
->
can_prefix
.
'-update'
,
'href'
=>
'#'
,
'class'
=>
'confirm'
,
'data-href'
=>
[
'url'
=>
[
'route'
=>
$this
->
route_prefix
.
'.reset-position'
,
'args'
=>
[[
'callback'
=>
[
'function'
=>
'current_query_to_string()'
]]]
]],
],
'[SEPARATOR]'
=>
'<div class="dropdown-divider"></div>'
);
// Recherche des tags de modèles à remplacer
foreach
(
$datas
as
$key
=>
$data
)
{
if
(
is_array
(
$data
))
{
$datas_default
[
$key
]
=
$this
->
replaceDefaultsAction
(
$data
);
}
else
{
$datas_default
[
$key
]
=
data_get
(
$models_action
,
$data
,
$data
);
}
}
return
$datas_default
;
}
/**
* Retire les élements d'un tableau lorsqu'une permission est spécifié et que l'utilisateur ne dispose pas des droits
*
* @param array $datas
* @return array
*/
private
function
removeWithoutPermission
(
array
$datas
)
{
$datas_permission
=
[];
foreach
(
$datas
as
$key
=>
$data
)
{
if
(
$key
===
'permission'
&&
!
auth
()
->
user
()
->
can
(
$data
))
{
return
null
;
}
if
(
is_array
(
$data
))
{
$datas_permission
[
$key
]
=
$this
->
removeWithoutPermission
(
$data
);
}
else
{
$datas_permission
[
$key
]
=
$data
;
}
}
// Filtre des éléments vides
$datas_permission
=
array_filter
(
$datas_permission
,
function
(
$item
)
{
return
!
is_null
(
$item
)
&&
$item
!==
''
;
});
return
$datas_permission
;
}
/**
* Retourne le rendu d'un tableau liste
* @return string le rendu du tableau liste
...
...
@@ -54,7 +199,7 @@ class Template4Bt4
$render
=
vsprintf
(
$template
,
[
empty
(
$this
->
table_id
)
?
'table-'
.
str_
slug
(
$this
->
route_prefix
)
:
$this
->
table_id
,
empty
(
$this
->
table_id
)
?
'table-'
.
Str
::
slug
(
$this
->
route_prefix
)
:
$this
->
table_id
,
trim
(
'table table-sm table-hover table-striped '
.
$this
->
table_class
),
$this
->
renderIndent
(
$this
->
renderListHead
(),
3
),
$this
->
renderIndent
(
$this
->
renderListBody
(),
2
),
...
...
@@ -83,6 +228,11 @@ class Template4Bt4
$sortable
=
data_get
(
$column
,
'sortable'
);
$class
=
data_get
(
$column
,
'class'
);
// Pas de classe dynamique pour le header
if
(
is_array
(
$class
))
{
$class
=
''
;
}
$render
.=
vsprintf
(
$template
,
[
is_null
(
$class
)
?
''
:
' '
.
$class
,
data_get
(
$column
,
'label'
),
...
...
@@ -117,7 +267,7 @@ class Template4Bt4
if
(
count
(
$collection
)
==
0
)
{
$render_cels_row
=
vsprintf
(
$template_cel
,
[
' colspan="'
.
(
count
(
$columns
)
+
1
)
.
'"'
,
'Aucun élément disponible'
__
(
'Aucun élément disponible'
)
]);
$render
.=
vsprintf
(
$template_row
,
[
...
...
@@ -144,8 +294,8 @@ class Template4Bt4
// Ajout du menu en fin de ligne
$render_cels_row
.=
vsprintf
(
$template_cel
,
[
null
,
data_get
(
$this
->
_menu
,
'display'
)
?
$this
->
renderListMenuItems
(
$item
)
:
''
' class="text-right"'
,
$this
->
renderAction
(
$this
->
_menu
,
$item
)
]);
}
...
...
@@ -160,219 +310,6 @@ class Template4Bt4
return
$render
;
}
/**
* Retourne le rendu du menu item
* @param Object $source Source des données
* @return string Le rendu
*/
private
function
renderListMenuItems
(
$source
)
:
string
{
$template
=
'<div class="dropdown">'
.
PHP_EOL
;
$template
.=
' <button class="btn btn-default btn-xs dropdown-toggle no-caret square-to-circle item-option" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
.
PHP_EOL
;
$template
.=
' <i class="fa fa-cog" aria-hidden="true"></i>'
.
PHP_EOL
;
$template
.=
' </button>'
.
PHP_EOL
;
$template
.=
' <div class="dropdown-menu dropdown-menu-right">'
.
PHP_EOL
;
$template
.=
'%s'
;
$template
.=
'%s'
;
$template
.=
'%s'
;
$template
.=
'%s'
;
$template
.=
'%s'
;
$template
.=
'%s'
;
$template
.=
' </div>'
.
PHP_EOL
;
$render
=
''
;
$render
=
vsprintf
(
$template
,
[
$this
->
renderIndent
(
$this
->
renderListMenuItemRead
(
$source
),
2
),
$this
->
renderIndent
(
$this
->
renderListMenuItemUpdate
(
$source
),
2
),
$this
->
renderIndent
(
$this
->
renderListMenuItemTag
(
$source
),
2
),
$this
->
renderIndent
(
$this
->
renderListMenuItemMore
(
$source
),
2
),
$this
->
renderIndent
(
$this
->
renderListMenuItemDuplicate
(
$source
),
2
),
$this
->
renderIndent
(
$this
->
renderListMenuItemDelete
(
$source
),
2
),
]);
return
$render
;
}
/**
* Retourne l'element voir du menu item
* @param Object $source Source des données
* @return string Le rendu
*/
private
function
renderListMenuItemRead
(
$source
)
:
string
{
$render
=
''
;
if
(
auth
()
->
user
()
->
can
(
$this
->
can_prefix
.
'-read'
))
{
if
(
data_get
(
$this
->
_menu
,
'is_readable'
))
{
$template
=
'<a class="dropdown-item" href="%s">'
.
PHP_EOL
;
$template
.=
' <i class="fa fa-eye mr-1"></i>Voir'
.
PHP_EOL
;
$template
.=
'</a>'
.
PHP_EOL
;
if
(
empty
(
$this
->
route_param
))
{
$render
=
sprintf
(
$template
,
route
(
$this
->
route_prefix
.
'.'
.
'read'
,
array_merge
([
$source
->
id
],
Request
::
query
())));
}
else
{
$render
=
sprintf
(
$template
,
route
(
$this
->
route_prefix
.
'.'
.
'read'
,
array_merge
([
$this
->
route_param
,
$source
->
id
],
Request
::
query
())));
}
}
}
return
$render
;
}
/**
* Retourne l'element modifier du menu item
* @param Object $source Source des données
* @return string Le rendu
*/
private
function
renderListMenuItemUpdate
(
$source
)
:
string
{
$render
=
''
;
if
(
auth
()
->
user
()
->
can
(
$this
->
can_prefix
.
'-update'
))
{
if
(
data_get
(
$this
->
_menu
,
'is_editable'
))
{
$template
=
'<a class="dropdown-item" href="%s">'
.
PHP_EOL
;
$template
.=
' <i class="fa fa-pencil-square-o mr-1"></i>Modifier'
.
PHP_EOL
;
$template
.=
'</a>'
.
PHP_EOL
;
if
(
empty
(
$this
->
route_param
))
{
$render
=
sprintf
(
$template
,
route
(
$this
->
route_prefix
.
'.'
.
'update'
,
array_merge
([
$source
->
id
],
Request
::
query
())));
}
else
{
$render
=
sprintf
(
$template
,
route
(
$this
->
route_prefix
.
'.'
.
'update'
,
array_merge
([
$this
->
route_param
,
$source
->
id
],
Request
::
query
())));
}
}
}
return
$render
;
}
/**
* Retourne l'element tag du menu item
* @param Object $source Source des données
* @return string Le rendu
*/
private
function
renderListMenuItemTag
(
$source
)
:
string
{
$render
=
''
;
if
(
auth
()
->
user
()
->
hasRole
(
'admin'
))
{
$tags
=
data_get
(
$this
->
_menu
,
'tags'
,
[]);
if
(
count
(
$tags
)
>
0
)
{
$template
=
'<a class="dropdown-item clipboard-copy" href="#" title="Copier le Tag" data-clipboard-action="copy" data-clipboard-text="%s">'
.
PHP_EOL
;
$template
.=
' <i class="fa fa-clipboard mr-1"></i>%s'
.
PHP_EOL
;
$template
.=
'</a>'
.
PHP_EOL
;
foreach
(
$tags
as
$tag
)
{
$tag_value
=
$this
->
getValue
(
$tag
,
$source
);
$render
.=
vsprintf
(
$template
,
[
$tag_value
,
$tag_value
]);
}
}
}
return
$render
;
}
/**
* Retourne les éléments supplémentaires du menu item
* @param Object $source Source des données
* @return string Le rendu
*/
private
function
renderListMenuItemMore
(
$source
)
:
string
{
$render
=
''
;
if
(
auth
()
->
user
()
->
can
(
$this
->
can_prefix
.
'-read'
))
{
$menu_more
=
data_get
(
$this
->
_menu
,
'more'
,
[]);
if
(
count
(
$menu_more
)
>
0
)
{
$template
=
'<a class="dropdown-item%s"%s>'
.
PHP_EOL
;
$template
.=
' %s'
.
PHP_EOL
;
$template
.=
'</a>'
.
PHP_EOL
;
foreach
(
$menu_more
as
$menu_item
)
{
$href
=
data_get
(
$menu_item
,
'href'
);
$name
=
data_get
(
$menu_item
,
'name'
);
$class
=
data_get
(
$menu_item
,
'class'
);
$attrs
=
collect
(
$menu_item
)
->
except
([
'label'
,
'name'
,
'class'
]);
// Rendu de l'élément
$render
.=
vsprintf
(
$template
,
[
empty
(
$class
)
?
''
:
' '
.
$class
,
$this
->
renderAttributes
(
$attrs
,
$source
),
$menu_item
[
'label'
]
]);
}
}
}
return
$render
;
}
/**
* Retourne l'element dupliqué du menu item
* @param Object $source Source des données
* @return string Le rendu
*/
private
function
renderListMenuItemDuplicate
(
$source
)
:
string
{
$render
=
''
;
if
(
auth
()
->
user
()
->
can
(
$this
->
can_prefix
.
'-create'
))
{
if
(
data_get
(
$this
->
_menu
,
'is_duplicable'
))
{
$template
=
'<a class="dropdown-item" href="%s">'
.
PHP_EOL
;
$template
.=
' <i class="fa fa-clone mr-1"></i>Dupliquer'
.
PHP_EOL
;
$template
.=
'</a>'
.
PHP_EOL
;
if
(
empty
(
$this
->
route_param
))
{
$render
=
sprintf
(
$template
,
route
(
$this
->
route_prefix
.
'.'
.
'duplicate'
,
array_merge
([
$source
->
id
],
Request
::
query
())));
}
else
{
$render
=
sprintf
(
$template
,
route
(
$this
->
route_prefix
.
'.'
.
'duplicate'
,
array_merge
([
$this
->
route_param
,
$source
->
id
],
Request
::
query
())));
}
}
}
return
$render
;
}
/**
* Retourne l'element supprimer du menu item
* @param Object $source Source des données
* @return string Le rendu
*/
private
function
renderListMenuItemDelete
(
$source
)
:
string
{
$render
=
''
;
if
(
auth
()
->
user
()
->
can
(
$this
->
can_prefix
.
'-delete'
))
{
if
(
data_get
(
$this
->
_menu
,
'is_deletable'
))
{
$template
=
'<div class="dropdown-divider"></div>'
.
PHP_EOL
;
$template
.=
'<a class="dropdown-item delete" href="#" data-href="%s">'
.
PHP_EOL
;
$template
.=
' <i class="fa fa-trash mr-1"></i>Supprimer'
.
PHP_EOL
;
$template
.=
'</a>'
.
PHP_EOL
;
if
(
empty
(
$this
->
route_param
))
{
$render
=
sprintf
(
$template
,
route
(
$this
->
route_prefix
.
'.'
.
'delete'
,
array_merge
([
$source
->
id
],
Request
::
query
())));
}
else
{
$render
=
sprintf
(
$template
,
route
(
$this
->
route_prefix
.
'.'
.
'delete'
,
array_merge
([
$this
->
route_param
,
$source
->
id
],
Request
::
query
())));
}
}
}
return
$render
;
}
/**
* Retourne le rendu d'attributs avec leur valeur
* @param array $attrs Les attributs avec la colonne de l'object conteant la valeur
...
...
@@ -386,15 +323,8 @@ class Template4Bt4
if
(
is_iterable
(
$attrs
))
{
$template
=
' %s="%s"'
;
foreach
(
$attrs
as
$name
=>
$data
)
{
if
(
is_null
(
$source
)
||
!
is_array
(
$data
))
{
$value
=
$data
;
}
else
if
(
is_array
(
$data
))
{
$value
=
$this
->
getValue
(
$data
,
$source
);
}
$value
=
$this
->
getValue
(
$data
,
$source
);
$render
.=
vsprintf
(
$template
,
[
$name
,
$value
]);
}
}
...
...
@@ -453,8 +383,6 @@ class Template4Bt4
return
$render
;
}
/**
* Mise à jour des attributs depuis le tableau passé en paramètre
* @param Array $attrs Liste des attributs à traiter
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment