diff --git a/openbis-ipad/openBIS/openBIS.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate b/openbis-ipad/openBIS/openBIS.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate index ff460a772283e3809f2ef5ffa71d726cdb5ad530..90b853ce2aee4e36e9b026d16e6b77b5e5c93dbb 100644 Binary files a/openbis-ipad/openBIS/openBIS.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate and b/openbis-ipad/openBIS/openBIS.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/openbis-ipad/openBIS/openBIS/CISDOBMasterViewController.m b/openbis-ipad/openBIS/openBIS/CISDOBMasterViewController.m index b5b29cd41bccd5169a6e4d7a2cca253cb4bad4df..f60006503765e68eebc3be92d3d2a985da5cc11f 100644 --- a/openbis-ipad/openBIS/openBIS/CISDOBMasterViewController.m +++ b/openbis-ipad/openBIS/openBIS/CISDOBMasterViewController.m @@ -63,19 +63,8 @@ - (void)insertNewObject:(id)sender { - NSManagedObjectContext *context = [self.openBisModel.fetchedResultsController managedObjectContext]; - - // TODO Implement insert - NSLog(@"Do not support adding new objects"); - abort(); - -// NSEntityDescription *entity = [[self.openBisModel.fetchedResultsController fetchRequest] entity]; -// NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context]; - - - // Save the context. - NSError *error = nil; - if (![context save:&error]) { + NSError *error; + if (![self.openBisModel insertNewObjectOrError: &error]) { // TODO Implement error handling NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); @@ -86,13 +75,12 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return [[self.openBisModel.fetchedResultsController sections] count]; + return [self.openBisModel numberOfSections]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - id <NSFetchedResultsSectionInfo> sectionInfo = [self.openBisModel.fetchedResultsController sections][section]; - return [sectionInfo numberOfObjects]; + return [self.openBisModel numberOfEntitiesInSection: section]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath @@ -107,11 +95,7 @@ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { - id <NSFetchedResultsSectionInfo> sectionInfo = [[self.openBisModel.fetchedResultsController sections] objectAtIndex: section]; - NSArray *objects = [sectionInfo objects]; - if ([objects count] < 1) return @""; - - return ((CISDOBIpadEntity *)[objects objectAtIndex: 0]).group; + return [self.openBisModel titleForHeaderInSection: section]; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath @@ -122,11 +106,8 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { - NSManagedObjectContext *context = [self.openBisModel.fetchedResultsController managedObjectContext]; - [context deleteObject:[self.openBisModel.fetchedResultsController objectAtIndexPath:indexPath]]; - NSError *error = nil; - if (![context save:&error]) { + if (![self.openBisModel deleteObjectAtIndexPath: indexPath error: &error]) { // TODO Implement error handling NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); @@ -145,13 +126,12 @@ // Segue to the detail view unless we are on the ipad if ([[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPad) return; - CISDOBIpadEntity *object = [self.openBisModel.fetchedResultsController objectAtIndexPath:indexPath]; + CISDOBIpadEntity *object = [self.openBisModel objectAtIndexPath: indexPath]; if ([object.childrenPermIds count] > 0) { UIStoryboard *storyboard = self.storyboard; - CISDOBMasterViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"Drill"]; + CISDOBMasterViewController *controller = [storyboard instantiateViewControllerWithIdentifier: @"Master"]; controller.openBisModel = self.openBisModel; controller.title = object.summaryHeader; - // TODO Initialize the fetch results controller [self.navigationController pushViewController: controller animated: YES]; } else { @@ -164,14 +144,14 @@ { if ([[segue identifier] isEqualToString:@"showDetail"]) { NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; - CISDOBIpadEntity *object = [self.openBisModel.fetchedResultsController objectAtIndexPath:indexPath]; + CISDOBIpadEntity *object = [self.openBisModel objectAtIndexPath: indexPath]; [[segue destinationViewController] setDetailItem:object]; } } - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath { - CISDOBIpadEntity *object = [self.openBisModel.fetchedResultsController objectAtIndexPath:indexPath]; + CISDOBIpadEntity *object = [self.openBisModel objectAtIndexPath: indexPath]; cell.textLabel.text = [object valueForKey:@"summaryHeader"]; cell.detailTextLabel.text = [object valueForKey:@"summary"]; if ([object.childrenPermIds count] > 0) { diff --git a/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.h b/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.h index e0b5d97c36e42a601f7d012eaeceee91b1d7b87e..f5175614ecedcaa440212b20ebac2a6c634d3b9c 100644 --- a/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.h +++ b/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.h @@ -22,6 +22,8 @@ #import <Foundation/Foundation.h> +@class CISDOBIpadEntity; + /** * \brief A model for the interaction with openBIS. */ @@ -33,5 +35,16 @@ @property (strong, nonatomic) NSManagedObjectContext *managedObjectContext; @property (weak, nonatomic) id <NSFetchedResultsControllerDelegate> delegate; +// Model + +- (NSInteger)numberOfSections; //!< Get the number of categories for the current selection +- (NSInteger)numberOfEntitiesInSection:(NSInteger)section; +- (NSString *)titleForHeaderInSection:(NSInteger)section; +- (CISDOBIpadEntity *)objectAtIndexPath:(NSIndexPath *)indexPath; + +// Actions +- (BOOL)insertNewObjectOrError:(NSError **)error; //!< Return YES if operation succeeded +- (BOOL)deleteObjectAtIndexPath:(NSIndexPath *)indexPath error:(NSError **)error; //!< Return YES if operation succeeded + @end diff --git a/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.m b/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.m index 571ff1d55d0d0f3b123e92ac9c057e382f619cf6..3cb5409924c0a59a8db033f0396cd46c4b2bf500 100644 --- a/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.m +++ b/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.m @@ -21,9 +21,61 @@ // #import "CISDOBOpenBisModel.h" +#import "CISDOBIpadEntity.h" @implementation CISDOBOpenBisModel +#pragma mark - Model +- (NSInteger)numberOfSections +{ + return [[self.fetchedResultsController sections] count]; +} + +- (NSInteger)numberOfEntitiesInSection:(NSInteger)section +{ + id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section]; + return [sectionInfo numberOfObjects]; +} + +- (NSString *)titleForHeaderInSection:(NSInteger)section +{ + id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex: section]; + NSArray *objects = [sectionInfo objects]; + if ([objects count] < 1) return @""; + + return ((CISDOBIpadEntity *)[objects objectAtIndex: 0]).group; +} + +- (CISDOBIpadEntity *)objectAtIndexPath:(NSIndexPath *)indexPath +{ + return [self.fetchedResultsController objectAtIndexPath:indexPath]; +} + +#pragma mark - Actions +- (BOOL)insertNewObjectOrError:(NSError **)error +{ + NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; + + // TODO Implement insert + NSLog(@"Do not support adding new objects"); + abort(); + +// NSEntityDescription *entity = [[self.openBisModel.fetchedResultsController fetchRequest] entity]; +// NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context]; + + + // Save the context. + return [context save: error]; +} + +- (BOOL)deleteObjectAtIndexPath:(NSIndexPath *)indexPath error:(NSError **)error +{ + NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; + [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]]; + + return [context save: error]; +} + #pragma mark - Fetched results controller - (NSFetchedResultsController *)fetchedResultsController diff --git a/openbis-ipad/openBIS/openBIS/en.lproj/MainStoryboard_iPad.storyboard b/openbis-ipad/openBIS/openBIS/en.lproj/MainStoryboard_iPad.storyboard index c61bc11da637cabdee5bccbdf72b6e3b59638638..4415cd622e553b6ee561c660cf666cf157ff49ff 100644 --- a/openbis-ipad/openBIS/openBIS/en.lproj/MainStoryboard_iPad.storyboard +++ b/openbis-ipad/openBIS/openBIS/en.lproj/MainStoryboard_iPad.storyboard @@ -189,63 +189,11 @@ </connections> </tableView> <navigationItem key="navigationItem" title="Entity" id="40"/> - <connections> - <segue destination="bnd-KV-hgw" kind="push" id="IOV-fM-pGv"/> - </connections> </tableViewController> <placeholder placeholderIdentifier="IBFirstResponder" id="23" sceneMemberID="firstResponder"/> </objects> <point key="canvasLocation" x="859" y="-631"/> </scene> - <!--Master View Controller - Drill--> - <scene sceneID="2DG-VL-A5G"> - <objects> - <tableViewController storyboardIdentifier="Drill" title="Drill" clearsSelectionOnViewWillAppear="NO" id="bnd-KV-hgw" customClass="CISDOBMasterViewController" sceneMemberID="viewController"> - <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="ocJ-l0-Xdp"> - <rect key="frame" x="0.0" y="64" width="320" height="704"/> - <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> - <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> - <simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/> - <prototypes> - <tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Cell" textLabel="R6S-e4-MrX" detailTextLabel="rFb-Zf-Pqq" style="IBUITableViewCellStyleSubtitle" id="HOg-QU-DjF"> - <rect key="frame" x="0.0" y="22" width="320" height="44"/> - <autoresizingMask key="autoresizingMask"/> - <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center"> - <rect key="frame" x="0.0" y="0.0" width="320" height="43"/> - <autoresizingMask key="autoresizingMask"/> - <subviews> - <label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="R6S-e4-MrX"> - <rect key="frame" x="10" y="2" width="38" height="22"/> - <autoresizingMask key="autoresizingMask"/> - <fontDescription key="fontDescription" type="boldSystem" pointSize="18"/> - <color key="textColor" cocoaTouchSystemColor="darkTextColor"/> - <color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/> - </label> - <label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Subtitle" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="rFb-Zf-Pqq"> - <rect key="frame" x="10" y="24" width="47" height="18"/> - <autoresizingMask key="autoresizingMask"/> - <fontDescription key="fontDescription" type="system" pointSize="14"/> - <color key="textColor" red="0.50196078430000002" green="0.50196078430000002" blue="0.50196078430000002" alpha="1" colorSpace="calibratedRGB"/> - <color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/> - </label> - </subviews> - <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> - </view> - <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> - </tableViewCell> - </prototypes> - <sections/> - <connections> - <outlet property="dataSource" destination="bnd-KV-hgw" id="1A3-FU-zTq"/> - <outlet property="delegate" destination="bnd-KV-hgw" id="wzq-ge-uU1"/> - </connections> - </tableView> - <navigationItem key="navigationItem" title="Drill" id="XAx-6Y-R2e"/> - </tableViewController> - <placeholder placeholderIdentifier="IBFirstResponder" id="xid-0A-wMU" sceneMemberID="firstResponder"/> - </objects> - <point key="canvasLocation" x="1287" y="-630"/> - </scene> <!--Navigation Controller--> <scene sceneID="50"> <objects>