Mobile support for label plugin

Mobile support for label plugin

by Andreas Grabs -
Number of replies: 6
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Translators

Hi,

I am really inspired by the last developer meeting and the presentation of the mobile dev api by Sam Marshall and Mark Johnson. Thank you very much for sharing that.

Now I am wondering how can I start to do this with a label plugin (like core mod_label) which has no view page but a presentation on the course page.
I'd love to have an example for such type of plugin but I can't find any sad. Maybe someone could give me some directions how to start.

Thank you very much!

Andreas

Average of ratings: Useful (2)
In reply to Andreas Grabs

Re: Mobile support for label plugin

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hi Andreas!

There is no "easy" way to support plugins like mod_label right now, the system was designed to open a new page when the activity is clicked (so the template can be retrieved from the server). I've been wanting to improve this for a while, but I didn't have time to do it yet (I opened an issue so I don't forget: https://tracker.moodle.org/browse/MOBILE-3095).

Mark Johnson had the same problem, but in their case they always use the module inside their custom course format, so they fixed in the template of their course format.

Recently Frédéric Massart contacted me with the same issue. He tried a workaround, returning the contents as the description of the module (because the description is displayed on course page), but that solution has a problem: clicking the module will still open a new page saying the module isn't supported.

So the only way to support this properly is by creating the "handler" manually, using plain JS and the init function. Basically, you'll have to:

- Create the mobile.php file as explained in the guide, specifying an "init" function but without any delegate because you'll register the handler yourself.

- In this "init" function, you'll have to return the JS code that will register the handler.

- This JS code should do something like:

this.CoreCourseModuleDelegate.registerHandler(myHandler)

The myHandler handler should be similar to the label one:

https://github.com/moodlehq/moodlemobile2/blob/master/src/addon/mod/label/providers/module-handler.ts

Cheers,
Dani
Average of ratings: Useful (1)
In reply to Dani Palou

Re: Mobile support for label plugin

by Andreas Grabs -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Translators

Hi Dani,

thank you for your really helpful response! I will definitely go into that.

Best regards and have a nice weekend
Andreas

In reply to Andreas Grabs

Re: Mobile support for label plugin

by Melissa Newman -

Recently I had found this excellent video on using a book instead of Topics/Weeks:


If I understand things correctly, using this method would get around the whole label activity not working on a mobile device.

Hope this helps.

In reply to Melissa Newman

Re: Mobile support for label plugin

by Andreas Grabs -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Translators

Hi Melissa,

thank you for this very interesting video. Unfortunately it shows how to avoid a label but it does not help to develop a label plugin that is compatible with the mobile app.

Have a nice weekend

Andreas

In reply to Andreas Grabs

Re: Mobile support for label plugin

by Melissa Newman -
However you solve this problem, I hope you find a generic solution that will allow any activity to be displayed on the main page instead of having to click on an activity to get it to be shown. I am specifically thinking about the checklist plugin. In my head,I wanted to create a checklist activity and have it shown the main page. So if you can find a solution to that scenario, everything else should fall into place automatically. But that would most likely mean modification to the main moodle code, not something that can be done in a plugin -- unless there is the ability to catch an event -- but those are a pain to code for in the plugin level.

All of the events seems to be post events. "You already created a course". There really should be 3 events. "before event" (preparations); "take over the event" (instead of event); and "post event" (do something after the event is created). But that would mean changes to the moodle code. It is not complicated code. Just look at the course plugin "course/lib.php" under "create_course" and you can see an event being fired. But it is only a post event. It is not an "in place of event".

Although, I have never looked at anything with mobile beyond just making sure that my website is easy to use with a mobile device. So we are probably thinking about two different things.
In reply to Andreas Grabs

Re: Mobile support for label plugin

by Melissa Newman -
At least for specifically the label, I think that I found a solution to your problem. It has to be implemented as a JavaScript plugin. This page should give you the information that you need:

https://docs.moodle.org/dev/Mobile_support_for_plugins#Delegates

The reason why the label activity does not work is that the templates are only downloaded when the activity is selected. Labels don't have any selection. That is why the label plugin does not work. So the solution is that the plugin needs to be tagged, so it is loaded at login.

If you make a javascript solution, you will need "CoreCourseModulePrefetchDelegate".

And that is the only solution, unless you modify things in the core application by using "CoreQuestionDelegate".

In the mobile app, there seems to be a lot of trigger events missing.

But I think that the solution still lies with finding a solution to whole issue of displaying an activity or resource directly on the main page instead of requiring a different dialog box to be opened. Then the triggers in the main code just need to be added to say that a mobile device is being used and not a web device.

But the part of this whole conversation that make no sense is that there should be no real difference between the mobile app and the webapp except

1. The mobile app needs to sync the data with a local database.
2. Activities that make no sense to have in a mobile app, should be turned off / not included.