Skip to content

Commit

Permalink
SV-26 Set up the plugin to work on the mobile app
Browse files Browse the repository at this point in the history
  • Loading branch information
odeialba committed Jan 29, 2024
1 parent a6eab54 commit e4b7c8a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 31 deletions.
6 changes: 5 additions & 1 deletion classes/output/mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace mod_sortvoting\output;
use context_module;

defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/sortvoting/lib.php');
Expand Down Expand Up @@ -89,15 +90,18 @@ public static function mobile_sort_voting_view($args): array {
return $a['position'] <=> $b['position'];
});

$canseeresults = \mod_sortvoting\permission::can_see_results($sortvoting, context_module::instance($cm->id));

// Result of existing votes.
$existingvotes = sortvoting_get_response_data($sortvoting);
$existingvotes = $canseeresults ? sortvoting_get_response_data($sortvoting) : [];
$maxvotescount = empty($existingvotes) ? 0 : (int) max(array_column($existingvotes, 'votescount'));

$data = [
'sortvoting' => $sortvoting,
'allowupdate' => $allowupdate,
'options' => $optionsclean,
'max' => count($options),
'canseeresults' => $canseeresults,
'votes' => $existingvotes,
'maxvotescount' => $maxvotescount,
];
Expand Down
4 changes: 1 addition & 3 deletions mobile/js/mobile_sortvoting.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
this.submitResponses = () => {
// TODO: Check if all elements of the positions array are unique.
// TODO: Add allowupdate option.
let promise;
promise = Promise.resolve();
promise.then(() => {
Expand All @@ -43,7 +41,7 @@ this.submitResponses = () => {

return this.sortVotingProvider.submitResponses(this.module.instance, votes).then(() => {
// Responses have been sent to server or stored to be sent later.
this.CoreDomUtilsProvider.showToast(this.TranslateService.instant('plugin.mod_sortVoting.votesuccess'));
this.CoreDomUtilsProvider.showToast(this.TranslateService.instant('plugin.mod_sortvoting.votesuccess'));

// Check completion since it could be configured to complete once the user submits a vote.
this.CoreCourseProvider.checkModuleCompletion(this.courseId, this.module.completiondata);
Expand Down
63 changes: 37 additions & 26 deletions templates/mobile_sort_voting_view.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{!
@template mod_sortvoting/mobile_sort_voting_view
TODO describe template mobile_sort_voting_view
Template for showing list of options to sort and the results of the votes on the mobile app.
Example context (json):
{
Expand All @@ -29,13 +29,17 @@
<ion-item><%sortvoting.intro%></ion-item>
</ion-card>
<ion-card>
<ion-item><p>{{ 'plugin.mod_sortvoting.instructions' | translate }}</p></ion-item>
<%#allowupdate%>
<ion-item><p>{{ 'plugin.mod_sortvoting.instructions' | translate }}</p></ion-item>
<%/allowupdate%>
<ion-list id="sortvotinglist" class="ml-0 fa-ul">
<%#options%>
<ion-item class="d-flex card p-3 mb-2 optionitem draggable">
<ion-item-content>
<div class="text-wrap">
<input type="number" name="option[]" data-optionid="<% id %>" value="<% position %>" max="<% max %>" min="1" class="d-none" />
<%#allowupdate%>
<input type="number" name="option[]" data-optionid="<% id %>" value="<% position %>" max="<% max %>" min="1" class="d-none" />
<%/allowupdate%>
<% text %>
</div>
</ion-item-content>
Expand All @@ -49,46 +53,53 @@
</ion-button>
<%/allowupdate%>
</ion-card>
TODO: Check if user has permission to view results.
<ion-card>
<table class="table table-bordered">
<thead>
<tr>
<th class="w-25">

<%#canseeresults%>
<ion-card>
<ion-grid class="ion-margin">
<ion-row class="thead">
<ion-col size="3">
<div
data-toggle="tooltip"
data-placement="left"
class="text-info"
title="{{ 'mod_sortvoting.xvotesreceived' | translate:{$a: maxvotescount} }}"
title="{{ 'plugin.mod_sortvoting.xvotesreceived' | translate:{$a: <%maxvotescount%>} }}"
>
{{ 'mod_sortvoting.position' | translate }}
{{ 'plugin.mod_sortvoting.position' | translate }}
</div>
</th>
<th class="w-75">{{ 'mod_sortvoting.option' | translate }}</th>
</tr>
</thead>
<tbody>
</ion-col>
<ion-col class="w-75">{{ 'plugin.mod_sortvoting.option' | translate }}</ion-col>
</ion-row>
<%#votes%>
<tr>
<td>
<ion-row>
<ion-col size="3">
<%#showvotescount%>
<div
data-toggle="tooltip"
data-placement="left"
class="text-info"
title="{{ 'mod_sortvoting.xvotesreceived' | translate:{$a: votescount} }}"
title="{{ 'plugin.mod_sortvoting.xvotesreceived' | translate:{$a: <%votescount%>} }}"
>
<%/showvotescount%>
<%^showvotescount%>
<div>
<%/showvotescount%>
<%position%>
</div>
</td>
<td><%text%></td>
</tr>
</ion-col>
<ion-col><%text%></ion-col>
</ion-row>
<%/votes%>
</tbody>
</table>
</ion-card>
</div>
</ion-grid>
</ion-card>
<%/canseeresults%>
</div>
<style>
ion-col {
border: 0.5px solid #dee2e6;
}
.thead {
font-weight: bold;
background-color: #f8f9fa;
}
</style>
2 changes: 1 addition & 1 deletion templates/sort_voting_results.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{!
@template mod_sortvoting/sort_voting_results
Template for showing list of options to sort.
Template for showing the results of the votes.
Example context (json):
{
Expand Down

0 comments on commit e4b7c8a

Please sign in to comment.