1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
| #import "ViewControllerData.h"
#import "Data.h"
#import "CompositeCard.h"
@interface ViewControllerData ()
@end
@implementation ViewControllerData
- (void)loadTimeline {
// Charger le modèle via RestKit
RKObjectManager* objectManager = [RKObjectManager sharedManager];
objectManager.client.baseURL = [RKURL URLWithString:@"http://localhost:8080/CulturalNetworksMuseumServer/resources"];
[objectManager loadObjectsAtResourcePath:@"/compositecards/1/artifactcards" delegate:self];
}
- (void)viewDidLoad
{
[super viewDidLoad];
RKLogConfigureByName("RestKit/Network*", RKLogLevelTrace);
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
// Initialisation de RestKit
RKObjectManager* objectManager = [RKObjectManager managerWithBaseURLString:@"http://localhost:8080/CulturalNetworksMuseumServer/resources"];
// Active la gestion automatique de l'indicateur de l'activité réseau
objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;
//Configuration du mappage de l'objet CompositeCard
RKObjectMapping* compositeMapping = [RKObjectMapping mappingForClass:[CompositeCard class]];
// [compositeMapping mapKeyPath:@"id" toAttribute:@"cc_id"];
// [compositeMapping mapKeyPath:@"name" toAttribute:@"cc_name"];
[compositeMapping mapAttributes:@"id", @"name", nil];
//[[objectManager mappingProvider] setObjectMapping:compositeMapping forKeyPath:@"/compositecards"];
//Configuration du mappage de l'objet Data
RKObjectMapping * dataMapping = [RKObjectMapping mappingForClass:[Data class]];
[dataMapping mapKeyPath:@"id" toAttribute:@"ac_id"];
[dataMapping mapKeyPath:@"file" toAttribute:@"ac_file"];
[dataMapping mapKeyPath:@"typefile" toAttribute:@"ac_typefile"];
[dataMapping mapKeyPath:@"author" toAttribute:@"ac_author"];
[dataMapping mapKeyPath:@"title_topic" toAttribute:@"ac_title_topic"];
[dataMapping mapKeyPath:@"year" toAttribute:@"ac_year"];
[dataMapping mapKeyPath:@"technical" toAttribute:@"ac_technical"];
[dataMapping mapKeyPath:@"support_media" toAttribute:@"ac_support_media"];
[dataMapping mapKeyPath:@"format" toAttribute:@"ac_format"];
[dataMapping mapKeyPath:@"owner" toAttribute:@"ac_owner"];
[dataMapping mapKeyPath:@"collection" toAttribute:@"ac_collection"];
[dataMapping mapKeyPath:@"descritpion_remarks" toAttribute:@"ac_descritpion_remarks"];
[dataMapping mapKeyPath:@"compositeCard" toRelationship:@"ac_compositeCard" withMapping:compositeMapping];
// Permet de mapper l'objet artifactCard avec la source de ce dernier
[objectManager.mappingProvider setObjectMapping:dataMapping forResourcePathPattern:@"/compositecards/1/artifactcards"];
//[[objectManager mappingProvider] addObjectMapping:dataMapping];
NSString * test = @"Mappage dans la View Controller";
NSLog(@"%@",test);
// // mise en place d'une TableView
// _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-64) style:UITableViewStylePlain];
// _tableView.dataSource = self;
// _tableView.delegate = self;
// _tableView.backgroundColor = [UIColor clearColor];
// _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
// [self.view addSubview:_tableView];
// appel de la fonction qui charge le modèle
[self loadTimeline];
}
#pragma mark RKObjectLoaderDelegate methods
- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response
{
NSLog(@"Loaded payload: %@", [response bodyAsString]);
}
/**
** Permet de charger la liste des adresses provenant des services Rest sous forme de tableau
** Remplir le tableau _addresses (local) avec le tableau d'objects
** Mettre à jour la TableView
**/
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
NSLog(@"Load collection of ArtifactCards: %@", objects);
_data = [NSArray arrayWithArray:objects];
[_tableView reloadData];
}
- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
NSLog(@"Hit error: %@", error);
}
//#pragma mark UITableViewDataSource methods
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// return 1;
//}
//
//- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
// return [_data count];
//}
//
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// NSString* reuseIdentifier = @"Data Cell";
// UITableViewCell* cell = [_tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
// if (nil == cell) {
// cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
// cell.textLabel.numberOfLines = 0;
// cell.textLabel.backgroundColor = [UIColor clearColor];
// }
// Data *data = [_data objectAtIndex:indexPath.row];
//
// //[cell.textLabel setText:[NSString stringWithFormat:@"%@ %@", address.ad_lat, address.ad_lon]];
//
// [cell.textLabel setText:[NSString stringWithFormat:@"%@", data.ac_title_topic]];
// [cell.detailTextLabel setText:[NSString stringWithFormat:@"%@", data.ac_author]];
//
// return cell;
//}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end |
Partager