APEX and shuttle filter - Revisited

Category APEX and jQuery

Previously I did write post about APEX and shuttle filter. I received comments that filtering does not work when shuttle have parent cascading item. Issue was that JavaScript code stores shuttle values to variable for filtering only on page load.

I did receive also proposal to add button for clearing filter item. This is also included to new JavaScript code along with some style changes for APEX 19.2.

Here is modified code for page JavaScript Function and Global Variable Declaration:

(function($) {
  $.fn.htmldbShuttlefilter = function(options) {

    options = $.extend({}, {
      "filterPlaceholder": "Filter",
      "buttonTitle": "Clear filter",
      "buttonClass": "a-Button a-Button--noLabel a-Button--withIcon a-Button--small a-Button--noUI a-Button--shuttle margin-top-none",
      "buttonIcon": "fa-times"
    }, options);

    function getShuttleValues(elem$) {
      return elem$.children("option").map(function() {
        return {
          text: $(this).text(),
          value: $(this).val(),
          option: this
        };
      });
    }

    return this.each(function(i) {
      
      var $self = $(this),
        shuttleResetBtnId = $self.attr("id") + "_RESET",
        $select = $self.find("select"),
        // get shuttle values
        shuttleValues = getShuttleValues($select),
        // filter reset button
        $resetBtn = $("<button/>", {
          "type": "button",
          "title": options.buttonTitle,
          "aria-label": options.buttonTitle,
          "class": options.buttonClass,
          "css": {"padding": "4px"}
        }).append(
          $("<span/>", {
            "aria-hidden": "true",
            "class": "a-Icon fa " + options.buttonIcon,
          })
        ).click(function() {
          // clear filter text field
          $filter.val("").keyup();
        }),
        // filter text field
        $filter = $("<input/>", {
          "type": "text",
          "value": "",
          "autocomplete": "off",
          "placeholder": options.filterPlaceholder,
          "class": "text_field apex-item-text",
          "css": {"width": "100%"}
        }).keyup(function() {
          // filter shuttle when typing to text field
          var filterval = new RegExp("^" + $(this).val() + ".*", "i"),
          selectedValues = $select.eq(1).children("option").map(function() {
            return $(this).val();
          });

        // empty shuttle available values
        $select.eq(0).empty();
        // add values that match filter criteria
        $.each(shuttleValues, function(idx, obj) {
          if (obj["text"].match(filterval) && $.inArray(obj["value"], selectedValues) < 0) {
            $select.eq(0).append(obj["option"]);
          }
        });
      });
      // add needed elements to page
      $self.prepend(
        $("<div/>", {
          "class": "t-Form-itemWrapper"
        }).append($filter).append(
          $("<span/>", {
            "class": "t-Form-itemText t-Form-itemText--post"
          }).append($resetBtn)
        )
      ).on("apexafterrefresh", function() {
        // initiliaze filter when shuttle is refreshed by parent item
        $filter.val("");
        shuttleValues = getShuttleValues($select);
      });
      // clear also filter from shuttle reset button
      $("#" + shuttleResetBtnId).click(function() {
        $filter.val("");
      });

    });
  }
})(apex.jQuery);

If you like add filter to all shuttles in page, then add to page JavaScript Execute when Page Loads:

$(".apex-item-group--shuttle").htmldbShuttlefilter();

Depending on your need, change jQuery selector.

See working example where Dept shuttle is parent for Emp.

Stopping XE 18c properly when shutting down CentOs 7

Category Oracle Database

You can configure automatically start and stop Oracle XE 18c database on operating system startup and shutdown. See details from installation guide.

I did install XE 18c on CentOs 7 and executed steps mentioned in installation guide.
When viewing database alert.log after system reboot, noticed that database wasn't actually stopped properly. Processes were just killed.
I didn't investigate more why that happens on my system. For workaround I did revert steps mentioned in installation guide and created service file for systemd.

First stop XE database and revert automatically start and stop:

systemctl stop oracle-xe-18c
systemctl disable oracle-xe-18c

Create service file:

cat >> /usr/lib/systemd/system/ora-xe-18c.service << EOF
[Unit]
Description=Oracle 18c XE databases service
After=syslog.target network.target

[Service]
Type=forking
Restart=no
KillMode=none
TimeoutStopSec=10min
RemainAfterExit=yes
User=oracle
Group=oinstall
ExecStart=/opt/oracle/product/18c/dbhomeXE/bin/dbstart /opt/oracle/product/18c/dbhomeXE &
ExecStop=/opt/oracle/product/18c/dbhomeXE/bin/dbshut /opt/oracle/product/18c/dbhomeXE

[Install]
WantedBy=multi-user.target
EOF

Backup and modify /etc/oratab:

cp /etc/oratab /etc/oratab.backup_`date +%Y%m%d`
sed -i 's/XE:\/opt\/oracle\/product\/18c\/dbhomeXE:N/XE:\/opt\/oracle\/product\/18c\/dbhomeXE:Y/g' /etc/oratab

