Tuesday, May 05, 2015

ColumnValuesIndex property of NotesViewColumn

Since there is no documentation about property ColumnValuesIndex of class NotesViewColumn. Let me describe it.
Let's create a view with 7 columns:
  1. @DocNumber
  2. Hidden (sorting) column that does sorting
  3. Column with formula value: Form
  4. Icon (static value: 12)
  5. Column with formula value: @Created
  6. Constant value: 100
  7. Total with 'hide details row' enabled (for each row value: 1)

Analyze ColumnValuesIndex

Let's write some code and check what exactly ColumnValuesIndex returns
  Dim ws As New NotesUIWorkspace
  Dim view As NotesView
  Dim col As NotesViewColumn
  Dim i As Integer
 
  Set view = ws.CurrentView.View
  For i = 0 To view.ColumnCount - 1
    Set col = view.Columns(i)
    Msgbox col.ColumnValuesIndex
  Next
The result for columns will be: -1, 0, 1, -1, 2, -1, 3.
We may see now that for some of columns we got (-1). Let's look on these 3 columns and try to guess how they are different compare to other columns. Here is my assumptions for what cases it returns (-1)
  • A formula containing a UI-only function such as @IsExpandable or @DocNumber.
  • A constant.

Summary for ColumnValuesIndex

Otherwise it returns columns position (without taking into account columns with -1), It looks like it is exactly same logic as in notesViewEntry.ColumnValues

Monday, May 04, 2015

Refresh embedded view

Here is the classic old issue. I've a form with embedded view on it (Show single category is used as well). There is an action on a view that create a new documents (which should be displayed in that embedded view). These solutions most likely wont work
  • ws.ViewRefresh will not help
  • Refreshing NotesUIDocument may cause a Notes client to crash, so it is not a way to go as well.
Here are some possible ways to solve it:

Refresh view by simulating of pressing F9

While searching for an example I found it on my blog :-), so you can easily find it here: how to emulate F9 key and save some minutes.

Refresh view by changing focus to another fields

The idea is to have 2 fields (let's call them FieldA and fieldB). Once you need to refresh embedded view - set focus to fieldA and then change it to fieldB. You also need either add refresh logic on Exiting property of fieldA (I prefer it, as it will not cause the perfomance on a form) or enable Automatically Refresh fields.

Refresh embedded view using hidden formula

Here the idea is to make sure we have hidden formula on Embedded View (even such like 1 = 0) and use Refresh
And here is code examples
  Call ws.ViewRefresh
  Call uidoc.RefreshHideFormulas
  Call ws.ViewRefresh

Please have a look on these 2 articles that inspired me:
  1. Refreshing an embedded view
  2. How to refresh NotesUIDocument from categorized embedded view

Monday, January 05, 2015

Find Orphan pages on website

You have a website and want to be sure that there are no Orphan pages? Not sure how to develop it? If so - you found a right place to go :), let's talk about most important steps.
I assume you have a list of all pages you want to verify (otherwise - it will be your first task)

Here is a logic/snippets
  1. We need functionality that can extract HTML from a web page. Later we will scan it and get internal links.
    private String getPageContent(String pageurl) throws Exception {
       StringBuffer buf = new StringBuffer();
       URL url = new URL(pageurl);
       InputStream is = url.openConnection().getInputStream();
       BufferedReader reader = new BufferedReader( new InputStreamReader( is )  );
       String line = null;
       while( ( line = reader.readLine() ) != null )  {
          buf.append(line);
       }
       reader.close();  
       return buf.toString();
    }
  2. Make a logic that can deal with DOM. I use jsoup to manipulate with HTML and I really recommend it (easy and fast). The method below select all links that begin with baseurl (it's domain of your website), in that way we can cut all external links and get only internal links.
    private List<string> getAllInernalLinks(String html, String baseurl) throws Exception {
       List<string> res = new ArrayList<string>();
       String select = "a[href^="+baseurl+"]";
       org.jsoup.nodes.Document dom = Jsoup.parse(html);
       Elements links = dom.select(select);
    
       for (Element link : links) {
          String src = link.attr("href");
          res.add(src);
       }
       return res;
    }
  3. Now we must build a List with all internal links from all pages on your website.
    String List<string> alllinks = getAllInernalLinks(html_from_all_pages, baseurl);
  4. We need to make sure that pageurl can be found in alllinks more then in pagelinks (to avoid case when page has link to itself).
    private boolean isOrphan(List<string> pagelinks, List<string> alllinks, String url) throws Exception {
       if (Collections.frequency(alllinks, url) > Collections.frequency(pagelinks, url)) {
          return false;
       }
       return true;
    }

Wednesday, October 29, 2014

Formatting a URL link in Drupal using function l

Another nice function in Drupal. It's called function l.
It formats a URL link as an HTML anchor tag.
I know it looks really easy and simple, it's just nice to use it after doing that manually many times.
$option = array();
$option['attributes'] = array('title' => $label);
l($label_trimmed, $uri['path'], $option));// will output [a href="$uri-path" title="$label">[/a]

Tuesday, October 28, 2014

Truncating a string on a word boundary in Drupal

Typical task: "truncate a string only on a word boundary and add a some postfix to resulting string". Every developer did it many times, I'm sure. Here is a how Drupal solves it with it's api: function views_trim_text
define(MAX_LENGTH, 30);

$alter = array(
    'max_length' => MAX_LENGTH,
    'word_boundary' => TRUE,
    'ellipsis' => TRUE
);

$mystring = "truncate a string only on a word boundary and add a some postfix to resulting string";
$mystring = views_trim_text($alter, $mystring); //result is 'truncate a string only on a...'