[nodebb-plugin-ns-custom-fields] NS Custom Fields


  • Plugin & Theme Dev

    Provides full set of instruments to create custom fields in user's profiles: admin control panel (manage available fields), user account (edit and view fields);

    Install

    npm install nodebb-plugin-ns-custom-fields
    

    ACP

    Preview of Admin Control Panel for Custom Fields Plugin, ver. 1.0

    Screen Shot 2015-04-23 at 11.01.24 PM.png

    Theme Status

    Currently zero themes support this plugin. With template engine of NodeBB, some changes should be made manually to the theme, if you want to see custom fields in the user's profile.

    It will look like:

    Screen-Shot-2015-04-23-at-10.55.07-PM.png



  • When I try to access user profile page I got error:

    24/4 08:46 [27022] - error: TypeError: Cannot read property 'proglangs' of null at /home/apps/nodebb/node_modules/nodebb-plugin-ns-custom-fields/app/filters.js:28:40

    proglangs is the first key in custom fields. I use NodeBB 0.7



  • result.data is empty, thats why it has error, to fix this you have to add check in:
    /nodebb-plugin-ns-custom-fields/app/filters.js from line 24:

                if (result.data) { 
                var i = 0, len = result.fields.length, fieldMeta, customFields = [];
                for (i; i < len; ++i) {
                    fieldMeta = result.fields[i];
                    var value = result.data[fieldMeta.key];
                    if (value) {
                        customFields.push({
                            name : fieldMeta.name,
                            value: value
                        });
                    }
                }
                params.userData.customFields = customFields;
                }            
                callback(null, params);
    

    @Nicolas can you show template changes for account/edit.tpl file. I found it in nodebb-plugin-ns-custom-fields/templates/account/edit.tpl


  • Community Rep

    Looks cool.

    @Sergey Same issue for me, 0.7


  • Plugin & Theme Dev

    @Sergey thanks for report and participating in testing of the plugin on It's earlier stages 😉 I will fix it today. I think I know that is the problem.


  • Community Rep

    @Nicolas Consider changing

    customFields = [];
    

    to

    customFields = params.userData.customFields || [];
    

    So that you don't overwrite customFields added by other plugins.



  • Last error I found in : nodebb-plugin-ns-custom-fields/public/js/fields-edit.js

    line 61:
    - .val(content[fieldEntity.key]);
    + .val(content && content[fieldEntity.key]);

    Now it works as expected. Thanks @Nicolas ! 👍



  • @yariplus said:

    customFields = params.userData.customFields || [];

    good catch. Thanks!



  • Small suggestion, check if Custom Field value is url and replace it with link.

    filters.js:

    4: var urlRegex = /(((https?:\/\/)|(www\.))[^\s]+)/i;
    ..
    ..
    26:  if (result.data) { 
                var i = 0, len = result.fields.length, fieldMeta, customFields = params.userData.customFields || [];
                for (i; i < len; ++i) {
                    fieldMeta = result.fields[i];
                    var value = result.data[fieldMeta.key];
                    if (value) {
                        customFields.push({
                            name : fieldMeta.name,
                            value: value.match(urlRegex)? urlify(value) : value
                        });
                    }
                }
                params.userData.customFields = customFields;
    39:   }            
    
    ..
    ..
    53:     function urlify(text) {
            return text.replace(urlRegex, function(url,b,c) {
                var url2 = (c == 'www.') ?  'http://' +url : url;
                return '<a href="' +url2+ '" target="_blank">' + url + '</a>';
            }) 
    58:  }

  • Plugin & Theme Dev

    @Sergey
    For such task, will be dedicated formatters.
    8-th list item in TODO list 😉



  • Can you also add those custom fields in post data, so we can display them somewhere under user's avatar or something like that.


  • Plugin & Theme Dev

    Critical fixes are made, also plugin is published to Node Package Manager.
    First post is updated, same as documentation on GitHub.


  • Plugin & Theme Dev

    @Sergey sure, but it will be optional (You should toggle it in ACP)


  • Admin

    Nice 🙂 I'm sure there is a way we can add something to core without having you required to edit the theme manually. What if it was a widget area in the profile page? I'd accept that PR if you were willing to change how this works



  • If this works and I'll try it tommorow you sir are my hero. I was looking forward this feature since the begining and didn't had the time to jump in.


  • Plugin & Theme Dev

    New version 1.1.0 has been released.
    Now you have ability to populate Topic View with custom fields. Also this feature is optional, so Settings was introduced also.

    @psychobunny I'm not familiar with widgets in NodeBB. Can you collaborate and give me some example? (link on repo, benefits, etc.)


  • Plugin & Theme Dev

    @psychobunny Also I'm going to create another plugin, and I need this space in user's profile. Do you have any suggestions how I can reach it without manual editing also? 😉

    Screen-Shot-space-for-future-plugin.jpg


  • Plugin & Theme Dev

    For example, render numeric values under avatar as metrics or accountStats

    						<div class="text-center account-stats">
    
    							<div class="inline-block text-center">
    								<span class="human-readable-number" title="{reputation}">{reputation}</span>
    								<span class="account-bio-label">[[global:reputation]]</span>
    							</div>
    
    							<div class="inline-block text-center">
    								<span class="human-readable-number" title="{postcount}">{postcount}</span>
    								<span class="account-bio-label">[[global:posts]]</span>
    							</div>
    
    							<div class="inline-block text-center">
    								<span class="human-readable-number" title="{profileviews}">{profileviews}</span>
    								<span class="account-bio-label">[[user:profile_views]]</span>
    							</div>
    						</div>
    

    Change on:

    				<!-- BEGIN metrics -->
    							<div class="inline-block text-center">
    								<span class="human-readable-number" title="{metrics.value}">{metrics.value}</span>
    								<span class="account-bio-label">{metrics.label}</span>
    							</div>
    				<!-- END metrics -->
    


  • NodeBB 0.7, new version error on startup:

    25/4 07:34 [27825] - error: Error: Cannot find module 'object-assign'
    

    Sorry, npm install should fix that problem.


  • Community Rep

    @Nicolas said:

    @psychobunny Also I'm going to create another plugin, and I need this space in user's profile. Do you have any suggestions how I can reach it without manual editing also? 😉

    Looks like it's the same problem, that part is tied to the theme, so it would need a widget area or a filter from core.

    I can probably help with the widget areas if needed.


Log in to reply
 


Star

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.