Skip to main content

Dynamic 'My Favorites' Links in your APEX Application

For a (even more) Web 2.0 like look-and-feel in your APEX application you can define a dynamic region 'My Favorite Tasks', that shows links to the pages you visit most frequently.
For these favorites we can query the APEX repository. Follow these steps to get this thing working:

  1. Enable logging on Application Level. Enabling the logging will result in records in the view apex_workspace_activity_log.
  2. Create a Report Page with a region based on a SQL Query.
  3. Enter the query to show the links for the three most visited pages:
select htf.anchor( 'f?p='||:APP_ID||':'||page_id||':'||:APP_SESSION
, page_name ) Task
from

(
select page_name
, page_id
, count(*)
from apex_workspace_activity_log
where application_id = :APP_ID
and apex_user = :APP_USER
and page_id <> :APP_PAGE_ID
group by page_name, page_id
order by 3 desc
)
where rownum <= 3
In a next post I will show how you can embed this report page in any other page in your application.

Comments

Anonymous said…
Nice Post Roel,

This can also be done using apex view apex_activity_log instead of wwv_flow_activity_log. Using apex_activity_log you would not need steps 1 and 2.

Thanks,
Todd
Stew said…
For those who were initially as clueless as me when they read "Enable logging on Application Level", that means to navigate to Shared Components -> Application Definition and set Logging := Yes in the Name section.

Stew
Stew said…
Roel,

It looks like the better bet would be to use the apex_workspace_activity_log table, since it's already granted to the workspace.

I'd use an inner query like:

SELECT *
FROM (SELECT page_id, page_name, MIN(seconds_ago) last_ones
FROM apex_workspace_activity_log
WHERE application_id = :APP_ID
AND page_id <> 101 -- Login page
AND userid = :APP_USER
GROUP BY page_id, page_name)
WHERE rownum <= 3
ORDER BY 3;

Or maybe I'm missing something?
Roel said…
Todd & Stew,

A combination of both suggestions seems to result in the best query:
- use apex_workspace_activity_log instead of the wwv_flow_activity_log (although the apex_.. view only contains data of the last 14 days).
- I think I don't have to exclude the login page, as there is no known user at the time that page pops up.
- the ORDER_BY should be inside the inline view, otherwise you don't get the Top-3.
- use APEX_USER instead of USERID
- exclude the current page from the query by filtering on :APP_PAGE_ID

I updated my post with your suggestions!

Thanks,
Roel
Anonymous said…
Excellent Roel.

I really like this.

One thing I found though was that my development team and I use some quite obscure 'Developer' coded page titles (e.g. Developer initials, module reference etc) and the Page Names are set to something more user friendly, after all, the Page Name is what the user sees at the top of their web browser.

A join in the query, as shown below, gave us a more user friendly result. Of course, if your page names and titles are the same then you needn't bother.

Just my thoughts.

As I said, nice post.

select htf.anchor( 'f?p='||:APP_ID||':'||page_id||':'||:APP_SESSION
, page_title ) "Favourite Pages"
from
(
select aap.page_title
, awal.page_id
, count(awal.page_id)
from apex_workspace_activity_log awal
join APEX_APPLICATION_PAGES aap on aap.application_id = awal.application_id and aap.page_id = awal.page_id
where awal.application_id = :APP_ID
and awal.apex_user = :APP_USER
and awal.page_id <> :APP_PAGE_ID
group by aap.page_title, awal.page_id
order by 3 desc
)
where rownum <= 3
Stew said…
Nice collaboration guys! :-)
Anonymous said…
Hi this adaptation will only show pages that are linked to from tabs:

select htf.anchor( 'f?p='||:APP_ID||':'||page_id||':'||:APP_SESSION, page_name ) Task
from (select act.page_name
, act.page_id
, count(*) "load_count"
from APEX_APPLICATION_TABS tab
join APEX_WORKSPACE_ACTIVITY_LOG act on tab.tab_page = act.page_id
where act.application_id = :APP_ID
and act.apex_user = :APP_USER
and act.page_id <> :APP_PAGE_ID
group by act.page_name, act.page_id
order by 3 desc)
where rownum <= 10;

Greets,
Maurice Kremer

Popular posts from this blog

Fix Interactive Report headers issue when using a Region Display Selector

When you have multiple Interactive Reports (IR) on your page and use a Region Display Selector to mimic tabs, you might notice some weird behaviour in the IR headings if you switch tabs. The headings are not positioned correctly and you get an extra empty row under the headings. It just looks weird and ugly. But if you resize your browser window, it all looks fine again (until you switch to another tab..) So can we fix this by creating a Dynamic Action that mimics that "browser window resize" event? Yes we can! Create a Dynamic Action that fires on Click of the jQuery selector li.apex-rds-item a . That should fire a JavaScript snippet :  apex.event.trigger(this.triggeringElement, "apexwindowresized"); So now a click on a tab not only switches from one IR to another but also fires that event that will "autofix" the IR headers. A simple solution for an annoying problem. This applies to APEX 5.0, I assume it will be solved in 5.1.

How to create neatly formatted Excel documents using PL/SQL?

If there is a requirement to produce output from an application into Excel, you would probably create a CSV (Comma Separated File) with the data and start Excel to show the data - at least that's what I did...until now. The drawback of this solution is that you could only produce data and no nice layout. But Excel is also capable of opening HTML-files and using this you could create Excel files with data and magnificent layout! Let me give an example: 1. Create a procedure to show the data in formatted in an HTML table. CREATE OR REPLACE PROCEDURE display_emp_list IS v_emp_count NUMBER(5); v_empno NUMBER(8); v_ename VARCHAR2(50); v_job emp.job%TYPE; v_sal emp.sal%TYPE; v_bg_color VARCHAR2(10) := ''; CURSOR c_emp IS SELECT empno, initcap(ename), job, sal FROM emp ORDER BY ename; BEGIN SELECT COUNT(*) INTO v_emp_count FROM emp; owa_util.mime_header('application/ms-excel', FALSE); htp.p('Content...

Refresh selected row(s) in an Interactive Grid

In my previous post I blogged about pushing changed rows from the dabatase into an Interactive Grid . The use case I'll cover right here is probably more common - and therefore more useful! Until we had the IG, we showed the data in a report (Interactive or Classic). Changes to the data where made by popping up a form page, making changes, saving and refreshing the report upon closing the dialog. Or by clicking an icon / button / link in your report that makes some changes to the data (like changing a status) and ... refresh the report.  That all works fine, but the downsides are: The whole dataset is returned from the server to the client - again and again. And if your pagination size is large, that does lead to more and more network traffic, more interpretation by the browser and more waiting time for the end user. The "current record" might be out of focus after the refresh, especially by larger pagination sizes, as the first rows will be shown. Or (even wors...