2 // APILogsViewController.m
5 // Created by Mike Mayo on 10/11/10.
6 // The OpenStack project is provided under the Apache 2.0 license.
9 #import "APILogsViewController.h"
10 #import "OpenStackAccount.h"
12 #import "APILogEntry.h"
13 #import "UIViewController+Conveniences.h"
14 #import "ActivityIndicatorView.h"
15 #import "LogEntryViewController.h"
18 @implementation APILogsViewController
22 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
23 return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
27 #pragma mark Button Handlers
29 - (void)refreshButtonPressed:(id)sender {
30 activityIndicatorView = [[ActivityIndicatorView alloc] initWithFrame:[ActivityIndicatorView frameForText:@"Loading..."] text:@"Loading..."];
31 [activityIndicatorView addToView:self.view];
33 loggerEntries = [APILogger loggerEntries];
35 [activityIndicatorView removeFromSuperviewAndRelease];
37 [self.tableView reloadData];
41 #pragma mark View lifecycle
46 self.navigationItem.title = @"API Logs";
48 UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshButtonPressed:)];
49 self.navigationItem.rightBarButtonItem = refreshButton;
50 [refreshButton release];
53 - (void)viewWillAppear:(BOOL)animated {
54 [super viewWillAppear:animated];
55 [self refreshButtonPressed:nil];
59 - (void)viewDidAppear:(BOOL)animated {
60 [super viewDidAppear:animated];
64 - (void)viewWillDisappear:(BOOL)animated {
65 [super viewWillDisappear:animated];
69 - (void)viewDidDisappear:(BOOL)animated {
70 [super viewDidDisappear:animated];
75 #pragma mark Table view data source
77 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
78 // Return the number of sections.
83 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
84 // Return the number of rows in the section.
85 return entriesLoaded ? [loggerEntries count] : 0;
89 // Customize the appearance of table view cells.
90 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
92 static NSString *CellIdentifier = @"Cell";
94 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
96 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
97 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
100 // Configure the cell...
102 APILogEntry *entry = [loggerEntries objectAtIndex:indexPath.row];
103 cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", entry.requestMethod, [entry.url path]];
104 cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", entry.responseStatusMessage];
106 if (entry.responseStatusCode == 0) {
107 cell.detailTextLabel.text = @"No response";
110 if (entry.responseStatusCode < 200 || entry.responseStatusCode >= 300) {
111 cell.textLabel.textColor = [UIColor redColor];
112 cell.detailTextLabel.textColor = [UIColor redColor];
114 cell.textLabel.textColor = [UIColor blackColor];
115 cell.detailTextLabel.textColor = [UIColor grayColor];
122 #pragma mark Table view delegate
124 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
125 LogEntryViewController *vc = [[LogEntryViewController alloc] initWithNibName:@"LogEntryViewController" bundle:nil];
126 vc.logEntry = [loggerEntries objectAtIndex:indexPath.row];
127 [self.navigationController pushViewController:vc animated:YES];
133 #pragma mark Memory management
135 - (void)didReceiveMemoryWarning {
136 // Releases the view if it doesn't have a superview.
137 [super didReceiveMemoryWarning];
139 // Relinquish ownership any cached data, images, etc that aren't in use.
142 - (void)viewDidUnload {
143 // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
144 // For example: self.myOutlet = nil;