Statistics
| Branch: | Tag: | Revision:

root / Classes / LBVirtualIPTypeViewController.m @ 64929bae

History | View | Annotate | Download (7.1 kB)

1
//
2
//  LBVirtualIPTypeViewController.m
3
//  OpenStack
4
//
5
//  Created by Mike Mayo on 5/2/11.
6
//  Copyright 2011 __MyCompanyName__. All rights reserved.
7
//
8

    
9
#import "LBVirtualIPTypeViewController.h"
10
#import "OpenStackAccount.h"
11
#import "LoadBalancer.h"
12
#import "AccountManager.h"
13
#import "UIViewController+Conveniences.h"
14
#import "LBLinkSharedVIPViewController.h"
15

    
16
#define kPublic 0
17
#define kServiceNet 1
18
#define kSharedVirtualIP 2
19

    
20
@implementation LBVirtualIPTypeViewController
21

    
22
@synthesize account, loadBalancer;
23

    
24
- (id)initWithAccount:(OpenStackAccount *)a loadBalancer:(LoadBalancer *)lb {
25
    self = [self initWithNibName:@"LBVirtualIPTypeViewController" bundle:nil];
26
    if (self) {
27
        self.account = a;
28
        self.loadBalancer = lb;
29
        descriptions = [[NSDictionary alloc] initWithObjectsAndKeys:
30
                        @"This Load Balancer is accessible over the Internet.", @"Public", 
31
                        @"This Load Balancer can only be reached from within the data center. Inbound and outbound bandwidth fees don’t apply.", @"ServiceNet", 
32
                        @"Share a common address between multiple load balancers. Useful to balance HTTP and HTTPS on a common IP for DNS. Unique ports must be used for each load balancer behind the IP.", @"Shared Virtual IP",
33
                        nil];
34
    }
35
    return self;
36
}
37

    
38
- (id)initWithStyle:(UITableViewStyle)style
39
{
40
    self = [super initWithStyle:style];
41
    if (self) {
42
        // Custom initialization
43
    }
44
    return self;
45
}
46

    
47
- (void)dealloc
48
{
49
    [account release];
50
    [loadBalancer release];
51
    [descriptions release];
52
    [super dealloc];
53
}
54

    
55
- (void)didReceiveMemoryWarning
56
{
57
    // Releases the view if it doesn't have a superview.
58
    [super didReceiveMemoryWarning];
59
    
60
    // Release any cached data, images, etc that aren't in use.
61
}
62

    
63
#pragma mark - View lifecycle
64

    
65
- (void)viewDidLoad {
66
    [super viewDidLoad];
67
    self.navigationItem.title = @"Virtual IP Type";
68
}
69

    
70
- (void)viewDidUnload
71
{
72
    [super viewDidUnload];
73
    // Release any retained subviews of the main view.
74
    // e.g. self.myOutlet = nil;
75
}
76

    
77
- (void)viewWillAppear:(BOOL)animated
78
{
79
    [super viewWillAppear:animated];
80
}
81

    
82
- (void)viewDidAppear:(BOOL)animated
83
{
84
    [super viewDidAppear:animated];
85
}
86

    
87
- (void)viewWillDisappear:(BOOL)animated
88
{
89
    [super viewWillDisappear:animated];
90
}
91

    
92
- (void)viewDidDisappear:(BOOL)animated
93
{
94
    [super viewDidDisappear:animated];
95
}
96

    
97
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
98
    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
99
}
100

    
101
#pragma mark - Table view data source
102

    
103
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {    
104
    NSString *endpoint = [self.account loadBalancerEndpointForRegion:self.loadBalancer.region];
105
    return [self.account.loadBalancers objectForKey:endpoint] > 0 ? 3 : 2;
106
}
107

    
108
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
109
    return 2;
