[ 78 posts ] Go to page Previous1, 2, 3, 4, 5, 6 ... 8 Next

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Thu Sep 09, 2010 5:54 am
+0-
@L Ravi Kiran

At first I didn't know what you meant by freezing, I had to look at the code to see that you meant that the row would remain in place when sorting. I see that you plan to freeze columns as well, but I don't understand what that would mean.

Anyway, since you are asking for feedback, this is what I would suggest:

Add a configuration attribute that can take a function that identifies which records are to be frozen. You can't count on your data to have a specific field name to identify those records. I guess that allowing the developer to provide a function to make that identification would be the best. The function would receive the Record instance and return a boolean.

Though you expect more than one record to be frozen in sortRecords, I believe you can't handle more than one record frozen in reverseRecords. Perhaps the easiest way to do it is to use array.splice to pull out the frozen records, let the original methods do their thing and then use splice again to re-insert those records in their original positions.

It is usually better to extend the original component so that you can still count on the original component to do their thing. Instead of fully replacing sortRecords, you could do the splicing out, call the original sortRecords and then splice the frozen records back in. You would use YAHOO.lang.extend to create a new flavor of DataTable instead of augmenting the existing DataTable.

With RecordSet is more tricky because DataTable expects to create instances of RecordSet and it will not create any other flavor of it. There are two ways of doing this. One is overriding DataTable's _initRecordSet which is, I believe, the only place where it creates the RecordSet instance so you can create your specific flavor of RecordSet.

The other way (if _initRecordSet was not available or if there were too many places to fix) would be to copy the reference of YAHOO.widget.RecordSet to another variable and make YAHOO.widget.RecordSet point to your flavor of RecordSet, which would inherit from the original which you preserved elsewhere.

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Thu Sep 09, 2010 6:35 am
+0-
Matt,

I think I didn't opt for the best solution and you have the right of it. The way it now works is that you define your DataSource and DataSchema and tell it which fields there are and it will read all of them and add default FieldDefs for everything that comes in that is not already defined. So, in the way it is now, you are not forced to have FieldDefs for fields you don't care much about. If there is a FieldDef for a particular field, it will use it, in this case, it will take the server.parser function. In the way you suggest, which seems more formal, you would have to have FieldDefs for all fields because the resultFields would be build out of that.

Perhaps I could have it both ways. If there is no resultFields defined, take them from the FieldsDefs for the RecordSet, otherwise, accept what there is.

Regarding 'visible' I have it all messed up in my mind along with filtering. I can't figure out a way of doing it properly. Filtering out visible records is no different than filtering page one for a paged DataTable. To start with, I'm not sure if it should be a Record attribute or it should be a filtering function.

I'm not sure about setting 'visible' on a FieldDefs either (column instead of record visibility). I am more inclined to think that it would be up to the UI widget to decide on that though, I guess, it might be both ways, have the 'visible' fieldDef attribute (for example, on primary keys) and be able to override it in the UI widget as well.

I am quite sure by now that I can't have RecordSet be augmented from ArrayList just like that. Filtering is one reason, I can't let, say, DataTable, loop through all the records via ArrayList.each(). Also, I need to keep in mind missing records when using server-side paging. I should fire an event when a Record is not there (either by using the search() method to fetch by key or the item() method to search by index) so that a new request can be sent to the server.

The enumerating function should also be able to take a start index and item count so it can loop through a specific page of Records.

I know I'm missing lots in the area of events. Sort should first fire an event and the actual sorting function should be the default action for that event. That would allow, for example, to handle server-side sorting.

And I'm unhappy with sing 'key' to refer to the field name. I guess I'll go on and replace fieldName for key everywhere.

Thanks for the ideas. I have two more clear items on my todo list and the filtering stuff I'm still unclear about.

Matt Parker

YUI Contributor

  • Username: mattatlamplight
  • Joined: Mon Apr 20, 2009 12:03 pm
  • Posts: 466
  • Location: London UK
  • GitHub: mattparker
  • Gists: mattparker
  • Offline
  • Profile
Tags:

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Thu Sep 09, 2010 7:00 am
+0-
Satyam,

"I am quite sure by now that I can't have RecordSet be augmented from ArrayList just like that." Not doubting you, but why not?

And if not, can we use the interface, so there's still RecordSet.each(), for example?

