Moodle for mobile

JavaScript code can not be customized :(

 
Picture of Alvarez SH
JavaScript code can not be customized :(
 

I'm trying to customize the file build/mm.bundle.js

I'm testing a console.log but it does not work sad


this is the code:


angular.module('mm.core.course')
.factory('$mmCourse', function($mmSite, $translate, $q, $log) {
    $log = $log.getInstance('$mmCourse');
    var self = {},
        mods = ["assign", "assignment", "book", "chat", "choice", "data", "database", "date", "external-tool",
            "feedback", "file", "folder", "forum", "glossary", "ims", "imscp", "label", "lesson", "lti", "page", "quiz",
            "resource", "scorm", "survey", "url", "wiki", "workshop"
        ];
        self.getModule = function(courseid, moduleid, sectionid) {
        if (!moduleid) {
            return $q.reject();
        }
        $log.debug('Getting module ' + moduleid + ' in course ' + courseid + ' and section ' +sectionid);
        var params = {
                courseid: courseid,
                options: [
                    {
                        name: 'cmid',
                        value: moduleid
                    }
                ]
            },
            preSets = {
                cacheKey: getModuleCacheKey(moduleid)
            };
        if (sectionid) {
            params.options.push({
                name: 'sectionid',
                value: sectionid
            });
        }
        return $mmSite.read('core_course_get_contents', params, preSets).then(function(sections) {
            var section,
                module;
            for (var i = 0; i < sections.length; i++) {
                section = sections[i];
                console.log(sections[i]);  //IT IS NOT WORK
                for (var j = 0; j < section.modules.length; j++) {
                    module = section.modules[i];
                    if (module.id === moduleid) {
                        console.log(module.id);    //IT IS NOT WORK
                        return module;
                    }
                }
            }
            return $q.reject();
        });
    };


why JavaScript code can not be customized?


Thanks!

 
Average of ratings: -
Picture of Dani Palou
Re: JavaScript code can not be customized :(
Core developersMoodle HQParticularly helpful MoodlersPlugin developers

Hi Alvarez,

can you please explain me how are you doing this customization? Did you fork the moodlemobile-phonegapbuild repository and build an app using Phonegap Build? Or are you building using Ionic CLI?

Regards,

Dani

 
Average of ratings: -
Picture of Alvarez SH
Re: JavaScript code can not be customized :(
 

Hi Daniel Palou,

Thanks for answering, I developed phonegapbuild and ionic framework, and I never had problems of this type.

I try to do is simple: 

I want to customize the javascript, I tried to modify the following directories:

core/components

build/mm.bundle.js

but without success.

I am testing a simple console.log(), but it does not work anywhere sad

the repository is moodlemobile-phonegapbuild.

 
Average of ratings: -
Picture of Dani Palou
Re: JavaScript code can not be customized :(
Core developersMoodle HQParticularly helpful MoodlersPlugin developers

Hi again,

that's weird, if you modify build/mm.bundle.js it should work since it's the file included in the index.html. If you build using PhonegapBuild, do you use a repository or do you upload a ZIP file? If you use a repository, can you send me the URL of that repo?

Regards,

Dani

 
Average of ratings: -
Picture of Alvarez SH
Re: JavaScript code can not be customized :(
 

Hi, I'm doing tests on localhost and profit not identify that part of the console where shown my console.log.

I'm sending the message repository project.

If you do a test and it works. Please tell me which part of the code you modified exactly.

Thanks!

 
Average of ratings: -
Picture of Dani Palou
Re: JavaScript code can not be customized :(
Core developersMoodle HQParticularly helpful MoodlersPlugin developers

Hello Alvarez,

I checked your code and you're adding the console.log to the wrong function. You added it to the function $mmCourse->getModule and that function is barely used. If you want to see that console.log when listing the sections you need to add it to $mmCourse->getSections function. I suggest you to use the development files and use gulp to build mm.bundle.js, that way code is more readable. This guide can help you:

https://docs.moodle.org/dev/Setting_up_your_development_environment_for_Moodle_Mobile_2

Regards,

Dani

 
Average of ratings: -
Picture of Alvarez SH
Re: JavaScript code can not be customized :(
 

Hi Daniel, apparently it works elsewhere code. But but I want to list the sections consolelog.



I
try what you said:

self.getSection = function(courseid, sectionid, refresh) {
        var deferred = $q.defer();
        if (sectionid < 0) {
            deferred.reject('Invalid section ID');
            return deferred.promise;
        }
        self.getSections(courseid, refresh).then(function(sections) {
            for (var i = 0; i < sections.length; i++) {
                if (sections[i].id == sectionid) {
                    console.log(sections[i]);                                               //Sections List!!
                    deferred.resolve(sections[i])
                    return;
                }
            }
            deferred.reject('Unkown section');
        }, function(error) {
            deferred.reject(error);
        });
        return deferred.promise;
    };

Apparently not work, another idea?

thank you very much for trying to help!!!


 
Average of ratings: -