Skip to content

Commit

Permalink
Merge pull request #11 from devmynd/develop
Browse files Browse the repository at this point in the history
Cutting 0.1.1 release
  • Loading branch information
littlelazer authored Jul 19, 2016
2 parents 1defac4 + 027de07 commit 0101a0a
Show file tree
Hide file tree
Showing 88 changed files with 4,956 additions and 1,057 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ xcuserdata/
## Other
*.moved-aside
*.xcuserstate
.DS_Store

## Obj-C/Swift specific
*.hmap
Expand Down Expand Up @@ -52,7 +53,7 @@ Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md
Expand Down
8 changes: 4 additions & 4 deletions Components/InteractorModule.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

class InteractorModule: AppModule {
func inject() -> Settings {
func inject() -> SettingsType {
return single {
Settings(
defaults: $0.system.inject(),
keychain: $0.system.inject(),
notificationCenter: $0.system.inject())
notificationCenter: $0.system.inject()) as SettingsType
}
}

Expand All @@ -17,12 +17,12 @@ class InteractorModule: AppModule {
}
}

func inject() -> TimerCoordinator {
func inject() -> TimerCoordinatorType {
return single {
TimerCoordinator(
runLoop: $0.system.inject(),
projectsInteractor: $0.interactor.inject(),
settings: $0.interactor.inject())
settings: $0.interactor.inject()) as TimerCoordinatorType
}
}
}
7 changes: 4 additions & 3 deletions Components/PreferencesViewModule.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

