-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add base classes and refactor tab management
- Loading branch information
Showing
5 changed files
with
147 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Google.Cloud.Firestore; | ||
using Terminal.Gui; | ||
|
||
namespace nfirestore_cli.Tabs | ||
{ | ||
internal class CollectionTab : FirestoreTab | ||
{ | ||
public CollectionReference CollectionReference { get; } | ||
|
||
public CollectionTab(CollectionReference cr, IEnumerable<DocumentReference> children) | ||
{ | ||
this.CollectionReference = cr; | ||
var view = new TableView | ||
{ | ||
Width = Dim.Fill(), | ||
Height = Dim.Fill(), | ||
Table = new TableFromCollection(cr, children) | ||
}; | ||
|
||
SetTab(cr.Id, view); | ||
} | ||
|
||
public override bool Is(DocumentReference dr) | ||
{ | ||
return false; | ||
} | ||
|
||
public override bool Is(CollectionReference cr) | ||
{ | ||
return cr == CollectionReference; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Google.Cloud.Firestore; | ||
using Newtonsoft.Json; | ||
using Terminal.Gui; | ||
|
||
namespace nfirestore_cli.Tabs | ||
{ | ||
internal class DocumentTab : FirestoreTab | ||
{ | ||
public DocumentReference DocumentReference { get; } | ||
|
||
public DocumentTab(DocumentSnapshot snap) | ||
{ | ||
this.DocumentReference = snap.Reference; | ||
|
||
var view = new TextView | ||
{ | ||
Width = Dim.Fill(), | ||
Height = Dim.Fill(), | ||
WordWrap = false, | ||
AllowsReturn = false, | ||
Multiline = true, | ||
}; | ||
|
||
OpenDocumentIn(view, snap); | ||
|
||
SetTab(snap.Id, view); | ||
} | ||
|
||
internal static void OpenDocumentIn(TextView currentDocumentTextView, DocumentSnapshot snap) | ||
{ | ||
currentDocumentTextView.Text = JsonConvert.SerializeObject(snap.ToDictionary(), Formatting.Indented); | ||
} | ||
|
||
public override bool Is(DocumentReference dr) | ||
{ | ||
return dr == DocumentReference; | ||
} | ||
|
||
public override bool Is(CollectionReference cr) | ||
{ | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Google.Cloud.Firestore; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Terminal.Gui; | ||
|
||
namespace nfirestore_cli.Tabs | ||
{ | ||
abstract class FirestoreTab : IFirestoreTab | ||
{ | ||
public Tab Tab { get; private set; } | ||
|
||
public abstract bool Is(DocumentReference dr); | ||
|
||
public abstract bool Is(CollectionReference cr); | ||
|
||
protected void SetTab(string name, View view) | ||
{ | ||
Tab = new Tab() | ||
{ | ||
Text = GetTabName(name), | ||
View = view | ||
}; | ||
} | ||
|
||
private string GetTabName(string name) | ||
{ | ||
if (name.Length > 8) | ||
{ | ||
name = name.Substring(0, 6) + "…"; | ||
} | ||
|
||
return "[X]" + name; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Google.Cloud.Firestore; | ||
using Terminal.Gui; | ||
|
||
namespace nfirestore_cli.Tabs | ||
{ | ||
internal interface IFirestoreTab | ||
{ | ||
public Tab Tab { get; } | ||
public bool Is(DocumentReference dr); | ||
public bool Is(CollectionReference cr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters