Moodle mobile addon help

Moodle mobile addon help

by r q -
Number of replies: 4
Hello,

I'm trying to add a simple addon to the mobile app (specifically, the moodlemobile2 project). I'm having trouble getting the addon registered, although I can see that it is being loaned into the minified JS asset and I have followed the docs as best as I am able to.

To give you an overview of what I'm trying to do, I'm adding a course content handler module for the mod_zoom feature in the Moodle PHP app. As an example, the "URL" addon under www/addons/mod/url works quite similarly to the one I am trying to add. This component handles displaying URLs under course content.

A few specific questions:

  1. How can I tell what key/ID the app is requesting when it load the Angular module? There is nothing in the logs to indicate what I should name my new module so that the Moodle system can pick it up. If a handler is not found it simply redirects to "mm_course-modcontent" and displays an error message, and nothing is logged.
  2. How do I force my new Angular module to be loaded? I noticed that there is a big static list of modules under the course factory in www/core/components/course/services/course.js.  Do I need to add my module there?

Other details:

Thanks in advance. I know this project is being reworked but I'm hoping to get this working in the meantime.

Average of ratings: -
In reply to r q

Re: Moodle mobile addon help

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers

Hello,

Unfortunately our core team do not have the resources here to help people use the open source code version (this include maintain all the development documentation update). We provide a service where we can customise the app for anyone who needs it including the Push notifications (Airnotifier) service management. This service helps fund the improvement of the app in general: https://moodle.com/mobileapp/

You should use $mmCourseDelegate to register your addon. If you already do, you should try to debug it to check why is it failing. Make sure you run gulp to "compile" your changes. 

Cheers,

Dani

In reply to Dani Palou

Re: Moodle mobile addon help

by r q -
Hey Dani,

Thanks for your reply. I surmised from the code and another thread i found that the content handler must be registered with the course delegate module. I have been looking into this and as far as I can tell, the structure of my plugin is correct, but something is missing in wiring up the components. Maybe something here will look familiar or another forum member will know the anwer.

In my main.js file, I register the content handler like so (I am basically just copying what the url module is doing to get a simple working example):

.config(function($mmCourseDelegateProvider, $mmContentLinksDelegateProvider) {
$mmCourseDelegateProvider.registerContentHandler('mmaModZoom', 'zoom', '$mmaModZoomHandlers.courseContent');

// Register content links handler.
$mmContentLinksDelegateProvider.registerLinkHandler('mmaModZoom', '$mmaModZoomHandlers.linksHandler');

});

So that should make the plugin system look for a '$mmaModZoomHandlers' content handler factory, right? Using that, it should then call `getController` to find the controller file in controllers/index.js, which I've named 'mmaModZoomIndexCtrl' following the naming convention (where is this name actually determined?). The controller then gets the main module '$mmaModZoom' injected as an argument, which we can then call into and return data from the web service endpoint. Makes sense to me so far.

However, when `getContentHandlerControllerFor` gets called, I noticed that the module is *not* in the registered set of `enabledHandlers`. The app still thinks that the module is disabled. When the "modcontent.html" template gets rendered to show the user a message about a non-supported plugin, the following permissions flags are set:

isDisabledOnSite = false
isSupportedByTheApp = true
isContributedPlugin = false

My main module '$mmaModZoom' has the following methods stubbed out to true just to force it to be enabled:

self.isGetUrlWSAvailable = function() {
return true;
// return $mmSite.wsAvailable(ZOOM_GET_STATE);
};

self.isPluginEnabled = function(siteId) {
return true;
// return $mmSitesManager.getSite(siteId).then(function(site) {
// // All WS were introduced at the same time so checking one is enough.
// return site.wsAvailable(ZOOM_GET_STATE);
// });
};

Still no dice. The plugin is considered disabled for some reason, and my content handler gets removed from the list of "enabledHandlers" by the time the view is rendered.

Does any of this ring a bell? I really just want to stub out all this permissions code for now so I can get a very simple empty module to appear on the screen.

Thanks
In reply to r q

Re: Moodle mobile addon help

by r q -
Hello,

Just to update and document my solution, I did get this working. I ran into several stumbling blocks with the content handlers. My issue turned out to be that the static string used to attach the binding to the module's method did not align with the method name. This is a tight coupling, so just be aware of this if you're having issues getting a new addon to work. If you're using a fancy editor like WebStorm, it won't be able to parse the static string bindings.

For what it's worth, I think it would be a lot nicer if the system logged out something useful to let you know *why* the bindings are failing. Or even let you know that the content handler wasn't found. Some kind of informative error message or stack trace. It's very hard as a developer to figure out why the component isn't being found. Is there somewhere in moodle mobile's core where we could catch the exception and log it out at debug level?

Anyway, thanks for the help and hints, I was able to get my code working. Hope somebody finds this thread useful!
In reply to r q

Re: Moodle mobile addon help

by nikolas stylianides -

Hi r q . 

I am straggling with the same problem. Can you please elaborate on the solution? 

Thank you in advance.