Compare commits
No commits in common. "e54c2a0570b4141ea2a0c74422a65920a4d6e210" and "9488c108b693607e827ef77e5bc16f2cdd491f7c" have entirely different histories.
e54c2a0570
...
9488c108b6
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="16085" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15702" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16085"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15702"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
||||
|
@ -107,8 +107,7 @@
|
|||
<action selector="saveDocumentAs:" target="-1" id="mDf-zr-I0C"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Revert to Saved" id="KaW-ft-85H">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menuItem title="Revert to Saved" keyEquivalent="r" id="KaW-ft-85H">
|
||||
<connections>
|
||||
<action selector="revertDocumentToSaved:" target="-1" id="iJ3-Pv-kwq"/>
|
||||
</connections>
|
||||
|
@ -363,11 +362,6 @@
|
|||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Database" id="nD3-Xo-LUZ">
|
||||
<items>
|
||||
<menuItem title="Refresh" keyEquivalent="r" id="kpI-5J-eaC">
|
||||
<connections>
|
||||
<action selector="refresh:" target="-1" id="S5L-sX-Z2j"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Run Query" id="RSP-nH-a1I">
|
||||
<string key="keyEquivalent" base64-UTF8="YES">
|
||||
DQ
|
||||
|
|
|
@ -33,13 +33,5 @@ class MongoController {
|
|||
|
||||
client = try! MongoClient(connectionString, using: group)
|
||||
}
|
||||
|
||||
func db(for collection: DatabaseCollection) -> MongoDatabase {
|
||||
return client.db(collection.database)
|
||||
}
|
||||
|
||||
func collection(_ collection: DatabaseCollection) -> MongoCollection<Document> {
|
||||
return db(for: collection).collection(collection.name)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,17 +12,16 @@ import MongoSwift
|
|||
class Node {
|
||||
let key: Key?
|
||||
let value: BSON
|
||||
weak var parent: Node?
|
||||
|
||||
lazy private(set) var children: [Node] = {
|
||||
switch value {
|
||||
case let .array(array):
|
||||
return array.enumerated().map { (index, val) in
|
||||
Node(key: .index(index), value: val, parent: self)
|
||||
Node(key: .index(index), value: val)
|
||||
}
|
||||
case let .document(doc):
|
||||
return doc.map { (key, val) in
|
||||
Node(key: .name(key), value: val, parent: self)
|
||||
Node(key: .name(key), value: val)
|
||||
}
|
||||
default:
|
||||
return []
|
||||
|
@ -37,9 +36,8 @@ class Node {
|
|||
numberOfChildren > 0
|
||||
}
|
||||
|
||||
init(key: Key? = nil, value: BSON, parent: Node? = nil) {
|
||||
init(key: Key? = nil, value: BSON) {
|
||||
self.value = value
|
||||
self.parent = parent
|
||||
|
||||
if key == nil,
|
||||
case let .document(doc) = value,
|
||||
|
|
|
@ -150,11 +150,10 @@ class DatabaseViewController: NSViewController {
|
|||
}
|
||||
|
||||
@IBAction func runQuery(_ sender: Any) {
|
||||
queryViewController?.runQuery()
|
||||
}
|
||||
|
||||
@IBAction func refresh(_ sender: Any) {
|
||||
queryViewController?.refresh()
|
||||
guard let queryViewController = queryViewController else {
|
||||
return
|
||||
}
|
||||
queryViewController.runQuery()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,8 +27,6 @@ class QueryViewController: NSViewController {
|
|||
return queryTextView.string != defaultQuery
|
||||
}
|
||||
|
||||
var mostRecentQuery: String? = nil
|
||||
|
||||
var rootNodes: [Node] = []
|
||||
|
||||
init(mongoController: MongoController, collection: DatabaseCollection) {
|
||||
|
@ -45,8 +43,11 @@ class QueryViewController: NSViewController {
|
|||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
refresh()
|
||||
|
||||
let db = mongoController.client.db(collection.database)
|
||||
let collection = db.collection(self.collection.name)
|
||||
let documents = try! collection.find().all()
|
||||
rootNodes = documents.map { Node(document: $0) }
|
||||
|
||||
verticalSplitView.delegate = self
|
||||
verticalSplitView.setHoldingPriority(.defaultHigh, forSubviewAt: 0)
|
||||
|
||||
|
@ -60,6 +61,9 @@ class QueryViewController: NSViewController {
|
|||
outlineView.target = self
|
||||
outlineView.doubleAction = #selector(outlineCellDoubleClicked)
|
||||
|
||||
title = "\(self.collection.database).\(self.collection.name)"
|
||||
|
||||
documentCountLabel.stringValue = "\(documents.count) document\(documents.count == 1 ? "" : "s")"
|
||||
}
|
||||
|
||||
override func viewWillAppear() {
|
||||
|
@ -76,77 +80,14 @@ class QueryViewController: NSViewController {
|
|||
view.window!.makeFirstResponder(outlineView)
|
||||
}
|
||||
|
||||
func refresh(reload: Bool = true) {
|
||||
if let query = mostRecentQuery {
|
||||
let connStr = "\(mongoController.connectionString)/\(collection.database)"
|
||||
|
||||
rootNodes = MongoEvaluator.eval(command: query, connectingTo: connStr).map {
|
||||
Node(value: $0)
|
||||
}
|
||||
|
||||
title = query
|
||||
documentCountLabel.stringValue = "\(rootNodes.count) result\(rootNodes.count == 1 ? "" : "s")"
|
||||
} else {
|
||||
let documents = try! mongoController.collection(collection).find().all()
|
||||
rootNodes = documents.map { Node(document: $0) }
|
||||
|
||||
title = "\(self.collection.database).\(self.collection.name)"
|
||||
documentCountLabel.stringValue = "\(documents.count) document\(documents.count == 1 ? "" : "s")"
|
||||
}
|
||||
if reload {
|
||||
outlineView.reloadData()
|
||||
}
|
||||
}
|
||||
|
||||
func runQuery() {
|
||||
mostRecentQuery = queryTextView.string
|
||||
refresh()
|
||||
}
|
||||
|
||||
func deleteRootNode(_ node: Node) {
|
||||
guard case let .document(doc) = node.value else { return }
|
||||
let alert = NSAlert()
|
||||
alert.alertStyle = .warning
|
||||
alert.messageText = "Confirm deletion"
|
||||
alert.informativeText = "Are you sure you want to delete the document"
|
||||
let id: ObjectId?
|
||||
if case let .objectId(docId) = doc["_id"] {
|
||||
id = docId
|
||||
alert.informativeText += " with id \(docId)"
|
||||
} else {
|
||||
id = nil
|
||||
}
|
||||
let query = queryTextView.string
|
||||
let connStr = "\(mongoController.connectionString)/\(collection.database)"
|
||||
|
||||
alert.addButton(withTitle: "Delete")
|
||||
alert.addButton(withTitle: "Cancel")
|
||||
|
||||
alert.beginSheetModal(for: view.window!) { (response) in
|
||||
guard response == .alertFirstButtonReturn else { return }
|
||||
|
||||
self.mongoController.collection(self.collection).deleteOne(doc).whenComplete { (result) in
|
||||
DispatchQueue.main.async {
|
||||
switch result {
|
||||
case let .success(result):
|
||||
guard let result = result, result.deletedCount == 1 else {
|
||||
let alert = NSAlert()
|
||||
alert.alertStyle = .critical
|
||||
alert.messageText = "Error deleting document"
|
||||
if let id = id {
|
||||
alert.informativeText = "The document with id \(id) could not be deleted."
|
||||
} else {
|
||||
alert.informativeText = "The document could not be deleted."
|
||||
}
|
||||
alert.beginSheetModal(for: self.view.window!, completionHandler: nil)
|
||||
return
|
||||
}
|
||||
self.refresh()
|
||||
case let .failure(error):
|
||||
let alert = NSAlert(error: error)
|
||||
alert.beginSheetModal(for: self.view.window!, completionHandler: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
rootNodes = MongoEvaluator.eval(command: query, connectingTo: connStr).map {
|
||||
Node(document: $0)
|
||||
}
|
||||
outlineView.reloadData()
|
||||
}
|
||||
|
||||
@objc func outlineCellDoubleClicked() {
|
||||
|
@ -158,27 +99,9 @@ class QueryViewController: NSViewController {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func deleteNode(_ sender: Any) {
|
||||
guard let node = outlineView.item(atRow: outlineView.clickedRow) as? Node else {
|
||||
return
|
||||
}
|
||||
if node.parent == nil {
|
||||
deleteRootNode(node)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension QueryViewController: NSMenuItemValidation {
|
||||
func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
|
||||
if menuItem.action == #selector(deleteNode(_:)) {
|
||||
return outlineView.clickedRow != -1
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
extension QueryViewController: NSSplitViewDelegate {
|
||||
func splitView(_ splitView: NSSplitView, constrainSplitPosition proposedPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
|
||||
return max(80, min(splitView.bounds.height / 2, proposedPosition))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="16085" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15702" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16085"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15702"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
|
@ -994,18 +994,19 @@
|
|||
<rect key="frame" x="0.0" y="96" width="741" height="371"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<clipView key="contentView" id="eia-Pq-LIB">
|
||||
<rect key="frame" x="1" y="0.0" width="724" height="355"/>
|
||||
<rect key="frame" x="1" y="0.0" width="739" height="370"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<outlineView verticalHuggingPriority="750" allowsExpansionToolTips="YES" alternatingRowBackgroundColors="YES" columnReordering="NO" multipleSelection="NO" autosaveName="QueryOutline" rowSizeStyle="automatic" headerView="jah-QY-QbI" viewBased="YES" indentationPerLevel="16" outlineTableColumn="emg-oX-7XY" id="uu9-9q-MWr">
|
||||
<rect key="frame" x="0.0" y="0.0" width="724" height="330"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="739" height="345"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<size key="intercellSpacing" width="3" height="2"/>
|
||||
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
|
||||
<tableColumns>
|
||||
<tableColumn identifier="FieldNameCol" width="334" minWidth="40" maxWidth="1000" id="emg-oX-7XY">
|
||||
<tableColumn identifier="FieldNameCol" width="339" minWidth="40" maxWidth="1000" id="emg-oX-7XY">
|
||||
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Field Name">
|
||||
<font key="font" metaFont="controlContent" size="11"/>
|
||||
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
|
||||
</tableHeaderCell>
|
||||
|
@ -1017,11 +1018,11 @@
|
|||
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
|
||||
<prototypeCellViews>
|
||||
<tableCellView identifier="FieldNameCell" id="8dc-a6-0k5">
|
||||
<rect key="frame" x="1" y="1" width="334" height="17"/>
|
||||
<rect key="frame" x="1" y="1" width="339" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qEd-h6-M2A">
|
||||
<rect key="frame" x="0.0" y="0.0" width="334" height="17"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="339" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="8JQ-A4-jXh">
|
||||
<font key="font" metaFont="system"/>
|
||||
|
@ -1036,8 +1037,9 @@
|
|||
</tableCellView>
|
||||
</prototypeCellViews>
|
||||
</tableColumn>
|
||||
<tableColumn identifier="FieldValueCol" width="292" minWidth="40" maxWidth="1000" id="ggz-sp-EaO">
|
||||
<tableColumn identifier="FieldValueCol" width="297" minWidth="40" maxWidth="1000" id="ggz-sp-EaO">
|
||||
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Field Value">
|
||||
<font key="font" metaFont="controlContent" size="11"/>
|
||||
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
|
||||
</tableHeaderCell>
|
||||
|
@ -1049,11 +1051,11 @@
|
|||
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
|
||||
<prototypeCellViews>
|
||||
<tableCellView identifier="FieldValueCell" id="E6Z-9f-0gg">
|
||||
<rect key="frame" x="338" y="1" width="292" height="17"/>
|
||||
<rect key="frame" x="343" y="1" width="297" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Px2-mb-c5m">
|
||||
<rect key="frame" x="0.0" y="0.0" width="292" height="17"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="297" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="rED-77-VFk">
|
||||
<font key="font" metaFont="system"/>
|
||||
|
@ -1068,8 +1070,9 @@
|
|||
</tableCellView>
|
||||
</prototypeCellViews>
|
||||
</tableColumn>
|
||||
<tableColumn identifier="ValueTypeCol" width="89" minWidth="10" maxWidth="3.4028234663852886e+38" id="Tow-Y6-pc7">
|
||||
<tableColumn identifier="ValueTypeCol" width="94" minWidth="10" maxWidth="3.4028234663852886e+38" id="Tow-Y6-pc7">
|
||||
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Value Type">
|
||||
<font key="font" metaFont="controlContent" size="11"/>
|
||||
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
</tableHeaderCell>
|
||||
|
@ -1081,11 +1084,11 @@
|
|||
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
|
||||
<prototypeCellViews>
|
||||
<tableCellView identifier="ValueTypeCell" id="tUj-Jd-Rj1">
|
||||
<rect key="frame" x="633" y="1" width="89" height="17"/>
|
||||
<rect key="frame" x="643" y="1" width="94" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="mBU-Qs-G4S">
|
||||
<rect key="frame" x="0.0" y="0.0" width="89" height="17"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="94" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="tmE-QF-vUZ">
|
||||
<font key="font" metaFont="system"/>
|
||||
|
@ -1104,16 +1107,16 @@
|
|||
</outlineView>
|
||||
</subviews>
|
||||
</clipView>
|
||||
<scroller key="horizontalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="WBg-uK-bLa">
|
||||
<rect key="frame" x="1" y="355" width="724" height="15"/>
|
||||
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="WBg-uK-bLa">
|
||||
<rect key="frame" x="1" y="119" width="223" height="15"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</scroller>
|
||||
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="Sj7-M1-no8">
|
||||
<rect key="frame" x="725" y="25" width="15" height="330"/>
|
||||
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="Sj7-M1-no8">
|
||||
<rect key="frame" x="224" y="17" width="15" height="102"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</scroller>
|
||||
<tableHeaderView key="headerView" id="jah-QY-QbI">
|
||||
<rect key="frame" x="0.0" y="0.0" width="724" height="25"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="739" height="25"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</tableHeaderView>
|
||||
</scrollView>
|
||||
|
@ -1132,21 +1135,7 @@
|
|||
<constraint firstAttribute="trailing" secondItem="E3D-CM-hk3" secondAttribute="trailing" id="pjR-Xa-8co"/>
|
||||
<constraint firstItem="E3D-CM-hk3" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="sR0-qd-Vco"/>
|
||||
</constraints>
|
||||
<connections>
|
||||
<outlet property="menu" destination="nL5-kg-dty" id="KQ4-CJ-Hz4"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="271.5" y="262.5"/>
|
||||
</customView>
|
||||
<menu id="nL5-kg-dty">
|
||||
<items>
|
||||
<menuItem title="Delete" id="nn0-ZF-eDZ">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="deleteNode:" target="-2" id="dgm-SC-hn5"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
<point key="canvasLocation" x="887" y="210"/>
|
||||
</menu>
|
||||
</objects>
|
||||
</document>
|
||||
|
|
Loading…
Reference in New Issue