-
-
Notifications
You must be signed in to change notification settings - Fork 7
Advanced Features
These features are considered "advanced" in the sense that they require some additional setup before they can be used.
Namely:
- iFrameWnd
- Heartbeat Monitoring
- User Preferences
- Account Logging
- Remote SW Updates (the page and view setup will come soon)
- User and Public Filters automatic Upload and Download
Some of them provide/use communication mechanisms between various parts of your app, thus leveraging quite powerful administration features.
Before proceeding with the Setup section that follows, it is assumed that the reader is familiar with the principles of KTL Customization found in this page: https://github.com/cortexrd/Knack-Toolkit-Library/wiki/Customizing-Features#customizing-features
Also, it is assumed that your Accounts table still has its default name. If you renamed it, you will need to use the function ktl.iFrameWnd.setCfg
to set the variable accountsObjName
accordingly.
Important!!! Throughout the following sections, whenever we mention the name of a table, a field or a view title, it must be written exactly as shown, case sensitive, spaces, punctuation, everything. It is recommended to copy/paste such text to avoid any typos.
Having an invisible menu is very useful. It allows hosting any utility pages that the user don't need to see, but still accessible by the developers via its direct URL, and also by the KTL to perform background tasks.
We will now create a hidden menu that will be your default place for any future utility hidden pages.
- Add a new Dropdown Menu named Invisible Menu.
- Do not add any page yet, click Continue at bottom.
- In settings, uncheck Include this page in the Page Menu.
The iFrameWnd will soon be its first resident.
For a description of what is the iFrameWnd, see this page: https://github.com/cortexrd/Knack-Toolkit-Library/wiki/Features-Overview#iframe-window
To use this feature, you must set the iFrameWnd flag to true in the ktl.core.setCfg function.
If this is not done, take a moment to read that page: https://github.com/cortexrd/Knack-Toolkit-Library/wiki/Customizing-Features#customizing-features
This section contains what you’ll need to set-up: https://github.com/cortexrd/Knack-Toolkit-Library/wiki/Customizing-Features#the-ktl-setupscallbacks
Create a new Login Page and give permission to all users. Set Page Name to: iFrameWnd. Its URL should automatically be set to iframewnd. This page will be the placeholder for the next features. For now, leave it blank as we need to create a few tables first. Now, go back to the Invisible Menu and assign the iFrameWnd to it.
To add User Preferences to your app, there are some already built-in, and you can also add your own. Follow this procedure:
- Create a role called Developer and assign it to yourself.
- In the Accounts table (see Pre-requisites above if you changed the name), add a Paragraph Text field named User Prefs.
- In the iFrameWnd page, add a view: Type: Details, For: Logged-in Account. Once the view is added, remove all fields, then add User Prefs. Set the view title to Current User Prefs _ar=10.
- Add a Form view that updates the currently logged-in account. Once the view is added, remove all fields, then add User Prefs. Set the view title to Update User Prefs. Enable the form's auto-reload in the Submit rule.
- Align both views on the same row to save space.
- Go to User Pages (at the bottom of the Pages view) and edit the Account Settings page.
- Add a menu entitled My Settings and move it to the top of the page.
- Add a link to a new page entitled My Preferences and enter to edit that page.
- Add a Form view that updates the currently logged-in account. Once the view is added, remove all fields, then add User Prefs. Set the view title to My Preferences. Enable the form's auto-reload in the Submit rule.
- Refresh your app and click on the - Account Settings link, then on My Preferences button in top menu.
- You will see 4 new checkboxes (dynamically generated by code): Show View ID, Show iFrameWnd, Show DebugWnd and Show Extra Debug.
- Check all 4, submit and view the result: view IDs will be shown in red next to each view, the iFrameWnd will appear at the bottom of the app, the DebugWnd will show up, and some new logs about WndMsg processing (REQ, ACK, etc.) will be shown in the console output.
- To close the DebugWnd, you have to click anywhere in the background of your app.
- Uncheck all those you don’t want and submit. It is recommended to leave Show iFrameWnd on if you’re planning to set up the User Preferences that follow.
To add Heartbeat Monitoring to your app to assess an account's presence and generate alerts, or perform remote SW updates, follow this procedure:
- Add the User Preferences feature from the above procedure.
- In the Accounts table, add these fields:
- SW Version: Type: Short text.
- UTC HB: Type: Date/Time, Date Format: mm/dd/yyyy, Default Date: none, Time Format: military, Default Time: none.
- TZ: Type: Number, no decimals.
- LOC HB: Type: Equation, Equation Type: Date, Date Type: hours, Result Type: Date, Equation Editor: {UTC HB}+{TZ}, Date Format: mm/dd/yyyy, Time Format: military.
- Online: Type: Yes/No, Default No, Input: Checkbox.
- UTC ACT: Type: Date/Time, Date Format: mm/dd/yyyy, Time Format: military.
- LOC ACT: Type: Equation, Equation Type: Date, Date Type: hours, Result Type: Date, Equation Editor: {UTC ACT}+{TZ}, Date Format: mm/dd/yyyy, Time Format: military.
- Create a new table called App Settings with these fields:
- Rename the default first field from App Settings Name to Item: Type: Short Text, set as the table’s Display Field and Sort in Alphabetic order.
- Value: Type: Paragraph Text.
- Date/Time: Type: Date/Time, Date Format: mm/dd/yyyy, Time Format: military.
- In the iFrameWnd page created above, add a Form view that updates the currently logged-in account. Set the view title to Heartbeat. In the form’s Submit rules, enable auto-reload and set the Confirmation message to “Heartbeat sent successfully.”. Remove all fields, then add on a first line: SW Version, UTC HB and LOC HB. Set LOC HB as read-only. Then on a second line: Online, UTC ACT and TZ.
- Still in the iFrameWnd, add a grid view that displays App Settings, with title: App Settings _ar=20. No Search, inline editing = On, 10 records at a time, no filtering allowed. Add all fields. Set Value’s Shorten Text to 75 characters. Source filter: Item starts with APP, sorted alphabetically A to Z.
- Be sure you have the Show iFrameWnd checkbox on in User Prefs above.
- Refresh the app and you should see in the iFrameWnd the heartbeat being submitted every minute and the Online being set to Yes.
Creating an Account Status Viewer:
To view the heartbeats, online status, latest activity, SW Version, etc., create a new Login page accessible to Developer role only, entitled Status Monitoring. Add a grid view that shows all Accounts, entitled Account Status _ar=60 _ts. Data source filter: User Status is active. Fields: Name, Online, LOC HB, UTC HB, UTC ACT, LOC ACT, SW Version and User Prefs. This view will refresh itself every minute, so you can assess the presence, latest activity and SW Version for each account.
Add the high-density class in the description:
_cls=[ktlDenseGrid],[ktlTarget, $('.kn-table')]
Note about the Online status flag:
This flag is set to Yes programmatically by the KTL, but obviously, the only way to reset it (No) would be to use some supervision mechanism that declares the account offline after a specific amount of time.
This being said, you have 3 options:
a) Ignore the Online status if it’s not important to your organization.
b) You can create some (1, 2 or 3+) daily task(s) to reset it.
c) Leave the Status Monitoring page running 24/7, so the KTL code will take care of this in real-time using API calls. This is the best option and Cortex R&D Inc. can provide such solutions using Linux devices in Kiosk mode to do it. Please enquire for more information.
- In the Status Monitoring page previously created (see section above), add a grid view for App Settings table. Title: SW Update. Filter the data source on Item is APP_KTL_VERSIONS. Settings: no search, Inline Edit = On, 10 records, no filtering. Leave three fields: Item, Value and Date/Time. Add the narrow margins class in the description:
_cls=[ktlNarrowMarginsPage], [ktlTarget,scene]
- Add an Action column: Header: Broadcast SW Update, Link Text: BROADCAST NOW. Action is Update this record, Item to a field value: Item. Confirmation msg: SW Update in progress...
You can set the text style in bold red with the display rule: when Item is not blank. - Move this view at top of screen.
When you have a new code release, and you want all users to be updated synchronously:
- Be sure to close all browsers that you have opened on this app.
- Open the Status Monitoring page created above.
- Go back in the Builder’s Javascript pane and increment your App's version number in the global variable: window.APP_VERSION = '1.0.0';
- Copy/paste your code in the Javascript pane –but don’t save yet!
- Update the KTL version in the Loader if needed. Sometimes you intentionally hold back a KTL update until you have an App update, then do both at the same time.
- Save the Javascript code.
- Refresh your app to get the latest version.
- Click the BROADCAST NOW action link.
This will update the App Settings' APP_KTL_VERSIONS record. All users with opened browsers will have their iFrameWnd detect the version change and force a page reload to get the latest code.
Those who are not online will simply get the latest code when they launch the app next time.
In addition to being able to create named buttons for the User Filters that are saved in localStorage, it is possible with a bit of setup to upload your settings to Knack and download them back wherever and whenever needed. This two-way process is automatically done in the background, and can be seen as a backup method, but also to migrate them to other devices (or browsers, see note below). Note that if you migrate filters from one app to another, typically a temporary development copy, some filters may stop working due to the record IDs that have changed for connected fields. This is a normal behavior, and the only way to fix this is to redo their settings and save back to the same button name.
To support automatic Upload and Download, follow this procedure:
- Create a table named User Filters and add these fields:
- Account: Type: Connection to Accounts, all settings at default.
- Date/Time: Type: Date/Time, Date Format: mm/dd/yyyy, Default Date: Current Date, Time Format: military, Default Time: Current Time.
- Filters Code: Type: Paragraph Text.
- Table’s settings : Display Field: Account, Sort Order: Account, a to z.
- Delete the first default field created: User Filters Name.
- Go to the iFrameWnd page and add a grid that displays User Filters connected to the logged-in account. Call it User Filters, remove the Account column and leave only the Date/Time and Filters Code. Set Filters Code’s Truncate Text to 75 characters.
- Source: Limit number of records to 1.
- Settings: no search, Inline Editing = On, 10 records at a time, no filtering. Title: User Filters _ar=30 (you can change the 30 for 10 seconds temporarily for quicker testing, then put back to 30)
To test this feature:
Open two different browsers (ex: Chrome and Edge) and log-in with your own account in both. Open them to the same page, where there’s a grid with filtering enabled. Create a couple of filters in the first browser, wait about 30 seconds and you will see those filters appear in the second browser. Same applies for Public Filters: set a filter to Public, make changes to it, and all will be reflected in the other browser, but also for all users of that view.
*Note about browsers: the localStorage is not shared across different browsers (and also within the same browser but in private/incognito mode). This is when the automatic upload/download functionality has its usefulness, by allowing this transfer to occur in real-time, within about 30 seconds.
If you want to add Account Logging to your app, follow this procedure:
- Create a grid named Account Logs and add these fields:
- Log Nb: Type: Auto-Increment.
- Account: Type: Connection to Accounts, all settings at default.
- Date/Time: Type: Date/Time, Date Format: mm/dd/yyyy, Default Date: Current Date, Time Format: military, Default Time: Current Time.
- Log Type: Type: Short Text.
- Details: Type: Paragraph Text.
- Log Id: Type: Short Text. See note below for details.
- Email To: Type: Email.
- Table’s settings: Display Field: Account, Sort Order: Log Nb, low to high.
- In the iFrameWnd, add a grid view for Account Logs, connected to the logged-in Account.
- Once the view is added, remove all fields, then add Date/Time, Log Type, Details, Log ID, Email To and an Custom Email action with these settings, as from the screen capture KTL Account Logs Email Settings.jpg.
- The blank value to Email To in Action #2 is intended. This field also acts as a flag and resetting it to blank prevents sending the email more than once.
- The Outcome phrase “Account Logs - Email sent successfully” is used in the code to confirm completion, so it must be exactly the same.
- Set the view title to Account Logs _ar=30, disable search, enable Inline editing, 10 records at a time, no filter.
- Sort by Log Nb: high to low, limit to 5 records.
*Note about the Log Id field: This is a unique ID that is a UTC millisecond timestamp. It is generated by the code at the moment the log is sent via the API call. Its purpose is to validate that the log has been sent and received properly. With that confirmation, the log can safely be deleted from localStorage.