-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b25de29
commit b8d5be9
Showing
1,047 changed files
with
261,346 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* AppController.j | ||
* EngJourneering | ||
* | ||
* Created by Chandler Kent on September 23, 2009. | ||
* Copyright 2009, Your Company All rights reserved. | ||
*/ | ||
|
||
@import <Foundation/CPObject.j> | ||
|
||
@import "Models/EJUser.j" | ||
@import "Categories/EJ+CPString.j" | ||
@import "Controllers/EJUserController.j" | ||
@import "Controllers/EJSourceController.j" | ||
@import "Views/EJSourceView.j" | ||
@import "Views/EJToolbarDelegate.j" | ||
|
||
@implementation AppController : CPObject | ||
{ | ||
EJUserController _userController; | ||
EJSourceController _sourceController; | ||
} | ||
|
||
- (void)applicationDidFinishLaunching:(CPNotification)aNotification | ||
{ | ||
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask], | ||
contentView = [theWindow contentView]; | ||
|
||
var toolbar = [[CPToolbar alloc] initWithIdentifier:@"Toolbar"]; | ||
[theWindow setToolbar:toolbar]; | ||
|
||
var toolbarDelegate = [[EJToolbarDelegate alloc] init]; | ||
[toolbar setDelegate:toolbarDelegate]; | ||
|
||
// Set up the controllers | ||
_userController = [[EJUserController alloc] init]; | ||
_sourceController = [[EJSourceController alloc] init]; | ||
|
||
// Set up views | ||
var splitView = [[CPSplitView alloc] initWithFrame:[contentView bounds]]; | ||
[splitView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; | ||
[splitView setVertical:YES]; | ||
[splitView setIsPaneSplitter:YES]; | ||
|
||
var sourceView = [[EJSourceView alloc] initWithFrame:CGRectMake(0, 0, 150.0, CGRectGetHeight([contentView bounds]))]; | ||
[sourceView setAutoresizingMask:CPViewHeightSizable | CPViewMaxXMargin]; | ||
[splitView addSubview:sourceView]; | ||
|
||
var detailView = [[EJDetailView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth([contentView bounds]) - CGRectGetWidth([sourceView bounds]), CGRectGetHeight([contentView bounds]))]; | ||
[detailView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; | ||
[splitView addSubview:detailView]; | ||
|
||
[sourceView setDetailView:detailView]; | ||
[contentView addSubview:splitView]; | ||
|
||
[theWindow orderFront:self]; | ||
|
||
// Set up observers | ||
[_userController addObserver:sourceView forKeyPath:@"users" options:CPKeyValueObservingOptionNew context:nil]; | ||
[_userController addObserver:[EJAllUsers sharedAllUsers] forKeyPath:@"users" options:CPKeyValueObservingOptionNew context:nil]; | ||
[_userController readUsersFromBundle]; | ||
|
||
[_userController addObserver:_sourceController forKeyPath:@"currentUser" options:CPKeyValueObservingOptionNew context:nil]; | ||
// We should have to do the following line? But we get 2 notifications if we do. | ||
// [_userController addObserver:detailView forKeyPath:@"currentUser" options:CPKeyValueObservingOptionNew context:nil]; | ||
[_userController addObserver:detailView forKeyPath:@"currentUser.data" options:CPKeyValueObservingOptionNew context:nil]; | ||
// [_userController addObserver:[EJAllUsers sharedAllUsers] forKeyPath:@"currentUser.data" options:CPKeyValueObservingOptionNew context:nil]; | ||
[sourceView addObserver:_userController forKeyPath:@"currentUser" options:CPKeyValueObservingOptionNew context:nil]; | ||
|
||
// We would like to do this, but toolbars are a bit tricky to update its contents. | ||
// [_sourceController addObserver:toolbarDelegate forKeyPath:@"sources" options:CPKeyValueObservingOptionNew context:nil]; | ||
[_sourceController readSourcesFromBundle]; | ||
|
||
[toolbarDelegate addObserver:detailView forKeyPath:@"currentSource" options:CPKeyValueObservingOptionNew context:nil]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
@import <Foundation/CPString.j> | ||
|
||
var timeRegEx = new RegExp("t:(\\d+)h(\\d+)m", "gi"); | ||
|
||
@implementation CPString (EJ) | ||
|
||
- (CPNumber)findTime | ||
{ | ||
var time = 0; | ||
|
||
var matches = timeRegEx.exec(self); | ||
if (matches) { | ||
time = 60 * parseInt(matches[1]) + parseInt(matches[2]); | ||
} | ||
|
||
return time; | ||
} | ||
|
||
- (CPString)removeTime | ||
{ | ||
return self.replace(timeRegEx, ""); | ||
} | ||
|
||
- (CPString)removeOccurencesOfString:(CPString)removeString | ||
{ | ||
return [self stringByReplacingOccurrencesOfString:removeString withString:""]; | ||
} | ||
|
||
- (CPDate)convertFromGitHubDateToCPDate | ||
{ | ||
var dayThenTime = [self componentsSeparatedByString:@"T"]; | ||
|
||
if (dayThenTime) { | ||
var date = [dayThenTime[0] componentsSeparatedByString:@"-"]; | ||
var time = [dayThenTime[1] componentsSeparatedByString:@":"]; | ||
|
||
if (date && time) { | ||
return new Date(date[0], date[1] - 1, date[2], time[0], time[1], time[2].substring(0, 2)); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
@import <Foundation/CPObject.j> | ||
@import "../Models/EJUserData.j" | ||
|
||
@implementation EJAbstractSourceController : CPObject | ||
{ | ||
CPString _key @accessors(property=key, readonly); | ||
EJUser _currentUser @accessors(property=currentUser); | ||
} | ||
|
||
- (id)initWithKey:(CPString)aKey | ||
{ | ||
self = [super init]; | ||
|
||
if (self) | ||
{ | ||
_key = aKey; | ||
_currentUser = nil; | ||
_currentUserData = []; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (BOOL)currentUserHasSource | ||
{ | ||
if (!_currentUser) | ||
return NO; | ||
|
||
return ([[_currentUser handles] objectForKey:_key] != nil) | ||
} | ||
|
||
- (BOOL)currentUserHasData | ||
{ | ||
if (!_currentUser) | ||
return NO; | ||
|
||
return ([[_currentUser data] count] > 0); | ||
} | ||
|
||
- (void)fetchDataForCurrentUser | ||
{ | ||
console.warn("You should override me."); | ||
} | ||
|
||
- (void)connection:(CPJSONPConnection)connection didReceiveData:(CPString)data | ||
{ | ||
console.warn("You should really override me."); | ||
} | ||
|
||
- (void)connection:(CPJSONPConnection)connection didFailWithError:(CPString)error | ||
{ | ||
console.error("An error occurred for the connection", connection, "on class", class_getName(self), ":", error); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
@import "EJAbstractSourceController.j" | ||
|
||
@implementation EJGitHubController : EJAbstractSourceController | ||
{ | ||
CPURL _gitHubURL; | ||
CPArray _gitHubCommits; | ||
} | ||
|
||
- (id)initWithKey:(CPString)key | ||
{ | ||
self = [super initWithKey:key]; | ||
|
||
if (self) | ||
{ | ||
_gitHubCommits = []; | ||
_gitHubURL = [[CPURL alloc] initWithString:@"https://github.com/api/v2/json/commits/list/hammerdr/Omni-Software-Localization/master"]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)fetchDataForCurrentUser | ||
{ | ||
if (![self currentUserHasSource] || [self currentUserHasData]) | ||
return; | ||
|
||
// console.log("getting data from", _key, "for", [_currentUser displayName]); | ||
|
||
if ([_gitHubCommits count] <= 0) | ||
{ | ||
var request = [CPURLRequest requestWithURL:_gitHubURL]; | ||
var connection = [CPJSONPConnection sendRequest:request callback:@"callback" delegate:self]; | ||
} | ||
else | ||
{ | ||
[self processGitHubCommits:_gitHubCommits]; | ||
} | ||
} | ||
|
||
- (void)connection:(CPJSONPConnection)connection didReceiveData:(CPJSObject)data | ||
{ | ||
var commits = data.commits; | ||
|
||
_gitHubCommits = commits; | ||
|
||
[self processGitHubCommits:_gitHubCommits] | ||
} | ||
|
||
- (void)processGitHubCommits:(CPArray)commits | ||
{ | ||
var user = [self currentUser]; | ||
var gitHubHandle = [[user handles] objectForKey:[self key]]; | ||
|
||
for (var i = 0; i < [commits count]; i++) { | ||
var commit = [commits objectAtIndex:i]; | ||
if (commit.author.name === gitHubHandle) { | ||
var message = [commit.message removeTime]; | ||
var time = [commit.message findTime]; | ||
var date = [commit.authored_date convertFromGitHubDateToCPDate]; | ||
var link = [CPURL URLWithString:commit.url]; | ||
|
||
var dictionary = [[CPDictionary alloc] initWithObjects:[message, time, date, link, @"Github", [user displayName]] | ||
forKeys:[@"message", @"time", @"date", @"link", @"source", @"user"]]; | ||
|
||
var data = [[EJUserData alloc] initWithDictionary:dictionary]; | ||
[user insertObject:data inDataAtIndex:[[user data] count]]; | ||
} | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
@import "EJAbstractSourceController.j" | ||
|
||
@implementation EJRSSController : EJAbstractSourceController | ||
{ | ||
CPDictionary _connections; | ||
} | ||
|
||
- (void)fetchDataForCurrentUser | ||
{ | ||
if (![self currentUserHasSource] || [self currentUserHasData]) | ||
return; | ||
|
||
// console.log("getting data from", _key, "for", [_currentUser displayName]); | ||
if (!_connections) | ||
{ | ||
_connections = [CPDictionary dictionary]; | ||
} | ||
|
||
var url = [[CPURL alloc] initWithString:[[_currentUser handles] objectForKey:_key]]; | ||
var request = [CPURLRequest requestWithURL:url]; | ||
var connection = [CPJSONPConnection sendRequest:request callback:@"callback" delegate:self]; | ||
[_connections setObject:_currentUser forKey:connection]; | ||
} | ||
|
||
- (void)connection:(CPJSONPConnection)connection didReceiveData:(CPJSObject)data | ||
{ | ||
var user = [_connections objectForKey:connection]; | ||
|
||
var posts = data.items; | ||
|
||
for (var i = 0; i < [posts count]; i++) | ||
{ | ||
var post = [posts objectAtIndex:i]; | ||
|
||
var message = post.title; | ||
var link = [CPURL URLWithString:post.link]; | ||
var date = [[CPDate alloc] initWithString:post.date]; | ||
var dictionary = [[CPDictionary alloc] initWithObjects:[message, 0, date, link, @"Blog", [user displayName]] | ||
forKeys:[@"message", @"time", @"date", @"link", @"source", @"user"]]; | ||
|
||
var data = [[EJUserData alloc] initWithDictionary:dictionary]; | ||
[user insertObject:data inDataAtIndex:[[user data] count]]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
@import <Foundation/CPObject.j> | ||
|
||
@import "EJTwitterController.j" | ||
@import "EJGitHubController.j" | ||
@import "EJRSSController.j" | ||
@import "EJUserController.j" | ||
|
||
/* | ||
* Initializes and tracks the individual source controllers. | ||
*/ | ||
@implementation EJSourceController : CPObject | ||
{ | ||
CPArray _sources @accessors(property=sources); | ||
} | ||
|
||
- (id)init | ||
{ | ||
self = [super init]; | ||
|
||
if (self) | ||
{ | ||
_sources = []; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)readSourcesFromBundle | ||
{ | ||
var bundle = [CPBundle mainBundle]; | ||
var bundleSources = [bundle objectForInfoDictionaryKey:@"EJSources"]; | ||
|
||
for (var i = 0; i < [bundleSources count]; i++) | ||
{ | ||
var source = [bundleSources objectAtIndex:i]; | ||
var key = [source objectForKey:@"key"]; | ||
var classAsString = objj_getClass([source objectForKey:@"class"]); | ||
[self insertObject:[[classAsString alloc] initWithKey:key] inSourcesAtIndex:i]; | ||
} | ||
} | ||
|
||
- (void)insertObject:(EJAbstractSourceController)source inSourcesAtIndex:(CPInteger)index | ||
{ | ||
[_sources insertObject:source atIndex:index]; | ||
} | ||
|
||
- (void)fetchDataForUser:(EJUser)user | ||
{ | ||
if (user === [EJAllUsers sharedAllUsers]) | ||
{ | ||
var users = [[EJAllUsers sharedAllUsers] users]; | ||
for (var i = 0; i < [users count]; i++) | ||
{ | ||
[self fetchDataForUser:[users objectAtIndex:i]]; | ||
} | ||
} | ||
else | ||
{ | ||
for (var i = 0; i < [_sources count]; i++) | ||
{ | ||
var source = [_sources objectAtIndex:i]; | ||
[source setCurrentUser:user]; | ||
[source fetchDataForCurrentUser]; | ||
} | ||
} | ||
} | ||
|
||
- (void)observeValueForKeyPath:(CPString)keyPath ofObject:(id)object change:(CPDictionary)change context:(void)context | ||
{ | ||
switch (keyPath) | ||
{ | ||
case @"currentUser": | ||
var user = [change objectForKey:CPKeyValueChangeNewKey]; | ||
[self fetchDataForUser:user]; | ||
break; | ||
|
||
default: | ||
console.warn("Unhandled keyPath in EJSourceController."); | ||
break; | ||
} | ||
} | ||
|
||
@end |
Oops, something went wrong.