99import Cocoa
1010
1111let rootElement : String = " VERSION SERIES "
12- let items : [ String ] = [ " All " , " Node.js 10.x " , " Node.js 9.x " , " Node.js 8.x " , " Node.js 6.x " , " Node.js 4.x " , " Node.js 0.12.x " , " Node.js 0.10.x " ]
1312
1413class DownloadViewController : NSSplitViewController ,
1514 NSOutlineViewDelegate ,
@@ -25,43 +24,34 @@ class DownloadViewController: NSSplitViewController,
2524 static let DateCell = " DATE_CELL "
2625 }
2726
28- var versions : Array < Dictionary < String , Any > > ? ;
29- var branches : Array < Dictionary < String , Any > > ? ;
30- var currentList : Array < Dictionary < String , Any > > ? ;
27+ var store : Store ? ;
28+ var currentList : Array < Version > ? ;
3129
3230 override func viewDidLoad( ) {
3331 super. viewDidLoad ( )
3432 sidebarView. expandItem ( rootElement)
35- sidebarView. selectRowIndexes ( IndexSet ( integer: 1 ) , byExtendingSelection: false )
36- self . initData ( )
33+ self . initStore ( )
3734 }
3835
3936 /**
4037 * Prepare the downloadable version list for the app
4138 */
42- func initData( ) {
43- let data = VersionManager . getData ( )
44- if data != nil {
45- print ( " already exists " )
46- versions = data![ " versions " ]
47- branches = data![ " branches " ]
48- updateList ( )
49- sidebarView. reloadData ( )
50- tableView. reloadData ( )
51- } else {
52- print ( " not exists, downloading... " )
53- VersionManager . updateDownloadList {
54- self . initData ( )
55- }
39+ func initStore( ) {
40+ Store . getStore { ( s) -> Void in
41+ self . store = s
42+ self . sidebarView. reloadData ( )
43+ self . sidebarView. selectRowIndexes ( IndexSet ( integer: 1 ) , byExtendingSelection: false )
5644 }
5745 }
5846
5947 /**
6048 * Update downloadable version list when sidebar item cliked
6149 */
6250 func updateList( ) {
63- print ( sidebarView. selectedRow)
64- currentList = versions
51+ let branch = self . store? . branches [ sidebarView. selectedRow - 1 ]
52+ let pattern : String = branch? . pattern ?? " "
53+ currentList = self . store? . versions. filter { $0. version. starts ( with: pattern) }
54+ tableView. reloadData ( )
6555 }
6656
6757 /* ---------- Sidebar ---------- */
@@ -70,7 +60,7 @@ class DownloadViewController: NSSplitViewController,
7060 if item == nil {
7161 return 1
7262 }
73- return branches ? . count ?? 0
63+ return self . store ? . branches . count ?? 0
7464 }
7565
7666 func outlineView( _ outlineView: NSOutlineView , isItemExpandable item: Any ) -> Bool {
@@ -102,7 +92,7 @@ class DownloadViewController: NSSplitViewController,
10292 // root element
10393 return rootElement
10494 } else {
105- return ( branches ? [ index] as! Dictionary < String , String > ) [ " name " ] ?? " "
95+ return self . store ? . branches [ index] . name ?? " "
10696 }
10797 }
10898
@@ -118,7 +108,6 @@ class DownloadViewController: NSSplitViewController,
118108 }
119109
120110 func outlineViewSelectionDidChange( _ notification: Notification ) {
121- print ( " outlineViewSelectionDidChange ... " )
122111 updateList ( )
123112 }
124113
@@ -132,16 +121,16 @@ class DownloadViewController: NSSplitViewController,
132121 var identifier : String = " " ;
133122
134123 // Get an item from list
135- guard let item: Dictionary < String , Any > = currentList ? [ row] else {
124+ guard let item: Version = currentList ? [ row] else {
136125 return nil
137126 }
138127
139128
140129 if tableColumn == tableView. tableColumns [ 0 ] {
141- text = item [ " version " ] as! String
130+ text = item. version
142131 identifier = CellIdentifiers . VersionCell
143132 } else if tableColumn == tableView. tableColumns [ 1 ] {
144- text = item [ " date " ] as! String
133+ text = item. date
145134 identifier = CellIdentifiers . DateCell
146135 }
147136
0 commit comments