Alphabetically sort database and collection names

Closes #1
This commit is contained in:
Shadowfacts 2020-01-27 22:31:13 -05:00
parent 01418e44ad
commit 624befaec2
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 7 additions and 4 deletions

View File

@ -47,9 +47,11 @@ class DatabaseViewController: NSViewController {
super.viewDidLoad()
mongoController.client.listDatabaseNames().flatMap { (databaseNames) -> EventLoopFuture<[DatabaseCollections]> in
let futures = databaseNames.map { (name) in
self.mongoController.client.db(name).listCollectionNames().map { (collectionNames) in
DatabaseCollections(database: name, collections: collectionNames)
let futures = databaseNames.map { (name: String) -> EventLoopFuture<DatabaseCollections> in
let db = self.mongoController.client.db(name)
return db.listCollectionNames().map { (collectionNames: [String]) -> DatabaseCollections in
let sortedNames = collectionNames.sorted()
return DatabaseCollections(database: name, collections: sortedNames)
}
}
return EventLoopFuture.whenAllSucceed(futures, on: futures.first!.eventLoop)
@ -58,7 +60,8 @@ class DatabaseViewController: NSViewController {
switch res {
case let .success(databaseCollections):
self.databaseCollections = databaseCollections
let sortedCollections = databaseCollections.sorted(by: { $0.database < $1.database })
self.databaseCollections = sortedCollections
DispatchQueue.main.async {
self.collectionsOutlineView.reloadData()
}