From c12396f9c23b99591b0c28db486e77747abb5a55 Mon Sep 17 00:00:00 2001 From: PMKuipers Date: Sat, 3 Jun 2023 00:01:18 +0200 Subject: [PATCH] Upgraded site-badges to display properly --- amd/src/report-viewer-components.js | 87 ++++++++++++++++++++++++-- amd/src/studyplan-editor-components.js | 56 +++++++++++++++-- classes/badgeinfo.php | 25 +++++++- classes/studyplanservice.php | 9 ++- css/devstyles.css | 29 +++++---- lang/en/local_treestudyplan.php | 7 ++- lang/nl/local_treestudyplan.php | 7 ++- 7 files changed, 193 insertions(+), 27 deletions(-) diff --git a/amd/src/report-viewer-components.js b/amd/src/report-viewer-components.js index 754fdb5..44fe31b 100644 --- a/amd/src/report-viewer-components.js +++ b/amd/src/report-viewer-components.js @@ -30,7 +30,18 @@ export default { unsubmitted: "unsubmitted", nogrades: "nogrades", unknown: "unknown", + }, + completion: { + completion_completed: "completion_completed", + completion_incomplete: "completion_incomplete", + }, + badge: { + share_badge: "share_badge", + dateissued: "dateissued", + dateexpire: "dateexpire", + badgeinfo: "badgeinfo", } + }); /************************************ @@ -1640,22 +1651,88 @@ export default { }, data() { return { + txt: strings }; }, computed: { completion() { return this.value.badge.issued?"completed":"incomplete"; }, + issued_icon(){ + switch(this.value.badge.issued){ + default: // "nogrades": + return "circle-o"; + case true: + return "check"; + } + }, }, methods: { }, template: ` -
- - - - +
+ + {{value.badge.name}} + + + + + + + + + + + + +

{{value.badge.description}}

+
    +
  • + {{txt.badge.dateissued}}: {{ value.badge.dateissued }}
  • +
  • + {{txt.badge.dateexpired}}: {{ value.badge.dateexpired }}
  • +
  • + {{txt.badge.share_badge}}
  • +
+
+

+ {{ txt.badge.badgeinfo }}

+
+
+
+ `, }); }, diff --git a/amd/src/studyplan-editor-components.js b/amd/src/studyplan-editor-components.js index cba1da7..3b051aa 100644 --- a/amd/src/studyplan-editor-components.js +++ b/amd/src/studyplan-editor-components.js @@ -169,6 +169,16 @@ export default { invalid: { error: 'error', }, + completion: { + completion_completed: "completion_completed", + completion_incomplete: "completion_incomplete", + }, + badge: { + share_badge: "share_badge", + dateissued: "dateissued", + dateexpire: "dateexpire", + badgeinfo: "badgeinfo", + } }); @@ -1934,7 +1944,7 @@ export default { return !(["start",].includes(this.value.type)); }, hasContext() { - return ['start','junction','finish',].includes(this.value.type); + return ['junction','finish'].includes(this.value.type); } }, created(){ @@ -2456,21 +2466,57 @@ export default { props: { value : { type: Object, - default: function(){ return {};}, + default: function(){ return { badge: {}};}, }, }, data() { return { + txt: strings, }; }, methods: { }, template: `
- - + + {{value.badge.name}} + + - + + + + + + + +

{{value.badge.description}}

+
+

+ {{ txt.badge.badgeinfo }}

+
+
+
+
`, }); diff --git a/classes/badgeinfo.php b/classes/badgeinfo.php index c69e9c4..bc2db63 100644 --- a/classes/badgeinfo.php +++ b/classes/badgeinfo.php @@ -43,9 +43,11 @@ class badgeinfo { public static function editor_structure($value=VALUE_REQUIRED){ return new \external_single_structure([ "id" => new \external_value(PARAM_INT, 'id of badge'), + "infolink" => new \external_value(PARAM_TEXT, 'badge issue information link', VALUE_OPTIONAL), "name" => new \external_value(PARAM_TEXT, 'badge name'), "status" => new \external_value(PARAM_TEXT, 'badge status'), "locked" => new \external_value(PARAM_TEXT, 'badge lock status'), + "criteria" => new \external_multiple_structure(new \external_value(PARAM_RAW, 'criteria text'),'badge criteria',VALUE_OPTIONAL), "description"=> new \external_value(PARAM_TEXT, 'badge description'), "imageurl" => new \external_value(PARAM_TEXT, 'url of badge image'), ],"Badge info",$value); @@ -55,11 +57,18 @@ class badgeinfo { { $context = ($this->badge->type == BADGE_TYPE_SITE) ? \context_system::instance() : \context_course::instance($this->badge->courseid); // If the user is viewing another user's badge and doesn't have the right capability return only part of the data. + + $criteria = []; + foreach($this->badge->get_criteria() as $bc){ + $criteria[] = $bc->get_title()." ".$bc->get_details(); + } $model = [ 'id' => $this->badge->id, + 'infolink' => (new \moodle_url('/badges/overview.php', ['id' => $this->badge->id]))->out(false), 'name' => $this->badge->name, 'status' => self::STATUSINFO[$this->badge->status], 'locked' => self::LOCKEDINFO[$this->badge->status], + 'criteria' => $criteria, 'description' => $this->badge->description, 'imageurl' => \moodle_url::make_pluginfile_url($context->id, 'badges', 'badgeimage', $this->badge->id, '/','f1')->out(false), ]; @@ -70,10 +79,14 @@ class badgeinfo { { return new \external_single_structure([ "id" => new \external_value(PARAM_INT, 'id of badge'), + "infolink" => new \external_value(PARAM_TEXT, 'badge issue information link', VALUE_OPTIONAL), "name" => new \external_value(PARAM_TEXT, 'badge name'), + "criteria" => new \external_multiple_structure(new \external_value(PARAM_RAW, 'criteria text'),'badge criteria',VALUE_OPTIONAL), "description"=> new \external_value(PARAM_TEXT, 'badge description'), "imageurl" => new \external_value(PARAM_TEXT, 'url of badge image'), "issued" => new \external_value(PARAM_BOOL, 'badge is issued'), + "dateissued" => new \external_value(PARAM_TEXT, 'date the badge was issued',VALUE_OPTIONAL), + "dateexpire" => new \external_value(PARAM_TEXT, 'date the badge will expire',VALUE_OPTIONAL), "uniquehash" => new \external_value(PARAM_TEXT, 'badge issue hash', VALUE_OPTIONAL), "issuedlink" => new \external_value(PARAM_TEXT, 'badge issue information link', VALUE_OPTIONAL), ],"Badge info",$value); @@ -87,18 +100,28 @@ class badgeinfo { $issued = $this->badge->is_issued($userid); // If the user is viewing another user's badge and doesn't have the right capability return only part of the data. + $criteria = []; + foreach($this->badge->get_criteria() as $bc){ + $criteria[] = $bc->get_title()."".$bc->get_details(); + } $badge = [ 'id' => $this->badge->id, 'name' => $this->badge->name, 'description' => $this->badge->description, 'imageurl' => \moodle_url::make_pluginfile_url($context->id, 'badges', 'badgeimage', $this->badge->id, '/','f1')->out(false), + 'criteria' => $criteria, 'issued' => $issued, + 'infolink' => (new \moodle_url('/badges/overview.php', ['id' => $this->badge->id]))->out(false), ]; if($issued) { $issueinfo = $DB->get_record('badge_issued', array('badgeid' => $this->badge->id, 'userid' => $userid)); + $badge['dateissued'] = userdate($issueinfo->dateissued,"%e %b %G"); + if($issueinfo->expiredate){ + $badge['dateexpire'] = userdate($issueinfo->dateexpire,"%e %b %G"); + } $badge['uniquehash'] = $issueinfo->uniquehash; - $badge['issuedlink'] = new \moodle_url('/badges/badge.php', array('hash' => $issueinfo->uniquehash)); + $badge['issuedlink'] = (new \moodle_url('/badges/badge.php', ['hash' => $issueinfo->uniquehash]))->out(false); } return $badge; diff --git a/classes/studyplanservice.php b/classes/studyplanservice.php index d129652..285e058 100644 --- a/classes/studyplanservice.php +++ b/classes/studyplanservice.php @@ -616,13 +616,18 @@ class studyplanservice extends \external_api public static function list_badges() { - //TODO: Include course badges somehow... Just site badges is not enough $systemcontext = webservicehelper::system_context(); $result = []; $badges = badges_get_badges(BADGE_TYPE_SITE,"timemodified"); foreach ($badges as $badge) { - $result[] = (new badgeinfo($badge))->editor_model(); +// TODO: Add config option to list only active badges +// if($badge->is_active()){ + $result[] = (new badgeinfo($badge))->editor_model(); +// } + +//TODO: Include course badges somehow... Just site badges is not enough + } return $result; diff --git a/css/devstyles.css b/css/devstyles.css index bf71ccc..de103d9 100644 --- a/css/devstyles.css +++ b/css/devstyles.css @@ -382,7 +382,7 @@ ul.t-toolbox li { color: #009900; } -.t-item-badge i { +.t-item-badge svg { color: #ddaa00; } @@ -412,6 +412,14 @@ a.t-item-config { right: -5px; } +a.t-item-config.badge { + top: -5px; + right: -5px; + font-size: 16px; +} + + + a.t-item-course-config { font-size: 16pt; vertical-align: middle; @@ -463,12 +471,6 @@ a.t-item-course-config { transform: translate(-50%, -50%); } -.t-item-badge svg.t-badge-backdrop circle { - stroke: black; - stroke-width: 2px; - fill: #ccc; - -} .l-leaderline-linewrapper { width: 0; @@ -660,13 +662,12 @@ a.t-item-course-config { stroke: black; stroke-width: 2px; fill: #ccc; - } .r-studyplan-line-wrapper { width: 0; height: 0; - position: relative; /* Origin of coordinates for lines, and scrolled content (i.e. not `absolute`) */ + position: relative; /* Origin of coordinates for lines, and scrolled content (i.e. not `abcomsolute`) */ } .r-item-module-children { @@ -773,7 +774,7 @@ table.r-item-course-grade-details td { .t-timing-past, .r-timing-past { - color: darkgreen; + color: var(--purple); } .t-timing-present, .r-timing-present { @@ -802,7 +803,7 @@ table.r-item-course-grade-details td { .t-timing-indicator.timing-past, .r-timing-indicator.timing-past { - background-color: #3a3; + background-color: var(--purple); } .t-timing-indicator.timing-present, @@ -951,4 +952,8 @@ table.r-item-course-grade-details td { } .s-edit-mod-form [data-fieldtype=submit] { display: none ! important; } -.s-edit-mod-form.genericonly form > fieldset:not(#id_general) { display: none ! important; } \ No newline at end of file +.s-edit-mod-form.genericonly form > fieldset:not(#id_general) { display: none ! important; } + +.border-grey { + border-color: #aaa; +} \ No newline at end of file diff --git a/lang/en/local_treestudyplan.php b/lang/en/local_treestudyplan.php index 7977c42..bf1aab9 100644 --- a/lang/en/local_treestudyplan.php +++ b/lang/en/local_treestudyplan.php @@ -243,4 +243,9 @@ $string["myreport_teachermode"] = 'Studyplans I am teaching'; $string["aggregation_overall_all"] = "Complete all of the categories"; $string["aggregation_overall_any"] = "Complete one or more of the categories"; $string["aggregation_all"] = "Complete all"; -$string["aggregation_any"] = "Complete one or more"; \ No newline at end of file +$string["aggregation_any"] = "Complete one or more"; + +$string["share_badge"] = "Share badge"; +$string["dateissued"] = "Issued on"; +$string["dateexpire"] = "Expires on"; +$string["badgeinfo"] = "Badge details"; \ No newline at end of file diff --git a/lang/nl/local_treestudyplan.php b/lang/nl/local_treestudyplan.php index e93a2f3..62ef23e 100644 --- a/lang/nl/local_treestudyplan.php +++ b/lang/nl/local_treestudyplan.php @@ -246,4 +246,9 @@ $string["myreport_teachermode"] = 'Studieplannen waar ik les aan geef'; $string["aggregation_overall_all"] = "Behaal alle categorieë"; $string["aggregation_overall_any"] = "Behaal één of meer categorieën"; $string["aggregation_all"] = "Alles behalen"; -$string["aggregation_any"] = "Eén of meer behalen"; \ No newline at end of file +$string["aggregation_any"] = "Eén of meer behalen"; + +$string["share_badge"] = "Bewijs delen"; +$string["dateissued"] = "Afgegeven op"; +$string["dateexpire"] = "Veloopt op"; +$string["badgeinfo"] = "Meer details"; \ No newline at end of file