110
}
111

    
112
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
113
    if (indexPath.row == 0) {
114
        return tableView.rowHeight;
115
    } else {
116
        NSString *description = @"";
117
        if (indexPath.section == kPublic) {
118
            description = [descriptions objectForKey:@"Public"];
119
        } else if (indexPath.section == kServiceNet) {
120
            description = [descriptions objectForKey:@"ServiceNet"];
121
        } else if (indexPath.section == kSharedVirtualIP) {
122
            description = [descriptions objectForKey:@"Shared Virtual IP"];
123
        }
124
        UIFont *font = [UIFont systemFontOfSize:14];
125
        CGSize size = [description sizeWithFont:font constrainedToSize:CGSizeMake(tableView.frame.size.width - 40, 25000) lineBreakMode:UILineBreakModeWordWrap];
126
        return 30 + size.height;
127
    }
128
}
129

    
130
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
131
    static NSString *CellIdentifier = @"Cell";
132
    
133
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
134
    if (cell == nil) {
135
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
136
        cell.textLabel.backgroundColor = [UIColor clearColor];
137
        cell.detailTextLabel.numberOfLines = 0;
138
    }
139
    
140
    // Configure the cell...
141
    if (indexPath.row == 0) {
142
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
143
        cell.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"grey-highlight.png"]] autorelease];
144
    } else {
145
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
146
    }
147

    
148
    if (indexPath.section == kPublic) {
149
        if (indexPath.row == 0) {
150
            cell.textLabel.text = @"Public";
151
            cell.detailTextLabel.text = @"";
152
        } else {
153
            cell.textLabel.text = @"";
154
            cell.detailTextLabel.text = [descriptions objectForKey:@"Public"];
155
        }
156
    } else if (indexPath.section == kServiceNet) {
157
        if (indexPath.row == 0) {
158
            cell.textLabel.text = @"ServiceNet";
159
            cell.detailTextLabel.text = @"";
160
        } else {
161
            cell.textLabel.text = @"";
162
            cell.detailTextLabel.text = [descriptions objectForKey:@"ServiceNet"];
163
        }
164
    } else if (indexPath.section == kSharedVirtualIP) {
165
        if (indexPath.row == 0) {
166
            cell.textLabel.text = @"Shared Virtual IP";
167
            cell.detailTextLabel.text = @"";
168
        } else {
169
            cell.textLabel.text = @"";
170
            cell.detailTextLabel.text = [descriptions objectForKey:@"Shared Virtual IP"];
171
        }
172
    }
173
    
174
    if ([self.loadBalancer.virtualIPType isEqualToString:cell.textLabel.text]) {
175
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
176
        [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
177
    } else {
178
        cell.accessoryType = UITableViewCellAccessoryNone;
179
        [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
180
    }
181
    
182
    return cell;
183
}
184

    
185
#pragma mark - Table view delegate
186

    
187
- (void)selectRow:(NSTimer *)timer {
188
    [self.tableView selectRowAtIndexPath:[timer.userInfo objectForKey:@"indexPath"] animated:NO scrollPosition:UITableViewScrollPositionNone];
189
}
190

    
191
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
192
    if (indexPath.row == 1) {
193
        [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:indexPath.section] animated:NO scrollPosition:UITableViewScrollPositionNone];
194
    }
195
    
196
    if (indexPath.section == kPublic) {
197
        self.loadBalancer.virtualIPType = @"Public";
198
    } else if (indexPath.section == kServiceNet) {
199
        self.loadBalancer.virtualIPType = @"ServiceNet";
200
    } else if (indexPath.section == kSharedVirtualIP) {
201
        self.loadBalancer.virtualIPType = @"Shared Virtual IP";
202
        LBLinkSharedVIPViewController *vc = [[LBLinkSharedVIPViewController alloc] initWithAccount:self.account loadBalancer:self.loadBalancer];
203
        [self.navigationController pushViewController:vc animated:YES];
204
        [vc release];
205
    }    
206

    
207
    [self.tableView reloadData];
208
}
209

    
210
@end