.. ******************************************************************************* * MetaFactory.io R2 * Technical Documentation * * File name : H2UserPreferences.rst * Created by : Ralph Oudejans * Last update : 02-03-2021 * Updated by : Niels de Nies * * MetaFactory BV Amsterdam ******************************************************************************* User Preferences ================ .. rubric:: Steps to implement the feature In order to implement this feature take the following steps: #. Add the object with name UserPreferences to model.xml by copying the content of :ref:`user-preferences-object.xml `. into model.xml. .. code-block:: xml :caption: model.xml :name: model.xml5 :linenos: :emphasize-lines: 7-9 .. note:: If you are reading this documentation on paper you can find the file in the next section :ref:`Files `. #. Add the highlighted code to the package metadata in model.xml: .. code-block:: xml :caption: model.xml :name: model.xml12 :linenos: :emphasize-lines: 5-9 Owner USER owner ... #. Add the highlighted line to pattern.xml: .. code-block:: xml :caption: pattern.xml :name: pattern.xml1 :linenos: :emphasize-lines: 3 #. Generate the Runtime Model with the Runtime Model buildset. #. Generate all #. Have Liquibase create the UserPreferences table upon startup of the application: | | Copy the two changeSets in the generated changeset-create-table-user_preferences.xml to the end of | [*project*]\\[*backend*]\\src\\main\\resources\\config\\liquibase\\liquibase-alters-changeLog.xml | for the creation of the UserPreferences table. | .. code-block:: xml :caption: liquibase-alters-changeLog.xml :name: liquibase-alters-changeLog.xml1 :linenos: :emphasize-lines: 4 ... [insert changesets here] In liquibase-alters-changeLog.xml replace referencedTableName="user" with referencedTableName="jhi_user" in the highlighted line: .. code-block:: xml :caption: liquibase-alters-changeLog.xml :name: liquibase-alters-changeLog.xml2 :linenos: :emphasize-lines: 10 #. Adjust the custom file generated for the user preferences Angular component: - [*project*]-metafactory\\src\\snippets\\[*frontend*]\\owner\\edit\\edit-component-userpreferences.ftl Add the parameter *this.id* to the *getMyUserPreferencesEditDto* call: .. code-block:: :caption: edit-component-userpreferences.ftl :name: edit-component-userpreferences.ftl :linenos: :emphasize-lines: 4 <#assign onInitCode> ngOnInit() { // EDIT: retrieve the instance of this UserPreferences this.subs.sink = this.ownerUserPreferencesService.getMyUserPreferencesEditDto(this.id).subscribe((data: OwnerUserPreferencesEditDto) => { this.ownerUserPreferencesEditDto = data; this.buildFormGroup(); }); } #. Add the project specific user preferences to model.xml: User preferences can be added to attributes and references. #. Attributes For each attribute of an object that you would like to be initially set to a user preference, perform the following steps: #. Add to the existing attribute. #. Add a new attribute to the UserPreferences object with the name [*object.name?uncap_first*][*attribute.name?cap_first*], e.g. hourAmount. #. Add metadata to the new attribute in the UserPreferences object: .. code-block:: xml :caption: model.xml :name: model.xml3 :linenos: :emphasize-lines: 3-14 <<<<<<< HEAD ======= >>>>>>> 64e54eae0b2fb05be64238bd915b09495d6b5888 label 3 widget 3 #. Add code to [*project*]-metafactory\\src\\snippets\\[*frontend*]\\owner\\edit\\edit-template-userpreferences.ftl to generate the rendering of the newly added user preference. .. code-block:: :caption: edit-template-userpreferences.ftl for rendering an attribute :name: edit-template-userpreferences.ftl2 <@generalMaterial.renderField false ''> <@generalMaterial.renderFieldLabel userPreferences.[attribute.name] metadataKey tsUserPreferences /> <@generalMaterial.renderFieldBody wrapDivField=true wrapSecondDivField=true> <@am.renderFormGroup userPreferences.[attribute.name]> <@am.renderEdit userPreferences.[attribute.name] metadataKey tsUserPreferences /> Replace [attribute.name] with the attribute name as defined in the UserPreferences object, e.g. hourAmount. #. Add a changeSet for the creation of the newly added project specific user preferences attribute at the end of liquibase-alters-changeLog.xml. #. References For each reference of an object that you would like to be initially set to a user preference, perform the following steps: #. Add to the reference that you would like to be initially set to a user preference. #. Add a reference to the UserPreferences object with the name [*object.name?uncap_first*][*reference.name?cap_first*], e.g. hourTask. #. Add metadata to this reference: .. code-block:: xml :caption: model.xml :name: model.xml4 :linenos: :emphasize-lines: 3-14 <<<<<<< HEAD ======= >>>>>>> 64e54eae0b2fb05be64238bd915b09495d6b5888 label 3 widget 3 #. Add code to [*project*]-metafactory\\src\\snippets\\[*frontend*]\\owner\\edit\\edit-template-userpreferences.ftl to generate the rendering of the newly added user preference. <<<<<<< HEAD .. code-block:: ======= .. code-block:: >>>>>>> 64e54eae0b2fb05be64238bd915b09495d6b5888 :caption: edit-template-userpreferences.ftl for rendering a reference :name: edit-template-userpreferences.ftl3 <@generalMaterial.renderField> <@generalMaterial.renderFieldLabel userPreferences.[reference.name] metadataKey tsUserPreferences /> <@generalMaterial.renderFieldBody wrapDivField=true> <@am.renderFormGroup userPreferences.[reference.name]> <@am.renderEdit userPreferences.[reference.name] metadataKey tsUserPreferences /> Replace [reference.name] with the reference name as defined in the UserPreferences object, e.g. hourTask. #. Add a changeSet for the creation of the newly added project specific user preferences reference at the end of liquibase-alters-changeLog.xml. #. Generate the Runtime Model with the Runtime Model buildset. #. Generate all #. Translate User Preferences - [*project*]\\[*frontend*]\\src\\main\\webapp\\i18n\\en\\userpreferences.json - [*project*]\\[*frontend*]\\src\\main\\webapp\\i18n\\nl\\userpreferences.json #. Add menu item for User Preferences to the project's top menu: Different projects have different top menu's. So adding a menu item for User Preferences requires manual addition. #. Run the application .. _Files: Files ----- In this section you can find the files you can use in implementing the feature. .. _user-preferences-object.xml: .. literalinclude:: /_static/user-preferences-sources/user-preferences-object.xml :caption: user-preferences-object.xml :language: xml Developer notes --------------- .. important:: For projects that **do not have** a UserPreferences object in model.xml yet, the aim is to generate **no user preferences related code**. For projects like AMI that **do have** a UserPreferences object in model.xml, the aim is to let AMI's custom patterns/snippets generate all user preferences related code, so no significant outgoing changes should occur.