MDL-57447 block_myoverview: add context for courses view
authorRyan Wyllie <ryan@moodle.com>
Thu, 23 Feb 2017 04:42:07 +0000 (04:42 +0000)
committerDamyon Wiese <damyon@moodle.com>
Mon, 3 Apr 2017 03:36:32 +0000 (11:36 +0800)
Part of MDL-55611 epic.

blocks/myoverview/amd/src/paging_bar.js
blocks/myoverview/block_myoverview.php
blocks/myoverview/classes/output/courses_view.php [new file with mode: 0644]
blocks/myoverview/classes/output/main.php [new file with mode: 0644]
blocks/myoverview/classes/output/renderer.php
blocks/myoverview/templates/courses-view.mustache
blocks/myoverview/templates/main.mustache
blocks/myoverview/templates/paging-bar-item.mustache
blocks/myoverview/templates/paging-bar.mustache

index cdb9ad2..5f6e6ef 100644 (file)
@@ -43,7 +43,7 @@ define(['jquery', 'core/custom_interaction_events'],
         root.one(CustomEvents.events.activate, SELECTORS.PAGE_LINK, function(e, data) {
             var page = $(e.target).closest(SELECTORS.PAGE_LINK);
             var activePage = root.find(SELECTORS.ACTIVE_PAGE_LINK);
-            var isSamePage = page.is(activatePage);
+            var isSamePage = page.is(activePage);
 
             if (!isSamePage) {
                 root.find(SELECTORS.PAGE_LINK).removeClass('active');
index 170aae1..f22ce15 100644 (file)
@@ -50,8 +50,7 @@ class block_myoverview extends block_base {
             return $this->content;
         }
 
-        $renderable = new \block_myoverview\output\course_summary();
-
+        $renderable = new \block_myoverview\output\main();
         $renderer = $this->page->get_renderer('block_myoverview');
 
         $this->content = new stdClass();
diff --git a/blocks/myoverview/classes/output/courses_view.php b/blocks/myoverview/classes/output/courses_view.php
new file mode 100644 (file)
index 0000000..74e95b1
--- /dev/null
@@ -0,0 +1,144 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Class containing data for courses view in the myoverview block.
+ *
+ * @package    block_myoverview
+ * @copyright  2017 Ryan Wyllie <ryan@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+namespace block_myoverview\output;
+defined('MOODLE_INTERNAL') || die();
+
+use renderable;
+use renderer_base;
+use templatable;
+/**
+ * Class containing data for courses view in the myoverview block.
+ *
+ * @copyright  2017 Simey Lameze <simey@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class courses_view implements renderable, templatable {
+
+    /**
+     * Export this data so it can be used as the context for a mustache template.
+     *
+     * @param \renderer_base $output
+     * @return stdClass
+     */
+    public function export_for_template(renderer_base $output) {
+        return [
+            'past' => [
+                'pagingbar' => [
+                    'first' => [
+                        'number' => 1,
+                        'page' => '&laquo;',
+                        'url' => '#',
+                    ],
+                    'last' => [
+                        'number' => 3,
+                        'page' => '&raquo;',
+                        'url' => '#',
+                    ],
+                    'pages' => [
+                        [
+                            'number' => 1,
+                            'page' => 1,
+                            'url' => '#',
+                            'active' => true,
+                        ],
+                        [
+                            'number' => 2,
+                            'page' => 2,
+                            'url' => '#',
+                        ],
+                        [
+                            'number' => 3,
+                            'page' => 3,
+                            'url' => '#',
+                        ],
+                    ]
+                ],
+            ],
+            'inprogress' => [
+                'pagingbar' => [
+                    'first' => [
+                        'number' => 1,
+                        'page' => '&laquo;',
+                        'url' => '#',
+                    ],
+                    'last' => [
+                        'number' => 3,
+                        'page' => '&raquo;',
+                        'url' => '#',
+                    ],
+                    'pages' => [
+                        [
+                            'number' => 1,
+                            'page' => 1,
+                            'url' => '#',
+                            'active' => true,
+                        ],
+                        [
+                            'number' => 2,
+                            'page' => 2,
+                            'url' => '#',
+                        ],
+                        [
+                            'number' => 3,
+                            'page' => 3,
+                            'url' => '#',
+                        ],
+                    ]
+                ],
+            ],
+            'future' => [
+                'pagingbar' => [
+                    'first' => [
+                        'number' => 1,
+                        'page' => '&laquo;',
+                        'url' => '#',
+                    ],
+                    'last' => [
+                        'number' => 3,
+                        'page' => '&raquo;',
+                        'url' => '#',
+                    ],
+                    'pages' => [
+                        [
+                            'number' => 1,
+                            'page' => 1,
+                            'url' => '#',
+                            'active' => true,
+                        ],
+                        [
+                            'number' => 2,
+                            'page' => 2,
+                            'url' => '#',
+                        ],
+                        [
+                            'number' => 3,
+                            'page' => 3,
+                            'url' => '#',
+                        ],
+                    ]
+                ],
+            ],
+        ];
+    }
+}
diff --git a/blocks/myoverview/classes/output/main.php b/blocks/myoverview/classes/output/main.php
new file mode 100644 (file)
index 0000000..4bd9405
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Class containing data for my overview block.
+ *
+ * @package    block_myoverview
+ * @copyright  2017 Ryan Wyllie <ryan@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+namespace block_myoverview\output;
+defined('MOODLE_INTERNAL') || die();
+
+use renderable;
+use renderer_base;
+use templatable;
+/**
+ * Class containing data for my overview block.
+ *
+ * @copyright  2017 Simey Lameze <simey@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class main implements renderable, templatable {
+
+    /**
+     * Export this data so it can be used as the context for a mustache template.
+     *
+     * @param \renderer_base $output
+     * @return stdClass
+     */
+    public function export_for_template(renderer_base $output) {
+        $coursesummary = new course_summary();
+        $coursesview = new courses_view();
+
+        return [
+            'courses' => $coursesummary->export_for_template($output),
+            'coursesview' => $coursesview->export_for_template($output),
+        ];
+    }
+}
index 9efcfcd..606dd3b 100644 (file)
@@ -39,10 +39,10 @@ class renderer extends plugin_renderer_base {
     /**
      * Return the main content for the block overview.
      *
-     * @param course_summary $coursesummary Course summary.
+     * @param main $main The main renderable
      * @return string HTML string
      */
-    public function render_course_summary(course_summary $coursesummary) {
-        return $this->render_from_template('block_myoverview/main', ['courses' => $coursesummary->export_for_template($this)]);
+    public function render_main(main $main) {
+        return $this->render_from_template('block_myoverview/main', $main->export_for_template($this));
     }
 }
index 440947a..14044e1 100644 (file)
     </div>
     <div class="tab-content">
         <div class="tab-pane active fade in" id="myoverview_courses_view_in_progress">
-            {{< block_myoverview/courses-view-by-status }}
-                {{$status}}1{{/status}}
-            {{/ block_myoverview/courses-view-by-status }}
+            {{#inprogress}}
+                {{< block_myoverview/courses-view-by-status }}
+                    {{$status}}1{{/status}}
+                {{/ block_myoverview/courses-view-by-status }}
+            {{/inprogress}}
         </div>
         <div class="tab-pane fade" id="myoverview_courses_view_future">
-            {{> block_myoverview/courses-view-future }}
+            {{#future}}
+                {{< block_myoverview/courses-view-by-status }}
+                    {{$status}}2{{/status}}
+                {{/ block_myoverview/courses-view-by-status }}
+            {{/future}}
         </div>
         <div class="tab-pane fade" id="myoverview_courses_view_past">
-            {{> block_myoverview/courses-view-past }}
+            {{#past}}
+                {{< block_myoverview/courses-view-by-status }}
+                    {{$status}}0{{/status}}
+                {{/ block_myoverview/courses-view-by-status }}
+            {{/past}}
         </div>
     </div>
 </div>
index 3732173..f9da733 100644 (file)
@@ -44,7 +44,9 @@
             {{> block_myoverview/timeline-view }}
         </div>
         <div role="tabpanel" class="tab-pane fade" id="myoverview_courses_view">
-            {{> block_myoverview/courses-view }}
+            {{#coursesview}}
+                {{> block_myoverview/courses-view }}
+            {{/coursesview}}
         </div>
     </div>
 </div>
index 45badf5..9b6cdc5 100644 (file)
@@ -29,7 +29,7 @@
        data-page-number="{{number}}"
        data-region="page-link">
         {{$item-content}}
-            {{page}}
+            {{{page}}}
             {{#active}}
                 <span class="sr-only">{{#str}}currentinparentheses, theme_boost{{/str}}</span>
             {{/active}}
index 4d4d8ed..69d1d4d 100644 (file)
@@ -23,6 +23,7 @@
     {
     }
 }}
+{{#pagingbar}}
 <nav aria-label="{{label}}"
      id="{{$id}}paging-bar-{{uniqid}}{{/id}}"
      data-region="paging-bar">
@@ -61,3 +62,4 @@ require(['jquery', 'block_myoverview/paging_bar'], function($, PagingBar) {
     PagingBar.registerEventListeners(root);
 });
 {{/js}}
+{{/pagingbar}}