Permalink
Browse files

Merge branch 'master' of github.com:fitzchak1/ravendb

  • Loading branch information...
2 parents 14b8a5a + 458dca7 commit 181a9c0cd87dc94675941021191e93b34520692e @ayende ayende committed Jul 7, 2011
Showing with 1,150 additions and 521 deletions.
  1. +19 −0 Raven.Studio/AppBootstrapper.cs
  2. +2 −2 Raven.Studio/Behaviors/DocumentsContextMenu.cs
  3. +9 −14 Raven.Studio/Commands/DeleteDocument.cs
  4. +3 −3 Raven.Studio/Commands/EditIndex.cs
  5. +33 −11 Raven.Studio/Commands/SaveDocument.cs
  6. +23 −0 Raven.Studio/Common/String.cs
  7. +55 −18 Raven.Studio/Features/Collections/CollectionsViewModel.cs
  8. +5 −1 Raven.Studio/Features/Database/DatabaseExplorer.cs
  9. +3 −5 Raven.Studio/Features/Database/SelectDatabaseViewModel.cs
  10. +3 −3 Raven.Studio/Features/Database/Server.cs
  11. +248 −254 Raven.Studio/Features/Database/SummaryViewModel.cs
  12. +9 −13 Raven.Studio/Features/Documents/BrowseDocumentsViewModel.cs
  13. +7 −7 Raven.Studio/Features/Documents/DocumentViewModel.cs
  14. +11 −5 Raven.Studio/Features/Documents/EditDocumentViewModel.cs
  15. +46 −15 Raven.Studio/Features/Indexes/BrowseIndexesViewModel.cs
  16. +11 −8 Raven.Studio/Features/Indexes/EditIndexViewModel.cs
  17. +104 −106 Raven.Studio/Features/Query/QueryViewModel.cs
  18. +13 −12 Raven.Studio/Features/Statistics/ErrorsViewModel.cs
  19. +1 −1 Raven.Studio/Features/Statistics/IndexesViewModel.cs
  20. +5 −2 Raven.Studio/Features/Statistics/StatisticsViewModel.cs
  21. +10 −6 Raven.Studio/Features/Tasks/ConsoleOutputTask.cs
  22. +4 −3 Raven.Studio/Features/Tasks/ExportTask.cs
  23. +5 −4 Raven.Studio/Features/Tasks/ImportTask.cs
  24. +27 −3 Raven.Studio/Features/Tasks/TasksViewModel.cs
  25. +4 −4 Raven.Studio/Framework/BindablePagedQuery.cs
  26. +2 −1 Raven.Studio/Framework/ConventionalCatalog.cs
  27. +8 −0 Raven.Studio/Framework/IRavenConductor.cs
  28. +40 −5 Raven.Studio/Framework/RavenScreen.cs
  29. +9 −0 Raven.Studio/Infrastructure/Navigation/INavigator.cs
  30. +18 −0 Raven.Studio/Infrastructure/Navigation/INavigatorMetdata.cs
  31. +90 −0 Raven.Studio/Infrastructure/Navigation/NavigationService.cs
  32. +8 −0 Raven.Studio/Infrastructure/Navigation/NavigationState.cs
  33. +19 −0 Raven.Studio/Infrastructure/Navigation/NavigatorExportAttribute.cs
  34. +46 −0 Raven.Studio/Infrastructure/Navigation/Navigators/BaseNavigator.cs
  35. +31 −0 Raven.Studio/Infrastructure/Navigation/Navigators/CollectionsNavigator.cs
  36. +38 −0 Raven.Studio/Infrastructure/Navigation/Navigators/DatabaseExplorerNavigator.cs
  37. +23 −0 Raven.Studio/Infrastructure/Navigation/Navigators/EditDocumentNavigator.cs
  38. +23 −0 Raven.Studio/Infrastructure/Navigation/Navigators/ErrorsNavigator.cs
  39. +31 −0 Raven.Studio/Infrastructure/Navigation/Navigators/IndexesNavigator.cs
  40. +23 −0 Raven.Studio/Infrastructure/Navigation/Navigators/SelectDatabaseNavigator.cs
  41. +37 −0 Raven.Studio/Infrastructure/Navigation/Navigators/TasksNavigator.cs
  42. +2 −3 Raven.Studio/Plugins/Database/ExportDatabaseExplorerItemAttribute.cs
  43. +1 −1 Raven.Studio/Plugins/IServer.cs
  44. +16 −0 Raven.Studio/Raven.Studio.csproj
  45. +7 −2 Raven.Studio/Shell/IShell.cs
  46. +1 −0 Raven.Studio/Shell/NavigationViewModel.cs
  47. +17 −9 Raven.Studio/Shell/ShellViewModel.cs
