Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Better error handling. Scroll view around collection view of results.

  • Loading branch information...
commit ae89309b575edc6eb6e61b93c41a0dd54100594c 1 parent 5ca38e6
@topfunky authored
View
97 AppController.j
@@ -26,10 +26,16 @@
[contentView setBackgroundColor:[CPColor colorWithHexString:"eeeeee"]];
+ var scrollView = [[CPScrollView alloc] initWithFrame:[contentView frame]];
+ [scrollView setHasHorizontalScroller:NO];
+ [scrollView setAutohidesScrollers:YES];
+ [scrollView setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
+ [contentView addSubview:scrollView];
+
collectionView = [[TFCollectionView alloc] initWithItemPrototypeClass:[TFCustomCell class]
parentView:contentView
delegate:self];
- [contentView addSubview:collectionView];
+ [scrollView setDocumentView:collectionView];
[theWindow orderFront:self];
[self startRelaxing];
@@ -49,21 +55,28 @@
// Drop and re-create the database
[couchdb drop:{
success:function(doc) {
- var result = {text:"Database: Drop",
- detailText:"Drop the cappuccino-couchdb-test database, if it exists.",
- pass:YES};
- [self addResult:result];
+ [self addResultWithText:"Database: Drop"
+ detailText:"Drop the cappuccino-couchdb-test database, if it exists."
+ pass:YES];
[couchdb create:{
success:function(doc) { [self runCouchDemo]; }
}];
+ },
+ error:function(doc) {
+ [self addResultWithText:"Database:Drop"
+ detailText:"Couldn't drop the database: " + doc.reason
+ pass:NO];
+ [couchdb create:{ success:function(doc) { [self runCouchDemo]; } }];
}
}];
}
- (void)runCouchDemo
{
- [self addResult:{text:"Database: Create", detailText:"Create the cappuccino-couchdb-test database", pass:YES}];
+ [self addResultWithText:"Database: Create"
+ detailText:"Create the cappuccino-couchdb-test database"
+ pass:YES];
[self runClassMethods];
[self runInstanceMethods];
@@ -73,44 +86,48 @@
{
[CouchDB info:{
success: function(doc) {
- var result = {text:"Server: Info",
- detailText:"Running CouchDB server version " + doc.version,
- pass:YES};
- [self addResult:result];
+ [self addResultWithText:"Server: Info"
+ detailText:"Running CouchDB server version " + doc.version
+ pass:YES];
}
}];
[CouchDB activeTasks:{
success: function(doc) {
- var result = {text:"Server: Active Tasks",
- detailText:"Number of active tasks: " + doc.length,
- pass:YES};
- [self addResult:result];
+ [self addResultWithText:"Server: Active Tasks"
+ detailText:"Number of active tasks: " + doc.length
+ pass:YES];
}
}];
[CouchDB allDbs:{
success: function(doc) {
- var result = {text:"Server: All Databases",
- detailText:"Number of databases on this server: " + doc.length,
- pass:YES};
- [self addResult:result];
+ [self addResultWithText:"Server: All Databases"
+ detailText:"Number of databases on this server: " + doc.length
+ pass:YES];
}
}];
- // TODO: Fails if the db exists. Needs to respond to errors.
var mirror = [CouchDB couchWithDatabase:"cappuccino-couchdb-test-mirror"];
[mirror create:{
- success:function(doc) {
+ success:function(doc)
+ {
[CouchDB replicateSource:"cappuccino-couchdb-test" target:"cappuccino-couchdb-test-mirror" options:{
- success:function(doc) {
- var result = {text:"Server: Replicate",
- detailText:"Replicated the database.",
- pass:YES};
- [self addResult:result];
+ success:function(doc)
+ {
+ [self addResultWithText:"Server: Replicate"
+ detailText:"Replicated the database."
+ pass:YES];
[mirror drop:{}];
}
}];
+ },
+ error:function(doc)
+ {
+ [self addResultWithText:"Server: Replicate"
+ detailText:"Could prepare for replication: " + doc.reason
+ pass:NO];
+ [mirror drop:{}];
}
}];
}
@@ -119,23 +136,30 @@
{
[couchdb info:{
success: function(doc) {
- var result = {text:"Database: Info",
- detailText:"Info about " + doc.db_name + ": Disk Size " + doc.disk_size,
- pass:YES};
- [self addResult:result];
+ [self addResultWithText:"Database: Info"
+ detailText:"Info about " + doc.db_name + ": Disk Size " + doc.disk_size
+ pass:YES];
}
}];
var myDoc = {title:"Chunky Bacon", meaningOfLife:42};
[couchdb saveDoc:myDoc options:{
success: function(doc) {
- var result = {text:"Database: Save Document",
- detailText:"Saved new document with id " + myDoc._id + ", rev " + myDoc._rev,
- pass:YES};
- [self addResult:result];
+ [self addResultWithText:"Database: Save Document"
+ detailText:"Saved new document with id " + myDoc._id + ", rev " + myDoc._rev
+ pass:YES];
+ }
+ }];
+
+ [couchdb allDocs:{limit: 5,
+ success: function(doc) {
+ [self addResultWithText:"Database: All Documents"
+ detailText:"Total documents: " + doc.total_rows
+ pass:YES];
}
}];
+
// NOTE: Compacting the database seems to confuse other concurrent demos.
// [couchdb compact:{
// success: function(doc) {
@@ -148,9 +172,12 @@
}
-- (void)addResult:(id)theResult
+- (void)addResultWithText:(CPString)theText detailText:(CPString)theDetailText pass:(BOOL)shouldPass
{
- [results addObject:theResult];
+ var result = {text:theText,
+ detailText:theDetailText,
+ pass:shouldPass};
+ [results addObject:result];
[collectionView reloadContent];
}
View
10 Classes/CouchDB/CPDictionary-ParamUtils.j
@@ -1,6 +1,14 @@
+/*
+ * CPDictionary+ParamUtils.j
+ * cappuccino-couchdb
+ *
+ * Created by Geoffrey Grosenbach on October 1, 2009.
+ * MIT Licensed.
+ */
+
@import <Foundation/CPDictionary.j>
-// From the HTTPRiot project by Justin Palmer.
+// Translated from the HTTPRiot project by Justin Palmer.
// http://github.com/Caged/httpriot/blob/master/Source/HTTPRiot/Extensions/NSDictionary+ParamUtils.m
@implementation CPDictionary (ParamUtils)
View
35 Classes/CouchDB/CouchDB.j
@@ -1,3 +1,11 @@
+/*
+ * CouchDB.j
+ * cappuccino-couchdb
+ *
+ * Created by Geoffrey Grosenbach on October 1, 2009.
+ * MIT Licensed.
+ */
+
@import <Foundation/CPObject.j>
// TODO: CouchDB incorrectly serves files with a + in the path. Should file a bug.
@import "CPDictionary-ParamUtils.j"
@@ -269,8 +277,16 @@
- (void)connection:(CPURLConnection)connection didFailWithError:(CPString)error
{
+ [self respondWithError:{error:"connection_failed", reason:error}];
+}
+
+// TODO: jquery.couch.js error is (status, error, reason)
+- (void)respondWithError:(JSObject)error
+{
if (options.error)
options.error(error);
+ else
+ alert("Sorry, an error occurred: " + error.reason);
}
// Other delegate methods
@@ -282,18 +298,17 @@
{
try
{
-// console.log(data);
+ // console.log(data);
var responseObject = [data objectFromJSON];
- // TODO: Should throw error if key is present,
- // but ignore errors for some requests like dropping a database.
- // if (responseObject.error)
- // {
- // [self connection:aConnection didFailWithError:responseObject.reason];
- // return;
- // }
- if (options.success)
+ if (responseObject.error)
+ {
+ [self respondWithError:responseObject];
+ return;
+ }
+ else if (options.success)
+ {
options.success(responseObject);
-
+ }
}
catch (anException)
{
View
39 Classes/Views/TFCollectionView/TFCollectionView.j
@@ -1,10 +1,9 @@
@import <AppKit/CPCollectionView.j>
+/**
+ Full-featured collection view with pre-defined item prototype styles.
-/*
- Full-featured collection view with pre-defined item prototype styles.
-
- TODO: Wrap in scrollview.
+ See the Subtitle view in the same directory.
*/
@implementation TFCollectionView : CPCollectionView
@@ -15,23 +14,21 @@
parentView:(CPView)theParentView
delegate:(id)theDelegate
{
- // TODO: Wrap in a scrollview
- self = [super initWithFrame:[theParentView frame]];
- if (self)
- {
- [self setDelegate:theDelegate];
- [self setBackgroundColor:[CPColor colorWithHexString:@"F2F2F2"]];
- [self setMinItemSize:CGSizeMake(0.0, 43.0)];
- [self setMaxItemSize:CGSizeMake(10000.0, 43.0)];
- [self setAllowsMultipleSelection:NO];
- [self setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
- [self setMaxNumberOfColumns:1];
- [self setVerticalMargin:1];
-
- var theItemPrototype = [[CPCollectionViewItem alloc] init];
- [theItemPrototype setView:[[theItemPrototypeClass alloc] initWithFrame:CGRectMakeZero()]];
- [self setItemPrototype:theItemPrototype];
- }
+ if (![super initWithFrame:[theParentView frame]])
+ return nil;
+
+ [self setDelegate:theDelegate];
+ [self setBackgroundColor:[CPColor colorWithHexString:@"F2F2F2"]];
+ [self setMinItemSize:CGSizeMake(0.0, 43.0)];
+ [self setMaxItemSize:CGSizeMake(10000.0, 43.0)];
+ [self setAllowsMultipleSelection:NO];
+ [self setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
+ [self setMaxNumberOfColumns:1];
+ [self setVerticalMargin:1];
+
+ var theItemPrototype = [[CPCollectionViewItem alloc] init];
+ [theItemPrototype setView:[[theItemPrototypeClass alloc] initWithFrame:CGRectMakeZero()]];
+ [self setItemPrototype:theItemPrototype];
return self;
}
Please sign in to comment.
Something went wrong with that request. Please try again.