Permalink
Browse files

add delete support

  • Loading branch information...
1 parent 521f61c commit 3d471b8b715f8665973960b8b519c924a59a7f83 vickeryj committed Jan 30, 2009
View
@@ -112,6 +112,14 @@
</object>
<int key="connectionID">17</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">noteListController</string>
+ <reference key="source" ref="664661524"/>
+ <reference key="destination" ref="295249404"/>
+ </object>
+ <int key="connectionID">18</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -211,7 +219,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<string>UIApplication</string>
<string>UIResponder</string>
- <string>{{59, 617}, {320, 480}}</string>
+ <string>{{87, 153}, {320, 480}}</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>NoteListController</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
@@ -253,7 +261,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">17</int>
+ <int key="maxID">18</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -269,13 +277,41 @@
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">external_libs/ObjectiveResource/Classes/lib/NSObject+ObjectiveResource.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
<string key="minorKey">external_libs/ObjectiveSupport/Core/NSObject+PropertySupport.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">external_libs/ObjectiveSupport/Serialization/JSON/NSObject+JSONSerializableSupport.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">external_libs/ObjectiveSupport/Serialization/NSObject+Serialize.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">external_libs/ObjectiveSupport/Serialization/XML/NSObject+XMLSerializableSupport.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
<string key="minorKey">external_libs/ObjectiveSupport/json-framework/NSObject+SBJSON.h</string>
</object>
</object>
@@ -299,11 +335,13 @@
<object class="NSMutableArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>navigationController</string>
+ <string>noteListController</string>
<string>window</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>UINavigationController</string>
+ <string>NoteListController</string>
<string>UIWindow</string>
</object>
</object>
@@ -12,9 +12,11 @@
@interface Note : SQLitePersistentObject {
NSString *noteText;
+ NSString *noteId;
}
@property(nonatomic, retain) NSString *noteText;
+@property(nonatomic, retain) NSString *noteId;
@end
@@ -10,12 +10,13 @@
@implementation Note
-@synthesize noteText;
+@synthesize noteText, noteId;
#pragma mark cleanup
- (void) dealloc
{
[noteText release];
+ [noteId release];
[super dealloc];
}
@@ -7,9 +7,9 @@
//
#import <UIKit/UIKit.h>
+#import "OSYSyncDelegate.h"
-
-@interface NoteListController : UITableViewController {
+@interface NoteListController : UITableViewController <OSYSyncDelegate> {
NSMutableArray *notes;
@@ -22,9 +22,20 @@ - (IBAction) addButtonPressed {
[self.navigationController pushViewController:editor animated:YES];
}
+- (void) loadNotes {
+ self.notes = [NSMutableArray arrayWithArray:[Note findByCriteria:@""]];
+}
+
+#pragma mark OSYSyncDelegate methods
+- (void) syncCompleteWithSuccess:(BOOL)success {
+ if (success) {
+ [self loadNotes];
+ }
+}
+
#pragma mark UIViewController methods
- (void)viewDidLoad {
- self.notes = [NSMutableArray arrayWithArray:[Note findByCriteria:@""]];
+ [self loadNotes];
}
- (void)viewDidAppear:(BOOL)animated {
@@ -49,6 +60,21 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}
+- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
+
+ if (editingStyle == UITableViewCellEditingStyleDelete) {
+ [aTableView beginUpdates];
+ [aTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
+ withRowAnimation:YES];
+ Note *note = [notes objectAtIndex:indexPath.row];
+ [note deleteObject];
+ [notes removeObject:note];
+ [aTableView endUpdates];
+ }
+
+
+}
+
#pragma mark cleanup
- (void)dealloc {
[notes release];
@@ -8,14 +8,17 @@
#import <UIKit/UIKit.h>
+@class NoteListController;
@interface objectivesyncAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
+ NoteListController *noteListController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
+@property (nonatomic, retain) IBOutlet NoteListController *noteListController;
@end
@@ -12,12 +12,11 @@
@implementation objectivesyncAppDelegate
-@synthesize window, navigationController;
-
+@synthesize window, navigationController, noteListController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[ObjectiveResourceConfig setSite:@"http://localhost:3000/"];
- [OSYService setup];
+ [OSYService setupWithSyncDelegate:(id)noteListController];
// Override point for customization after application launch
[window addSubview:navigationController.view];
@@ -28,6 +27,7 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
- (void)dealloc {
[window release];
[navigationController release];
+ [noteListController release];
[super dealloc];
}
@@ -14,6 +14,6 @@ typedef enum {
@protocol ORCDataChangedDelegate
-- (void) objectOfClass:(Class)cls withPk:(int)pk was:(ORCActionTypes)action;
-
+- (void) objectOfClass:(Class)cls withPk:(int)pk
+ andRemoteId:(NSString *)remoteId was:(ORCActionTypes)action;
@end
@@ -23,6 +23,7 @@
#import "NSString-UppercaseFirst.h"
#import "NSObject+PropertySupport.h"
#import "NSDate-SQLitePersistence.h"
+#import "ObjectiveResource.h"
id findByMethodImp(id self, SEL _cmd, id value)
{
@@ -240,7 +241,7 @@ -(void)save
[[SQLiteInstanceManager sharedManager] executeQuery:updateSQL substitutions:substitutions];
if (isNew) {
- [__delegate objectOfClass:self.class withPk:pk was:CreatedAction];
+ [__delegate objectOfClass:self.class withPk:pk andRemoteId:nil was:CreatedAction];
}
}
@@ -255,6 +256,7 @@ -(void)deleteObject
NSString *deleteQuery = [NSString stringWithFormat:@"DELETE FROM %@ WHERE pk = %d", [[self class] tableName], pk];
[[SQLiteInstanceManager sharedManager] executeQuery:deleteQuery];
+ [__delegate objectOfClass:self.class withPk:pk andRemoteId:[self getORSId] was:DeletedAction];
}
#pragma mark -
@@ -12,9 +12,9 @@
@implementation OSYDataChangedDelegate
-- (void) objectOfClass:(Class)cls withPk:(int)pk was:(ORCActionTypes)action {
+- (void) objectOfClass:(Class)cls withPk:(int)pk andRemoteId:(NSString *)remoteId was:(ORCActionTypes)action {
if (![[cls className] isEqualTo:@"OSYLog"]) {
- [OSYLog logAction:action toDBWithClass:cls andPk:pk];
+ [OSYLog logAction:action toDBWithClass:cls andRemoteId:remoteId andPk:pk];
[[OSYService instance] dataChanged];
}
}
View
@@ -15,18 +15,23 @@
int loggedPk;
int loggedAction;
NSDate *loggedAt;
+ NSString *remoteId;
}
@property(nonatomic, retain) NSString *loggedClassName;
@property(nonatomic) int loggedPk;
@property(nonatomic) int loggedAction;
@property(nonatomic, retain) NSDate *loggedAt;
+@property(nonatomic, retain) NSString *remoteId;
-/*! log an object creation */
-+(void) logAction:(ORCActionTypes)action toDBWithClass:(Class)createdClass andPk:(int)createdPk;
+/*! log an object that was Created, Deleted or Updated */
++(void) logAction:(ORCActionTypes)action toDBWithClass:(Class)loggedClass
+ andRemoteId:(NSString *)loggedRemoteId andPk:(int)loggedPk;
-/*! findAll newly created objects that have not yet been uploaded */
+
+//finders
+(NSArray *)newlyCreated;
++(NSArray *)newlyDeleted;
@end
View
@@ -9,22 +9,38 @@
#import "OSYLog.h"
#import "ORCDataChangedDelegate.h"
+@interface OSYLog()
+
++(NSArray *)findByAction:(ORCActionTypes)action;
+
+@end
+
@implementation OSYLog
-@synthesize loggedClassName, loggedPk, loggedAction, loggedAt;
+@synthesize loggedClassName, loggedPk, loggedAction, loggedAt, remoteId;
+
++(NSArray *)findByAction:(ORCActionTypes)action {
+ return [self findByCriteria:[NSString stringWithFormat:@"WHERE logged_action=%d",action]];
+}
+(NSArray *)newlyCreated {
- NSString *query = [NSString stringWithFormat:@"WHERE logged_action = '%d'", CreatedAction];
- return [self findByCriteria:query];;
+ return [self findByAction:CreatedAction];
+}
++(NSArray *)newlyDeleted {
+ return [self findByAction:DeletedAction];
}
-+(void) logAction:(ORCActionTypes)action toDBWithClass:(Class)createdClass andPk:(int)createdPk {
++(void) logAction:(ORCActionTypes)action toDBWithClass:(Class)loggedClass
+ andRemoteId:(NSString *)loggedRemoteId andPk:(int)loggedPk
+
+{
OSYLog *log = [[[OSYLog alloc] init] autorelease];
log.loggedAction = action;
- log.loggedClassName = [createdClass className];
- log.loggedPk = createdPk;
+ log.loggedClassName = [loggedClass className];
+ log.loggedPk = loggedPk;
log.loggedAt = [NSDate date];
+ log.remoteId = loggedRemoteId;
[log save];
}
@@ -34,6 +50,7 @@ - (void) dealloc
{
[loggedClassName release];
[loggedAt release];
+ [remoteId release];
[super dealloc];
}
View
@@ -7,14 +7,20 @@
//
#import <Foundation/Foundation.h>
+#import "OSYSyncDelegate.h"
@interface OSYService : NSObject {
+ NSObject<OSYSyncDelegate> *delegate;
+
}
-+(void)setup;
+@property(nonatomic, retain) NSObject<OSYSyncDelegate> *delegate;
+
++(void)setupWithSyncDelegate:(NSObject<OSYSyncDelegate> *)delegate;
+(OSYService *)instance;
+
-(void)dataChanged;
@end
View
@@ -16,10 +16,13 @@
@implementation OSYService
-+(void)setup {
+@synthesize delegate;
+
++(void)setupWithSyncDelegate:(NSObject<OSYSyncDelegate> *)delegate {
__instance = [[OSYService alloc] init];
- OSYDataChangedDelegate *delegate = [[OSYDataChangedDelegate alloc] init];
- [SQLitePersistentObject setDataChangedDelegate:delegate];
+ [__instance setDelegate:delegate];
+ OSYDataChangedDelegate *dataChanged = [[OSYDataChangedDelegate alloc] init];
+ [SQLitePersistentObject setDataChangedDelegate:dataChanged];
}
+(OSYService *)instance {
@@ -32,6 +35,15 @@ -(void)dataChanged {
//basic, sync immediately strategy
OSYSync *sync = [[[OSYSync alloc] init] autorelease];
[sync runSync];
+ [delegate syncCompleteWithSuccess:YES];
+}
+
+#pragma mark cleanup
+- (void) dealloc
+{
+ [delegate release];
+ [super dealloc];
}
+
@end
Oops, something went wrong.

0 comments on commit 3d471b8

Please sign in to comment.