From a6975ceab182de8f6857a8ccda22472a1aa9ac1c Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 5 Nov 2019 09:49:32 +0100 Subject: [PATCH] Improve grid UI + disable actions for students. --- config/services.yaml | 20 ++- main/exercise/exercise.class.php | 17 +- main/exercise/exercise.php | 7 +- .../Resources/views/Resource/grid.html.twig | 141 +-------------- .../views/Resource/grid_theme.html.twig | 161 ++++++++++++++++++ .../Resources/views/grid.html.twig | 135 --------------- 6 files changed, 191 insertions(+), 290 deletions(-) create mode 100644 src/ThemeBundle/Resources/views/Resource/grid_theme.html.twig delete mode 100644 src/ThemeBundle/Resources/views/grid.html.twig diff --git a/config/services.yaml b/config/services.yaml index 8edd89dc86..5d92d02560 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -122,7 +122,6 @@ services: class: Chamilo\LtiBundle\Util\Utils arguments: ['@chamilo.settings.manager'] - apy_grid.factory: class: APY\DataGridBundle\Grid\GridFactory arguments: ['@service_container', '@apy_grid.registry'] @@ -141,9 +140,22 @@ sonata_doctrine_orm_admin: force: false # Audits are set in the admin.yml files with audit:true # Grid default template -#apy_data_grid: -# theme: ChamiloThemeBundle::grid.html.twig -# +apy_data_grid: + theme: '@ChamiloTheme/Resource/grid_theme.html.twig' + limits: [20, 50, 100] +# persistence: false +# no_data_message: "No data" +# no_result_message: "No result" +# actions_columns_size: -1 +# actions_columns_title: "Actions" +# actions_columns_separator: "
" +# pagerfanta: +# enable: false +# view_class: "Pagerfanta\View\DefaultView" +# options: +# prev_message: "«" +# next_message: "»" + # Course settings chamilo_course: diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php index fb78b23c3c..e74f65a2dc 100755 --- a/main/exercise/exercise.class.php +++ b/main/exercise/exercise.class.php @@ -8363,7 +8363,7 @@ class Exercise } } - public static function exerciseGridResource($categoryId, $keyboard) + public static function exerciseGridResource($categoryId, $keyword) { $courseId = api_get_course_int_id(); $sessionId = api_get_session_id(); @@ -8382,7 +8382,6 @@ class Exercise //$category = $repo->find($categoryId); $qb->andWhere($qb->expr()->eq('resource.exerciseCategory', $categoryId)); } else { - $qb->andWhere($qb->expr()->isNull('resource.exerciseCategory')); } @@ -8392,6 +8391,8 @@ class Exercise // 4. Get the grid builder. $builder = Container::$container->get('apy_grid.factory'); + $editAccess = Container::getAuthorizationChecker()->isGranted(ResourceNodeVoter::ROLE_CURRENT_COURSE_TEACHER); + // 5. Set parameters and properties. $grid = $builder->createBuilder( 'grid', @@ -8399,8 +8400,8 @@ class Exercise [ 'persistence' => false, 'route' => 'home', - 'filterable' => true, - 'sortable' => true, + 'filterable' => $editAccess, + 'sortable' => $editAccess, 'max_per_page' => 10, ] )->add( @@ -8416,6 +8417,7 @@ class Exercise 'text', [ 'title' => get_lang('Name'), + 'safe' => false // does not escape html ] ); @@ -8423,13 +8425,13 @@ class Exercise // Url link. $grid->getColumn('title')->manipulateRenderCell( - function ($value, $row, $router) use ($course) { - //?cidReq=TEST123&id_session=0&gidReq=0&gradebook=0&origin=&exerciseId=1 + function ($value, $row, $router) use ($course, $sessionId) { $url = $router->generate( 'legacy_main', [ 'name' => 'exercise/overview.php', 'cidReq' => $course->getCode(), + 'id_session' => $sessionId, 'exerciseId' => $row->getField('id'), ] ); @@ -8438,7 +8440,7 @@ class Exercise ); // 7. Add actions - if (Container::getAuthorizationChecker()->isGranted(ResourceNodeVoter::ROLE_CURRENT_COURSE_TEACHER)) { + if ($editAccess) { // Add row actions $myRowAction = new RowAction( get_lang('Edit'), @@ -8453,7 +8455,6 @@ class Exercise 'name' => 'exercise/admin.php', 'cidReq' => $course->getCode(), 'id_session' => $sessionId, - //'choice' => 'edit', ] ); diff --git a/main/exercise/exercise.php b/main/exercise/exercise.php index d9d876dd33..25c6c37cc9 100644 --- a/main/exercise/exercise.php +++ b/main/exercise/exercise.php @@ -4,8 +4,6 @@ /** * Exercise list: This script shows the list of exercises for administrators and students. * - * @package chamilo.exercise - * * @author Olivier Brouckaert, original author * @author Wolfgang Schneider, code/html cleanup * @author Julio Montoya , lots of cleanup + several improvements @@ -460,7 +458,7 @@ if ($is_allowedToEdit && $origin !== 'learnpath') { } // Create a search-box - $form = new FormValidator('search_simple', 'get', $currentUrl, null, null, FormValidator::LAYOUT_INLINE); + /*$form = new FormValidator('search_simple', 'get', $currentUrl, null, null, FormValidator::LAYOUT_INLINE); $form->addCourseHiddenParams(); if (api_get_configuration_value('allow_exercise_categories')) { @@ -485,7 +483,8 @@ if ($is_allowedToEdit && $origin !== 'learnpath') { ] ); $form->addButtonSearch(get_lang('Search')); - $actionsRight = $form->returnForm(); + $actionsRight = $form->returnForm();*/ + $actionsRight = ''; } if ($is_allowedToEdit) { diff --git a/src/ThemeBundle/Resources/views/Resource/grid.html.twig b/src/ThemeBundle/Resources/views/Resource/grid.html.twig index e3934bc57c..ff2cb217ba 100644 --- a/src/ThemeBundle/Resources/views/Resource/grid.html.twig +++ b/src/ThemeBundle/Resources/views/Resource/grid.html.twig @@ -1,142 +1,5 @@ - - -{% if is_granted('ROLE_CURRENT_COURSE_TEACHER') %} -{# #} -{% endif %} - -{{ grid_search(grid) }} +{#{{ grid_search(grid) }}#} {{ grid(grid) }} - diff --git a/src/ThemeBundle/Resources/views/Resource/grid_theme.html.twig b/src/ThemeBundle/Resources/views/Resource/grid_theme.html.twig new file mode 100644 index 0000000000..87a585d8f4 --- /dev/null +++ b/src/ThemeBundle/Resources/views/Resource/grid_theme.html.twig @@ -0,0 +1,161 @@ +{% extends 'APYDataGridBundle::blocks.html.twig' %} + +{# See block documentation here: #} +{# https://github.com/APY/APYDataGridBundle/blob/master/Resources/doc/template/overriding_internal_blocks.md #} + +{% block grid_actions %} +
+ + {% apply spaceless %} +
+ {{ 'Action'|trans }} + + + +
+ {% endapply %} +
+{% endblock grid_actions %} + +{# Bootstrap changes #} +{% block grid_column_actions_cell %} + {% set actions = column.getActionsToRender(row) %} +
+ {% for action in actions %} + {% if action.attributes.form_delete is defined and action.attributes.form_delete %} +
+
+ + +
+
+ {% else %} + + {{ action.title|trans }} + + {% endif %} + {% endfor %} +
+{% endblock grid_column_actions_cell %} + +{% block grid %} +
+
+
+ {% if grid.totalCount > 0 or grid.isFiltered or grid.noDataMessage is same as(false) %} +
+
+ {% if grid.massActions|length > 0 %} + {{ grid_actions(grid) }} + {% endif %} +
+
+ + {% if grid.isTitleSectionVisible %} + {{ grid_titles(grid) }} + {% endif %} + {% if grid.isFilterSectionVisible %} + {{ grid_filters(grid) }} + {% endif %} + {{ grid_rows(grid) }} +
+
+ + {% if withjs %} + {{ grid_scripts(grid) }} + {% endif %} +
+ {% else %} + {{ grid_no_data(grid) }} + {% endif %} +
+
+
+{% endblock grid %} + +{% block grid_search %} + {% if grid.isFilterSectionVisible %} +
+ {% set searchContent %} + + {% endset %} +
+
{{ 'Filters' | trans }}
+
+ {{ searchContent }} +
+
+
+ {% endif %} +{% endblock grid_search %} + +{% block grid_column_filter_type_input %} + {% set btwOperator = constant('APY\\DataGridBundle\\Grid\\Column\\Column::OPERATOR_BTW') %} + {% set btweOperator = constant('APY\\DataGridBundle\\Grid\\Column\\Column::OPERATOR_BTWE') %} + {% set isNullOperator = constant('APY\\DataGridBundle\\Grid\\Column\\Column::OPERATOR_ISNULL') %} + {% set isNotNullOperator = constant('APY\\DataGridBundle\\Grid\\Column\\Column::OPERATOR_ISNOTNULL') %} + {% set op = column.data.operator is defined ? column.data.operator : column.defaultOperator %} + {% set from = column.data.from is defined ? column.data.from : null %} + {% set to = column.data.to is defined ? column.data.to : null %} +
+ +
+ +
+
+{% endblock grid_column_filter_type_input %} \ No newline at end of file diff --git a/src/ThemeBundle/Resources/views/grid.html.twig b/src/ThemeBundle/Resources/views/grid.html.twig deleted file mode 100644 index 2b345b90be..0000000000 --- a/src/ThemeBundle/Resources/views/grid.html.twig +++ /dev/null @@ -1,135 +0,0 @@ -{% import "@ChamiloTheme/Macros/box.html.twig" as macro %} - - -{% extends 'APYDataGridBundle::blocks.html.twig' %} - -{% block grid_actions %} -
- - {% apply spaceless %} -
- {{ 'Action'|trans }} - - - -
- {% endapply %} -
-{% endblock grid_actions %} - -{# Bootstrap changes #} -{% block grid_column_actions_cell %} - {% set actions = column.getActionsToRender(row) %} -
- {% for action in actions %} - {% if action.attributes.form_delete is defined and action.attributes.form_delete %} -
-
- - -
-
- {% else %} - - {{ action.title|trans }} - - {% endif %} - {% endfor %} -
-{% endblock grid_column_actions_cell %} - -{% block grid %} -
-
-
- {% if grid.totalCount > 0 or grid.isFiltered or grid.noDataMessage is same as(false) %} -
-
- {% if grid.massActions|length > 0 %} - {{ grid_actions(grid) }} - {% endif %} -
-
- - {% if grid.isTitleSectionVisible %} - {{ grid_titles(grid) }} - {% endif %} - {% if grid.isFilterSectionVisible %} - {{ grid_filters(grid) }} - {% endif %} - {{ grid_rows(grid) }} -
-
- - {% if withjs %} - {{ grid_scripts(grid) }} - {% endif %} -
- {% else %} - {{ grid_no_data(grid) }} - {% endif %} -
-
-
-{% endblock grid %} - -{% block grid_search %} - {% if grid.isFilterSectionVisible %} -
- {% set searchContent %} - - {% endset %} - {{ macro.panel('Filters' | trans, searchContent) }} -
- {% endif %} -{% endblock grid_search %}