Browse Source

Alphabetically sort database and collection names

Closes #1
master
Shadowfacts 5 months ago
parent
commit
624befaec2
Signed by: Shadowfacts <me@shadowfacts.net> GPG Key ID: 94A5AB95422746E5
1 changed files with 7 additions and 4 deletions
  1. 7
    4
      MongoView/View Controllers/DatabaseViewController.swift

+ 7
- 4
MongoView/View Controllers/DatabaseViewController.swift View File

@@ -47,9 +47,11 @@ class DatabaseViewController: NSViewController {
47 47
         super.viewDidLoad()
48 48
         
49 49
         mongoController.client.listDatabaseNames().flatMap { (databaseNames) -> EventLoopFuture<[DatabaseCollections]> in
50
-            let futures = databaseNames.map { (name) in
51
-                self.mongoController.client.db(name).listCollectionNames().map { (collectionNames) in
52
-                    DatabaseCollections(database: name, collections: collectionNames)
50
+            let futures = databaseNames.map { (name: String) -> EventLoopFuture<DatabaseCollections> in
51
+                let db = self.mongoController.client.db(name)
52
+                return db.listCollectionNames().map { (collectionNames: [String]) -> DatabaseCollections in
53
+                    let sortedNames = collectionNames.sorted()
54
+                    return DatabaseCollections(database: name, collections: sortedNames)
53 55
                 }
54 56
             }
55 57
             return EventLoopFuture.whenAllSucceed(futures, on: futures.first!.eventLoop)
@@ -58,7 +60,8 @@ class DatabaseViewController: NSViewController {
58 60
             
59 61
             switch res {
60 62
             case let .success(databaseCollections):
61
-                self.databaseCollections = databaseCollections
63
+                let sortedCollections = databaseCollections.sorted(by: { $0.database < $1.database })
64
+                self.databaseCollections = sortedCollections
62 65
                 DispatchQueue.main.async {
63 66
                     self.collectionsOutlineView.reloadData()
64 67
                 }

Loading…
Cancel
Save