Enable new service and start XE database again:

systemctl daemon-reload
systemctl enable ora-xe-18c
systemctl start ora-xe-18c

Caching APEX static files

Category APEX and Apache HTTPD

The APEX installation includes static files that are located on the web server. These files may changed normally only when you upgrade or apply patch to APEX. Because files are changing rarely, they are good subject stored to cache. If you use Apache HTTPD to serve static files, you can configure mod_file_cache for ones that are used most in your applications.

You might have also other static content e.g. images, JavaScript and CSS files that are stored to APEX workspace or application static files. Also these files aren't usually changed often and you can store files to cache and reduce calls to database. This can be done using HTTPD modules mod_cache and mod_cache_disk.

I provide here only basic information that you are aware about these HTTPD cache features and how those may used with APEX. Assumption is that you have knowledge how configure HTTPD. You need test and see how these works on your system.

First check are needed modules loaded to HTTPD. In Linux machine you can use command httpd -M to list all modules that are loaded.
You should look cache_module, cache_disk_module and file_cache_module. 
Output of command httpd -M lists HTTPD loaded modules

Create configuration file called e.g. apex_file_cache.conf to specify the APEX static files you like cache. Here is example configuration file content for APEX 5.1.4 when applications use Universal Theme and styles Vita:

# APEX 5.1.4 mod_file_cache configuration for Universal Theme style Vita
<IfModule file_cache_module>
  # CSS
  CacheFile /apex/images/app_ui/css/Core.min.css
  CacheFile /apex/images/app_ui/css/Theme-Standard.min.css
  CacheFile /apex/images/libraries/jquery-ui/1.10.4/themes/base/jquery-ui.min.css
  CacheFile /apex/images/libraries/font-apex/1.0/css/font-apex.min.css
  CacheFile /apex/images/themes/theme_42/1.1/css/Core.min.css
  CacheFile /apex/images/themes/theme_42/1.1/css/Vita.min.css
  # JavaScript
  CacheFile /apex/images/libraries/apex/minified/desktop.min.js
  CacheFile /apex/images/libraries/hammer/2.0.4/hammer-2.0.4.min.js
  CacheFile /apex/images/libraries/apex/minified/widget.apexTabs.min.js
  CacheFile /apex/images/libraries/apex/minified/widget.stickyWidget.min.js
  CacheFile /apex/images/libraries/apex/minified/widget.stickyTableHeader.min.js
  CacheFile /apex/images/themes/theme_42/1.1/js/modernizr-custom.min.js
  CacheFile /apex/images/themes/theme_42/1.1/js/theme42.min.js
</IfModule>

In example I use CacheFile directive but you should test does your platform support it or do you get better result with MMapFile directive. Check also path where the files are located in server. Include configuration file to your httpd.conf file, run test for configuration and restart HTTPD.

NOTE! when you upgrade or patch APEX, you need check are same files still relevant for cache and do changes accordingly to the configuration file. Also you need restart HTTPD to avoid end up serving requests that are completely bogus as mod_file_cache documentation says.
You shouldn't try cache all APEX +12 000 static files, that installation contains, with mod_file_cache. Most probably your applications isn't using those all even in special cases. You need carefully select only most used files.

To configure cache for APEX workspace and application static files create configuration file called e.g. apex_cache_disk.conf. Here is example configuration for workspaces ws1, ws2, ws3 and ws4:

# APEX 5.1.4 mod_cache configuration for static workspace and application files
<IfModule cache_disk_module>
  CacheRoot      /var/cache/httpd/proxy
  CacheEnable    disk /apex/ws1/r/
  CacheEnable    disk /apex/ws2/r/
  CacheEnable    disk /apex/ws3/r/
  CacheEnable    disk /apex/ws4/r/
  CacheLock      on
</IfModule>

You need check what are URL's in your system relating to APEX workspace and application static files and adjust configuration accordingly. Include configuration file to your httpd.conf file, run test for configuration and restart HTTPD.

Optionally you can also add CacheIgnoreCacheControl directive that clients can't force refresh cache in HTTPD. Then it is recommended where you refer static file add query string to end. That way developers can force HTTPD fetch new file when files are changed. You can use e.g. APP_VERSION substitution string like:

#APP_IMAGES#style#MIN#.css?v=#APP_VERSION#

If you change file in workspace or application static files, change also version attribute in application definitions so HTTPD knows reload file.
After enabling mod_cache, you should also see and setup htcachecleanup.

Depending if you aren't using RESTful services from APEX workspaces, after configuring mod_cache for workspace and application files, you might like check and change ORDS configuration for APEX_REST_PUBLIC_USER and APEX_LISTENER users pool. See if you can lower those pools jdbc.MinLimit so there aren't connections waiting for nothing while HTTPD serves workspace and application static files from cache.

Global Right Column

Search

Archives

Subscribe in a Reader