• Swedes

    I have a number of custom templates in my plugin and for some reason browsing to them can sometimes cause issues. In Chrome it looks like it works fine, but Firefox seems to have issues.

    It seems to originate from ajaxify.loadTemplate.

    The template has a script attached to it via plugin.json as such: "static/lib/communityAnalytics.js",.

    The script itself is defined as follows define('forum/community/analytics',...

    Clicking on a link that takes you to that template/page works fine in Chrome, but fails in Firefox. Browsing directly to that page works in both browsers.

    Any ideas?

  • Global Moderator Plugin & Theme Dev

    @magnusvhendin are there any errors in the browser console? Have you tried rebuilding and restarting and clearing your cache?

  • Swedes

    @pitaj Yep.

    Unable to load template: community/analytics nodebb.min.js:25493:12
    

    and

    Uncaught Error: Script error for "/assets/templates/community/analytics.js"
    https://requirejs.org/docs/errors.html#scripterror
    

    These actually come up twice in one navigation.

    I have tried rebuild/restart and clear cache.

  • Swedes

    @pitaj I also have this issue in another plugin, but then it was only in the admin panel so I didn't put any effort into fixing it. This is on the forum itself, which is why I would like to sort it out.

  • NodeBB

    Can you share your plugin.json and how you render the template in your plugin? If the plugin is open source a link to the source code would help as well.

  • Swedes

    @baris The plugin is not open source as of yet. It hopefully will be in the future but right now it's not ready.

    This is the plugin.json:

    {
    	"id": "nodebb-plugin-community-analytics",
    	"library": "./library.js",
    	"hooks": [
    		{
    			"hook": "static:app.load", "method": "init"
    		},
    		{
    			"hook": "static:api.routes", "method": "addRoutes"
    		},
    		{
    			"hook": "filter:admin.header.build", "method": "addAdminNavigation"
    		},
    		{
    			"hook": "action:events.log", "method": "writeEventLog"
    		}
    	],
    	"staticDirs": {
    		"static": "./static"
    	},
    	"less": [
    		"static/style.less"
    	],
    	"modules": {
    		"chroma.js": "static/external/chroma.min.js"
    	},
    	"scripts": [
    		"static/lib/communityAnalytics.js",
    		"static/lib/globalAnalytics.js",
    		"static/lib/activityReport.js",
    		"static/lib/chartHelpers.js"
    	],
    	"acpScripts": [
    		"static/lib/admin.js"
    	],
    	"templates": "static/templates",
    	"languages": "languages"
    }
    

    This is in the controllers.js-file.

    Controllers.renderCommunityAnalyticsPage = async (req, res) => {
    	const cid = parseInt(req.params.category_id, 10);
    
    	if (Number.isNaN(cid)) return Helpers.notAllowed(req, res);
    
    	const category = await Categories.getCategoryData(cid);
    
    	const { from, to } = getTimestamps(req.query.from, req.query.to);
    
    	return res.render('community/analytics', {
    		category,
    		filters: {
    			from,
    			to,
    		}
    	});
    };
    

    This is the script (not all obviously) that's not being found and the cause of an error being thrown:

    'use strict';
    
    define('forum/community/analytics', ['api', 'components'], (api, components) => {
        const Analytics = {
            category: ajaxify.data.category,
        };
    
        Analytics.init = () => {
    
        };
    
        return Analytics;
    });
    
    

    There are some functions in there that are not relevant, since the script doesn't even load. I just wanted to show how I defined it.

  • Global Moderator Plugin & Theme Dev

    @magnusvhendin what about your template file? And also where is the template located?

  • Swedes

    @pitaj This is the template:

    <div class="row">
        <div class="col-xs-12 col-md-2 no-print">
            <div class="row">
                <div class="col-xs-12 col-sm-6 col-md-12 form-group">
                    <label for="start">[[admin/advanced/events:filter-start]]</label>
                    <input type="date" component="analytics/input-start" name="start" value="{query.start}"
                        class="form-control" />
                </div>
                <div class="col-xs-12 col-sm-6 col-md-12 form-group">
                    <label for="end">[[admin/advanced/events:filter-end]]</label>
                    <input type="date" id="end" component="analytics/input-end" value="{query.end}"
                        class="form-control" />
                </div>
                <div class="form-group col-xs-12">
                    <button class="btn btn-primary" component="analytics/apply-btn">Apply</button>
                </div>
                <div class="form-group col-xs-12">
                    <button class="btn btn-primary" component="analytics/view-activity-report">Activity report</button>
                </div>
            </div>
        </div>
        <div class="col-xs-12 col-md-10" id="events-chart">
            <canvas></canvas>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12" id="companies-chart">
            <canvas></canvas>
        </div>
    </div>
    

    The two canvases are used to draw diagrams with chart.js included from NodeBB core.

    The template is located in static/templates/community/analytics.tpl

    To me though, the error suggests that it tries to load a js file that it assumes exists (and it does) but then fails and halts everything. It's also seems a bit odd that it works fine on Chrome, but not Firefox.

  • Global Moderator Plugin & Theme Dev

    Can you try Chrome incognito mode and Firefox private browsing?

    Can you check nodebb/build/public/templates/community for analytics.tpl and analytics.js?

Suggested Topics

| |