From 1917a8ad7c3ae3d2b9c5463f3e3f08dab0fa13ef Mon Sep 17 00:00:00 2001 From: kgiszewski Date: Wed, 1 Jul 2015 12:19:35 -0400 Subject: [PATCH 01/33] Hijack the navigation for future search --- .../UmbracoBookshelf/js/directives.js | 41 ++++++++ .../UmbracoBookshelf/js/interceptors.js | 19 ++++ .../UmbracoBookshelf/js/library.controller.js | 4 +- .../UmbracoBookshelf/package.manifest | 3 +- .../UmbracoBookshelf/views/navigation.html | 99 +++++++++++++++++++ .../views/navigation.router.html | 1 + 6 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 src/App_Plugins/UmbracoBookshelf/js/interceptors.js create mode 100644 src/App_Plugins/UmbracoBookshelf/views/navigation.html create mode 100644 src/App_Plugins/UmbracoBookshelf/views/navigation.router.html diff --git a/src/App_Plugins/UmbracoBookshelf/js/directives.js b/src/App_Plugins/UmbracoBookshelf/js/directives.js index cabee43..5ae78e3 100644 --- a/src/App_Plugins/UmbracoBookshelf/js/directives.js +++ b/src/App_Plugins/UmbracoBookshelf/js/directives.js @@ -176,5 +176,46 @@ restrict: "A", link: linker } +}).directive('umbracoBookshelfNavigation', function ($http, $compile) { + + function linker(scope, element, attrs) { + function getView(view) { + $http.get(view, { cache: false }).then(function (data) { + + element.html(data.data).show(); + + $compile(element.contents())(scope); + }); + } + + scope.$on("$routeChangeSuccess", function(event, current, previous) { + + var isComingFromBookshelf = (previous && previous.pathParams.section.toLowerCase().indexOf("umbracobookshelf") != -1); + var isOnBookshelf = (current.pathParams.section.toLowerCase().indexOf("umbracobookshelf") != -1); + + //if on bookshelf but not coming from bookshelf + if (isOnBookshelf) { + if (!isComingFromBookshelf) { + getView("/App_Plugins/UmbracoBookshelf/Views/navigation.html"); + } + } else { + //if first time viewed + if (!previous) { + getView("views/directives/umb-navigation.html?intercepted=1"); + } else { + //if coming from bookshelf + if (isComingFromBookshelf) { + getView("views/directives/umb-navigation.html?intercepted=1"); + } + } + } + }); + } + + return { + restrict: "E", + link: linker, + replace: true + } }); diff --git a/src/App_Plugins/UmbracoBookshelf/js/interceptors.js b/src/App_Plugins/UmbracoBookshelf/js/interceptors.js new file mode 100644 index 0000000..e1c988c --- /dev/null +++ b/src/App_Plugins/UmbracoBookshelf/js/interceptors.js @@ -0,0 +1,19 @@ +angular.module('umbraco').service('umbracoBookshelfInterceptor', function ($location, $templateCache) { + var service = this; + + service.request = function (request) { + if (request.url == "views/directives/umb-navigation.html") { + request.url = "/App_Plugins/UmbracoBookshelf/Views/navigation.router.html"; + } + + return request; + }; + + service.responseError = function (response) { + return response; + }; +}); + +angular.module('umbraco').config(function ($httpProvider) { + $httpProvider.interceptors.push('umbracoBookshelfInterceptor'); +}); \ No newline at end of file diff --git a/src/App_Plugins/UmbracoBookshelf/js/library.controller.js b/src/App_Plugins/UmbracoBookshelf/js/library.controller.js index 6a7aebb..7334484 100644 --- a/src/App_Plugins/UmbracoBookshelf/js/library.controller.js +++ b/src/App_Plugins/UmbracoBookshelf/js/library.controller.js @@ -34,7 +34,7 @@ } $scope.getUpdatedOn = function(item) { - if (item.details) { + if (item.details && item.details.pushed_at) { return item.details.pushed_at.replace('T', ' '); } @@ -49,7 +49,7 @@ umbracoBookshelfResource.getBookFeed().then(function(data) { $scope.model.feed = data; }).then(function () { - angular.forEach($scope.model.feed.gitHub, function(feedItem) { + angular.forEach($scope.model.feed.gitHub, function (feedItem) { umbracoBookshelfResource.getContributors(feedItem).then(function(contributors) { feedItem.authors = contributors; }); diff --git a/src/App_Plugins/UmbracoBookshelf/package.manifest b/src/App_Plugins/UmbracoBookshelf/package.manifest index c9f6572..b89e895 100644 --- a/src/App_Plugins/UmbracoBookshelf/package.manifest +++ b/src/App_Plugins/UmbracoBookshelf/package.manifest @@ -12,7 +12,8 @@ "~/App_Plugins/UmbracoBookshelf/js/marked.min.js", "~/App_Plugins/UmbracoBookshelf/js/highlight.pack.js", "~/App_Plugins/UmbracoBookshelf/js/autogrow.js", - "~/App_Plugins/UmbracoBookshelf/js/imageSelector.controller.js" + "~/App_Plugins/UmbracoBookshelf/js/imageSelector.controller.js", + "~/App_Plugins/UmbracoBookshelf/js/interceptors.js" ], "css": [ "~/App_Plugins/UmbracoBookshelf/css/application.css" diff --git a/src/App_Plugins/UmbracoBookshelf/views/navigation.html b/src/App_Plugins/UmbracoBookshelf/views/navigation.html new file mode 100644 index 0000000..2360fde --- /dev/null +++ b/src/App_Plugins/UmbracoBookshelf/views/navigation.html @@ -0,0 +1,99 @@ +
+ + + + + + +
\ No newline at end of file diff --git a/src/App_Plugins/UmbracoBookshelf/views/navigation.router.html b/src/App_Plugins/UmbracoBookshelf/views/navigation.router.html new file mode 100644 index 0000000..6c2bf86 --- /dev/null +++ b/src/App_Plugins/UmbracoBookshelf/views/navigation.router.html @@ -0,0 +1 @@ + \ No newline at end of file From 673651104c044a3ec387de31eef0a750c56827d9 Mon Sep 17 00:00:00 2001 From: kgiszewski Date: Wed, 1 Jul 2015 12:37:36 -0400 Subject: [PATCH 02/33] Mockup UI for search --- .../UmbracoBookshelf/js/search.controller.js | 34 +++++++++++++++++++ .../UmbracoBookshelf/package.manifest | 3 +- .../UmbracoBookshelf/views/navigation.html | 32 +++++++---------- 3 files changed, 49 insertions(+), 20 deletions(-) create mode 100644 src/App_Plugins/UmbracoBookshelf/js/search.controller.js diff --git a/src/App_Plugins/UmbracoBookshelf/js/search.controller.js b/src/App_Plugins/UmbracoBookshelf/js/search.controller.js new file mode 100644 index 0000000..0320ed2 --- /dev/null +++ b/src/App_Plugins/UmbracoBookshelf/js/search.controller.js @@ -0,0 +1,34 @@ +angular.module('umbraco').controller('umbracoBookshelfSearchController', function ($scope, umbracoBookshelfResource) { + + $scope.model = {}; + $scope.model.keywords = ""; + + $scope.model.books = [ + { + name: "Learn Umbraco 7", + results: [ + { + name: "04 - Surface, RenderMVC and API Controllers", + url: "#" + }, + { + name: "06 - Blah Chapter", + url: "#" + } + ] + }, + { + name: "Official Umbraco Docs", + results: [ + { + name: "Surface Controllers", + url: "#" + }, + { + name: "API Controllers", + url: "#" + } + ] + } + ]; +}); \ No newline at end of file diff --git a/src/App_Plugins/UmbracoBookshelf/package.manifest b/src/App_Plugins/UmbracoBookshelf/package.manifest index b89e895..ea5fa6a 100644 --- a/src/App_Plugins/UmbracoBookshelf/package.manifest +++ b/src/App_Plugins/UmbracoBookshelf/package.manifest @@ -13,7 +13,8 @@ "~/App_Plugins/UmbracoBookshelf/js/highlight.pack.js", "~/App_Plugins/UmbracoBookshelf/js/autogrow.js", "~/App_Plugins/UmbracoBookshelf/js/imageSelector.controller.js", - "~/App_Plugins/UmbracoBookshelf/js/interceptors.js" + "~/App_Plugins/UmbracoBookshelf/js/interceptors.js", + "~/App_Plugins/UmbracoBookshelf/js/search.controller.js" ], "css": [ "~/App_Plugins/UmbracoBookshelf/css/application.css" diff --git a/src/App_Plugins/UmbracoBookshelf/views/navigation.html b/src/App_Plugins/UmbracoBookshelf/views/navigation.html index 2360fde..1c300ca 100644 --- a/src/App_Plugins/UmbracoBookshelf/views/navigation.html +++ b/src/App_Plugins/UmbracoBookshelf/views/navigation.html @@ -10,7 +10,7 @@ @@ -38,6 +38,18 @@
Bookshelf Search Results
+
+ LOADING... +
+ + + - diff --git a/src/Controllers/UmbracoBookshelfController.cs b/src/Controllers/UmbracoBookshelfController.cs index ef546ba..bfa25f6 100644 --- a/src/Controllers/UmbracoBookshelfController.cs +++ b/src/Controllers/UmbracoBookshelfController.cs @@ -8,12 +8,12 @@ using System.Net; using System.Text.RegularExpressions; using System.Web; +using Examine; using ICSharpCode.SharpZipLib.Core; using ICSharpCode.SharpZipLib.Zip; using Newtonsoft.Json.Linq; using Umbraco.Core; using Umbraco.Core.Logging; -using Umbraco.Core.Media; using UmbracoBookshelf.Examine; using UmbracoBookshelf.Models; using UmbracoBookshelf.Helpers; @@ -310,6 +310,8 @@ public object DownloadUrl(string url) Directory.Delete(downloadsDirectory, true); + ExamineManager.Instance.IndexProviderCollection["BookshelfIndexer"].RebuildIndex(); + return new { Status = "Downloaded" @@ -353,7 +355,7 @@ public object GetImages(string currentPath) var systemPath = Path.GetDirectoryName(_ensureRootPath(currentPath).ToSystemPath()); //search for any media files - var imageFiles = systemPath.GetFilesRecursively(); + var imageFiles = systemPath.GetFilesRecursively(Constants.ALLOWED_IMAGE_EXTENSIONS); return imageFiles.Select(x => new ImageModel() { @@ -372,10 +374,10 @@ public object SearchFiles(string keywords) if (results.Any()) { - LogHelper.Info("Results=>" + results.Count()); - var books = results.GroupBy(x => x.Fields["book"]); + var resultsPerBook = 10; + foreach (var book in books) { var bookData = new BookResultModel() @@ -385,12 +387,12 @@ public object SearchFiles(string keywords) var resultsList = new List(); - foreach(var result in book.OrderByDescending(x => x.Score).Take(3)) + foreach(var result in book.OrderByDescending(x => x.Score).Take(resultsPerBook)) { var hintUrl = HttpUtility.UrlDecode(HttpUtility.UrlDecode(result.Fields["url"])); var title = HttpUtility.UrlDecode(HttpUtility.UrlDecode(result.Fields["title"])); - hintUrl = hintUrl.Substring(0, hintUrl.Length - title.Length - 1); + hintUrl = hintUrl.Substring(0, hintUrl.Length - title.Length - 3); var hintWindowLength = 50; @@ -403,8 +405,11 @@ public object SearchFiles(string keywords) { Title = title, Url = result.Fields["url"], - HintUrl = hintUrl + HintUrl = hintUrl, + Score = result.Score.ToString() }); + + bookData.TotalScore += result.Score; } bookData.Results = resultsList; @@ -412,7 +417,7 @@ public object SearchFiles(string keywords) } } - return data; + return data.OrderByDescending(x => x.TotalScore); } private void ExtractZipFile(string archiveFilenameIn, string outFolder, string password = "") diff --git a/src/Examine/BookResultModel.cs b/src/Examine/BookResultModel.cs index c011d64..63ffa70 100644 --- a/src/Examine/BookResultModel.cs +++ b/src/Examine/BookResultModel.cs @@ -7,11 +7,14 @@ public class BookResultModel public string Name { get; set; } public IEnumerable Results { get; set; } + public double TotalScore { get; set; } + public class BookEntry { public string Title { get; set; } public string Url { get; set; } public string HintUrl { get; set; } + public string Score { get; set; } } } } \ No newline at end of file diff --git a/src/Examine/BookshelfExamineDataService.cs b/src/Examine/BookshelfExamineDataService.cs index f080340..f953ead 100644 --- a/src/Examine/BookshelfExamineDataService.cs +++ b/src/Examine/BookshelfExamineDataService.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Web; using Examine; using Examine.LuceneEngine; using Umbraco.Core.Logging; @@ -12,20 +11,18 @@ namespace UmbracoBookshelf.Examine public class BookshelfExamineDataService : ISimpleDataService { public IEnumerable GetAllData(string indexType) - { - LogHelper.Info("Building the Bookshelf index..."); - + { var data = new List(); var count = 1; + LogHelper.Info("Building index..."); + foreach (var bookPath in _getBooksAsDirectories()) { - LogHelper.Info("Processing Book... " + bookPath); + var files = bookPath.GetFilesRecursively(Constants.ALLOWED_FILE_EXTENSIONS); - foreach (var file in bookPath.GetFilesRecursively(false)) + foreach (var file in files) { - LogHelper.Info("Processing... " + file); - var dataset = new SimpleDataSet() { NodeDefinition = new IndexedNode() @@ -38,6 +35,7 @@ public IEnumerable GetAllData(string indexType) dataset.RowData = new Dictionary() { {"book", Path.GetFileName(bookPath)}, + {"path", bookPath.ToWebPath()}, {"title", Path.GetFileNameWithoutExtension(file)}, {"text", File.ReadAllText(file)}, {"url", "/umbraco/#/UmbracoBookshelf/UmbracoBookshelfTree/file/" + file.ToWebPath().Replace("%2F", "%252F").Replace("%20F", "%2520F")} //total hack job here b/c of some sort of double encoding somewhere @@ -45,8 +43,6 @@ public IEnumerable GetAllData(string indexType) data.Add(dataset); count++; - - LogHelper.Info("Added=>" + Path.GetFileName(file)); } } diff --git a/src/Examine/BookshelfSearcher.cs b/src/Examine/BookshelfSearcher.cs index f0199b2..656993e 100644 --- a/src/Examine/BookshelfSearcher.cs +++ b/src/Examine/BookshelfSearcher.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using Examine; -using Umbraco.Core.Logging; namespace UmbracoBookshelf.Examine { @@ -19,10 +18,8 @@ public static ISearchResults Search(string keywords) foreach (var word in words) { - var contentRawQuery = string.Format("(+__IndexType:bookshelf && (title: {0}~{1} book: {0}~{1} text: {0}~{1}))", word, 0.5); + var contentRawQuery = string.Format("(+__IndexType:bookshelf && (title: {0}~{1} path: {0}~{1} book: {0}~{1} text: {0}~{1}))", word, 0.5); rawQueries.Add(contentRawQuery); - - LogHelper.Info(contentRawQuery); } } diff --git a/src/Helpers/Constants.cs b/src/Helpers/Constants.cs index 7bfd9fe..20a5659 100644 --- a/src/Helpers/Constants.cs +++ b/src/Helpers/Constants.cs @@ -13,7 +13,7 @@ public class Constants public const string MARKDOWN_FILE_EXTENSION = ".md"; public static List ALLOWED_FILE_EXTENSIONS = - new List() { ".pdf", ".doc", ".docx", ".xls", ".xlsx", ".csv"}; + new List() { ".pdf", ".doc", ".docx", ".xls", ".xlsx", ".csv", ".md"}; public static List ALLOWED_IMAGE_EXTENSIONS = new List() { ".jpg", ".png", ".gif" }; diff --git a/src/Helpers/FileSystemExtensions.cs b/src/Helpers/FileSystemExtensions.cs index 647c9f4..4b4d184 100644 --- a/src/Helpers/FileSystemExtensions.cs +++ b/src/Helpers/FileSystemExtensions.cs @@ -47,41 +47,18 @@ public static string ToWebPath(this string mappedPath, bool preserveSlashes = fa return path; } - public static IEnumerable GetFilesRecursively(this string startingDirectory, bool onlyImages = true) + public static IEnumerable GetFilesRecursively(this string directory, IEnumerable extensions) { - var list = new List(); - try { - foreach (string dir in Directory.GetDirectories(startingDirectory)) - { - foreach (string file in Directory.GetFiles(dir)) - { - if (onlyImages) - { - if(Constants.ALLOWED_IMAGE_EXTENSIONS.Any(file.EndsWith)) - { - list.Add(file); - } - } - else - { - if (Constants.ALLOWED_FILE_EXTENSIONS.Any(file.EndsWith) || file.EndsWith(Constants.MARKDOWN_FILE_EXTENSION)) - { - list.Add(file); - } - } - } - - GetFilesRecursively(dir); - } + return Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories).Where(x => extensions.Any(x.EndsWith)); } catch (Exception ex) { LogHelper.Error(ex.Message, ex); - } - return list; + return new List(); + } } } } \ No newline at end of file diff --git a/src/UmbracoBookshelf.csproj b/src/UmbracoBookshelf.csproj index b3d05d1..df0101f 100644 --- a/src/UmbracoBookshelf.csproj +++ b/src/UmbracoBookshelf.csproj @@ -222,6 +222,7 @@ + From 0729eedfee26c6b17d8d123c75fc50f66e29817d Mon Sep 17 00:00:00 2001 From: kgiszewski Date: Wed, 8 Jul 2015 12:36:48 -0400 Subject: [PATCH 06/33] Install PackageActions, cleanup hotkey, cleanup css --- .../backoffice/UmbracoBookshelfTree/file.html | 2 +- .../UmbracoBookshelf/js/directives.js | 17 ----- .../UmbracoBookshelf/js/search.controller.js | 4 + .../UmbracoBookshelf/views/navigation.html | 22 +++--- src/Assets/less/application.less | 23 ++++++ src/Events/PackageActions.cs | 76 ++++++++++++++++++- src/Examine/BookshelfSearcher.cs | 2 +- 7 files changed, 111 insertions(+), 35 deletions(-) diff --git a/src/App_Plugins/UmbracoBookshelf/backoffice/UmbracoBookshelfTree/file.html b/src/App_Plugins/UmbracoBookshelf/backoffice/UmbracoBookshelfTree/file.html index e485fe8..314cb1b 100644 --- a/src/App_Plugins/UmbracoBookshelf/backoffice/UmbracoBookshelfTree/file.html +++ b/src/App_Plugins/UmbracoBookshelf/backoffice/UmbracoBookshelfTree/file.html @@ -26,7 +26,7 @@

{{model.filePath}}

- +
diff --git a/src/App_Plugins/UmbracoBookshelf/js/directives.js b/src/App_Plugins/UmbracoBookshelf/js/directives.js index 5ae78e3..5aedb87 100644 --- a/src/App_Plugins/UmbracoBookshelf/js/directives.js +++ b/src/App_Plugins/UmbracoBookshelf/js/directives.js @@ -118,23 +118,6 @@ restrict: "A", link: linker } -}).directive('umbracoBookshelfCtrlS', function() { - - var linker = function(scope, element, attrs) { - $(document).keydown(function(e) { - if ((e.which == '115' || e.which == '83') && (e.ctrlKey || e.metaKey)) { - e.preventDefault(); - scope.save(); - return false; - } - return true; - }); - } - - return { - restrict: "E", - link: linker - } }).directive('autoGrow', function ($timeout) { var insertAtCaret = function (element, text) { diff --git a/src/App_Plugins/UmbracoBookshelf/js/search.controller.js b/src/App_Plugins/UmbracoBookshelf/js/search.controller.js index 1b40554..1db0bfe 100644 --- a/src/App_Plugins/UmbracoBookshelf/js/search.controller.js +++ b/src/App_Plugins/UmbracoBookshelf/js/search.controller.js @@ -19,4 +19,8 @@ }); } } + + $scope.clear = function() { + $scope.model.keywords = ""; + } }); \ No newline at end of file diff --git a/src/App_Plugins/UmbracoBookshelf/views/navigation.html b/src/App_Plugins/UmbracoBookshelf/views/navigation.html index ba802ff..229e7cb 100644 --- a/src/App_Plugins/UmbracoBookshelf/views/navigation.html +++ b/src/App_Plugins/UmbracoBookshelf/views/navigation.html @@ -5,7 +5,7 @@ -