Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

 

Code Block
languagejava
titleImplementation of all basic abstract methods
collapsetrue
package org.joget.tutorial;
import org.joget.apps.app.service.AppPluginUtil;
import org.joget.apps.app.service.AppUtil;
import org.joget.apps.generator.model.GeneratorPlugin;
import org.joget.apps.generator.model.GeneratorResult;
public class FormSubmissionStatisticsGenerator extends GeneratorPlugin {
    
    private final static String MESSAGE_PATH = "messages/FormSubmissionStatisticsGenerator";
    
    public String getName() {
        return "File Link Datalist Formatter";
    }
 
    public String getVersion() {
        return "5.0.0";
    }
    
    public String getClassName() {
        return getClass().getName();
    }
 
    public String getLabel() {
        //support i18n
        return AppPluginUtil.getMessage("org.joget.tutorial.FormSubmissionStatisticsGenerator.pluginLabel", getClassName(), MESSAGE_PATH);
    }
    
    public String getDescription() {
        //support i18n
        return AppPluginUtil.getMessage("org.joget.tutorial.FormSubmissionStatisticsGenerator.pluginDesc", getClassName(), MESSAGE_PATH);
    }
 
    public String getPropertyOptions() {
        return AppUtil.readPluginResource(getClassName(), "/properties/formSubmissionStatisticsGenerator.json", null, true, MESSAGE_PATH);
    }
    @Override
    public String getExplanation() {
        //support i18n
        return AppPluginUtil.getMessage("generator.formSubmissionStatistics.explanation", getClassName(), MESSAGE_PATH);
    }
    @Override
    public GeneratorResult generate() {
        throw new UnsupportedOperationException("Not supported yet."); 
    }
}

Then, we have to do a UI for admin user to provide inputs for our plugin. In getPropertyOptions method, we already specify our Plugin Properties Options definition file is locate at "/properties/formSubmissionStatisticsGenerator.json". Let us create a directory "resources/properties" under "form_submission_statistics_generator/src/main" directory. After create the directory, create a file named "formSubmissionStatisticsGenerator.json" in the "properties" folder.

In the properties definition options file, we will need to provide options as below. Please note that we can use "@@message.key@@" syntax to support i18n in our properties options.

Code Block
languagejs
 [{
    title : '@@generator.formSubmissionStatistics.config@@',
    properties : [
    {
        name : 'userviewId',
        label : '@@generator.formSubmissionStatistics.userview@@',
        type : 'selectbox',
        value: '[default_userviewId]',
        options_ajax : '[CONTEXT_PATH]/web/json/console/app[APP_PATH]/userview/options'
    },
    {
        name : 'categoryLabel',
        label : '@@generator.formSubmissionStatistics.categoryLabel@@',
        type : 'textfield',
        required : 'true',
        value : '@@generator.formSubmissionStatistics.categoryLabel.value@@'
    },
    {
        name : 'monthlyMenuLabel',
        label : '@@generator.formSubmissionStatistics.monthlyMenuLabel@@',
        type : 'textfield',
        required : 'true',
        value : '@@generator.formSubmissionStatistics.monthlyMenuLabel.value@@'
    },
    {
        name : 'monthlyChartTitle',
        label : '@@generator.formSubmissionStatistics.monthlyChartTitle@@',
        type : 'textfield',
        required : 'true',
        value : '@@generator.formSubmissionStatistics.monthlyChartTitle.value@@'
    },
    {
        name : 'monthlyXAxisLabel',
        label : '@@generator.formSubmissionStatistics.monthlyXAxisLabel@@',
        type : 'textfield',
        required : 'true',
        value : '@@generator.formSubmissionStatistics.monthlyXAxisLabel.value@@'
    },
    {
        name : 'dailyMenuLabel',
        label : '@@generator.formSubmissionStatistics.dailyMenuLabel@@',
        type : 'textfield',
        required : 'true',
        value : '@@generator.formSubmissionStatistics.dailyMenuLabel.value@@'
    },
    {
        name : 'dailyChartTitle',
        label : '@@generator.formSubmissionStatistics.dailyChartTitle@@',
        type : 'textfield',
        required : 'true',
        value : '@@generator.formSubmissionStatistics.dailyChartTitle.value@@'
    },
    {
        name : 'dailyXAxisLabel',
        label : '@@generator.formSubmissionStatistics.dailyXAxisLabel@@',
        type : 'textfield',
        required : 'true',
        value : '@@generator.formSubmissionStatistics.dailyXAxisLabel.value@@'
    },
    {
        name : 'yAxisLabel',
        label : '@@generator.formSubmissionStatistics.yAxisLabel@@',
        type : 'textfield',
        required : 'true',
        value : '@@generator.formSubmissionStatistics.yAxisLabel.value@@'
    }]
}]
 
In the plugin properties option, you may notice we are using "[default_userviewId]" in "userviewId" property. We will use the "[formName]" in some properties as well. So, we will need to modify the getPropertyOptions method to cater for this values.

 

Code Block
languagejava
    public String getPropertyOptions() {
        String options = AppUtil.readPluginResource(getClassName(), "/properties/formSubmissionStatisticsGenerator.json", null, true, MESSAGE_PATH);
        
        //populate value like [formName]
        options = GeneratorUtil.populateFormMeta(options, getFormId(), getAppDefinition());
        
        //populate value of [default_userviewId]
        options = options.replace("[default_userviewId]", GeneratorUtil.getFirstAvailableUserviewId(getAppDefinition()));
        
        return options;
    }
 
Once we done the properties option to collect input, we can work on the main method of the plugin which is format method.