Another thought, without any idea of the answer. Would it make things easier if there were a RecordSet, RecordSetLocal and RecordSetRemote (or whatever they're called). RecordSet would be 'abstract', and RecordSetLocal and RecordSetRemote be the ones people actually use?

Re. visible: I was thinking that filters, paginators etc would set the visible flag of each Record, and then RecordSet would need a getVisible() or something so the UI only receives Records it needs (and here's a question: would it receive a new RecordSet that's contains a subset of the 'master' RecordSet.). This is about the point where I need to go and make a cup of tea!!! Although I can see the advantages - e.g. applying multiple filters.

so, (not tried this or anything, prob got YUI3 syntax wrong, but the idea):
Code:
RecordSet.filter( function(){ return this.get("color") == "green"; });

// and

  filter : function ( filterFn ) {
   this.each( function (r) {
      // do this in bits and maintain a current visible hash in RecordSet
      // so we don't have to keep iterating on every .getVisible() call
      var isVisible = filterFn.apply(r);
      if (isVisible) {
        this._currentVisible[r.get("fieldName")] = r;
      }
      r.set("visible", isVisible);
   });
  // and tell the ui subscribers
  this.fire("visibleChange"); 
},

  getVisible : function () {
     // or should this._currentVisible be a RecordSet that has add() and remove()
     // called on it by filter and others?  Probably.
     return new RecordSet(this._currentVisible);

  }

 


And you're right, paginating is just a variation on this based on position of the record in the set.

Matt

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Thu Sep 09, 2010 7:33 am
+0-
I would like to keep the public interface of ArrayList, methods like each() and item() but I'm afraid that I wouldn't be able to keep any of the implementation of it, since ArrayList always assumes that what it has is all there is and allows for no filtering. So, it is the implementation of ArrayList the one I cannot keep and as for the method names, some might not be possible or might need to have extra arguments.

In terms of filtering, visible would be one more filter and I believe I would have to allow to pipe records from one filter to the next. For example, a request for a certain page of visible records might require piping first from the 'visible' filter into the 'skip nth records' then to the 'count nth records'.

The order of these filters matters because, currently, if you want to filter on display (for example, via a row formatter) you get pages of different lengths since DataTable first picks rowsPerPage records and only then you get a chance to filter out, but you can't add extras to compensate for the ones you filtered out.

An item that has long been in my wishlist was paginating by initial(s) or date or other value ranges instead of plain page numbers. Filtering would allow this.

I'm not sure about putting DataSource functionality into RecordSet, I might be overstepping beyond safe boundaries if I set the schema on the DataSource automatically. In fact, that might be a reason to prevent me from doing it. The way you suggested, by using some getKeys() or getFieldList() might be proper.

Luke Smith

YUI Contributor

  • Username: lsmith
  • Joined: Thu Aug 28, 2008 7:50 am
  • Posts: 514
  • Location: Sunnyvale
  • Twitter: ls_n
  • GitHub: lsmith
  • Gists: lsmith
  • IRC: ls_n
  • YUI Developer
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Thu Sep 09, 2010 9:05 am
+0-
The ArrayList API doesn't include mutation/filtration methods by default to support augmenting classes that should be immutable. And mutation methods should emit events, which would add module requirements inappropriate for simpler collection classes. NodeList will be augmented with ArrayList in an upcoming version, but Matt is also exploring mutation methods for NodeLists.

For today, have a look at WidgetParent for a reference implementation that includes mutability (and events).

With that in mind, would ArrayList still be a poor fit for augmentation? If so, for structural reasons or because some functionality is inappropriate or missing?

Greg Hinch

YUI Contributor

  • Username: greghinch
  • Joined: Wed Jun 03, 2009 10:49 am
  • Posts: 73
  • Location: Fairfax, CA , USA
  • Twitter: greghinch
  • GitHub: ghinch
  • Gists: ghinch
  • IRC: gr-eg
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Thu Sep 09, 2010 9:32 pm
+0-
I'd like to throw my 2 cents in on this (sorry if it's a bit late, I was in meetings all day and only now was able to read all the thoughts coming in).. I'm not sure I agree with the idea that the fieldDefs are a property of the RecordSet. In my mind, all of that data lives with the fields on the Record itself. The Record should be a base constructor which you extend to represent various types of data you have. Fields could be a property of the class you create, similar to ATTRS now. Each field definition in that array could have all of what has been discussed already (a key, a way to parse and serialize itself for the server, a way to present, edit, and validate edits in the UI).

What I've found is that in working with the current Records/RecordSets from the YUI 2 DataTable, it is very convenient to pass around the Record instances themselves, but passing around the RecordSet itself as well is an extra burden. For example say I have a table representing a collection of books, and I want to click on one and edit it, I can have a BookEditor widget that takes a Record that represents a book, and draw itself accordingly as a form. I may also want to take books and push them into a cart for checking out, and that widget can also take a book Record and draw what it needs to (likely a small subset of the data).

