Google Calendar API - Modifying optParams - arrays

I finally managed to get my events out of the google calendar, but a executive decission was made and it was to switch the list of events around so that the last event is first on-screen. I think that the easiest way would be to change the optParams 'orderBy' to something other than startTime. So that it arrieves in descending order instead. But I have no idea how to alter this, so thats why I am here. If anyone have a way to flip the gianorums array around, then that is fine too.
It might be a bit too little to work with, but if you have done this before, you might know what I mean. Otherwise, please just leave it.

Possible late, but my coarse of action with objects and displaying results is to have an array in between. In this case I would use
$eventList = $service->events->listEvents($calendar->getId() , $optParams);
then I would use this:
foreach($eventList->getItems() as $event) {
$eventArray[]=$event->getSummary();
}
And then this:
$reverseEventArray = array_reverse($eventArray, false);

Related

Best, Better, or Simpler Way to Get the Label for a Content-Type's Field

I thought I was doing something easy, but it got so complicated that I feel like I am missing something. We have a Content-Type (CT) that moves through a workflow. In each phase of the workflow, the output changes which fields are visible.
We want to easily access both the record's Value and Label. In other words, lets say we have a CT named EventInstance and one of fields is Url. So in code we normally just do #Content.Url. However, for table headings (and in other output) we want to display "Website Link (Url)" instead of "Url". So in the CT we simply changed the Name* (Label):
So then I went looking for how to get that "Label" field (2) instead of the Name (1). What I came up with was this. But it seems crazy complicated...
public string GetLabelForField(dynamic de, string fieldName)
{
var attributes = AsEntity(de).Type.Attributes as IEnumerable<IContentTypeAttribute>;
return attributes.First(t => t.Name == fieldName).Metadata.GetBestValue<string>("Name", "#All");
}
And I call it like this
var ev = listEvent.First();
<pre>
help.GetLabelForField(ev): #help.GetLabelForField(ev, "Url")
</pre>
And that outputs what I want:
help.GetLabelForField: Website Link (Url)
I realize I should be satisfied because it works, but it seems like a lot of work and a steep learning curve. Is there a better way to get access to this (seemingly common) property?
These APIs are not documented much, because accessing input-field configuration used in the Edit-UI isn't that common.
But: I believe you could also do this (shorter, but probably not perfect):
var attribute = AsEntity(de).Type[fieldName];
var name = attribute.Metadata.GetBestValue<string>("Name");

Implementing "tab completion" in RichEdit Winapi

This is a feature you see in a lot of IRC clients. Basically, if you type a string "Ad" and then hit tab the client will fill in the first matching nick (in the case of an IRC client) mathcing 'Ad' - so let's say it fills in Adam. But, like bash, if you keep hitting tab it should cycle through all the names containing "Ad" as a prefix.
I'm not quite sure how to implement this in the Wndproc for a RichEdit though. Specifically, when a user hits tab I need to get the current 'token', save it, and get all the prefixes and fill in the first. If he hits tab again I need to get the next prefix, and so on, but I need to empty the prefix list once I get a WM_CHAR that's not tab -- I think?
I'm wondering if there's some easier, less hacky way though, or if anybody has seen code that does this?
Thanks.
Useful though Remy's comments are, it seems to me that this question is more about what the logic should be to implement kind-of-bash-style auto-completion than anything else. On that basis, and based on what you posted, which I found slightly confusing, I think it should be something like this (pseudo-code);
int autocomplete_index = 0;
string autocomplete_prefix;
on_tab:
if (autocomplete_prefix == "")
{
autocomplete_prefix = current_contents_of_edit_field ();
autocomplete_index = 0;
}
auto autocomplete_result = get_autocomplete_string (autocomplete_prefix, autocomplete_index++);
if (autocomplete_result != "")
replace_contents_of_edit_field_and_move_caret_to_end (autocomplete_result);
else
beep (); // or cycle round
done;
on_any_other_char:
autocomplete_prefix = "";
If the rich edit control is embedded in a dialog, you also need to ensure that the dialog manager does not speak in and snaffle VK_TAB before you do. That normally doesn't happen for rich edit controls (although it does for regular edit controls - go figure) but if it does you can handle WM_GETDLGCODE appropriately in your WndProc (details on request).
And 'hacky'? Why? I don't think so. Sounds like a good idea to me.

ngAnimate to detect changes from $http-call with interval