@@ -1,5 +1,8 @@
using System.IO;
using System.Security.Cryptography;
+using Raven.Studio.Features.Documents;
+using Raven.Studio.Infrastructure.Navigation;
+using Raven.Studio.Plugins;
namespace Raven.Studio
{
@@ -26,6 +29,22 @@ static AppBootstrapper()
LogManager.GetLog = type => new DebugLogger(type);
}
+ protected override void OnStartup(object sender, StartupEventArgs e)
+ {
+ base.OnStartup(sender, e);
+ var navigationService = container.GetExportedValue<NavigationService>();
+ navigationService.Initialize();
+
+ MessageBinder.CustomConverters.Add(typeof(IList<string>), (providedValue, context) =>
+ {
+ var id = providedValue as string;
+ if (id != null)
+ return new List<string> {id};
+
+ return providedValue;
+ });
+ }
+
protected override void Configure()
{
ConfigureConventions();
@@ -23,7 +23,7 @@ protected override void GenerateMenuItems()
if (SelectedItem.CollectionType != BuiltinCollectionName.Projection)
{
var deleteDocumentsMenuItem = new PopupMenuItem(null, string.Format(DocumentsResources.DocumentMenu_DeleteDocuments, SelectedItems.Count));
- deleteDocumentsMenuItem.Click += (s, ea) => IoC.Get<DeleteDocument>().Execute(SelectedItems);
+ deleteDocumentsMenuItem.Click += (s, ea) => IoC.Get<DeleteDocument>().Execute(SelectedItems.Select(document => document.Id).ToList());
Menu.AddItem(deleteDocumentsMenuItem);
}
}
@@ -49,7 +49,7 @@ protected override void GenerateMenuItems()
var deleteDocumentMenuItem = new PopupMenuItem(null, DocumentsResources.DocumentMenu_DeleteDocument);
deleteDocumentMenuItem.Click +=
- (s, ea) => IoC.Get<DeleteDocument>().Execute(SelectedItems);
+ (s, ea) => IoC.Get<DeleteDocument>().Execute(SelectedItems.Select(document => document.Id).ToList());
Menu.AddItem(deleteDocumentMenuItem);
}
}
@@ -1,15 +1,11 @@
using System.Collections.Generic;
-using Raven.Studio.Features.Collections;
namespace Raven.Studio.Commands
{
- using System.Collections;
- using System.ComponentModel.Composition;
+ using System.ComponentModel.Composition;
using System.Linq;
using Caliburn.Micro;
- using Features.Database;
- using Features.Documents;
- using Messages;
+ using Messages;
using Plugins;
using Shell.MessageBox;
@@ -28,19 +24,18 @@ public DeleteDocument(IServer server, IEventAggregator events, ShowMessageBox sh
this.showMessageBox = showMessageBox;
}
- public bool CanExecute(IList<DocumentViewModel> documents)
+ public bool CanExecute(IList<string> documentIds)
{
- if (documents == null || documents.Count == 0)
+ if (documentIds == null || documentIds.Count == 0)
return false;
- var document = documents.First();
- return document != null && document.CollectionType != BuiltinCollectionName.Projection;
+ return string.IsNullOrEmpty(documentIds.First()) == false;
}
- public void Execute(IList<DocumentViewModel> documents)
+ public void Execute(IList<string> documentIds)
{
- string message = documents.Count > 1 ? string.Format("Are you sure you want to delete these {0} documents?", documents.Count) :
- string.Format("Are you sure that you want to do this document? ({0})", documents.First().Id);
+ string message = documentIds.Count > 1 ? string.Format("Are you sure you want to delete these {0} documents?", documentIds.Count) :
+ string.Format("Are you sure that you want to delete this document? ({0})", documentIds.First());
showMessageBox(
message,
@@ -49,7 +44,7 @@ public void Execute(IList<DocumentViewModel> documents)
box => {
if (box.WasSelected(MessageBoxOptions.Ok))
{
- documents.Apply(document => ExecuteDeletion(document.Id)); // Is this the most efficient way?
+ documentIds.Apply(ExecuteDeletion); // Is this the most efficient way?
}
});
}
@@ -2,7 +2,6 @@
{
using System.ComponentModel.Composition;
using Caliburn.Micro;
- using Features.Database;
using Features.Indexes;
using Framework.Extensions;
using Messages;
@@ -26,8 +25,9 @@ public void Execute(string indexName)
server.OpenSession().Advanced.AsyncDatabaseCommands
.GetIndexAsync(indexName)
.ContinueOnSuccess(get =>
- {
- events.Publish(new DatabaseScreenRequested(() => new EditIndexViewModel(get.Result, server, events)));
+ {
+ events.Publish(
+ new DatabaseScreenRequested(() => new EditIndexViewModel(get.Result)));
events.Publish(new WorkCompleted());
});
}
@@ -1,4 +1,5 @@
using Raven.Abstractions.Extensions;
+using Raven.Studio.Shell.MessageBox;
namespace Raven.Studio.Commands
{
@@ -16,36 +17,57 @@ public class SaveDocument
{
readonly IEventAggregator events;
readonly IServer server;
+ private readonly ShowMessageBox showMessageBox;
[ImportingConstructor]
- public SaveDocument(IEventAggregator events, IServer server)
+ public SaveDocument(IEventAggregator events, IServer server, ShowMessageBox showMessageBox)
{
this.events = events;
this.server = server;
+ this.showMessageBox = showMessageBox;
}
public void Execute(EditDocumentViewModel document)
{
if(!ValidateJson(document.JsonData) || !ValidateJson(document.JsonMetadata)) return;
+ if (document.Id.StartsWith("Raven/"))
+ {
+ showMessageBox(
+ "Are you sure that you want to edit a system document?",
+ "Confirm Edit",
+ MessageBoxOptions.OkCancel,
+ box =>
+ {
+ if (box.WasSelected(MessageBoxOptions.Ok))
+ {
+ Delete(document);
+ }
+ });
+ return;
+ }
+ Delete(document);
+ }
+
+ private void Delete(EditDocumentViewModel document)
+ {
document.PrepareForSave();
var jdoc = document.JsonDocument;
server.OpenSession().Advanced.AsyncDatabaseCommands
.PutAsync(document.Id, jdoc.Etag, jdoc.DataAsJson, jdoc.Metadata)
.ContinueOnSuccess(put =>
- {
- var inner = document.JsonDocument;
- inner.Key = put.Result.Key;
- inner.Metadata = inner.Metadata.FilterHeaders(isServerDocument: false);
- inner.Etag = put.Result.ETag;
- inner.LastModified = DateTime.Now;
- document.UpdateDocumentFromJsonDocument();
+ {
+ var inner = document.JsonDocument;
+ inner.Key = put.Result.Key;
+ inner.Metadata = inner.Metadata.FilterHeaders(isServerDocument: false);
+ inner.Etag = put.Result.ETag;
+ inner.LastModified = DateTime.Now;
+ document.UpdateDocumentFromJsonDocument();
- events.Publish(new DocumentUpdated(document));
- });
-
+ events.Publish(new DocumentUpdated(document));
+ });
}
bool ValidateJson(string json)
@@ -0,0 +1,23 @@
+// -----------------------------------------------------------------------
+// <copyright file="CanGetStats.cs" company="Hibernating Rhinos LTD">
+// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
+// </copyright>
+// -----------------------------------------------------------------------
+
+namespace Raven.Studio.Common
+{
+ public static class StringExtensions
+ {
+ public static string FirstWord(this string text)
+ {
+ if (text == null)
+ return null;
+
+ var index = text.IndexOf(' ');
+ if (index == -1)
+ return text;
+
+ return text.Substring(0, index);
+ }
+ }
+}
@@ -1,4 +1,5 @@
using Raven.Client.Connection;
+using Raven.Studio.Infrastructure.Navigation;
namespace Raven.Studio.Features.Collections
{
@@ -16,25 +17,21 @@ namespace Raven.Studio.Features.Collections
using Plugins;
using Plugins.Database;
- [Export(typeof(CollectionsViewModel))]
- [ExportDatabaseExplorerItem("Collections", Index = 20)]
+ [Export]
+ [ExportDatabaseExplorerItem(DisplayName = "Collections", Index = 20)]
public class CollectionsViewModel : RavenScreen,
IHandle<DocumentDeleted>
{
- readonly IServer server;
CollectionViewModel activeCollection;
[ImportingConstructor]
- public CollectionsViewModel(IServer server, IEventAggregator events)
- : base(events)
+ public CollectionsViewModel()
{
DisplayName = "Collections";
- events.Subscribe(this);
+ Events.Subscribe(this);
- this.server = server;
-
- server.CurrentDatabaseChanged += delegate
+ Server.CurrentDatabaseChanged += delegate
{
Initialize();
};
@@ -63,6 +60,8 @@ public BindablePagedQuery<DocumentViewModel> ActiveCollectionDocuments
}
string status;
+ private System.Action executeAfterCollectionsFetched;
+
public string Status
{
get { return status; }
@@ -99,19 +98,34 @@ public bool HasCollections
void GetDocumentsForActiveCollection()
{
+ TrackCurrentCollection();
+
ActiveCollectionDocuments.ClearResults();
-
+
if (ActiveCollection == null) return;
ActiveCollectionDocuments.GetTotalResults = () => ActiveCollection.Count;
ActiveCollectionDocuments.LoadPage();
}
+ private void TrackCurrentCollection()
+ {
+ if (ActiveCollection == null)
+ return;
+
+ Execute.OnUIThread(() =>
+ NavigationService.Track(new NavigationState
+ {
+ Url = string.Format("collections/{0}", ActiveCollection.Name),
+ Title = string.Format("Collections: {0}", ActiveCollection.Name)
+ }));
+ }
+
Task<DocumentViewModel[]> GetDocumentsForActiveCollectionQuery(int start, int pageSize)
{
WorkStarted("retrieving documents for collection.");
- using (var session = server.OpenSession())
+ using (var session = Server.OpenSession())
{
var query = new IndexQuery { Start = start, PageSize = pageSize, Query = "Tag:" + ActiveCollection.Name };
return session.Advanced.AsyncDatabaseCommands
@@ -129,11 +143,28 @@ Task<DocumentViewModel[]> GetDocumentsForActiveCollectionQuery(int start, int pa
}
}
+ public void SelectCollectionByName(string name)
+ {
+ if (HasCollections)
+ {
+ var collection = Collections
+ .Where(item => item.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
+ .FirstOrDefault();
+
+ if (collection == null)
+ return;
+
+ ActiveCollection = collection;
+ return;
+ }
+ executeAfterCollectionsFetched = () => SelectCollectionByName(name);
+ }
+
protected override void OnActivate()
{
WorkStarted("fetching collections");
- using (var session = server.OpenSession())
+ using (var session = Server.OpenSession())
{
session.Advanced.AsyncDatabaseCommands
.GetCollectionsAsync(0, 25)
@@ -143,7 +174,7 @@ protected override void OnActivate()
WorkCompleted("fetching collections");
Collections = new BindableCollection<CollectionViewModel>(
- x.Result.Select(item => new CollectionViewModel {Name = item.Name, Count = item.Count}));
+ x.Result.Select(item => new CollectionViewModel { Name = item.Name, Count = item.Count }));
NotifyOfPropertyChange(() => LargestCollectionCount);
NotifyOfPropertyChange(() => Collections);
@@ -152,21 +183,27 @@ protected override void OnActivate()
if (ActiveCollection != null)
{
activeCollection = Collections
- .Where(collection => collection.Name == activeCollection.Name)
- .FirstOrDefault();
- NotifyOfPropertyChange(() => ActiveCollection);
+ .Where(collection => collection.Name == ActiveCollection.Name)
+ .FirstOrDefault();
+ NotifyOfPropertyChange(() => ActiveCollection);
+ TrackCurrentCollection();
}
else // select the first one if we weren't asked for one
{
ActiveCollection = Collections.FirstOrDefault();
}
+ if (executeAfterCollectionsFetched != null)
+ {
+ executeAfterCollectionsFetched();
+ executeAfterCollectionsFetched = null;
+ }
Status = Collections.Any() ? string.Empty : "The database contains no collections.";
},
faulted =>
{
WorkCompleted("fetching collections");
- var error = "Unable to retrieve collections from server.";
+ const string error = "Unable to retrieve collections from server."; ;
Status = error;
NotifyError(error);
});
@@ -176,7 +213,7 @@ protected override void OnActivate()
public void EditTemplate()
{
var vm = IoC.Get<EditCollectionTemplateViewModel>();
- vm.Collection = new Collection {Name = ActiveCollection.Name, Count = ActiveCollection.Count};
+ vm.Collection = new Collection { Name = ActiveCollection.Name, Count = ActiveCollection.Count };
Events.Publish(new DatabaseScreenRequested(() => vm));
}
Oops, something went wrong.

0 comments on commit 181a9c0

Please sign in to comment.