I spent my lunch time today working more on my Time Tracker application. I added 2 new tabs. The first is an Hour Log tab that lets you see all your hours, not just the ones for today, and you can do filters by client, projects, dates, or descriptions.
The date filter was pretty interesting. SQLite has a julianday function that returns the number of days since some date in the past (I don't have the docs in front of me, let's just say it was a really, really long time ago). So to do a date comparison you can use the julianday function to compare the date in the database with what you want to filter by.
The next tab I added is a basic Stats tab, which right now uses a Flex Pie Chart to show you the total number of hours spent on projects. One tip - you won't find the docs for charting in the main developer's guide for Flex 3. Instead, go to the docs page and download Adobe Flex 3 Data Visualization Developer Guide. The description focuses on advanced stuff, but the guide also covers basic charts. Not sure if there is a difference, but it is the guide to use.
So in general, the charts are super easy to use - however, mx:Legend refuses to work for me. Check out this screen shot:

See the 3 black squares? The legend tag is smart enough to know I had 3 pie items, but refused to actually show the labels. The docs say I need to use nameField in my series (although what I really want is the labelFunction!), but even though I did that it refused to show anything. I know it's partially working because when I change the filters to result in 2 pie wedges, my legend changes as well, but I still just get little unhappy black squares (which will be the next new band to come out of London, mark my words).
Anyway - I think this is it for now. I just want to add one more feature, and that's a CSV download from the Hours Log, but after that the application will be done.
Archived Comments
Ray,
I e-mailed you the SRC with the Legend fixed and some other warnings cleaned up.
I'm still going through email, but if you didn't explain your fix, please do so here so I can learn, and others. And if you did explain it in the email, I'll blog it tomorrow. (And take full credit. Muhahaha!)
OK -
There were a number of warnings about vars that were not properly/strongly typed - so I typed those appropriately. Then I commented out 2 styles that weren't used so that they would quit throwing warnings too. Then, when I looked at the <mx:Legend> tag - I saw that you were using the same dataprovider that you were using to generate your chart. the thing with Legend is - the CHART is the dataprovider for the Legend. Changed the dataprovider for your <mx:Legend> tag and viola - she works! Now trying to figure out why "Today's Hours" doesn't load data on start (or at all apparently) when there are hours for today.
Hey now - those warnings were a feature, not a bug. ;) I swear I was going to fix them.
Thanks for the legend fix. It makes sense now - but I swear the dcos didn't say it. (Or maybe I didn't read clearly.)
Took a little digging when I first did it too... but found it here:
-----------------------------------------------
Flex Data Visualization Developer's Guide / Flex Charting Components / Displaying Data and Labels
Midway down the page under the section: "Adding a Legend control to your chart"
"You use the Legend class to add a legend to your charts. The Legend control displays the label for each data series in the chart and a key that shows the chart element for the series.
The simplest way to create a Legend control is to bind a chart to it by using the dataProvider property..."
Granted I think it should read:
"The simplest way to create a Legend control is to bind a chart to it by using the CHART AS THE dataProvider property..."
Hery Ray, would you mind showing your code and Sid's code so we can see the change. Maybe you could comment the code so we can learn by 'our' mistakes.
A couple of issues:
1) There is something wonky about your Enter Time form... I think that I hit enter in the description field and it saved the time... it also reset everything. That seems ok if I wanted to submit from there, but I was actually trying to add rows of stuff I did for that project.
2) The Today's Hours on the Enter Time tab are not showing anything even though I've recorded time.
3) If I make a mistake (see #1) there is no way for me to adjust, edit or delete my time (and where is the logical place to do that? In the Today's Hours datagrid or in the Hours Log tab?)
I can go ahead and make these changes/fixes myself (thanks for the source), but I wanted run it past you first.
@Gary - See Sid's comment, it was a very small tweak to point the dataProvider right. In the next build I'll show the exact change.
@Leif - yea, the app kinda expects you to enter stuff perfectly. I don't quite get your first comment - hitting enter submitted, but you wanted to enter more? Wouldn't you need to submit more?
As for the hours not showing up - are you running this the first time? If not - find the db for me, zip it, and send it to me. I'll use the SQLite sql tool I have and see why it's not working.
As you guys know, I struggled with this date crap, so if it isn't working still, I guess I'm not all that surprised.
Ray, what I was saying in #1 from my first comment was this. I was entering text in the description field and wanted to add a new line so that I could list some of the tasks I completed for that project. Something like:
"Worked on Features:
- Added new type to database.
- Added new view for the new type
- Reviewed new wireframes"
As you can see, I wasn't entering items on a per task basis, but basically entering them as I remembered them and placing them under one task/time entry.
I peeked into the "data.db" file on my system... I am not seeing much in those tables that makes me think that there is something wrong with dates/times as far as that goes. I'll send it to you offline.
Ray,
Think I found what may be part of the problem... Every SQLite tool I use refuses to display the "date" field in the hours table. You may want to change the NAME of the date field to something other than "date" which is a reserved word in SQLite. Also, having a field named "hours" in a table named "hours" can cause a mixup as well. Just some "poking" I did in the db to see what I could see. I know this app was never meant to be a Project like Lighthouse, Canvas, CFCBlog, and the like - but doggone it - I actually LIKE this app (as I have all your others) and I could make USE of it to track the 50 some projects I seem to end up with. All in all - Good Work, my friend.
Sid - I haven't yet had a chance to catch up on your earlier notes, or look at your db (just got done playing WoW) - but I can say that I had no issues with the 'date' col on my side. I'm going to test your db though to see if yours act differently.
Yeah, I've looked at the db in both SQLAmdinistrator and SQLite Maestro and both of them show the date field as 'null' even though I know the data is in there. Means that data is either being stored in a very "odd" fashion (as in not the EXPECTED fashion that SQLite expects for a field of type DATE) or that there is some kind of conflict with a reserved word (date) being used as a field name. I have run into this issue (reserved words as field names) in MS SQL, MySQL, and Oracle - so I can't imagine that SQLite is much different in that respect. My true suspect is that the data is being stored in an "unexpected" format - as I can view the dates inside the App with the "log" view - but that it after your item renderer "massages" it a bit.
Nice app. Ray I can really use this!
One question... can hour records not be deleted?
There is no delete yet. I was thinking I'd add a delete, but no edit, since the records are, in general, so small.
@Sid - we may need to move to IM for this. I opened your DB on my system here, and it showed the column as date. I was also able to do date type sql operations on it.
How about you hit me up via IM. It may be quicker that way.
@Leif - I see what you mean. I think it's a change Kyle made to make it easier to enter hours, but it's definitely a bad idea now. I'll fix that after I apply Sid's fixes.
FYI, I found a new bug that maybe you guys can help me with. I removed the code to make the Enter key submit hours, but when I submit a description with line breaks, only line 1 is stored. It seems like my insert statement is barging on multi-line strings, even though I'm using bound parameters.