I have an array with a few items in it. Every x seconds, I receive a new array with the latest data. I check if the data has changed, and if it has, I replace the old one with the new one:
if (currentList != responseFromHttpCall) {
currentList = responseFromHttpCall;
}
This messes up the classes provided by ng-animate, as it acts like I replaced all of the items -- well, I do actually, but I don't know how to not.
These changes can occur in the list:
There's one (or more) new item(s) in the list - not necessaryly at the end of the list though.
One (or more) items in the list might be gone (deleted).
One (or more) items might be changed.
Two (or more) items might have been swapped.
Can anyone help me in getting ng-animate to understand what classes to show? I made a small "illustation" of my problem, found here: http://plnkr.co/edit/TS401ra58dgJS18ydsG1?p=preview
Thanks a lot!
To achieve what you want, you will need to modify existing list on controller (vm.list) on every action. I have one solution that may work for your particular example.
you would need to compare 2 lists (loop through first) similar to:
vm.list.forEach((val, index)=>{
// some code to check against array that's coming from ajax call
});
in case of adding you would need to loop against other list (in your case newList):
newList.forEach((val, index)=>{
// some code to check array on controller
});
I'm not saying this is the best solution but it works and will work in your case. Keep in mind - to properly test you will need to click reset after each action since you are looking at same global original list which will persist same data throughout the app cycle since we don't change it - if you want to change it just add before end of each function:
original = angular.copy(vm.list);
You could also make this more generic and put everything on one function, but for example, here's plnkr:
http://plnkr.co/edit/sr5CHji6DbiiknlgFdNm?p=preview
Hope it helps.

Paging with reverse cursors in appengine

I am trying to get forward and backwards pagination working for a query I have on my app.
I have started with the example at: https://developers.google.com/appengine/docs/python/ndb/queries#cursors
I would expect that example to do a typical forward/back pagination to create cursors that you can pass to your template in order to be used in a subsequent request for the page after/before the current one. But what it is doing is getting cursors for the same page, one from the beginning and the other from the end (if I have understood correctly).
What I want is a cursor to the beginning of the following page, and a cursor to the beginning of the previous page, to use in my UI.
I have managed to almost get that with the following code, based on the mentioned example:
curs = Cursor(urlsafe=self.request.get('cur'))
q = MyModel.query(MyModel.usett == usett_key)
q_forward = q.order(-MyModel.sugerida)
q_reverse = q.order(MyModel.sugerida)
ofus, next_curs, more = q_forward.fetch_page(num_items_page,
start_cursor=curs)
rev_cursor = curs.reversed()
ofus1, prev_curs, more1 = q_reverse.fetch_page(num_items_page,
start_cursor=rev_cursor)
context = {}
if more and next_curs:
context['next_curs'] = next_curs.urlsafe()
if more1 and prev_curs:
context['prev_curs'] = prev_curs.reversed().urlsafe()
The problem, and the point of this question, is that I use more and more1 to see if there is a next page. And that is not working in the backwards sense. For the first page, more1 is True, in the second page more1 is False, and subsequent pages give True.
I would need something that gives False for the first page and True for every other page. It seems like this more return value is the thing to use, but maybe I have a bad Query setup, or any other thing wrong.
Thanks everyone!
Edit: Since I didn't find a simple solution for this, I switched to using ndbpager.
There's no such thing.
You know thats theres (at least) one page before the current page if you started the query with a cursor (the first page usualy dosnt have a cursor).
A common trick to access the previous page is inverting the sort-order.
If you have a list, sorted by creationdate desc, you could take the creationdate of the first element of your current page, query for elements with creationdate < this creationdate using inverted sort order. This will return the oldest elements which are newer then the given creationdate. Flip the list of retrived elements (to bring them into the correct order again) and there you have the elements of the page before, without using a cursor.
Note: this requires the values of your sortorder beeing distinct.
In some cases, its also possible to use a prebuild index allowing random-access to different pages, see https://bitbucket.org/viur/server/src/98de79b91778bb9b16e520acb28e257b21091790/indexes.py for more.
I have a workaround and not the best solution. it is baiscally redirecting back to the previous page.
Previous
I think PagedQuery has the capability but still waiting for someone to post a more comprehensive tutorial about it.

How to reset vote count in bugzilla

I am using Bugzilla 3.6.3. I would like to reset the vote count for a bug back to zero if the status is changed to UNCONFIRMED. What perl file and method do I do this in and how would I do this?
There are a couple of different ways to do this, both involving hooks:
http://www.bugzilla.org/docs/3.6/en/html/api/Bugzilla/Extension.html
There are examples of how to use the hooks in extensions/Example/Extension.pm.
The way I would do this would be to use the bug_end_of_update hook.
There's code in extensions/Example/Extension.pm that is almost exactly what you want. If one of the changes is to bug_status and the new value is UNCONFIRMED, then directly manipulate the database to reset the number of votes to 0, i.e. DELETE FROM bugs WHERE bug_id = ?
The other way to do this would be to use object_end_of_update, which is basically the same as bug_end_of_update, but you'd have to check that the object is a Bugzilla::Bug.

Resources