In this new model, I would have a Book class, which has defined a number of fields. In my DataTable, I can define which keys I want to show, and then load in a set of Books, and each of those fields knows how to format itself for the UI and renders appropriately. Similarly, I go to edit one, and the BookEditor just has to take the Book instance and draw all the editors for the fields in the Book. Additionally, knowing that we are going to be working with Book instances, we can take the constructor class and easily define a DataSchema in JSON or XML or whatever from the fields defined there. Records could probably even have simple CRUD in user defined methods, though batch operations would be best handled elsewhere.

In this case the RecordSet itself becomes a lot more abstract. In fact, I'm not even sure we need an actual RecordSet class. Certainly there is a need for coordinating class that has a DataSource and a Record definition, and is able to make requests to the server (or take static data) an turn the results into an array of Records. But I would imagine it could just fire an event when it has that array, basically saying "anyone who wants these can have them."

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Thu Sep 09, 2010 11:00 pm
+0-
Greg,

I half agree with you and I mean to separate the FieldsDefs from RecordSet, but I don't want to attach it to each Record either since with tabular data, with several Records, that would be redundant and is open to the possibility of having Records in the same set pointing to different FieldsDefs. Thus, I plan to have the FieldsDefs a separate object which will normally be associated to a RecordSet and can be passed to Records to perform some of their duties. You would be able to have Records out of a RecordSet but you would need to provide a reference to a FieldsDefs for some of its methods, as RecordSet would.

I don't like the idea of subclassing Record, it would be the same as attaching a FieldsDefs to each Record. It is very OOPish but it is an unnecessary steep price for beginners. I'm still a little scared to thing this might already be a little too much the way I'm planning, I wouldn't want to add any more burden to developers.

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Thu Sep 09, 2010 11:07 pm
+0-
Luke,

Widget-Parent uses ArrayList but only overrides add and remove. I would need to override almost all other methods.

For a server-side paged set, I need to override item() so that if the item is not found, I can fire an event that will trigger a request to the DataSource to load that page.

If I use filtering, I can't use each() and some() since I have to get filtering functions stand in between the caller to each() and the actual array.

Widget-Parent rests at ease knowing that there are no more items than it has and that all items are good, none needs to be filtered out. Only add and remove need some special handling.

Matt Parker

YUI Contributor

  • Username: mattatlamplight
  • Joined: Mon Apr 20, 2009 12:03 pm
  • Posts: 466
  • Location: London UK
  • GitHub: mattparker
  • Gists: mattparker
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Fri Sep 10, 2010 12:36 am
+0-
Greg,

Don't we need a RecordSet class for sorting and filtering?

And your mention of CRUD - I was starting to wonder how we want to be thinking in database terms. For example, I was wondering on my way in this morning if we ought to give any thought to ACL in this? On a web-page it's probably not relevant, but did we ought to be starting to think about js as on the server too - node.js - or is that getting ahead of ourselves...

More generally, is it unhelpful to be thinking of RecordSets as (database) tables and Records as (database) rows, or in terms of Table Data Gateway or somesuch patterns?

All questions, no answers...!

Matt

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: YUI: Open Hours Wed Aug 18th

Post Posted: Fri Sep 10, 2010 4:59 am
+0-
Matt,

I think that Greg's point is not that there should be no RecordSet at all but that Records should have a life of their own. Forms, for example, cannot show more than one Record at a time so Records need to have some independence of RecordSets.

It would be great to have a DataSource.SQL to use in Node.js, whenever the time comes for Node.js to have access to any SQL engine: (good question for Dav for next Open Hours) or even some noSQL engine (which it should be possible right now since some NoSql engines use HTTP requests: note to Dav: some demo would be great), though NoSql engines are not really suited to serve tabular data but documents.

In either case, RecordSets would be the natural mechanism for all this to happen, after all, they do parsing and serialization so they could work nicely on both sides. The RecordSet on Node.js would not have any storage, all requests would produce a page fault which should be served by the DataBase engine .... or the storage for RecordSet would be the DataBase engine itself. Never mind, I hadn't thought about Node.js and YUI on the server side until right now that I read your message, so I'm just brainstorming .... more storming than braining. Luke: another guest for our not so open hours?
  [ 78 posts ] Go to page Previous1, 2, 3, 4, 5, 6 ... 8 Next
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum