Permalink
Browse files

Added concept of "project" when creating or querying datapoints

  • Loading branch information...
1 parent 390f78a commit 0594f76d90ed1a3beaf9322c2bd5658469e06bf4 Deepwinter committed May 11, 2012
View
@@ -1,5 +1,5 @@
-Rhus.xcodeproj/project.xcworkspace/
-Rhus.xcodeproj/xcuserdata/
+*/project.xcworkspace/
+*/xcuserdata/
*.DS_Store
iphone
testdata
@@ -218,6 +218,7 @@
F414D9E81549F325008A38F5 /* TimelineVisualizationView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TimelineVisualizationView.m; sourceTree = "<group>"; };
F414DA59154A017A008A38F5 /* swoopBarBottom.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = swoopBarBottom.png; path = graphics/swoopBarBottom.png; sourceTree = SOURCE_ROOT; };
F414DA5A154A017A008A38F5 /* swoopBarTop.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = swoopBarTop.png; path = graphics/swoopBarTop.png; sourceTree = SOURCE_ROOT; };
+ F415F1B5155DBD1A00E25BFF /* RHSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RHSettings.h; sourceTree = "<group>"; };
F43540DC14D1140D00C206CA /* mapPointPopup.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = mapPointPopup.png; path = graphics/mapPointPopup.png; sourceTree = SOURCE_ROOT; };
F43540DD14D1140D00C206CA /* mapPoint.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = mapPoint.png; path = graphics/mapPoint.png; sourceTree = SOURCE_ROOT; };
F43B7E7F1508F33A00584E8B /* orangeOverlay.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = orangeOverlay.png; path = graphics/orangeOverlay.png; sourceTree = SOURCE_ROOT; };
@@ -369,6 +370,7 @@
F414D9B71549F325008A38F5 /* DataModels */ = {
isa = PBXGroup;
children = (
+ F415F1B5155DBD1A00E25BFF /* RHSettings.h */,
F414D9B81549F325008A38F5 /* RHDataModel.h */,
F414D9B91549F325008A38F5 /* RHDataModel.m */,
F414D9BA1549F325008A38F5 /* RHDeviceUser.h */,
@@ -809,7 +811,7 @@
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Source/Supporting Files/Rhus-Prefix.pch";
- INFOPLIST_FILE = "Settings/Rhus-Info.plist";
+ INFOPLIST_FILE = "Targets/Rhus/$(PRODUCT_NAME)-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 3.1;
PRODUCT_NAME = Rhus;
PROVISIONING_PROFILE = "";
@@ -836,7 +838,7 @@
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Source/Supporting Files/Rhus-Prefix.pch";
- INFOPLIST_FILE = "Settings/Rhus-Info.plist";
+ INFOPLIST_FILE = "Targets/Rhus/$(PRODUCT_NAME)-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 3.1;
PRODUCT_NAME = Rhus;
PROVISIONING_PROFILE = "";
@@ -21,11 +21,13 @@ typedef void ( ^CompletedBlock )();
CompletedBlock syncCompletedBlock;
BOOL syncStarted;
NSTimer * syncTimeoutTimer;
+ NSString * project;
}
@property (nonatomic, strong) CouchDatabase *database;
@property (nonatomic, strong) CouchLiveQuery* query;
@property (nonatomic, strong) NSTimer * syncTimeoutTimer;
+@property (nonatomic, strong) NSString * project;
- (id) initWithBlock: ( void ( ^ )() ) didStartBlock ;
@@ -54,6 +56,10 @@ typedef void ( ^CompletedBlock )();
+ (NSDictionary *) getNextDocument: (NSString *) documentId;
+ (NSDictionary *) getPrevDocument: (NSString *) documentId;
+ (NSDictionary *) getDetailDocument: (NSString *) documentId;
++ (NSArray *) getDocuments;
++ (NSArray *) getAllDocuments;
++ (NSArray *) getDocumentsInProject: (NSString *) project;
++ (NSArray *) getDocumentsInProject: (NSString *) project since: (NSString*) date;
//+ (UIImage *) getThumbnailForId: (NSString *) documentId;
@@ -25,6 +25,7 @@ + (id)instance
@synthesize database;
@synthesize query;
@synthesize syncTimeoutTimer;
+@synthesize project;
- (id) initWithBlock:( void ( ^ )() ) didStartBlock {
@@ -93,12 +94,16 @@ - (id) initWithBlock:( void ( ^ )() ) didStartBlock {
[design defineViewNamed: @"galleryDocuments"
map: @"function(doc) { emit(doc.created_at,{'id':doc._id, 'thumb':doc.thumb, 'medium':doc.medium, 'latitude':doc.latitude, 'longitude':doc.longitude, 'reporter':doc.reporter, 'comment':doc.comment, 'created_at':doc.created_at, 'deviceuser_identifier':doc.deviceuser_identifier } );}"];
*/
- [design defineViewNamed: @"galleryDocuments"
- map: @"function(doc) { emit(doc.created_at,{'id':doc._id,'latitude':doc.latitude, 'longitude':doc.longitude, 'reporter':doc.reporter, 'comment':doc.comment, 'created_at':doc.created_at, 'deviceuser_identifier':doc.deviceuser_identifier } );}"];
+ [design defineViewNamed: @"rhusDocuments"
+ map: @"function(doc) { emit( [doc.project, doc.created_at],{'id':doc._id,'latitude':doc.latitude, 'longitude':doc.longitude, 'reporter':doc.reporter, 'comment':doc.comment, 'created_at':doc.created_at, 'deviceuser_identifier':doc.deviceuser_identifier } );}"];
[design defineViewNamed: @"documentDetail"
map: @"function(doc) { emit( doc._id, {'id' :doc._id, 'reporter' : doc.reporter, 'comment' : doc.comment, 'thumb' : doc.thumb, 'medium' : doc.medium, 'created_at' : doc.created_at} );}"];
+ [design defineViewNamed: @"projects"
+ map: @"function(doc) { emit(doc.project, null); }"
+ reduce: @"function(key, values) { return true;}"];
+
[design saveChanges];
/*
design = [database designDocumentWithName: @"rhusMobile"];
@@ -276,22 +281,32 @@ + (NSArray *) getDeviceUserGalleryDocumentsWithStartKey: (NSString *) startKey a
-+ (NSArray *) getGalleryDocumentsWithStartKey: (NSString *) startKey andLimit: (NSInteger) limit {
++ (NSArray *) getAllDocuments {
+ //TODO: Implement
+}
+
++ (NSArray *) getDocumentsInProject: (NSString *) project {
CouchDatabase * database = [self.instance database];
CouchDesignDocument* design = [database designDocumentWithName: @"rhusMobile"];
NSAssert(design, @"Couldn't find design document");
-
- CouchQuery * query = [design queryViewNamed: @"galleryDocuments"]; //asLiveQuery];
- query.descending = NO;
- // query.limit = 50;
- NSLog(@"%@", @"AAAA Limit to 50 docs");
+
+ CouchQuery * query = [design queryViewNamed: @"rhusDocuments"]; //asLiveQuery];
+ query.descending = YES;
+ query.endKey = [NSArray arrayWithObjects:project, nil];
+ query.startKey = [NSArray arrayWithObjects:project, [NSDictionary dictionary], nil];
NSArray * r = [self.instance runQuery:query];
NSLog(@"Count: %i", [r count]);
return r;
}
+
++ (NSArray *) getDocumentsInProject: (NSString *) project since: (NSString*) date {
+ //TODO: Implement
+}
+
+
+ (NSArray *) getDetailDocumentsWithStartKey: (NSString *) startKey andLimit: (NSInteger) limit {
CouchDatabase * database = [self.instance database];
@@ -328,6 +343,23 @@ + (NSArray *) getUserDocumentsWithOffset:(NSInteger)offset andLimit:(NSInteger)l
return [self.instance _getUserDocuments];
}
+- (NSArray *) _getProjects {
+ CouchDesignDocument* design = [database designDocumentWithName: @"rhusMobile"];
+ CouchQuery * couchQuery = [design queryViewNamed: @"projects"]; //asLiveQuery];
+ couchQuery.groupLevel = 1;
+ CouchQueryEnumerator * enumerator = [couchQuery rows];
+ NSMutableArray * r = [NSArray array];
+ CouchQueryRow * row;
+ while( (row =[enumerator nextRow]) ){
+ [r addObject:row.key];
+ }
+ return r;
+}
+
++ (NSArray *) getProjects {
+ return [self.instance _getProjects];
+}
+
+ (void) addDocument: (NSDictionary *) document {
//Add any additional properties
@@ -69,7 +69,8 @@ - (void) initializeAppDelegateAndLaunch {
[self.window makeKeyAndVisible];
- [RHDataModel instance];
+ RHDataModel * dataModel =[RHDataModel instance];
+ dataModel.project = @"default";
// check for internet connection
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];
@@ -260,6 +260,10 @@ - (IBAction) didTouchUploadButton:(id)sender{
- (IBAction) didTouchSendButton:(id)sender{
+ //Most of this needs to move to the DataModel
+ //Logic for saving should be contained in RHDocument
+ //i.e. build a new RHDocument, then call toCouchJson on it or something like that, then send to couchdb.
+
//Crop Thumbnail
CGRect cropBounds;
cropBounds.size.width = 320;
@@ -313,6 +317,7 @@ - (IBAction) didTouchSendButton:(id)sender{
[RESTBody base64WithData: thumbImageDataJpeg ], @"thumb",
[RESTBody base64WithData: mediumImageDataJpeg ], @"medium",
[RHDeviceUser uniqueIdentifier], @"deviceuser_identifier",
+ [[RHDataModel instance] project], @"project",
nil];
// NSLog(@"debuggin %@", [newDocument debugDescription]);
@@ -234,7 +234,7 @@ - (void) addAnnotations {
if(self.userDataOnly){
documents = [RHDataModel getDeviceUserGalleryDocumentsWithStartKey:nil andLimit:nil];
} else {
- documents = [RHDataModel getGalleryDocumentsWithStartKey:nil andLimit:nil];
+ documents = [RHDataModel getDocumentsInProject:[[RHDataModel instance] project] ];
}
self.galleryHeading2.text = [NSString stringWithFormat:@"%i Images", [documents count]];

0 comments on commit 0594f76

Please sign in to comment.