class PreferencesViewModule: ViewModule {
func inject<V: PreferencesView>(view: V) -> PreferencesPresenter<V> {
return single {
return single { component in
PreferencesPresenter(
view: view,
projectsInteractor: $0.app.interactor.inject(),
settings: $0.app.interactor.inject())
projectsInteractor: component.app.interactor.inject(),
settings: component.app.interactor.inject(),
timerCoordinator: component.app.interactor.inject())
}
}
}
66 changes: 43 additions & 23 deletions Harbor.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Harbor.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Harbor.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Harbor/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, StatusMenuDelegate {
// MARK: Dependencies
var component: AppComponent { return Application.component() }

private lazy var settings: Settings = self.component.interactor.inject()
private lazy var settings: SettingsType = self.component.interactor.inject()
private lazy var projectsInteractor: ProjectsInteractor = self.component.interactor.inject()
private lazy var timerCoordinator: TimerCoordinator = self.component.interactor.inject()
private lazy var timerCoordinator: TimerCoordinatorType = self.component.interactor.inject()

//
// MARK: Interface Elements
Expand Down
86 changes: 51 additions & 35 deletions Harbor/Build.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import Foundation
import ObjectMapper

final class Build: Mappable {
enum Status : String {
case Unknown = "codeshipLogo_black"
case Passing = "codeshipLogo_green"
case Failing = "codeshipLogo_red"
case Building = "codeshipLogo_blue"

func icon() -> NSImage {
let image = NSImage(named: self.rawValue)!
// allows black icon to work with light & dark menubars
image.template = self == .Unknown

return image
}
}

final class Build: ResponseObjectSerializable, ResponseCollectionSerializable {
var id: Int?
var uuid: String?
var projectID: Int?
var status: String?
var status = Build.Status.Unknown
var gitHubUsername: String?
var commitID: String?
var message: String?
Expand All @@ -13,44 +29,44 @@ final class Build: ResponseObjectSerializable, ResponseCollectionSerializable {
var finishedAt: NSDate?
var codeshipLinkString: String?

init?(response: NSHTTPURLResponse, representation: AnyObject){
self.id = representation.valueForKeyPath("id") as? Int
self.uuid = representation.valueForKeyPath("uuid") as? String
self.projectID = representation.valueForKeyPath("project_id") as? Int
self.status = representation.valueForKeyPath("status") as? String
self.gitHubUsername = representation.valueForKeyPath("github_username") as? String
self.commitID = representation.valueForKeyPath("commit_id") as? String
self.message = representation.valueForKeyPath("message") as? String
self.branch = representation.valueForKeyPath("branch") as? String
self.startedAt = self.convertDateFromString(representation.valueForKeyPath("started_at") as? String)
if let finishedAtString = representation.valueForKeyPath("finished_at") as? String{
self.finishedAt = self.convertDateFromString(finishedAtString)
}
}

static func collection(response response: NSHTTPURLResponse, representation: AnyObject) -> [Build] {
var builds: [Build] = []
// MARK: ObjectMapper - Mappable
init(_ map: Map) { }

if let representation = representation.valueForKeyPath("builds") as? [[String: AnyObject]] {
for buildRepresentation in representation {
if let build = Build(response: response, representation: buildRepresentation) {
builds.append(build)
}
}
}
return builds
func mapping(map: Map) {
id <- map["id"]
uuid <- map["uuid"]
projectID <- map["project_id"]
status <- map["status"]
gitHubUsername <- map["github_username"]
commitID <- map["commit_id"]
message <- map["message"]
branch <- map["branch"]
startedAt <- (map["started_at"], Transforms.date)
finishedAt <- (map["finished_at"], Transforms.date)
}

func convertDateFromString(aString: String?) -> NSDate{
let dateFormatter = NSDateFormatter();
dateFormatter.dateFormat = "YYYY-MM-dd'T'HH:mm:ss.SSSZ"
private struct Transforms {
static let dateFormatter: NSDateFormatter = ({ () -> NSDateFormatter in
let formatter = NSDateFormatter()
formatter.dateFormat = "YYYY-MM-dd'T'HH:mm:ss.SSSZ"
return formatter
})()

static let date = TransformOf<NSDate, String>(
fromJSON: Transforms.convertDateFromString,
toJSON: { _ in "" }
)

private static func convertDateFromString(aString: String?) -> NSDate? {
var date : String
if let dateString = aString {
date = dateString
} else {
date = ""
}

var date : String
if let dateString = aString {
date = dateString
} else {
date = ""
return dateFormatter.dateFromString(date)
}
return dateFormatter.dateFromString(date)!
}
}
17 changes: 0 additions & 17 deletions Harbor/BuildStatus.swift

This file was deleted.

7 changes: 6 additions & 1 deletion Harbor/BuildView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ class BuildView: NSView {
override func drawRect(dirtyRect: NSRect) {
let menuItem = self.enclosingMenuItem
if menuItem?.highlighted == true {
NSColor.blueColor().set()
if (NSAppearance.currentAppearance().name.hasPrefix("NSAppearanceNameVibrantDark")) {
NSColor(red: 0.004, green: 0.380, blue: 0.750, alpha: 1.0).set()
}
else {
NSColor(red: 0.705, green: 0.847, blue: 0.989, alpha: 1.0).set()
}
NSBezierPath.fillRect(dirtyRect)
} else {
super.drawRect(dirtyRect)
Expand Down
4 changes: 2 additions & 2 deletions Harbor/BuildView.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9532" systemVersion="14F1605" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9532"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="BuildView" customModule="Harbor" customModuleProvider="target">
Expand Down
9 changes: 5 additions & 4 deletions Harbor/CodeshipApi.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Alamofire
import AlamofireObjectMapper

protocol CodeshipApiType {
func getProjects(successHandler: ([Project]) -> (), errorHandler: (String)->())
Expand All @@ -7,19 +8,19 @@ protocol CodeshipApiType {
class CodeshipApi : CodeshipApiType {
static let apiRootPath = "https://codeship.com/api/v1/projects.json?api_key="

private let settings: Settings
private let settings: SettingsType

init(settings: Settings) {
init(settings: SettingsType) {
self.settings = settings
}

func getProjects(successHandler: ([Project]) -> (), errorHandler: (String)->()){
let apiKey = settings.apiKey
let apiURL = "\(CodeshipApi.apiRootPath)\(apiKey)"

Alamofire.request(.GET, apiURL).responseCollection{(response: Response<[Project], NSError> ) in
Alamofire.request(.GET, apiURL).responseObject{(response: Response<ProjectCollection, NSError> ) in
if(response.result.isSuccess) {
successHandler(response.result.value!)
successHandler(response.result.value!.projects)
} else {
//log the error
debugPrint(response.result)
Expand Down
12 changes: 12 additions & 0 deletions Harbor/NSButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import AppKit

extension NSButton {
var on: Bool {
get {
return (state == NSOnState) ? true : false
}
set {
state = newValue ? NSOnState : NSOffState
}
}
}
24 changes: 22 additions & 2 deletions Harbor/PreferencesPaneWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class PreferencesPaneWindowController: NSWindowController, NSWindowDelegate, NST
@IBOutlet weak var refreshRateTextField: TextField!
@IBOutlet weak var projectTableView: NSTableView!
@IBOutlet weak var launchOnLoginCheckbox: NSButton!
@IBOutlet weak var codeshipAPIKeyError: NSTextField!
@IBOutlet weak var refreshRateError: NSTextField!
@IBOutlet weak var savePreferencesButton: NSButton!

override init(window: NSWindow?) {
super.init(window: window)
Expand Down Expand Up @@ -60,13 +63,23 @@ class PreferencesPaneWindowController: NSWindowController, NSWindowDelegate, NST
}

func updateLaunchOnLogin(launchOnLogin: Bool) {
launchOnLoginCheckbox.enabled = launchOnLogin
launchOnLoginCheckbox.on = launchOnLogin
}

func updateApiKeyError(errorMessage: String) {
codeshipAPIKeyError.stringValue = errorMessage
enableOrDisableSaveButton()
}

func updateRefreshRateError(errorMessage: String) {
refreshRateError.stringValue = errorMessage
enableOrDisableSaveButton()
}

//
// MARK: Interface Actions
@IBAction func launchOnLoginCheckboxClicked(sender: AnyObject) {
presenter.updateLaunchOnLogin(launchOnLoginCheckbox.enabled)
presenter.updateLaunchOnLogin(launchOnLoginCheckbox.on)
}

@IBAction func isEnabledCheckboxClicked(sender: AnyObject) {
Expand All @@ -92,6 +105,7 @@ class PreferencesPaneWindowController: NSWindowController, NSWindowDelegate, NST
} else if textField == refreshRateTextField {
presenter.updateRefreshRate(textField.stringValue)
}
enableOrDisableSaveButton()
}
}

Expand Down Expand Up @@ -122,4 +136,10 @@ class PreferencesPaneWindowController: NSWindowController, NSWindowDelegate, NST

return view
}

//
// MARK: Validations
private func enableOrDisableSaveButton() {
savePreferencesButton.enabled = codeshipAPIKeyError.stringValue.isEmpty && refreshRateError.stringValue.isEmpty
}
}
Loading

0 comments on commit 0101a0a

Please sign in to comment.