For me, it is more important to be able to organise the contents of a folder by creation date rather than modified date. I have a routine that edits the NBS_CREATED field for each document I add to the document's own creation datetime, rather than defaulting to the upload to OpenKM time. This works nicely.
However, the FileBrowser only has a column for "Update date", so I cannot sort all the documents in a folder by their "Creation date" property. I have figured out how to do this, and I thought it might be useful to others struggling with this low level configuration of OpenKM to write something of a tutorial on how I achieved my task.
The Professional Edition has the facility to add custom columns to the FileBrowser based on your own metadata, so if you are using the Professional Edition, stop reading now, there is a better way to do this built in to your software. Community Edition users, continue.
First, the good news. OpenKM Community edition is open source, which means that you can actually change the source code to fit your own needs. This is excellent.
Next, the bad news. You need to be able to edit source code to do this. This is painful, if you are not an IT professional.
First of all you are going to need the Portable Development, which you can download from here: https://sourceforge.net/projects/openkmportabledev/
I am not going to cover setting this up. There is a useful readme file in in the downloaded archive that walks you through it. Suffice to say the only major problem I had was that the built in Maven software installed its repository folder (.m2) in my Documents folder. This should have been fine, but my Documents folder is mounted on a network drive, which gave me build errors.
To solve these I moved the .m2 repository to c:\, and created a new settings.xml file in c:\openkm-dev with the following contents:
So far, so good.
My solution to displaying "Creation date" is to change the nature of the "Update date" column. This means that I lose the "Update date" column functionality. If you want a "Creation date" column AND an "Update date" column, then this approach is not for you.
To get me started I read these threads in the forums:
https://forum.openkm.com/viewtopic.php?f=4&t=12587
https://forum.openkm.com/viewtopic.php?f=4&t=5520
https://forum.openkm.com/viewtopic.php?f=4&t=12493
From those, I gathered that the files that we need to edit in Eclipse are
FileBrowser.java
In brief, this lets us change the column header text.
ExtendedScrollTable.java
This lets us change the data displayed in the column.
ExtenderColumnSorter.java
This lets us change the way the column is sorted.
Starting with FileBrowser.java (/openkm-6.3-community/src/main/java/com/openkm/frontend/client/widget/filebrowser/FileBrowser.java), you want to search for the string: "isLastModifiedVisible". That will take you to all the places that change what they do depending on whether or not the "Update date" column should be displayed.
The first mention is in the method:
I looked through that table to see if I could find a "Creation date" text linked to a key I could use to prevent me from having to code my own. Happily there was with the key 'dashboard.workflow.task.created'. I decided to borrow this key. This is a terrible idea by the way. If the key changes in the future my column name will change as well. I really should make my own key, but I am a) not an IT professional and b) lazy.
So I changed the code in
If you build OpenKM now, you will have changed the column heading to "Creation date" and nothing else. So let's change the data displayed.
You now want to be editing ExtendedScrollTable.java (/openkm-6.3-community/src/main/java/com/openkm/frontend/client/widget/filebrowser/ExtendedScrollTable.java). Again you want to seach for "isLastModifiedVisible". There are three results. The first is in the method
To complete our task, you need to edit ExtenderColumnSorter.java (/openkm-6.3-community/src/main/java/com/openkm/frontend/client/widget/filebrowser/ExtendedColumnSorter.java). Searching for "isLastModifiedVisible" this time will not help. It takes you to one entry, which is in a method to help when other custom columns are added - not something I am covering here. Look for the method
Job done. I hope this had been useful.
However, the FileBrowser only has a column for "Update date", so I cannot sort all the documents in a folder by their "Creation date" property. I have figured out how to do this, and I thought it might be useful to others struggling with this low level configuration of OpenKM to write something of a tutorial on how I achieved my task.
The Professional Edition has the facility to add custom columns to the FileBrowser based on your own metadata, so if you are using the Professional Edition, stop reading now, there is a better way to do this built in to your software. Community Edition users, continue.
First, the good news. OpenKM Community edition is open source, which means that you can actually change the source code to fit your own needs. This is excellent.
Next, the bad news. You need to be able to edit source code to do this. This is painful, if you are not an IT professional.
First of all you are going to need the Portable Development, which you can download from here: https://sourceforge.net/projects/openkmportabledev/
I am not going to cover setting this up. There is a useful readme file in in the downloaded archive that walks you through it. Suffice to say the only major problem I had was that the built in Maven software installed its repository folder (.m2) in my Documents folder. This should have been fine, but my Documents folder is mounted on a network drive, which gave me build errors.
To solve these I moved the .m2 repository to c:\, and created a new settings.xml file in c:\openkm-dev with the following contents:
Code: Select all
In Eclipse I then set Windows/Preferences/Maven/User Settings to point to the new XML file. I got all this solution from http://wiki.openkm.com/index.php/Developer_Guide where it is listed as a solution to a different problem.<settings>
<localRepository>c:/.m2/repository</localRepository>
</settings>
So far, so good.
My solution to displaying "Creation date" is to change the nature of the "Update date" column. This means that I lose the "Update date" column functionality. If you want a "Creation date" column AND an "Update date" column, then this approach is not for you.
To get me started I read these threads in the forums:
https://forum.openkm.com/viewtopic.php?f=4&t=12587
https://forum.openkm.com/viewtopic.php?f=4&t=5520
https://forum.openkm.com/viewtopic.php?f=4&t=12493
From those, I gathered that the files that we need to edit in Eclipse are
FileBrowser.java
In brief, this lets us change the column header text.
ExtendedScrollTable.java
This lets us change the data displayed in the column.
ExtenderColumnSorter.java
This lets us change the way the column is sorted.
Starting with FileBrowser.java (/openkm-6.3-community/src/main/java/com/openkm/frontend/client/widget/filebrowser/FileBrowser.java), you want to search for the string: "isLastModifiedVisible". That will take you to all the places that change what they do depending on whether or not the "Update date" column should be displayed.
The first mention is in the method:
Code: Select all
It reads:
public void langRefresh()
Code: Select all
If you read through the code for Main.i18n, you find that what is happening is that a Translation service is used which takes the string "filebrowser.date.update" as a key, and searches against it in the OpenKM MySQL database (assuming you are using MySQL, no idea how this works if you are using another database), in the table `okm_translation`. if (profileFileBrowser.isLastModifiedVisible()) {
headerTable.setHTML(row, colLastModifiedIndex, Main.i18n("filebrowser.date.update"));
fBController.addOrderByItem(Main.i18n("filebrowser.date.update"), String.valueOf(GWTPaginated.COL_DATE));
}
I looked through that table to see if I could find a "Creation date" text linked to a key I could use to prevent me from having to code my own. Happily there was with the key 'dashboard.workflow.task.created'. I decided to borrow this key. This is a terrible idea by the way. If the key changes in the future my column name will change as well. I really should make my own key, but I am a) not an IT professional and b) lazy.
So I changed the code in
Code: Select all
to be:
public void langRefresh()
Code: Select all
The next mention of "isLastModifiedVisible" is in the method if (profileFileBrowser.isLastModifiedVisible()) {
headerTable.setHTML(row, colLastModifiedIndex, Main.i18n("dashboard.workflow.task.created"));
fBController.addOrderByItem(Main.i18n("dashboard.workflow.task.created"), String.valueOf(GWTPaginated.COL_DATE));
}
Code: Select all
I made the same type of change to this, so mine now reads:
public void setProfileFileBrowser(GWTProfileFileBrowser profileFileBrowser, GWTProfilePagination profilePagination)
Code: Select all
The last mention of "isLastModifiedVisible" does not need any edits.if (profileFileBrowser.isLastModifiedVisible()) {
headerTable.setHTML(row, col, Main.i18n("dashboard.workflow.task.created"));
colLastModifiedIndex = col;
ScrollTableHelper.setColumnWidth(table, col, Integer.parseInt(profileFileBrowser.getLastModifiedWidth()), ScrollTableHelper.MEDIUM);
col++;
fBController.addOrderByItem(Main.i18n("dashboard.workflow.task.created"), String.valueOf(GWTPaginated.COL_DATE));
}
If you build OpenKM now, you will have changed the column heading to "Creation date" and nothing else. So let's change the data displayed.
You now want to be editing ExtendedScrollTable.java (/openkm-6.3-community/src/main/java/com/openkm/frontend/client/widget/filebrowser/ExtendedScrollTable.java). Again you want to seach for "isLastModifiedVisible". There are three results. The first is in the method
Code: Select all
If the method name is not a good enough clue what this does is add a row to the filebrowser table when it is being displayed. As you might be able to see, this method takes as its input a folder object. I am concerned about displaying the Creation date of documents, not folders, but the code here is still useful. If you look down the method you will see this:
public void addRow(GWTFolder folder, boolean update)
Code: Select all
The important bit to look at is the "folder.getCreated()". This adds the creation date of folders to the "Update date" column in the filebrowser. I just want to do that with documents as well. Search for the next "isLastModifiedVisible", and you will come to the method: if (profileFileBrowser.isLastModifiedVisible()) {
DateTimeFormat dtf = DateTimeFormat.getFormat(Main.i18n("general.date.pattern"));
dataTable.setHTML(row, col, dtf.format(folder.getCreated()));
dataTable.getCellFormatter().setHorizontalAlignment(row, col++, HasHorizontalAlignment.ALIGN_CENTER);
}
Code: Select all
That method takes a document object as an input, and does what we want. The if..loop that applies "isLastModifiedVisible" in mine now reads:
public void addRow(GWTDocument doc, boolean update)
Code: Select all
I changed doc.getLastModified() to doc.getCreated(). That is the only change you need to make in ExtendedScrollTable.java. If you build OpenKM now, you will find that the column now headed "Creation date" actual displays the creation dates of documents. However, if you attempt to SORT the column it will still sort based on the underlying "Update date". if (profileFileBrowser.isLastModifiedVisible()) {
DateTimeFormat dtf = DateTimeFormat.getFormat(Main.i18n("general.date.pattern"));
dataTable.setHTML(row, col, dtf.format(doc.getCreated()));
dataTable.getCellFormatter().setHorizontalAlignment(row, col++, HasHorizontalAlignment.ALIGN_CENTER);
}
To complete our task, you need to edit ExtenderColumnSorter.java (/openkm-6.3-community/src/main/java/com/openkm/frontend/client/widget/filebrowser/ExtendedColumnSorter.java). Searching for "isLastModifiedVisible" this time will not help. It takes you to one entry, which is in a method to help when other custom columns are added - not something I am covering here. Look for the method
Code: Select all
The name sounds promising! The method contains a Select...Case section of code which contains the following:
public void sort(int column, boolean ascending)
Code: Select all
This code is run if the variable correctedColumn is 5. Why is this of interest? In the file /openkm-6.3-community/src/main/java/com/openkm/frontend/client/constants/ui/UIDesktopConstants.java:
case 5 :
// Date
if (data.get(Integer.parseInt(rowI[colDataIndex])) instanceof GWTFolder) {
rowToOrder.setObject(((GWTFolder) data.get(Integer.parseInt(rowI[colDataIndex]))).getCreated()); // Date value
rowToOrder.setDataId(""+ i); // Actual position value
elementToOrder.add(rowToOrder);
} else if (data.get(Integer.parseInt(rowI[colDataIndex])) instanceof GWTMail) {
rowToOrder.setObject(((GWTMail) data.get(Integer.parseInt(rowI[colDataIndex]))).getReceivedDate()); // Date value
rowToOrder.setDataId(""+ i); // Actual position value
elementToOrder.add(rowToOrder);
} else if (data.get(Integer.parseInt(rowI[colDataIndex])) instanceof GWTDocument) {
rowToOrder.setObject(((GWTDocument) data.get(Integer.parseInt(rowI[colDataIndex]))).getLastModified()); // Date value
rowToOrder.setDataId(""+ i); // Actual position value
elementToOrder.add(rowToOrder);
}
break;
Code: Select all
So, this case is run if we are dealing with the LastModified Column (how the method knows this, I have not worked out). I made the same change to the last "else if" which runs if the data type is a GWTDocument, that I made in the last file. I changed the "setOject" to grab the "Date value" from getCreated() instead of getLastModified(), so my select...case for '5' is now:
FILEBROWSER_COLUMN_LASTMODIFIED = 5
Code: Select all
If you now build OpenKM, you will find your LastModified column is now headed "Creation date", displays the Creation date of documents, and is sorted by the document's creation date.case 5 :
// Date
if (data.get(Integer.parseInt(rowI[colDataIndex])) instanceof GWTFolder) {
rowToOrder.setObject(((GWTFolder) data.get(Integer.parseInt(rowI[colDataIndex]))).getCreated()); // Date value
rowToOrder.setDataId(""+ i); // Actual position value
elementToOrder.add(rowToOrder);
} else if (data.get(Integer.parseInt(rowI[colDataIndex])) instanceof GWTMail) {
rowToOrder.setObject(((GWTMail) data.get(Integer.parseInt(rowI[colDataIndex]))).getReceivedDate()); // Date value
rowToOrder.setDataId(""+ i); // Actual position value
elementToOrder.add(rowToOrder);
} else if (data.get(Integer.parseInt(rowI[colDataIndex])) instanceof GWTDocument) {
rowToOrder.setObject(((GWTDocument) data.get(Integer.parseInt(rowI[colDataIndex]))).getCreated()); // Date value
rowToOrder.setDataId(""+ i); // Actual position value
elementToOrder.add(rowToOrder);
}
break;
Job done. I hope this had been useful.