Permalink
Browse files

Switch back to saving images as attachments, this is the final paradigm

  • Loading branch information...
Deepwinter
Deepwinter committed May 25, 2012
1 parent c1f9d52 commit 14e6d8205cd23fd08350dc0616b9c1fe127ea0b6
@@ -75,8 +75,6 @@
F414DA131549F325008A38F5 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F414D9D41549F325008A38F5 /* AppDelegate.m */; };
F414DA161549F325008A38F5 /* CameraViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F414D9D61549F325008A38F5 /* CameraViewController.m */; };
F414DA191549F325008A38F5 /* CameraViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F414D9D71549F325008A38F5 /* CameraViewController.xib */; };
- F414DA1C1549F325008A38F5 /* GalleryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F414D9DA1549F325008A38F5 /* GalleryViewController.m */; };
- F414DA1F1549F325008A38F5 /* GalleryViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F414D9DB1549F325008A38F5 /* GalleryViewController.xib */; };
F414DA221549F325008A38F5 /* ImageScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = F414D9DD1549F325008A38F5 /* ImageScrollView.m */; };
F414DA251549F325008A38F5 /* LoadingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F414D9DF1549F325008A38F5 /* LoadingViewController.m */; };
F414DA281549F325008A38F5 /* LoadingViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F414D9E01549F325008A38F5 /* LoadingViewController.xib */; };
@@ -202,9 +200,6 @@
F414D9D61549F325008A38F5 /* CameraViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CameraViewController.m; sourceTree = "<group>"; };
F414D9D71549F325008A38F5 /* CameraViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CameraViewController.xib; sourceTree = "<group>"; };
F414D9D81549F325008A38F5 /* FullscreenTransitionDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FullscreenTransitionDelegate.h; sourceTree = "<group>"; };
- F414D9D91549F325008A38F5 /* GalleryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GalleryViewController.h; sourceTree = "<group>"; };
- F414D9DA1549F325008A38F5 /* GalleryViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GalleryViewController.m; sourceTree = "<group>"; };
- F414D9DB1549F325008A38F5 /* GalleryViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = GalleryViewController.xib; sourceTree = "<group>"; };
F414D9DC1549F325008A38F5 /* ImageScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageScrollView.h; sourceTree = "<group>"; };
F414D9DD1549F325008A38F5 /* ImageScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageScrollView.m; sourceTree = "<group>"; };
F414D9DE1549F325008A38F5 /* LoadingViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoadingViewController.h; sourceTree = "<group>"; };
@@ -433,9 +428,6 @@
F414D9D61549F325008A38F5 /* CameraViewController.m */,
F414D9D71549F325008A38F5 /* CameraViewController.xib */,
F414D9D81549F325008A38F5 /* FullscreenTransitionDelegate.h */,
- F414D9D91549F325008A38F5 /* GalleryViewController.h */,
- F414D9DA1549F325008A38F5 /* GalleryViewController.m */,
- F414D9DB1549F325008A38F5 /* GalleryViewController.xib */,
F414D9DC1549F325008A38F5 /* ImageScrollView.h */,
F414D9DD1549F325008A38F5 /* ImageScrollView.m */,
F414D9DE1549F325008A38F5 /* LoadingViewController.h */,
@@ -655,7 +647,6 @@
F4F2859E150DEA3A009A24C9 /* mapDeviceUserPoint.png in Resources */,
F414DA0A1549F325008A38F5 /* InfoPlist.strings in Resources */,
F414DA191549F325008A38F5 /* CameraViewController.xib in Resources */,
- F414DA1F1549F325008A38F5 /* GalleryViewController.xib in Resources */,
F414DA281549F325008A38F5 /* LoadingViewController.xib in Resources */,
F414DA2E1549F325008A38F5 /* MapViewController.xib in Resources */,
F414DA341549F325008A38F5 /* SwoopTabViewController.xib in Resources */,
@@ -693,7 +684,6 @@
F414DA101549F325008A38F5 /* OrderedDictionary.m in Sources */,
F414DA131549F325008A38F5 /* AppDelegate.m in Sources */,
F414DA161549F325008A38F5 /* CameraViewController.m in Sources */,
- F414DA1C1549F325008A38F5 /* GalleryViewController.m in Sources */,
F414DA221549F325008A38F5 /* ImageScrollView.m in Sources */,
F414DA251549F325008A38F5 /* LoadingViewController.m in Sources */,
F414DA2B1549F325008A38F5 /* MapViewController.m in Sources */,
@@ -731,10 +721,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
- ARCHS = (
- armv6,
- "$(ARCHS_STANDARD_32_BIT)",
- );
+ ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -757,18 +744,15 @@
PROVISIONING_PROFILE = "";
SDKROOT = iphoneos5.0;
TARGETED_DEVICE_FAMILY = 1;
- VALID_ARCHS = "armv7 armv6";
+ VALID_ARCHS = armv7;
};
name = Debug;
};
F4D392BB14BBA6660051E831 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
- ARCHS = (
- armv6,
- "$(ARCHS_STANDARD_32_BIT)",
- );
+ ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -786,17 +770,14 @@
SDKROOT = iphoneos5.0;
TARGETED_DEVICE_FAMILY = 1;
VALIDATE_PRODUCT = YES;
- VALID_ARCHS = "armv7 armv6";
+ VALID_ARCHS = armv7;
};
name = Release;
};
F4D392BD14BBA6660051E831 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
- ARCHS = (
- armv6,
- "$(ARCHS_STANDARD_32_BIT)",
- );
+ ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
FRAMEWORK_SEARCH_PATHS = (
@@ -812,18 +793,15 @@
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = 1;
- VALID_ARCHS = "armv7 armv6";
+ VALID_ARCHS = armv7;
WRAPPER_EXTENSION = app;
};
name = Debug;
};
F4D392BE14BBA6660051E831 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
- ARCHS = (
- armv6,
- "$(ARCHS_STANDARD_32_BIT)",
- );
+ ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CODE_SIGN_IDENTITY = "iPhone Distribution";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
FRAMEWORK_SEARCH_PATHS = (
@@ -839,7 +817,7 @@
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = 1;
- VALID_ARCHS = "armv7 armv6";
+ VALID_ARCHS = armv7;
WRAPPER_EXTENSION = app;
};
name = Release;
@@ -64,11 +64,12 @@ typedef void ( ^CompletedBlock )();
+ (void) addProject:(NSString *) projectName;
-//+ (UIImage *) getThumbnailForId: (NSString *) documentId;
-//+ (UIImage *) getImageForId: (NSString *) documentId;
++ (UIImage *) getDocumentThumbnail: (NSString *) documentId;
++ (UIImage *) getDocumentImage: (NSString *) documentId;
-+ (void) addDocument: (NSDictionary *) document;
-+ (void) addDocument: (NSDictionary *) document withAttachments: (NSDictionary *) attachments;
++ (NSString *) addDocument: (NSDictionary *) document;
++ (NSString *) addDocument: (NSDictionary *) document withAttachments: (NSDictionary *) attachments;
++ (void) addAttachment:(NSString *) name toDocument: (NSString *) documentId withData: (NSData *) data andContentType: (NSString *) contentType;
+ (NSArray *) getDetailDocumentsWithStartKey: (NSString *) startKey andLimit: (NSInteger) limit;
@@ -220,23 +220,23 @@ - (id) initWithBlock:( void ( ^ )() ) didStartBlock {
}
-+ (NSData *) getDocumentThumbnailData: (NSString *) key {
++ (UIImage *) getDocumentThumbnail: (NSString *) key {
CouchDocument* doc = [[self.instance database] documentWithID: key];
CouchModel * model = [[CouchModel alloc] initWithDocument:doc];
CouchAttachment * thumbnail = [model attachmentNamed:@"thumb.jpg"];
if(thumbnail != nil){
- return thumbnail.body;
+ return [UIImage imageWithData: thumbnail.body];
} else {
return nil;
}
}
-+ (NSData *) getDocumentImageData: (NSString *) key {
++ (UIImage *) getDocumentImage: (NSString *) key {
CouchDocument* doc = [[self.instance database] documentWithID: key];
CouchModel * model = [[CouchModel alloc] initWithDocument:doc];
- CouchAttachment * thumbnail = [model attachmentNamed:@"medium.jpg"];
- if(thumbnail != nil){
- return thumbnail.body;
+ CouchAttachment * image = [model attachmentNamed:@"medium.jpg"];
+ if(image != nil){
+ return [UIImage imageWithData: image.body];
} else {
return nil;
}
@@ -264,7 +264,7 @@ - (NSArray *) runQuery: (CouchQuery *) couchQuery {
//Fix Image Attachments
//TODO: This code can be removed once we are reasonably certain everything has been transformed
//BOOL docNeedsSave = false;
- // CouchDocument * doc = row.document;
+ CouchDocument * doc = row.document;
// NSMutableDictionary * newProperties = [doc.properties mutableCopy ];
@@ -305,7 +305,7 @@ - (NSArray *) runQuery: (CouchQuery *) couchQuery {
}
*/
-
+ /*
NSMutableDictionary * properties = [(NSDictionary *) row.value mutableCopy];
//Translate the Base64 data into a UIImage
if([properties objectForKey:@"thumb"] != NULL && [properties objectForKey:@"thumb"] != @"" ){
@@ -337,9 +337,10 @@ - (NSArray *) runQuery: (CouchQuery *) couchQuery {
} else {
[properties removeObjectForKey:@"medium"];
}
-
+ */
//give em the data
+ NSDictionary * properties = doc.properties;
[data addObject: [[RHDocument alloc] initWithDictionary: [NSDictionary dictionaryWithDictionary: properties]]];
}
return data;
@@ -462,7 +463,7 @@ + (NSArray *) getProjects {
return [self.instance _getProjects];
}
-+ (void) addDocument: (NSDictionary *) document {
++ (NSString *) addDocument: (NSDictionary *) document {
//Add any additional properties
// Save the document, asynchronously:
@@ -480,8 +481,28 @@ + (void) addDocument: (NSDictionary *) document {
[op start];
[op wait]; //kickin it synchronous for right now.
+ RESTBody * responseBody = op.responseBody;
+ NSLog([op.responseBody asString]);
+
+ NSDictionary * object = (NSDictionary *)responseBody.fromJSON;
+ NSLog([object objectForKey:@"id"]);
+ return [object objectForKey:@"id"];
}
++ (void) addAttachment:(NSString *) name toDocument: (NSString *) documentId withData: (NSData *) data andContentType: (NSString *) contentType {
+
+ CouchDocument * doc = [self.instance.database documentWithID:documentId];
+ CouchRevision * revision = doc.currentRevision;
+
+ CouchAttachment * newAttachment = [revision createAttachmentWithName:name
+ type:contentType ];
+
+ RESTOperation * op2 = [newAttachment PUT:data contentType:contentType];
+ [op2 start];
+ [op2 wait];
+ //kickin it synchronous for right now.
+
+}
// Display an error alert, without blocking.
@@ -610,4 +631,6 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
}
+
+
@end
@@ -19,6 +19,8 @@
- (NSString *) getDateString;
- (float) getLatitude;
- (float) getLongitude;
+- (UIImage *) getThumbnail;
+- (UIImage *) getImage;
@end
@@ -7,6 +7,7 @@
//
#import "RHDocument.h"
+#import "RHDataModel.h"
@implementation RHDocument
@@ -80,6 +81,12 @@ - (void)removeObjectForKey:(id)aKey{
return [dictionary removeObjectForKey:aKey];
}
+- (UIImage *)getThumbnail {
+ return [RHDataModel getDocumentThumbnail:[self objectForKey:@"_id"]];
+}
+- (UIImage *)getImage {
+ return [RHDataModel getDocumentImage:[self objectForKey:@"_id"]];
+}
@end
@@ -7,7 +7,6 @@
//
#import "AppDelegate.h"
-#import "GalleryViewController.h"
#import "CameraViewController.h"
#import "MapViewController.h"
#import "RHDataModel.h"
@@ -314,8 +314,8 @@ - (IBAction) didTouchSendButton:(id)sender{
[RHLocation getLatitudeString], @"latitude",
[RHLocation getLongitudeString], @"longitude",
[RESTBody JSONObjectWithDate: [NSDate date]], @"created_at",
- [RESTBody base64WithData: thumbImageDataJpeg ], @"thumb",
- [RESTBody base64WithData: mediumImageDataJpeg ], @"medium",
+ //[RESTBody base64WithData: thumbImageDataJpeg ], @"thumb",
+ //[RESTBody base64WithData: mediumImageDataJpeg ], @"medium",
[RHDeviceUser uniqueIdentifier], @"deviceuser_identifier",
[[RHDataModel instance] project], @"project",
nil];
@@ -326,8 +326,12 @@ - (IBAction) didTouchSendButton:(id)sender{
[newDocument setObject:@"true" forKey:attribute];
}
- [RHDataModel addDocument:newDocument];
+ NSString * documentId = [RHDataModel addDocument:newDocument];
+
+ [RHDataModel addAttachment:@"thumb.jpg" toDocument:documentId withData:thumbImageDataJpeg andContentType:@"image/jpeg"];
+ [RHDataModel addAttachment:@"medium.jpg" toDocument:documentId withData:mediumImageDataJpeg andContentType:@"image/jpeg"];
+
[UIView beginAnimations:@"anim" context:nil];
[UIView setAnimationDuration:0.50];
CGRect frame = self.pictureInfo.frame;
Oops, something went wrong.

0 comments on commit 14e6d82

Please sign in to comment.