Skip to content

Commit

Permalink
MDL-42629 course: management peer-review alterations
Browse files Browse the repository at this point in the history
* Added confirmation when bulk moving courses.
* Increased min-width of category course count to allow for 3 digits.
* Fixed sub-category => subcategory
* Renamed console JS vars to managementconsole
* Added typeof operator
* Renamed oldcatcourses and newcatcourses as suggested
* Added a span around course count and interacted with that.
* Fixed icon sizing
* Fixed management behat tests
* Fixed wrapping of strings in menus
  • Loading branch information
Sam Hemelryk committed Nov 5, 2013
1 parent c7a2291 commit 38a1520
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 156 deletions.
4 changes: 2 additions & 2 deletions course/ajax/management.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
$a->total = $totalcourses;
$str = get_string('showingxofycourses', 'moodle', $a);
}
$outcome->newcatcourses = $category->get_courses_count();
$outcome->oldcatcourses = $totalcourses;
$outcome->totalcatcourses = $category->get_courses_count();
$outcome->fromcatcoursecount = $totalcourses;
$outcome->paginationtotals = $str;
break;
case 'movecourseafter' :
Expand Down
4 changes: 2 additions & 2 deletions course/classes/management/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public static function get_category_listitem_actions(\coursecat $category) {
$actions['assignroles'] = array(
'url' => new \moodle_url('/admin/roles/assign.php', array('contextid' => $category->get_context()->id,
'return' => 'management')),
'icon' => new \pix_icon('i/assignroles', new \lang_string('assignroles', 'role')),
'icon' => new \pix_icon('t/assignroles', new \lang_string('assignroles', 'role')),
'string' => new \lang_string('assignroles', 'role')
);
}
Expand All @@ -263,7 +263,7 @@ public static function get_category_listitem_actions(\coursecat $category) {
if ($category->can_review_cohorts()) {
$actions['cohorts'] = array(
'url' => new \moodle_url('/cohort/index.php', array('contextid' => $category->get_context()->id)),
'icon' => new \pix_icon('i/cohort', new \lang_string('cohorts', 'cohort')),
'icon' => new \pix_icon('t/cohort', new \lang_string('cohorts', 'cohort')),
'string' => new \lang_string('cohorts', 'cohort')
);
}
Expand Down
6 changes: 5 additions & 1 deletion course/classes/management_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ public function category_listitem(coursecat $category, array $subcategories, $to
}
$countid = 'course-count-'.$category->id;
$html .= html_writer::span(get_string('courses'), 'accesshide', array('id' => $countid));
$html .= html_writer::span($category->coursecount.$courseicon, 'course-count dimmed', array('aria-labelledby' => $countid));
$html .= html_writer::span(
html_writer::span($category->coursecount).$courseicon,
'course-count dimmed',
array('aria-labelledby' => $countid)
);
$html .= html_writer::end_div();
$html .= html_writer::end_div();
if ($isexpanded) {
Expand Down
35 changes: 26 additions & 9 deletions course/management.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
// - bulkmovecategories.
// - bulkresortcategories.
$redirectback = false;
$redirectmessage = false;
switch ($action) {
case 'resortcategories' :
$sort = required_param('resort', PARAM_ALPHA);
Expand Down Expand Up @@ -293,6 +294,12 @@
// If this fails we want to catch the exception and report it.
$redirectback = \core_course\management\helper::action_category_move_courses_into($category, $moveto,
$courseids);
if ($redirectback) {
$a = new stdClass;
$a->category = $moveto->get_formatted_name();
$a->courses = count($courseids);
$redirectmessage = get_string('bulkmovecoursessuccess', 'moodle', $a);
}
} catch (moodle_exception $ex) {
$redirectback = false;
$notificationsfail[] = $ex->getMessage();
Expand Down Expand Up @@ -349,6 +356,12 @@
// They're not sorting anything.
break;
}
if (!in_array($sortcategoriesby, array('idnumber', 'name'))) {
$sortcategoriesby = false;
}
if (!in_array($sortcoursesby, array('idnumber', 'fullname', 'shortname'))) {
$sortcoursesby = false;
}

if ($for === 'thiscategory') {
$categoryids = array(
Expand All @@ -364,22 +377,22 @@
}
$categories = coursecat::get_many($categoryids);
} else if ($for === 'allcategories') {
$categories = coursecat::get_all_visible();
if ($sortcategoriesby) {
\core_course\management\helper::action_category_resort_subcategories(coursecat::get(0), $sortcategoriesby);
}
$categorieslist = coursecat::make_categories_list('moodle/category:manage');
$categoryids = array_keys($categorieslist);
$categories = coursecat::get_many($categoryids);
unset($categorieslist);
} else {
break;
}
if (!in_array($sortcategoriesby, array('idnumber', 'name'))) {
$sortcategoriesby = false;
}
if (!in_array($sortcoursesby, array('idnumber', 'fullname', 'shortname'))) {
$sortcoursesby = false;
}
foreach ($categories as $cat) {
if ($sortcategoriesby) {
// Don't clean up here, we'll do it once we're all done.
\core_course\management\helper::action_category_resort_subcategories($cat, $sortcategoriesby, false);
}
if (in_array($sortcoursesby, array('idnumber', 'fullname', 'shortname'))) {
if ($sortcoursesby) {
\core_course\management\helper::action_category_resort_courses($cat, $sortcoursesby, false);
}
}
Expand All @@ -392,7 +405,11 @@
}
}
if ($redirectback) {
redirect($PAGE->url);
if ($redirectmessage) {
redirect($PAGE->url, $redirectmessage, 5);
} else {
redirect($PAGE->url);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion course/tests/behat/behat_course.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function i_create_a_course_with(TableNode $table) {
new Given('I should see the "'.get_string('categories').'" management page'),
new Given('I click on category "'.get_string('miscellaneous').'" in the management interface'),
new Given('I should see the "'.get_string('categoriesandcoures').'" management page'),
new Given('I click on "'.get_string('newcourse').'" "link" in the "#course-listing" "css_element"'),
new Given('I click on "'.get_string('createnewcourse').'" "link" in the "#course-listing" "css_element"'),
new Given('I fill the moodle form with:', $table),
new Given('I press "' . get_string('savechanges') . '"')
);
Expand Down
6 changes: 2 additions & 4 deletions course/tests/behat/category_management.feature
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ Feature: Test category management actions
And I log in as "admin"
And I go to the courses management page
And I should see the "Course categories" management page
And I click on "Create new" "link" in the ".category-listing-actions" "css_element"
And I click on "Top level category" "link" in the ".category-listing-actions" "css_element"
And I click on "Create new category" "link" in the ".category-listing-actions" "css_element"
# Redirect.
And I should see "Add new category"
And I fill the moodle form with:
Expand All @@ -197,8 +196,7 @@ Feature: Test category management actions
And I should see "Test category 2" in the "#course-listing h3" "css_element"
And I should see category listing "Cat 1" before "Test category 2"
And I should see "No courses in this category"
And I click on "Create new" "link" in the ".category-listing-actions" "css_element"
And I click on "Sub category" "link" in the ".category-listing-actions" "css_element"
And I click on "createnewsubcategory" action for "Test category 2" in management category listing
# Redirect
And I should see "Add new category"
And I fill the moodle form with:
Expand Down
44 changes: 20 additions & 24 deletions course/tests/behat/category_resort.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Test we can resort categories in the management interface.
I need to test we can resort sub categories.
I need to test we can manually sort categories.

Scenario Outline: Test resorting categories.
Scenario Outline: Test bulk sorting all categories.
Given the following "categories" exists:
| category | name | idnumber | sortorder |
| 0 | Social studies | Ext003 | 1 |
Expand All @@ -15,49 +15,45 @@ Feature: Test we can resort categories in the management interface.
And I log in as "admin"
And I go to the courses management page
And I should see the "Course categories" management page
And I should see "Sort categories" in the ".category-listing-actions" "css_element"
And I should see "Sort the top level categories by name" in the ".category-listing-actions" "css_element"
And I should see "Sort the top level categories by idnumber" in the ".category-listing-actions" "css_element"
And I click on <sortby> "link" in the ".category-listing-actions" "css_element"
And I select "All categories" from "menuselectsortby"
And I select <sortby> from "menuresortcategoriesby"
And I press "Go"
# Redirect.
And I should see the "Course categories" management page
And I should see category listing <cat1> before <cat2>
And I should see category listing <cat2> before <cat3>

Examples:
| sortby | cat1 | cat2 | cat3 |
| "Sort categories" | "Social studies" | "Applied sciences" | "Extended social studies" |
| "Sort the top level categories by name" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "Sort the top level categories by idnumber" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "By name" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "By idnumber" | "Extended social studies" | "Social studies" | "Applied sciences" |

@javascript
Scenario Outline: Test resorting categories with JS enabled.
Scenario Outline: Test bulk sorting current category.
Given the following "categories" exists:
| category | name | idnumber | sortorder |
| 0 | Social studies | Ext003 | 1 |
| 0 | Applied sciences | Sci001 | 2 |
| 0 | Extended social studies | Ext002 | 3 |
| 0 | Test category | Tes001 | 1 |
| Tes001 | Social studies | Ext003 | 2 |
| Tes001 | Applied sciences | Sci001 | 3 |
| Tes001 | Extended social studies | Ext002 | 4 |

And I log in as "admin"
And I go to the courses management page
And I should see the "Course categories" management page
And I should see "Sort categories" in the ".category-listing-actions" "css_element"
And I should not see "By name" in the ".category-listing-actions" "css_element"
And I should not see "By idnumber" in the ".category-listing-actions" "css_element"
And I click on "Sort categories" "link"
And I should see "Sort the top level categories by name" in the ".category-listing-actions" "css_element"
And I should see "Sort the top level categories by idnumber" in the ".category-listing-actions" "css_element"
And I click on <sortby> "link" in the ".category-listing-actions" "css_element"
And I click on "Test category" "link"
# Redirect.
And I should see the "Course categories" management page
And I should see the "Course categories and courses" management page
And I select "This category" from "menuselectsortby"
And I select <sortby> from "menuresortcategoriesby"
And I press "Go"
# Redirect.
And I should see the "Course categories and courses" management page
And I should see category listing <cat1> before <cat2>
And I should see category listing <cat2> before <cat3>

Examples:
| sortby | cat1 | cat2 | cat3 |
| "Sort categories" | "Social studies" | "Applied sciences" | "Extended social studies" |
| "Sort the top level categories by name" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "Sort the top level categories by idnumber" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "By name" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "By idnumber" | "Extended social studies" | "Social studies" | "Applied sciences" |

Scenario Outline: Test resorting subcategories.
Given the following "categories" exists:
Expand Down
12 changes: 5 additions & 7 deletions course/tests/behat/course_category_management_listing.feature
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,18 @@ Feature: Course category management interface performs as expected
And I log in as "admin"
And I go to the courses management page
And I should see the "Course categories" management page
And I click on "Sort categories" "link"
And I should see "Sort the top level categories by name" in the ".category-listing-actions" "css_element"
And I should see "Sort the top level categories by idnumber" in the ".category-listing-actions" "css_element"
And I click on <sortby> "link" in the ".category-listing-actions" "css_element"
And I select "All categories" from "menuselectsortby"
And I select <sortby> from "menuresortcategoriesby"
And I press "Go"
# Redirect.
And I should see the "Course categories" management page
And I should see category listing <cat1> before <cat2>
And I should see category listing <cat2> before <cat3>

Examples:
| sortby | cat1 | cat2 | cat3 |
| "Sort categories" | "Social studies" | "Applied sciences" | "Extended social studies" |
| "Sort the top level categories by name" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "Sort the top level categories by idnumber" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "By name" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "By idnumber" | "Extended social studies" | "Social studies" | "Applied sciences" |

@javascript
Scenario Outline: Sub categories are displayed correctly when resorted
Expand Down
Loading

0 comments on commit 38a1520

Please sign in to comment.