Permalink
Browse files

Handle pages in UI for Parking

And restrict filter search.
  • Loading branch information...
CyrilPeponnet committed Mar 23, 2016
1 parent 9bffcaa commit 220801d942acd8c49252072122b13fcf5b9d650d
@@ -28,6 +28,7 @@
@import <TNKit/TNAlert.j>
@import <TNKit/TNTableViewDataSource.j>
@import <TNKit/TNTableViewLazyDataSource.j>
@import "../../Model/TNModule.j"
@import "../../Views/TNButtonBar.j"
@@ -103,7 +104,7 @@ var TNModuleControlForSubscribe = @"Subscribe",
TNTableViewDataSource _virtualMachinesDatasource;
TNTableViewDataSource _virtualMachinesNotManagedDatasource;
TNTableViewDataSource _virtualMachinesParkedDatasource;
TNTableViewLazyDataSource _virtualMachinesParkedDatasource;
}
@@ -247,7 +248,7 @@ var TNModuleControlForSubscribe = @"Subscribe",
[buttonBarNotManagedVMControl setButtons:[[self buttonWithIdentifier:TNModuleControlForManage]]];
// Parked VM Table View
_virtualMachinesParkedDatasource = [[TNTableViewDataSource alloc] init];
_virtualMachinesParkedDatasource = [[TNTableViewLazyDataSource alloc] init];
[tableVirtualMachinesParked setDelegate:self];
[tableVirtualMachinesParked setTarget:self];
[tableVirtualMachinesParked setDoubleAction:@selector(openParkedXMLEditor:)];
@@ -288,6 +289,7 @@ var TNModuleControlForSubscribe = @"Subscribe",
[VMSubscriptionController setDelegate:self];
[VMCloneController setDelegate:self];
[VMManagerController setDelegate:self];
[VMParkingController setDataSource:_virtualMachinesParkedDatasource];
[VMParkingController setDelegate:self];
TNHypervisorVMCreationControllerLibvirtIcon = CPImageInBundle(@"libvirt-icon.png", nil, [CPBundle bundleForClass:[self class]]);
@@ -318,6 +320,10 @@ var TNModuleControlForSubscribe = @"Subscribe",
[tableVirtualMachinesParked setDelegate:nil];
[tableVirtualMachinesParked setDelegate:self];
if ([tabViewVMs selectedTabViewItem] == nil)
[tabViewVMs selectFirstTabViewItem:nil];
// simulate a tab change
[self tabView:tabViewVMs didSelectTabViewItem:[tabViewVMs selectedTabViewItem]];
@@ -332,6 +338,7 @@ var TNModuleControlForSubscribe = @"Subscribe",
[VMSubscriptionController closeAddSubscriptionWindow:nil];
[VMSubscriptionController closeRemoveSubscriptionWindow:nil];
[VMAllocationController closeWindow:nil];
[VMParkingController reset];
[super willHide];
}
@@ -388,6 +395,7 @@ var TNModuleControlForSubscribe = @"Subscribe",
[_virtualMachinesDatasource removeAllObjects];
[_virtualMachinesNotManagedDatasource removeAllObjects];
[_virtualMachinesParkedDatasource removeAllObjects];
[VMParkingController reset];
[tableVirtualMachines reloadData];
[tableVirtualMachinesNotManaged reloadData];
@@ -453,6 +461,7 @@ var TNModuleControlForSubscribe = @"Subscribe",
}
if ([[tabViewVMs selectedTabViewItem] identifier] == @"tabViewItemParkedVM")
[VMParkingController reset];
[VMParkingController listParkedVirtualMachines];
return YES;
@@ -975,6 +984,7 @@ var TNModuleControlForSubscribe = @"Subscribe",
break;
case @"tabViewItemParkedVM":
[VMParkingController reset];
[VMParkingController listParkedVirtualMachines];
break;
}
@@ -27,6 +27,27 @@
@import <StropheCappuccino/TNXMLNode.j>
@import <StropheCappuccino/TNStropheStanza.j>
@import <TNKit/TNAlert.j>
@import <TNKit/TNTableViewLazyDataSource.j>
@implementation TNTableViewLazyDataSource (paginate)
- (id)tableView:(CPTableView)aTable objectValueForTableColumn:(CPNumber)aCol row:(CPNumber)aRow
{
var identifier = [aCol identifier];
if (!_currentlyLoading
&& [_content count] < _totalCount
&& (aRow + _lazyLoadingTrigger >= [_content count])
&& _delegate
&& [_delegate respondsToSelector:@selector(tableViewDataSourceNeedsLoading:)])
{
_currentlyLoading = YES;
[_delegate tableViewDataSourceNeedsLoading:self];
}
return [_content[aRow] valueForKeyPath:identifier];
}
@end
@global CPLocalizedString
@global CPLocalizedStringFromTableInBundle
@@ -62,7 +83,11 @@ var TNArchipelTypeHypervisorParking = @"archipel:hypervisor:vmparkin
@outlet LPMultiLineTextField fieldXMLString;
TNVirtualMachineParkedObject _currentItem @accessors(property=currentItem);
id _delegate @accessors(property=delegate);
id _delegate @accessors(property=delegate);
TNTableViewLazyDataSource _datasource @accessors(getter=dataSource);
int _maxLoadedPage;
CPString _currentFilter;
}
@@ -80,6 +105,45 @@ var TNArchipelTypeHypervisorParking = @"archipel:hypervisor:vmparkin
[fieldXMLString setEnabled:YES];
}
#pragma mark -
#pragma mark Initialization
/*! Instaciate the class
*/
- (id)init
{
if (self = [super init])
{
_maxLoadedPage = 0;
_currentFilter = @""
}
return self;
}
#pragma mark -
#pragma mark Getters / Setters
/*! Set the target datasource, and set self ad datasource delegate
@pathForResource aDataSource the TNTableViewLazyDataSource to use
*/
- (void)setDataSource:(TNTableViewLazyDataSource)aDataSource
{
_datasource = aDataSource;
[_datasource setDelegate:self];
}
/*! Reset informations
*/
- (void)reset
{
_currentFilter = @"";
_maxLoadedPage = 0;
[_datasource setTotalCount:-1];
[_datasource setCurrentlyLoading:NO];
}
#pragma mark -
#pragma mark Action
@@ -178,14 +242,31 @@ var TNArchipelTypeHypervisorParking = @"archipel:hypervisor:vmparkin
/*! Get list of parked virtual machines
*/
- (void)listParkedVirtualMachines
{
[self listParkedVirtualMachines:_currentFilter];
}
/*! Get list of parked virtual machines with filter
*/
- (void)listParkedVirtualMachines:(CPString)aFilter
{
var stanza = [TNStropheStanza iqWithType:@"get"];
[stanza addChildWithName:@"query" andAttributes:{"xmlns": TNArchipelTypeHypervisorParking}];
[stanza addChildWithName:@"archipel" andAttributes:{
"action": TNArchipelTypeHypervisorParkingList}];
if (aFilter != @""){
[stanza addChildWithName:@"archipel" andAttributes:{
"action": TNArchipelTypeHypervisorParkingList,
"page": _maxLoadedPage,
"filter": aFilter}];
}
else {
[stanza addChildWithName:@"archipel" andAttributes:{
"action": TNArchipelTypeHypervisorParkingList,
"page": _maxLoadedPage}];
}
[_delegate setModuleStatus:TNArchipelModuleStatusWaiting];
[_datasource setCurrentlyLoading:YES];
[_delegate sendStanza:stanza andRegisterSelector:@selector(_didReceiveList:) ofObject:self];
}
@@ -200,7 +281,10 @@ var TNArchipelTypeHypervisorParking = @"archipel:hypervisor:vmparkin
datasource = [table dataSource],
virtualmachines = [aStanza childrenWithName:@"virtualmachine"];
[datasource removeAllObjects];
if (_maxLoadedPage == 0) {
[datasource removeAllObjects];
}
for (var i = 0; i < [virtualmachines count]; i++)
{
var vm = [virtualmachines objectAtIndex:i],
@@ -215,11 +299,16 @@ var TNArchipelTypeHypervisorParking = @"archipel:hypervisor:vmparkin
[datasource addObject:data];
}
[table reloadData];
if ([virtualmachines count] < 30)
[datasource setTotalCount:[datasource count]]
else
[datasource setTotalCount:[datasource count] + 10]
}
else
{
[_delegate handleIqErrorFromStanza:aStanza];
}
[_datasource setCurrentlyLoading:NO];
return NO;
}
@@ -363,8 +452,38 @@ var TNArchipelTypeHypervisorParking = @"archipel:hypervisor:vmparkin
return NO;
}
@end
/*! TNTableViewLazyDataSource delegate
*/
- (void)tableViewDataSourceNeedsLoading:(TNTableViewLazyDataSource)aDataSource
{
console.error(_maxLoadedPage)
console.error([_datasource count])
console.error([_datasource totalCount])
_maxLoadedPage++;
[self listParkedVirtualMachines];
}
/*! TNTableViewLazyDataSource delegate
*/
- (void)tableViewDataSource:(TNTableViewLazyDataSource)aDataSource applyFilter:(CPString)aFilter
{
[self reset];
if ([aFilter length] >= 3)
_currentFilter = aFilter;
[self listParkedVirtualMachines:aFilter];
}
/*! TNTableViewLazyDataSource delegate
*/
- (void)tableViewDataSource:(TNTableViewLazyDataSource)aDataSource removeFilter:(CPString)aFilter
{
[self reset];
_currentFilter = @""
[self listParkedVirtualMachines];
}
@end
// add this code to make the CPLocalizedString looking at
// the current bundle.
@@ -236,7 +236,8 @@ var TNArchipelTypeXMPPServerUsers = @"archipel:xmppserver:user
- (void)tableViewDataSource:(TNTableViewLazyDataSource)aDataSource applyFilter:(CPString)aFilter
{
[_delegate userFetcherClean];
[self getXMPPFilteredUsers:aFilter];
if ([aFilter length] >= 3)
[self getXMPPFilteredUsers:aFilter];
}
/*! TNTableViewLazyDataSource delegate

0 comments on commit 220801d

Please sign in to comment.