Daniele Grillo
Daniele Grillo

Reputation: 1023

sort getAllUnreadEntries() for repeat Control

I need to develop a custom control that for any notesview show in a little box a list of Unread Documents... So that I follow my previus question solution with repeat control:

show only unread document

The problem is that in my Target View..I have the first column (@modified is the value) order descending.

When the repeat control show the result..the entries is order Ascending.

Have you any suggest to resolve?

Tnx you

Upvotes: 0

Views: 569

Answers (2)

Daniele Grillo
Daniele Grillo

Reputation: 1023

I have used this code into my repeat control to solve the problem:

Ventry=function(ve:NotesViewEntry){
this.dataModify = ve.getDocument().getLastModified().toJavaDate().getTime();
this.unid=entry.getDocument().getUniversalID()
}

sortFunctionDescending = function(a,b) {
var x = a.dataModify;
var y = b.dataModify;
return ( (x<y) ? 1 : ((x>y) ? -1 : 0)); 
}

var viewEntries=[];
database.getView('(MY VIEW THAT I SHOW UNREAD)').refresh();
var Collection:NotesViewEntryCollection=database.getView('(AllDocumentsUnread)').getAllUnreadEntries();
var entry:NotesViewEntry=Collection.getFirstEntry();
while (entry!=null){ //loop over all entryes
viewEntries.push( new Ventry( entry) );
entry = Collection.getNextEntry();
}
Collection.recycle();
viewEntries.sort(sortFunctionDescending);  //effettua il sorting
return (viewEntries);

So that to access at document value I have use (for example into a computedfield the lastmodified data)

var unid=rowData.unid;
return(database.getDocumentByUNID(unid).getLastModified().toJavaDate());

Upvotes: 0

David Leedy
David Leedy

Reputation: 3593

Would be nice if you posted a little code... but here's some thoughts... Using the notes view navigator you an walk through the view in view sorted order. What I think you want to do then is get a "handle" on all those documents keeping the same order.

I assume you're not using Java and just SSJS. That's fine. But that doesn't mean you can't use a Java Object!

Now I did a NotesIn9 a while back on creating a JavaObject with SSJS for something pretty similar to what you want... http://notesin9.com/index.php/2011/07/11/notesin9-ee-009-using-java-hashmaps-and-treemaps-with-xpages/

In that show I was selecting docs live rather then using just SSJS logic to grab them.

What I think you want to do is make a SSJS function that get's a hold of, and walks your view. I don't have anything like that really handy for SSJS... Java I do. But here's a function that might get you started at least.

 function getViewEntryCollection(myKey:string) {
    // this assumes sub directories are involved.
var dbPath = database.getFilePath().split(database.getFileName())[0];
var myDb:NotesDatabase = session.getDatabase(session.getServerName(),dbPath + "myNSF",false);
var myView:NotesView = myDb.getView("viewName");
var vec:NotesViewEntryCollection = myView.getAllEntriesByKey(myKey, true);
return vec
}

Now here's the interesting part. You want to loop through the documents. There's an example of that on the cheatsheet at XpagesCheatsheet.com. While looping you want to store the UNIDS.

The video I mentioned above talk about the java object hashmap and treemap. They are cool but what you need I THINK is a java LinkedHashSet .. (possible a LinkedList - not sure) in place of HashMap. The video should hopefully tell you how to create them and add to them.

Try creating it in your function and then in the loop at the UNID's to the LinkedHashSet. My understanding is that it keeps the order in which they are entered. Which is now controlled my the view.

Actually I guess you don't need the UNIDS... you can put the viewEntry right into the LinkedHashSet... would be better in the long run.

anyway - hope that helps

Dave

Upvotes: 2

Related Questions