From d9d78b33bb35ebb876d38cb3202d5ae49193b2a2 Mon Sep 17 00:00:00 2001 From: Niels Hartvig Date: Sun, 20 May 2018 15:36:11 +0200 Subject: [PATCH 01/60] Initial check-in of high five markup Needs work for responsive styling --- .../src/scss/sections/_highFive.scss | 72 ++++++++++++++++ OurUmbraco.Client/src/scss/style.scss | 1 + .../Views/Partials/Community/Home.cshtml | 82 +++++++++++++++++++ .../Views/Partials/Community/Scripts.cshtml | 68 +++++++++++++++ 4 files changed, 223 insertions(+) create mode 100644 OurUmbraco.Client/src/scss/sections/_highFive.scss diff --git a/OurUmbraco.Client/src/scss/sections/_highFive.scss b/OurUmbraco.Client/src/scss/sections/_highFive.scss new file mode 100644 index 0000000000..c9b0a60504 --- /dev/null +++ b/OurUmbraco.Client/src/scss/sections/_highFive.scss @@ -0,0 +1,72 @@ +section.high-five { + background: rgba($color-space, .11); + background-size: 100%; + background-position: center bottom; + background-repeat: no-repeat; + position: relative; + + h3 { + margin: 1rem auto 3.5rem; + margin-bottom: 3rem; + line-height: 1.5; + padding: 0 10px; + font-size: 1.4rem; + color: darken($color-space, 15%); + text-align: center; + } + + h1 { + font-size: 1.8rem; + text-align: center; + position: relative; + z-index: 30; + //margin-bottom: 3.5rem; // Remove me when text is ready under this + @media (min-width: $md) { + font-size: 2.4rem; + } + + + p { + max-width: 700px; + margin: 1rem auto 3.5rem; + margin-bottom: 3rem; + line-height: 1.5; + padding: 0 10px; + font-size: 1rem; + color: darken($color-space, 15%); + text-align: center; + + @media (min-width: $md) { + padding: 0; + font-size: 1.2rem; + } + } + } + + input[type=text], select { + border: 0; + padding: 3px; + border-bottom: 2px solid #ccc; + background: none; + font-size: 1.4rem; + max-width: 200px; + } + + button { + font-size: 0.8em; + padding: 10px 20px; + } + + button img { + width: 20px; + height: 20px; + margin-right: 8px; + -webkit-filter: invert(100%); + filter: invert(100%); + } + + .flex { + display: flex; + flex-flow: row wrap; + justify-content: space-between; + } +} diff --git a/OurUmbraco.Client/src/scss/style.scss b/OurUmbraco.Client/src/scss/style.scss index d3e2d3bfe3..11c7f82d7e 100644 --- a/OurUmbraco.Client/src/scss/style.scss +++ b/OurUmbraco.Client/src/scss/style.scss @@ -65,6 +65,7 @@ @import 'sections/events'; @import 'sections/contributors'; @import 'sections/gitter'; +@import 'sections/highFive'; /** /* Pages diff --git a/OurUmbraco.Site/Views/Partials/Community/Home.cshtml b/OurUmbraco.Site/Views/Partials/Community/Home.cshtml index a4894b30b6..f468508aa2 100644 --- a/OurUmbraco.Site/Views/Partials/Community/Home.cshtml +++ b/OurUmbraco.Site/Views/Partials/Community/Home.cshtml @@ -61,6 +61,7 @@ @if (Members.IsLoggedIn()) { + @HighFiveActivity() @ForumActivity() @Gitter() @Meetups() @@ -78,6 +79,87 @@ else @TwitterSearch() } +@helper HighFiveActivity() + { +
+
+
+ +
+

Community Activity

+
+
+
+

+ High Five + for at + + +

+ +
+
+ + +
+
+
+ +} + @helper ForumActivity() {
diff --git a/OurUmbraco.Site/Views/Partials/Community/Scripts.cshtml b/OurUmbraco.Site/Views/Partials/Community/Scripts.cshtml index 99e43cc4f6..e2e1c032b4 100644 --- a/OurUmbraco.Site/Views/Partials/Community/Scripts.cshtml +++ b/OurUmbraco.Site/Views/Partials/Community/Scripts.cshtml @@ -4,6 +4,74 @@ $('#github-contributors .github-contributor-list').addClass('all'); } + + // from https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array + + function shuffle(array) { + var currentIndex = array.length, temporaryValue, randomIndex; + + // While there remain elements to shuffle... + while (0 !== currentIndex) { + + // Pick a remaining element... + randomIndex = Math.floor(Math.random() * currentIndex); + currentIndex -= 1; + + // And swap it with the current element. + temporaryValue = array[currentIndex]; + array[currentIndex] = array[randomIndex]; + array[randomIndex] = temporaryValue; + } + + return array; + } + + // from https://stackoverflow.com/questions/48815262/animate-placeholder-text-so-it-types-multiple-phrases + + // Add something to given element placeholder + function addToPlaceholder(toAdd, el) { + el.attr('placeholder', el.attr('placeholder') + toAdd); + // Delay between symbols "typing" + return new Promise(resolve => setTimeout(resolve, 100)); + } + + // Cleare placeholder attribute in given element + function clearPlaceholder(el) { + el.attr("placeholder", ""); + } + + // Print one phrase + function printPhrase(phrase, el) { + return new Promise(resolve => { + // Clear placeholder before typing next phrase + clearPlaceholder(el); + let letters = phrase.split(''); + // For each letter in phrase + letters.reduce( + (promise, letter, index) => promise.then(_ => { + // Resolve promise when all letters are typed + if (index === letters.length - 1) { + // Delay before start next phrase "typing" + setTimeout(resolve, 1000); + } + return addToPlaceholder(letter, el); + }), + Promise.resolve() + ); + }); + } + + // Print given phrases to element + function printPhrases(phrases, el) { + // For each phrase + // wait for phrase to be typed + // before start typing next + phrases.reduce( + (promise, phrase) => promise.then(_ => printPhrase(phrase, el)), + Promise.resolve() + ); + } + $(document).ready(function() { try { $("#twitter-search").load("@Url.Action("TwitterSearchResult", "TwitterSearch", new {numberOfResults = 6})"); From 5fd599ce7a30e8e689a08be893b61c25020cc8fb Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Sun, 20 May 2018 14:47:20 +0100 Subject: [PATCH 02/60] starting API and data work --- .../config/ClientDependency.config | 2 +- .../API/HighFiveFeedAPIController.cs | 44 +++++++++++++++++++ .../HighFiveFeed/Models/HighFiveCategory.cs | 22 ++++++++++ .../HighFiveFeed/Models/HighFiveFeed.cs | 32 ++++++++++++++ OurUmbraco/Our/MigrationsHandler.cs | 23 ++++++++++ OurUmbraco/OurUmbraco.csproj | 3 ++ 6 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs create mode 100644 OurUmbraco/HighFiveFeed/Models/HighFiveCategory.cs create mode 100644 OurUmbraco/HighFiveFeed/Models/HighFiveFeed.cs diff --git a/OurUmbraco.Site/config/ClientDependency.config b/OurUmbraco.Site/config/ClientDependency.config index 231bc31285..86b8995d84 100644 --- a/OurUmbraco.Site/config/ClientDependency.config +++ b/OurUmbraco.Site/config/ClientDependency.config @@ -10,7 +10,7 @@ NOTES: * Compression/Combination/Minification is not enabled unless debug="false" is specified on the 'compiliation' element in the web.config * A new version will invalidate both client and server cache and create new persisted files --> - + - +
+

Latest Community Activity

+
    + +
    diff --git a/OurUmbraco.Site/Views/Partials/Community/Scripts.cshtml b/OurUmbraco.Site/Views/Partials/Community/Scripts.cshtml index e2e1c032b4..1cb3a9f434 100644 --- a/OurUmbraco.Site/Views/Partials/Community/Scripts.cshtml +++ b/OurUmbraco.Site/Views/Partials/Community/Scripts.cshtml @@ -1,103 +1 @@ - + From 16568f301e0044a13b0948769cb1271f4be38d77 Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Mon, 21 May 2018 08:09:50 +0100 Subject: [PATCH 07/60] merge after conflict --- .../HighFiveFeed/API/HighFiveFeedAPIController.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index 938d0c9338..af3c5e201f 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -14,6 +14,9 @@ using Umbraco.Core.Persistence; ======= +using OurUmbraco.Community.People.Models; +using OurUmbraco.Community.People; + >>>>>>> 03f85a8b89320d3fa07d44a57a5130336884ca7c namespace OurUmbraco.HighFiveFeed.API { @@ -72,6 +75,15 @@ public string GetCategories() } + + public List GetUmbracians(string name) + { + var peopleService = new PeopleService(); + + var people = peopleService.GetPeopleByName(name); + + return people; + } } } From 15180b5c01fe7cb1470d36392f66233f34ec1626 Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Mon, 21 May 2018 08:38:17 +0100 Subject: [PATCH 08/60] fixing merge --- OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index af3c5e201f..14844c6bbc 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -6,18 +6,14 @@ using Umbraco.Web.WebApi; using Umbraco.Core; using OurUmbraco.HighFiveFeed.Models; -<<<<<<< HEAD using System.Web.Mvc; using Newtonsoft.Json; using System.Net.Http; using Newtonsoft.Json.Serialization; using Umbraco.Core.Persistence; - -======= using OurUmbraco.Community.People.Models; using OurUmbraco.Community.People; ->>>>>>> 03f85a8b89320d3fa07d44a57a5130336884ca7c namespace OurUmbraco.HighFiveFeed.API { public class HighFiveFeedAPIController : UmbracoApiController From 6b69dc229c00d68a4f097157669fc18376eef687 Mon Sep 17 00:00:00 2001 From: Kyle Weems Date: Mon, 21 May 2018 09:41:39 +0200 Subject: [PATCH 09/60] Added periodic polling to keep the high fives up to date. --- .../Assets/js/components/highfives.js | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/OurUmbraco.Site/Assets/js/components/highfives.js b/OurUmbraco.Site/Assets/js/components/highfives.js index faaa388f63..65bba431f2 100644 --- a/OurUmbraco.Site/Assets/js/components/highfives.js +++ b/OurUmbraco.Site/Assets/js/components/highfives.js @@ -32,6 +32,7 @@ * @var HighFives - JS functionality for the high fives module. */ var HighFives = { + list: [], /** * @method init * @returns {void} @@ -41,9 +42,10 @@ if (HighFives.doesHaveHighFive()) { HighFives.printPhrases(HighFives.shuffle(placeholderNames), $('#high-five-mention')); HighFives.getRecentHighFiveActivity(0, function(response) { - console.info('response', response); - HighFives.buildActivityList(response.highFives); - }) + HighFives.list = response.highFives; + HighFives.buildActivityList(HighFives.list ); + HighFives.checkForNewHighFivesPeriodically(30); + }); } }); }, @@ -54,6 +56,12 @@ return new Promise(resolve => setTimeout(resolve, 100)); }, + /** + * @method buildActivityList - Builds a list of list items that represent + * the activity list and adds them to an activity list for users to view. + * @param {JSON[]} highFives - a list of highFive items. + * @returns {void} + */ buildActivityList: function (highFives) { if (highFives && highFives.length > 0) { var list = document.querySelector("#high-five-activity .high-five-activity-list"); @@ -69,10 +77,49 @@ } }, + /** + * @method checkForNewHighFivesPeriodically + * @param {number} seconds + * @returns {void} + */ + checkForNewHighFivesPeriodically: function (seconds) { + window.setTimeout(function() { + HighFives.getRecentHighFiveActivity(0, function(response) { + HighFives.list = HighFives.combineUniqueHighFives(HighFives.list, response.highFives); + HighFives.list = HighFives.list.slice(0, 10); + HighFives.buildActivityList(HighFives.list); + HighFives.checkForNewHighFivesPeriodically(30); + }); + }, (seconds * 1000)); + }, + clearPlaceholder: function (el) { el.attr("placeholder", ""); }, + /** + * @method combineUniqueHighFives + * @param {JSON[]} original + * @param {JSON[]} additional + * @returns {JSON[]} + */ + combineUniqueHighFives: function(original, additional) { + for (var a = 0; a < additional.length; a++) { + var add = additional[a]; + var isUnique = true; + for (var o = 0; o < original.length; o++) { + var orig = original[o]; + if (orig.id === add.id) { + isUnique = false; + } + } + if (isUnique) { + original.unshift(add); + } + } + return original; + }, + /** * @method getRecentHighFiveActivity - Gets the most recent high fives * from the API. From c16fb58732ee6da7b823272d3c3e9e7a19bca1bb Mon Sep 17 00:00:00 2001 From: Niels Hartvig Date: Mon, 21 May 2018 09:47:17 +0200 Subject: [PATCH 10/60] Load categories, typeahead member search --- .../Views/Partials/Community/Home.cshtml | 23 ++++++++++- .../Views/Partials/Community/Scripts.cshtml | 40 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/OurUmbraco.Site/Views/Partials/Community/Home.cshtml b/OurUmbraco.Site/Views/Partials/Community/Home.cshtml index f468508aa2..bb6f14efd2 100644 --- a/OurUmbraco.Site/Views/Partials/Community/Home.cshtml +++ b/OurUmbraco.Site/Views/Partials/Community/Home.cshtml @@ -108,6 +108,12 @@ else high five Send + +
    +
      +
    +
    +
    From 2f9725d05585d71083c5407e546d2f8145a58a26 Mon Sep 17 00:00:00 2001 From: Kyle Weems Date: Mon, 21 May 2018 12:31:28 +0200 Subject: [PATCH 22/60] Set up functionality and mock API response for getting the suggested members from the member search field. --- .../Assets/js/components/highfives.js | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/OurUmbraco.Site/Assets/js/components/highfives.js b/OurUmbraco.Site/Assets/js/components/highfives.js index b42d20973c..02c2103f7a 100644 --- a/OurUmbraco.Site/Assets/js/components/highfives.js +++ b/OurUmbraco.Site/Assets/js/components/highfives.js @@ -31,10 +31,12 @@ // HighFives - JS functionality for the high fives module. var HighFives = { list: [], + suggestions: [], // init - Starts the high fives app functionality. init: function() { $(document).ready(function () { if (HighFives.doesHaveHighFive()) { + HighFives.bindOnMentionChange(); HighFives.printPhrases(HighFives.shuffle(placeholderNames), $('#high-five-mention')); HighFives.getCategories(function(response) { HighFives.buildCategoryDropdown(response); @@ -54,6 +56,12 @@ return new Promise(resolve => setTimeout(resolve, 100)); }, + bindOnMentionChange: function () { + jQuery('#high-five-mention').keyup(function(e) { + HighFives.getMember(e.target.value); + }); + }, + // buildActivityList - Builds a list of list items that represent the activity list and adds them to an activity list for users to view. buildActivityList: function () { var highFives = HighFives.list; @@ -71,6 +79,18 @@ } }, + buildSuggestionsList: function () { + var suggestions = HighFives.suggestions; + var list = document.querySelector("#high-five-form .suggestions-list"); + list.innerHTML = ''; + for (var i = 0; i < suggestions.length; i++) { + var suggestion = suggestions[i]; + list.innerHTML += '
  • ' + + '
  • '; + } + }, + // buildCategoryDropdown - Builds a list of options for the category dropdown. buildCategoryDropdown: function(categories) { if (categories && categories.length > 0) { @@ -108,6 +128,20 @@ } }, + getMember: function(member) { + if (member.length > 2) { + if (useMockApi) { + HighFives.suggestions = ApiMock.getUmbracians(); + HighFives.buildSuggestionsList(); + } else { + jquery.get('/Umbraco/Api/highFiveFeedApi/GetUmbracians?name=' + member, function (umbracians) { + HighFives.suggestions = umbracians; + HighFives.buildSuggestionsList(); + }); + } + } + }, + // getRecentHighFiveActivity - Gets the most recent high fives via API. getRecentHighFiveActivity: function(page, onSuccess) { page = typeof page === 'undefined' ? 0 : page; @@ -177,6 +211,8 @@ } }; + var memberSearch = _.debounce(HighFives.getMember, 300); + var ApiMock = { getCategories: function() { return [ @@ -208,6 +244,22 @@ } ] }; + }, + getUmbracians: function() { + return [ + { + MemberId: '123', + Username: 'Fred Johnson', + }, + { + MemberId: '124', + Username: 'Fred Samson', + }, + { + MemberId: '125', + Username: 'Fredina Hartvig' + } + ]; } }; From 0fa62677d04c69694f6c50463089e8f3fb9a3c06 Mon Sep 17 00:00:00 2001 From: Mike Masey Date: Mon, 21 May 2018 11:27:35 +0100 Subject: [PATCH 23/60] Add update to people service and highfive controller. --- OurUmbraco/Community/People/PeopleService.cs | 341 +++--------------- .../API/HighFiveFeedAPIController.cs | 9 + 2 files changed, 69 insertions(+), 281 deletions(-) diff --git a/OurUmbraco/Community/People/PeopleService.cs b/OurUmbraco/Community/People/PeopleService.cs index fc344f9c14..4fa61582d7 100644 --- a/OurUmbraco/Community/People/PeopleService.cs +++ b/OurUmbraco/Community/People/PeopleService.cs @@ -1,281 +1,4 @@ -<<<<<<< 9856a39bf3d03970f8d7715ceff7011345198a60 -using System; -using System.Collections.Generic; -using System.Linq; -using Examine; -using Examine.LuceneEngine.SearchCriteria; -using Examine.Providers; -using OurUmbraco.Community.People.Models; -using OurUmbraco.Our; -using Umbraco.Core; -using Umbraco.Core.Cache; -using Umbraco.Core.Models; -using Umbraco.Web; -using Umbraco.Web.Security; -using UmbracoExamine; - -namespace OurUmbraco.Community.People -{ - public class PeopleService - { - public List GetMostActiveDateRange(DateTime fromDate, DateTime toDate, int numberOfResults = 25) - { - var sqlQuery = GetMostActiveDateRangeQuery(fromDate, toDate, numberOfResults); - var results = ApplicationContext.Current.DatabaseContext.Database.Fetch(sqlQuery); - return results; - } - - private static string GetMostActiveDateRangeQuery(DateTime fromDate, DateTime toDate, int numberOfResults) - { - var where = string.Format("where (date BETWEEN '{0}' AND '{1}')", fromDate.ToString("yyyy-MM-dd"), toDate.ToString("yyyy-MM-dd")); - var top = string.Format("TOP {0}", numberOfResults); - - var query = string.Format(@";with score as( - SELECT receiverId AS memberId, 0 as performed, SUM(receiverPoints) as received - FROM [powersTopic] - {0} - group by receiverId - - UNION ALL - - SELECT receiverId AS memberId, 0 as performed, SUM(receiverPoints)as received - FROM [powersProject] - {0} - GROUP BY receiverId - - UNION ALL - SELECT receiverId AS memberId, 0 as performed, SUM(receiverPoints)as received - FROM [powersComment] - {0} - GROUP BY receiverId - - UNION ALL - SELECT memberId, SUM(performerPoints)as performed, 0 as received - FROM [powersComment] - {0} - GROUP BY memberId - - UNION ALL - SELECT memberId, SUM(performerPoints)as performed, 0 as received - FROM powersProject - {0} - GROUP BY memberId - - UNION ALL - SELECT memberId, SUM(performerPoints)as performed, 0 as received - FROM powersTopic - {0} - GROUP BY memberId - - UNION ALL - SELECT memberId, SUM(performerPoints)as performed, 0 as received - FROM powersWiki - {0} - GROUP BY memberId - ) - - select {1} text as memberName, memberId, sum(performed) as performed, SUM(received) as received, (sum(received) + sum(performed)) as totalPointsInPeriod from score - inner join umbracoNode ON memberId = id - where memberId IS NOT NULL and memberId > 0 - group by text, memberId order by totalPointsInPeriod DESC", @where, top); - - return query; - } - - public int? GetMemberIdFromGithubName(string githubName) - { - var searcher = ExamineManager.Instance.SearchProviderCollection["InternalMemberSearcher"]; - var criteria = (LuceneSearchCriteria)searcher.CreateSearchCriteria(); - criteria.Field("github", githubName); - var searchResults = searcher.Search(criteria); - var searchResult = searchResults.FirstOrDefault(); - return searchResult?.Id; - } - - public List GetMvps() - { - var memberService = UmbracoContext.Current.Application.Services.MemberService; - var ourMvps = UmbracoContext.Current.Application.ApplicationCache.RuntimeCache.GetCacheItem>("OurMvpsPerYear", - () => - { - var memberGroupService = UmbracoContext.Current.Application.Services.MemberGroupService; - var allMemberGroups = memberGroupService.GetAll().Where(x => x.Name.StartsWith("MVP ")); - - var mvpsPerYear = new List(); - foreach (var memberGroup in allMemberGroups) - { - var members = memberService.GetMembersByGroup(memberGroup.Name).ToList(); - - var yearString = memberGroup.Name.Split(' ')[1]; - var category = memberGroup.Name.Replace($"{memberGroup.Name.Split(' ')[0]} {yearString}", string.Empty); - category = category.TrimStart(" - "); - - int.TryParse(yearString, out var year); - var yearExists = mvpsPerYear.FirstOrDefault(x => x.Year == year); - if (yearExists != null) - { - foreach (var member in members) - { - var mvpMember = PopulateMemberData(member, category); - yearExists.Members.Add(mvpMember); - } - } - else - { - var yearMembers = new MvpsPerYear - { - Year = year, - Members = new List() - }; - - foreach (var member in members) - { - var mvpMember = PopulateMemberData(member, category); - yearMembers.Members.Add(mvpMember); - } - mvpsPerYear.Add(yearMembers); - } - } - - return mvpsPerYear; - - }, TimeSpan.FromHours(48)); - - return ourMvps; - } - - public List GetMembersInRole(string role) - { - var currentApplication = UmbracoContext.Current.Application; - var memberService = currentApplication.Services.MemberService; - - var ourMembersInRole = currentApplication.ApplicationCache.RuntimeCache.GetCacheItem>("OurMembersInRole" + role, - () => - { - var memberGroupService = currentApplication.Services.MemberGroupService; - var memberGroup = memberGroupService - .GetAll() - .FirstOrDefault(x => string.Equals(x.Name, role, StringComparison.InvariantCultureIgnoreCase)); - if (memberGroup == null) - return null; - - var badgeMembers = new List(); - var members = memberService.GetMembersByGroup(memberGroup.Name).ToList(); - - foreach (var member in members) - { - var badgeMember = PopulateBadgeMemberData(member); - badgeMembers.Add(badgeMember); - } - - return badgeMembers; - - }, TimeSpan.FromHours(24)); - - return ourMembersInRole; - } - - private static MvpMember PopulateMemberData(IMember member, string category) - { - var membershipHelper = new MembershipHelper(UmbracoContext.Current); - var m = membershipHelper.GetById(member.Id); - - var company = member.GetValue("company"); - var twitter = (member.GetValue("twitter") ?? "").Trim().TrimStart('@'); - var github = (member.GetValue("github") ?? "").Trim().TrimStart('@'); - - var avatarService = new AvatarService(); - var avatarHtml = avatarService.GetImgWithSrcSet(m, m.Name, 48); - - var mvpMember = new MvpMember - { - Id = member.Id, - Name = member.Name, - Avatar = avatarHtml, - Company = company, - Twitter = twitter, - GitHub = github, - Category = category - }; - return mvpMember; - } - - private static BadgeMember PopulateBadgeMemberData(IMember member) - { - var membershipHelper = new MembershipHelper(UmbracoContext.Current); - var m = membershipHelper.GetById(member.Id); - - var company = member.GetValue("company"); - var twitter = (member.GetValue("twitter") ?? "").Trim().TrimStart('@'); - var github = (member.GetValue("github") ?? "").Trim().TrimStart('@'); - - var avatarService = new AvatarService(); - var avatarHtml = avatarService.GetImgWithSrcSet(m, m.Name, 48); - - var badgeMember = new BadgeMember - { - Id = member.Id, - Name = member.Name, - Avatar = avatarHtml, - Company = company, - Twitter = twitter, - GitHub = github - }; - - return badgeMember; - } - - private const string MemberNameField = "nodeName"; - - public List GetPeopleByName(string name) - { - - List people = new List(); - - if(name.Length < 3) - { - return people; - } - - var memberSearcher = ExamineManager.Instance.SearchProviderCollection["InternalMemberSearcher"]; - - var criteria = memberSearcher.CreateSearchCriteria(IndexTypes.Member); - - ISearchResults results; - - if (name.Contains(" ")) - { - string[] terms = name.Split(' '); - var examineQuery = criteria.GroupedAnd(new List { MemberNameField }, terms); - results = memberSearcher.Search(examineQuery.Compile()); - } - else - { - var examineQuery = criteria.Field(MemberNameField, name.MultipleCharacterWildcard()); - results = memberSearcher.Search(examineQuery.Compile()); - } - - - if (results.TotalItemCount > 0) - { - var memberService = ApplicationContext.Current.Services.MemberService; - - int[] memberIds = results.Select(x => x.Id).ToArray(); - - var peopleResults = memberService.GetAllMembers(memberIds); - - foreach(var person in peopleResults) - { - people.Add(new Person(person)); - } - } - - return people; - } - } -} -======= -using System; +using System; using System.Collections.Generic; using System.Linq; using Examine; @@ -507,8 +230,9 @@ public List GetPeopleByName(string name) { List people = new List(); + List searchTerms = new List { MemberNameField }; - if(name.Length < 3) + if (name.Length < 3) { return people; } @@ -519,11 +243,19 @@ public List GetPeopleByName(string name) var examineQuery = criteria.Field("blocked", 0.ToString()); - examineQuery = examineQuery.And().Field(MemberNameField, name.Trim().MultipleCharacterWildcard()); + var q_split = name.Split(' '); + examineQuery.And().GroupedAnd(searchTerms, q_split.First().MultipleCharacterWildcard()); + foreach (var term in q_split.Skip(1)) + { + examineQuery.And().GroupedAnd(searchTerms, term.MultipleCharacterWildcard()); + } + + examineQuery.And().OrderByDescending(MemberNameField); var results = memberSearcher.Search(examineQuery.Compile()); + if (results.TotalItemCount > 0) { var memberService = ApplicationContext.Current.Services.MemberService; @@ -540,6 +272,53 @@ public List GetPeopleByName(string name) return people; } + + public List GetRandomPeople() + { + List people = new List(); + + var memberSearcher = ExamineManager.Instance.SearchProviderCollection["InternalMemberSearcher"]; + + var criteria = memberSearcher.CreateSearchCriteria(IndexTypes.Member); + + var examineQuery = criteria.Field("blocked", 0.ToString()); + criteria.Range("updateDate", DateTime.MinValue, DateTime.MaxValue); + + var results = memberSearcher.Search(examineQuery.Compile()); + + + if (results.TotalItemCount > 0) + { + var memberService = ApplicationContext.Current.Services.MemberService; + + int[] memberIds = GetRandomIds(results); + + var peopleResults = memberService.GetAllMembers(memberIds); + + foreach (var person in peopleResults) + { + people.Add(new Person(person)); + } + } + + return people; + } + + private int[] GetRandomIds(ISearchResults results) + { + var resultsList = results.ToList(); + var totalIndexes = results.TotalItemCount > 9 ? 9 : results.TotalItemCount; + int[] indexes = new int[totalIndexes + 1]; + + for(int i = 0; i < totalIndexes; i++) + { + Random r = new Random(); + int rInt = r.Next(0, results.TotalItemCount); + + indexes[i] = resultsList[rInt].Id; + } + + return indexes; + } } } ->>>>>>> Reworking umbrcians search. diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index 7ec3abbd67..ab6098876a 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -75,5 +75,14 @@ public List GetUmbracians(string name) return people; } + + public List GetRandomUmbracians() + { + var peopleService = new PeopleService(); + + var people = peopleService.GetRandomPeople(); + + return people; + } } } \ No newline at end of file From 44396f03ed21852f9a0ff7fb14f3fa5236087cdb Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Mon, 21 May 2018 11:34:06 +0100 Subject: [PATCH 24/60] retrieve feed logic --- OurUmbraco.Client/package-lock.json | 14 ++++---- OurUmbraco.Site/Views/CommunityHub.cshtml | 13 ++------ OurUmbraco.Site/Views/Search.cshtml | 13 ++------ OurUmbraco.Site/Views/Videos.cshtml | 13 ++------ .../umbraco/preview.old/readme.txt | 3 ++ .../API/HighFiveFeedAPIController.cs | 33 +++++++++++++++++-- .../Models/HighFiveFeedResponse.cs | 21 ++++++++++++ .../HighFiveFeed/Models/HighFiveResponse.cs | 20 +++++++++++ OurUmbraco/Our/MigrationsHandler.cs | 3 +- OurUmbraco/OurUmbraco.csproj | 2 ++ 10 files changed, 92 insertions(+), 43 deletions(-) create mode 100644 OurUmbraco.Site/umbraco/preview.old/readme.txt create mode 100644 OurUmbraco/HighFiveFeed/Models/HighFiveFeedResponse.cs create mode 100644 OurUmbraco/HighFiveFeed/Models/HighFiveResponse.cs diff --git a/OurUmbraco.Client/package-lock.json b/OurUmbraco.Client/package-lock.json index 702bc000b0..51c50ee28f 100644 --- a/OurUmbraco.Client/package-lock.json +++ b/OurUmbraco.Client/package-lock.json @@ -7,7 +7,7 @@ "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", - "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", + "integrity": "sha1-+PLIh60Qv2f2NPAFtph/7TF5qsg=", "dev": true }, "amdefine": { @@ -55,7 +55,7 @@ "aproba": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", - "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", + "integrity": "sha1-aALmJk79GMeQobDVF/DyYnvyyUo=", "dev": true }, "are-we-there-yet": { @@ -36080,7 +36080,7 @@ "normalize-package-data": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.4.0.tgz", - "integrity": "sha512-9jjUFbTPfEy3R/ad/2oNbKtW9Hgovl5O1FvFWKkKblNXoN/Oou6+9+KKohPK13Yc3/TyunyWhJp6gvRNR/PPAw==", + "integrity": "sha1-EvlaMH1YNSB1oEkHuErIvpisAS8=", "dev": true, "requires": { "hosted-git-info": "2.5.0", @@ -36092,7 +36092,7 @@ "npmlog": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", - "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", + "integrity": "sha1-CKfyqL9zRgR3mp76StXMcXq7lUs=", "dev": true, "requires": { "are-we-there-yet": "1.1.4", @@ -36371,7 +36371,7 @@ "rimraf": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", - "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", + "integrity": "sha1-LtgVDSShbqhlHm1u8PR8QVjOejY=", "dev": true, "requires": { "glob": "7.1.2" @@ -36700,7 +36700,7 @@ "which": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/which/-/which-1.3.0.tgz", - "integrity": "sha512-xcJpopdamTuY5duC/KnTTNBraPK54YwpenP4lzxU8H91GudWpFv38u0CKjclE1Wi2EH2EDz5LRcHcKbCIzqGyg==", + "integrity": "sha1-/wS9/AEO5UfXgL7DjhrBwnd9JTo=", "dev": true, "requires": { "isexe": "2.0.0" @@ -36715,7 +36715,7 @@ "wide-align": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.2.tgz", - "integrity": "sha512-ijDLlyQ7s6x1JgCLur53osjm/UXUYD9+0PbYKrBsYisYXzCxN+HC3mYDNy/dWdmf3AwqwU3CXwDCvsNgGK1S0w==", + "integrity": "sha1-Vx4PGwYEY268DfwhsDObvjE0FxA=", "dev": true, "requires": { "string-width": "1.0.2" diff --git a/OurUmbraco.Site/Views/CommunityHub.cshtml b/OurUmbraco.Site/Views/CommunityHub.cshtml index 7086b47d6b..3e82f2f0d2 100644 --- a/OurUmbraco.Site/Views/CommunityHub.cshtml +++ b/OurUmbraco.Site/Views/CommunityHub.cshtml @@ -1,13 +1,4 @@ -@using OurUmbraco.Our -@inherits OurUmbraco.Our.Models.OurUmbracoTemplatePage +@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ - Layout = "~/Views/CommunityHubPageLayout.cshtml"; - - var featuresService = new UpcomingFeaturesService(); - var allowed = featuresService.MemberHasAccessToFeature(); -} - -@if (allowed) -{ - @Html.Partial("~/Views/Partials/Community/Hub.cshtml") + Layout = null; } \ No newline at end of file diff --git a/OurUmbraco.Site/Views/Search.cshtml b/OurUmbraco.Site/Views/Search.cshtml index c1dbef44da..3e82f2f0d2 100644 --- a/OurUmbraco.Site/Views/Search.cshtml +++ b/OurUmbraco.Site/Views/Search.cshtml @@ -1,11 +1,4 @@ -@using OurUmbraco.Our.Models -@inherits UmbracoTemplatePage +@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ - Layout = "~/Views/Master.cshtml"; -} -
    - - @Html.Action("Render", "Search") - - -
    + Layout = null; +} \ No newline at end of file diff --git a/OurUmbraco.Site/Views/Videos.cshtml b/OurUmbraco.Site/Views/Videos.cshtml index 846ee203b1..3e82f2f0d2 100644 --- a/OurUmbraco.Site/Views/Videos.cshtml +++ b/OurUmbraco.Site/Views/Videos.cshtml @@ -1,13 +1,4 @@ -@using OurUmbraco.Our -@inherits OurUmbraco.Our.Models.OurUmbracoTemplatePage +@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ - Layout = "~/Views/Master.cshtml"; - - var featuresService = new UpcomingFeaturesService(); - var allowed = featuresService.MemberHasAccessToFeature(); -} - -@if (allowed) -{ - @Html.Partial("~/Views/Partials/Videos/Home.cshtml") + Layout = null; } \ No newline at end of file diff --git a/OurUmbraco.Site/umbraco/preview.old/readme.txt b/OurUmbraco.Site/umbraco/preview.old/readme.txt new file mode 100644 index 0000000000..e3360a965b --- /dev/null +++ b/OurUmbraco.Site/umbraco/preview.old/readme.txt @@ -0,0 +1,3 @@ +Static html files used for preview and canvas editing functionality no longer live in this directory. +Instead they have been recreated as MVC views and can now be found in '~/Umbraco/Views/Preview'. +See issue: http://issues.umbraco.org/issue/U4-11090 \ No newline at end of file diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index 7ec3abbd67..59442c028f 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -13,6 +13,8 @@ using Umbraco.Core.Persistence; using OurUmbraco.Community.People.Models; using OurUmbraco.Community.People; +using OurUmbraco.Forum.Services; +using Umbraco.Web.Mvc; namespace OurUmbraco.HighFiveFeed.API { @@ -37,12 +39,37 @@ public void SubmitHighFive(int fromUserId, int toUserId, int action, String url) dbContext.Database.Insert(highFive); } [HttpGet] - public List GetHighFiveFeed() + public string GetHighFiveFeed() { var dbContext = ApplicationContext.Current.DatabaseContext; var sql = new Sql().Select("*").From("highFivePosts"); - var result = dbContext.Database.Fetch(sql); - return result; + var result = dbContext.Database.Fetch(sql).OrderByDescending(x=>x.Id); + var avatarService = new AvatarService(); + var response = new HighFiveFeedResponse(); + foreach (var dbEntry in result.Take(10)) + { + var toMember = Members.GetById(dbEntry.ToMemberId); + var fromMember = Members.GetById(dbEntry.FromMemberId); + var toAvatar = avatarService.GetMemberAvatar(toMember); + var fromAvatar = avatarService.GetMemberAvatar(toMember); + var highFive = new HighFiveResponse() + { + url = dbEntry.Link, + type = dbEntry.ActionId.ToString(), + from = fromMember.Name, + fromAvatarUrl = fromAvatar, + to = toMember.Name, + toAvatarUrl = toAvatar, + Id = dbEntry.Id + + + }; + response.HighFives.Add(highFive); + } + var rawJson = JsonConvert.SerializeObject(response, Formatting.Indented); + + + return rawJson; } diff --git a/OurUmbraco/HighFiveFeed/Models/HighFiveFeedResponse.cs b/OurUmbraco/HighFiveFeed/Models/HighFiveFeedResponse.cs new file mode 100644 index 0000000000..ab830609c3 --- /dev/null +++ b/OurUmbraco/HighFiveFeed/Models/HighFiveFeedResponse.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OurUmbraco.HighFiveFeed.Models +{ + public class HighFiveFeedResponse + { + public HighFiveFeedResponse() + { + HighFives = new List(); + } + public int Count { get; set; } + public int PageCount { get; set; } + public int CurrentPage { get; set; } + + public List HighFives { get; set;} + } +} diff --git a/OurUmbraco/HighFiveFeed/Models/HighFiveResponse.cs b/OurUmbraco/HighFiveFeed/Models/HighFiveResponse.cs new file mode 100644 index 0000000000..8b90cd2499 --- /dev/null +++ b/OurUmbraco/HighFiveFeed/Models/HighFiveResponse.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OurUmbraco.HighFiveFeed.Models +{ + public class HighFiveResponse + { + public int Id { get; set; } + public string from{ get; set; } + public string to { get; set; } + public string fromAvatarUrl { get; set; } + public string toAvatarUrl { get; set; } + public string type { get; set; } + public string url { get; set; } + + } +} diff --git a/OurUmbraco/Our/MigrationsHandler.cs b/OurUmbraco/Our/MigrationsHandler.cs index 1897c53be0..c79cad6b95 100644 --- a/OurUmbraco/Our/MigrationsHandler.cs +++ b/OurUmbraco/Our/MigrationsHandler.cs @@ -53,6 +53,7 @@ protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplica AddVideosPage(); AddRetiredStatusToPackages(); AddPasswordResetTokenToMembers(); + AddHighFiveTable(); } private void EnsureMigrationsMarkerPathExists() @@ -1473,7 +1474,7 @@ private void AddHighFiveTable() } //locic var db = ApplicationContext.Current.DatabaseContext.Database; - db.Execute("CREATE TABLE [dbo].[highFivePosts]([Id][int] NULL,[FromMemberId] [int] NULL,[ToMemberId] [int] NULL,[ActionId] [varchar] (50) NULL,[Link][nvarchar](max) NULL,[Count] [int] NULL) ON[PRIMARY] TEXTIMAGE_ON[PRIMARY] GO"); + db.Execute("CREATE TABLE [dbo].[highFivePosts]([Id][int] NULL,[FromMemberId] [int] NULL,[ToMemberId] [int] NULL,[ActionId] [varchar] (50) NULL,[Link][nvarchar](max) NULL,[Count] [int] NULL) ON[PRIMARY] TEXTIMAGE_ON[PRIMARY]"); string[] lines = { "" }; File.WriteAllLines(path, lines); diff --git a/OurUmbraco/OurUmbraco.csproj b/OurUmbraco/OurUmbraco.csproj index 5104930507..78b9ebb762 100644 --- a/OurUmbraco/OurUmbraco.csproj +++ b/OurUmbraco/OurUmbraco.csproj @@ -520,6 +520,8 @@ + + From 3dd6e362b33a126ee4697698d5f8cb079a22ab6d Mon Sep 17 00:00:00 2001 From: Mike Masey Date: Mon, 21 May 2018 13:19:19 +0100 Subject: [PATCH 25/60] Add get random people endpoint. --- OurUmbraco/Community/People/PeopleService.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/OurUmbraco/Community/People/PeopleService.cs b/OurUmbraco/Community/People/PeopleService.cs index 4fa61582d7..d6613fed00 100644 --- a/OurUmbraco/Community/People/PeopleService.cs +++ b/OurUmbraco/Community/People/PeopleService.cs @@ -310,11 +310,13 @@ private int[] GetRandomIds(ISearchResults results) var totalIndexes = results.TotalItemCount > 9 ? 9 : results.TotalItemCount; int[] indexes = new int[totalIndexes + 1]; - for(int i = 0; i < totalIndexes; i++) + int rand = 0; + + for(int i = 0; i < totalIndexes + 1; i++) { - Random r = new Random(); + Random r = rand == 0 ? new Random() : new Random(rand); int rInt = r.Next(0, results.TotalItemCount); - + rand = rInt; indexes[i] = resultsList[rInt].Id; } From 378bc82b58b01b76c35641f29e7d51ac378df5c5 Mon Sep 17 00:00:00 2001 From: Niels Hartvig Date: Mon, 21 May 2018 14:54:56 +0200 Subject: [PATCH 26/60] Styling high five items --- .../src/scss/sections/_highFive.scss | 127 ++++++- .../Assets/js/components/highfives.js | 30 +- .../Views/Partials/Community/Home.cshtml | 9 +- .../Views/Partials/Community/Scripts.cshtml | 20 +- OurUmbraco/Community/People/PeopleService.cs | 320 ++---------------- 5 files changed, 198 insertions(+), 308 deletions(-) diff --git a/OurUmbraco.Client/src/scss/sections/_highFive.scss b/OurUmbraco.Client/src/scss/sections/_highFive.scss index c9b0a60504..fd78a27d21 100644 --- a/OurUmbraco.Client/src/scss/sections/_highFive.scss +++ b/OurUmbraco.Client/src/scss/sections/_highFive.scss @@ -5,7 +5,7 @@ background-repeat: no-repeat; position: relative; - h3 { + h2 { margin: 1rem auto 3.5rem; margin-bottom: 3rem; line-height: 1.5; @@ -69,4 +69,129 @@ flex-flow: row wrap; justify-content: space-between; } + + + .high-five-item { + flex: 0 0 100%; + display: flex; + overflow: hidden; + + @media (min-width: $md) { + flex: 1 0 49%; + + &:nth-child(odd) { + margin-right: 2%; + } + } + + .avatar { + flex: 0 0 23%; + margin-right: 20px; + + + @media (min-width: $md) { + flex: 0 0 15%; + } + + img { + width: 100%; + max-width: 112px; + height: auto; + } + } + + + + .meta { + display: flex; + flex-direction: column; + flex: 1 0 75%; + overflow: hidden; + padding: 0 10px 0 0; + + @media (min-width: $md) { + flex: 1 0 83%; + } + } + + + + .category { + margin: .5rem 0 0; + max-width: 95%; + + span { + font-size: .75rem; + } + } + } } + + +.high-five-item { + background: #fff; + padding: 25px; + margin-bottom: 30px; + border: 1px solid darken(#f6f6f6, 5%); + transition: box-shadow .2s ease, border-color .2s ease; + text-decoration: none; + display: flex; + align-items: center; + + &:hover { + border-color: white; + @include box_shadow(2); + } + + .row { + margin: 0; + } + + img { + border-radius: 50%; + width: 100%; + max-width: 112px; + height: auto; + + .package-forum-activity & { + border-radius: 0; + } + + @media (min-width: $md) { + width: 58px; + } + + + } + + .high-five-header { + margin-bottom: 2px; + font-weight: normal; + color: #000; + line-height: 1.3; + font-size: 1rem; + + @media (min-width: $md) { + font-size: 1.1rem; + } + } + + p { + margin: 0; + text-align: left; + font-size: .9rem; + color: $color-space; + } + + small { + font-size: .8rem; + } + + .col-xs-2 { + padding: 0 .1rem; + + @media (min-width: $md) { + padding: 0 .3rem; + } + } +} \ No newline at end of file diff --git a/OurUmbraco.Site/Assets/js/components/highfives.js b/OurUmbraco.Site/Assets/js/components/highfives.js index b42d20973c..ed60796b9a 100644 --- a/OurUmbraco.Site/Assets/js/components/highfives.js +++ b/OurUmbraco.Site/Assets/js/components/highfives.js @@ -26,6 +26,18 @@ "Ilham Boulghallat" ]; + var compliments = [ + "Awesome", + "Great job", + "Well done", + "Kudos", + "Nice", + "Woohooo", + "You Rock", + "Lovely", + "Genius", + "Thank you"] + var useMockApi = true; // HighFives - JS functionality for the high fives module. @@ -58,15 +70,23 @@ buildActivityList: function () { var highFives = HighFives.list; if (highFives && highFives.length > 0) { + var template = _.template($("script.high-five-template").html()); var list = document.querySelector("#high-five-activity .high-five-activity-list"); list.innerHTML = ''; for (var i = 0; i < highFives.length; i++) { var highFive = highFives[i]; - list.innerHTML += '
  • ' + highFive.from + ' has highfived ' + - '' + highFive.to + '' + - ' for a ' + highFive.type + '' + - ((highFive.url && highFive.url !== '') ? ' at ' + highFive.url + '' : '') + - '.
  • '; + + var highFiveObject = { + avatar: "/media/avatar/144494.png", + compliment: compliments[Math.floor(Math.random() * compliments.length)], + name: placeholderNames[Math.floor(Math.random() * placeholderNames.length)], + highFiver: placeholderNames[Math.floor(Math.random() * placeholderNames.length)], + url: highFive.url, + type: highFive.type, + timestamp: "2 minutes ago" + }; + + list.innerHTML += template(highFiveObject); } } }, diff --git a/OurUmbraco.Site/Views/Partials/Community/Home.cshtml b/OurUmbraco.Site/Views/Partials/Community/Home.cshtml index 22fab38381..1de0c98364 100644 --- a/OurUmbraco.Site/Views/Partials/Community/Home.cshtml +++ b/OurUmbraco.Site/Views/Partials/Community/Home.cshtml @@ -90,21 +90,20 @@ else
    -

    +

    High Five for at -
      -

      +
        +
        -
        -

        Latest Community Activity

        +
          -
          +
            + +
            + From cd17e2f160595188b9116c882fc3ebfba7ee25f5 Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Mon, 21 May 2018 14:41:33 +0100 Subject: [PATCH 30/60] API feed updates --- .../API/HighFiveFeedAPIController.cs | 8 -------- OurUmbraco/HighFiveFeed/Models/HighFiveFeed.cs | 18 ------------------ .../HighFiveFeed/Models/HighFiveResponse.cs | 6 ------ OurUmbraco/Our/MigrationsHandler.cs | 1 - 4 files changed, 33 deletions(-) diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index 7eab16abd1..158ca7d4b2 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -44,7 +44,6 @@ public string GetHighFiveFeed() { var dbContext = ApplicationContext.Current.DatabaseContext; var sql = new Sql().Select("*").From("highFivePosts"); - var result = dbContext.Database.Fetch(sql).OrderByDescending(x=>x.Id); var result = dbContext.Database.Fetch(sql).OrderByDescending(x=>x.CreatedDate); var avatarService = new AvatarService(); var response = new HighFiveFeedResponse(); @@ -56,13 +55,6 @@ public string GetHighFiveFeed() var fromAvatar = avatarService.GetMemberAvatar(toMember); var highFive = new HighFiveResponse() { - url = dbEntry.Link, - type = dbEntry.ActionId.ToString(), - from = fromMember.Name, - fromAvatarUrl = fromAvatar, - to = toMember.Name, - toAvatarUrl = toAvatar, - Id = dbEntry.Id Url = dbEntry.Link, Type = dbEntry.ActionId.ToString(), From = fromMember.Name, diff --git a/OurUmbraco/HighFiveFeed/Models/HighFiveFeed.cs b/OurUmbraco/HighFiveFeed/Models/HighFiveFeed.cs index 32d5a798c5..27641cda4c 100644 --- a/OurUmbraco/HighFiveFeed/Models/HighFiveFeed.cs +++ b/OurUmbraco/HighFiveFeed/Models/HighFiveFeed.cs @@ -3,12 +3,6 @@ namespace OurUmbraco.HighFiveFeed.Models { - [TableName("highFivePosts")] - [PrimaryKey("id", autoIncrement = false)] - [ExplicitColumns] - public class HighFiveFeed - { - [Column("id")] [TableName("highFivePosts")] [PrimaryKey("id", autoIncrement = false)] [ExplicitColumns] @@ -17,33 +11,21 @@ public class HighFiveFeed [Column("id")] public int Id { get; set; } - [Column("fromMemberId")] - public int FromMemberId { get; set; } [Column("fromMemberId")] public int FromMemberId { get; set; } - [Column("toMemberId")] - public int ToMemberId { get; set; } [Column("toMemberId")] public int ToMemberId { get; set; } - [Column("actionId")] - public int ActionId { get; set; } [Column("actionId")] public int ActionId { get; set; } - [Column("link")] - public string Link { get; set; } [Column("link")] public string Link { get; set; } - [Column("count")] - public int Count { get; set; } [Column("count")] public int Count { get; set; } - - } [Column("createdDate")] public DateTime CreatedDate { get; set; } } diff --git a/OurUmbraco/HighFiveFeed/Models/HighFiveResponse.cs b/OurUmbraco/HighFiveFeed/Models/HighFiveResponse.cs index 7ceccadd21..d00a371b02 100644 --- a/OurUmbraco/HighFiveFeed/Models/HighFiveResponse.cs +++ b/OurUmbraco/HighFiveFeed/Models/HighFiveResponse.cs @@ -9,12 +9,6 @@ namespace OurUmbraco.HighFiveFeed.Models public class HighFiveResponse { public int Id { get; set; } - public string from{ get; set; } - public string to { get; set; } - public string fromAvatarUrl { get; set; } - public string toAvatarUrl { get; set; } - public string type { get; set; } - public string url { get; set; } public string From{ get; set; } public string To { get; set; } public string FromAvatarUrl { get; set; } diff --git a/OurUmbraco/Our/MigrationsHandler.cs b/OurUmbraco/Our/MigrationsHandler.cs index 5577aa96ec..ce9e9a397e 100644 --- a/OurUmbraco/Our/MigrationsHandler.cs +++ b/OurUmbraco/Our/MigrationsHandler.cs @@ -1474,7 +1474,6 @@ private void AddHighFiveTable() } //locic var db = ApplicationContext.Current.DatabaseContext.Database; - db.Execute("CREATE TABLE [dbo].[highFivePosts]([Id][int] NULL,[FromMemberId] [int] NULL,[ToMemberId] [int] NULL,[ActionId] [varchar] (50) NULL,[Link][nvarchar](max) NULL,[Count] [int] NULL) ON[PRIMARY] TEXTIMAGE_ON[PRIMARY]"); db.Execute("CREATE TABLE [dbo].[highFivePosts]([Id][int] NULL,[FromMemberId] [int] NULL,[ToMemberId] [int] NULL,[ActionId] [varchar] (50) NULL,[Link][nvarchar](max) NULL,[Count] [int] NULL, [CreatedDate] [datetime] NULL) ON[PRIMARY] TEXTIMAGE_ON[PRIMARY]"); string[] lines = { "" }; From 016c5d56ac3d40fd78428f785e67bda24e1401b4 Mon Sep 17 00:00:00 2001 From: Kyle Weems Date: Mon, 21 May 2018 15:53:29 +0200 Subject: [PATCH 31/60] Added in functionality to get random members for placeholder from API. --- .../Assets/js/components/highfives.js | 78 +++++++++++-------- .../Views/Partials/Community/Home.cshtml | 8 +- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/OurUmbraco.Site/Assets/js/components/highfives.js b/OurUmbraco.Site/Assets/js/components/highfives.js index bf22cde20c..8b74c3c463 100644 --- a/OurUmbraco.Site/Assets/js/components/highfives.js +++ b/OurUmbraco.Site/Assets/js/components/highfives.js @@ -1,31 +1,5 @@ (function() { - var placeholderNames = [ - "Marcin Zajkowski", - "Callum Whyte", - "Anders Bjerner", - "Emma Garland", - "Lars - Erik Aabech", - "Matt Brailsford", - "Carole Rennie Logan", - "Emma Burstow", - "Lee Kelleher", - "Jeffrey Schoemaker", - "Erica Quessenberry", - "Kyle Weems", - "Mike Masey", - "Niels Hartvig", - "Jeavon Leopold", - "Damiaan Peeters", - "Marc Goodson", - "Mads Rasmussen", - "Shannon Deminick", - "Stéphane Gay", - "Sebastiaan Janssen", - "Jacob Midtgaard - Olesen", - "Ilham Boulghallat" - ]; - var useMockApi = true; // HighFives - JS functionality for the high fives module. @@ -39,13 +13,15 @@ if (HighFives.doesHaveHighFive()) { HighFives.bindOnMentionChange(); HighFives.bindOnMemberSelect(); - HighFives.printPhrases(HighFives.shuffle(placeholderNames), $('#high-five-mention')); - HighFives.getCategories(function(response) { - HighFives.buildCategoryDropdown(response); - HighFives.getRecentHighFiveActivity(0, function(response) { - HighFives.list = response.highFives; - HighFives.buildActivityList(HighFives.list); - HighFives.checkForNewHighFivesPeriodically(30); + HighFives.getRandomUmbracians(function(people) { + HighFives.printPhrases(HighFives.shuffle(_.map(people, 'Username')), $('#high-five-mention')); + HighFives.getCategories(function(categories) { + HighFives.buildCategoryDropdown(categories); + HighFives.getRecentHighFiveActivity(0, function(activity) { + HighFives.list = activity.highFives; + HighFives.buildActivityList(HighFives.list); + HighFives.checkForNewHighFivesPeriodically(30); + }); }); }); } @@ -163,6 +139,15 @@ } }, + // getRandomUmbracians - Get a random list of Umbracians to use for placeholder. + getRandomUmbracians: function(onSuccess) { + if (useMockApi) { + onSuccess(ApiMock.getRandomUmbracians()); + } else { + jQuery.get('/umbraco/api/HighFiveFeedAPI/getRandomUmbracians', onSuccess); + } + }, + // getRecentHighFiveActivity - Gets the most recent high fives via API. getRecentHighFiveActivity: function(page, onSuccess) { page = typeof page === 'undefined' ? 0 : page; @@ -305,6 +290,33 @@ Username: 'Fredina Hartvig' } ]; + }, + getRandomUmbracians: function() { + return [ + {MemberId: '0001', Username: "Marcin Zajkowski"}, + {MemberId: '0002', Username: "Callum Whyte"}, + {MemberId: '0003', Username: "Anders Bjerner"}, + {MemberId: '0004', Username: "Emma Garland"}, + {MemberId: '0005', Username: "Lars - Erik Aabech"}, + {MemberId: '0006', Username: "Matt Brailsford"}, + {MemberId: '0007', Username: "Carole Rennie Logan"}, + {MemberId: '0008', Username: "Emma Burstow"}, + {MemberId: '0009', Username: "Lee Kelleher"}, + {MemberId: '0010', Username: "Jeffrey Schoemaker"}, + {MemberId: '0011', Username: "Erica Quessenberry"}, + {MemberId: '0012', Username: "Kyle Weems"}, + {MemberId: '0013', Username: "Mike Masey"}, + {MemberId: '0014', Username: "Niels Hartvig"}, + {MemberId: '0015', Username: "Jeavon Leopold"}, + {MemberId: '0016', Username: "Damiaan Peeters"}, + {MemberId: '0017', Username: "Marc Goodson"}, + {MemberId: '0018', Username: "Mads Rasmussen"}, + {MemberId: '0019', Username: "Shannon Deminick"}, + {MemberId: '0020', Username: "Stéphane Gay"}, + {MemberId: '0021', Username: "Sebastiaan Janssen"}, + {MemberId: '0022', Username: "Jacob Midtgaard - Olesen"}, + {MemberId: '0023', Username: "Ilham Boulghallat"} + ] } }; diff --git a/OurUmbraco.Site/Views/Partials/Community/Home.cshtml b/OurUmbraco.Site/Views/Partials/Community/Home.cshtml index 4750545d59..dcc9b37e24 100644 --- a/OurUmbraco.Site/Views/Partials/Community/Home.cshtml +++ b/OurUmbraco.Site/Views/Partials/Community/Home.cshtml @@ -91,12 +91,12 @@ else

            - High Five - for + for at - -

            From 4e822b5478aaa41fa14ae72055e3d047b6864c08 Mon Sep 17 00:00:00 2001 From: Kyle Weems Date: Mon, 21 May 2018 16:22:09 +0200 Subject: [PATCH 32/60] Added submit form functionality and mock. --- .../Assets/js/components/highfives.js | 53 +++++++++++++++++-- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/OurUmbraco.Site/Assets/js/components/highfives.js b/OurUmbraco.Site/Assets/js/components/highfives.js index 8b74c3c463..ca83a584f1 100644 --- a/OurUmbraco.Site/Assets/js/components/highfives.js +++ b/OurUmbraco.Site/Assets/js/components/highfives.js @@ -13,6 +13,7 @@ if (HighFives.doesHaveHighFive()) { HighFives.bindOnMentionChange(); HighFives.bindOnMemberSelect(); + HighFives.bindOnSubmitForm(); HighFives.getRandomUmbracians(function(people) { HighFives.printPhrases(HighFives.shuffle(_.map(people, 'Username')), $('#high-five-mention')); HighFives.getCategories(function(categories) { @@ -55,6 +56,17 @@ // unbind from previous versions just in case }, + bindOnSubmitForm: function() { + jQuery('#high-five-form').submit(function(e) { + e.preventDefault(); + if (HighFives.isFormValid()) { + HighFives.submitHighFive(HighFives.selectedMember.id, jQuery('#high-five-task').val(), jQuery('#high-five-url').val(), function() { + HighFives.resetForm(); + }); + } + }); + }, + // buildActivityList - Builds a list of list items that represent the activity list and adds them to an activity list for users to view. buildActivityList: function () { var highFives = HighFives.list; @@ -116,6 +128,15 @@ el.attr("placeholder", ""); }, + // doesHaveHighFive - returns true if highFive element exists + doesHaveHighFive: function() { + var highFive = document.querySelector('section[data-high-five]'); + if (highFive && typeof highFive !== 'null' && typeof highFive !== 'undefined') { + return true; + } + return false; + }, + // getCategories - Get the categories for the high fives. getCategories: function(onSuccess) { if (useMockApi) { @@ -158,11 +179,13 @@ } }, - // doesHaveHighFive - returns true if highFive element exists - doesHaveHighFive: function() { - var highFive = document.querySelector('section[data-high-five]'); - if (highFive && typeof highFive !== 'null' && typeof highFive !== 'undefined') { - return true; + isFormValid: function() { + if (HighFives.selectedMember) { + if (jQuery('#high-five-url').val() !== '') { + if (typeof jQuery('#high-five-task').val() !== 'object') { + return true; + } + } } return false; }, @@ -197,6 +220,14 @@ ); }, + resetForm: function () { + HighFives.selectedMember = false; + HighFives.suggestions = []; + jQuery('#high-five-url').val(''); + jQuery('#high-five-mention').val(''); + HighFives.buildSuggestionsList(); + }, + // selectMember selectMember: function (member) { var list = document.querySelector("#high-five-form .suggestions-list"); @@ -220,6 +251,15 @@ } } }, + + // submitHighFive + submitHighFive: function(to, action, url, onSuccess) { + if (useMockApi) { + onSuccess(ApiMock.submitHighFive()); + } else { + jQuery.get('/umbraco/api/HighFiveFeedAPI/SubmitHighFive?toUserId=' + to + '&action=' + action + '&url=' + url, onSuccess); + } + }, shuffle: function(array) { var currentIndex = array.length, temporaryValue, randomIndex; @@ -317,6 +357,9 @@ {MemberId: '0022', Username: "Jacob Midtgaard - Olesen"}, {MemberId: '0023', Username: "Ilham Boulghallat"} ] + }, + submitHighFive: function() { + return {}; } }; From 748f4228cd5c9104de1ab298fd2e57f76495403b Mon Sep 17 00:00:00 2001 From: Kyle Weems Date: Mon, 21 May 2018 16:23:11 +0200 Subject: [PATCH 33/60] Switched off mock API. --- OurUmbraco.Site/Assets/js/components/highfives.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OurUmbraco.Site/Assets/js/components/highfives.js b/OurUmbraco.Site/Assets/js/components/highfives.js index ca83a584f1..aa698b372e 100644 --- a/OurUmbraco.Site/Assets/js/components/highfives.js +++ b/OurUmbraco.Site/Assets/js/components/highfives.js @@ -1,6 +1,6 @@ (function() { - var useMockApi = true; + var useMockApi = false; // HighFives - JS functionality for the high fives module. var HighFives = { From 8b30bb9de82b036f94b6c30992d49ebd954ce6aa Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Mon, 21 May 2018 15:38:46 +0100 Subject: [PATCH 34/60] removing fromid --- .../API/HighFiveFeedAPIController.cs | 67 +++++++++++-------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index 158ca7d4b2..d9f1b0490d 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -20,24 +20,43 @@ namespace OurUmbraco.HighFiveFeed.API { public class HighFiveFeedAPIController : UmbracoApiController { - public HighFiveFeedAPIController() { } + public List Categories; + public HighFiveFeedAPIController() + { + Categories = new List(); + Categories.Add(new HighFiveCategory(1, "A Package")); + Categories.Add(new HighFiveCategory(2, "A Talk")); + Categories.Add(new HighFiveCategory(3, "A Blog Post")); + Categories.Add(new HighFiveCategory(4, "A Meetup")); + Categories.Add(new HighFiveCategory(5, "A Skrift Article")); + Categories.Add(new HighFiveCategory(6, "A Tutorial")); + Categories.Add(new HighFiveCategory(7, "Advice")); + Categories.Add(new HighFiveCategory(8, "A Video")); + Categories.Add(new HighFiveCategory(9, "A PR")); + } //this will be for authorized members only [HttpPost] - public void SubmitHighFive(int fromUserId, int toUserId, int action, String url) + public void SubmitHighFive(int toUserId, int action, String url) { + var memberService = ApplicationContext.Current.Services.MemberService; - var member = memberService.GetById(fromUserId); - var dbContext = ApplicationContext.Current.DatabaseContext; - var highFive = new OurUmbraco.HighFiveFeed.Models.HighFiveFeed(); - highFive.FromMemberId = fromUserId; - highFive.ToMemberId = toUserId; - highFive.ActionId = action; - highFive.Link = url; - highFive.CreatedDate = DateTime.Now; - - dbContext.Database.Insert(highFive); + var currentMember = Members.GetCurrentMember(); + if (currentMember != null && currentMember.Id != 0) + { + var fromUserId = currentMember.Id; + + var dbContext = ApplicationContext.Current.DatabaseContext; + var highFive = new OurUmbraco.HighFiveFeed.Models.HighFiveFeed(); + highFive.FromMemberId = fromUserId; + highFive.ToMemberId = toUserId; + highFive.ActionId = action; + highFive.Link = url; + highFive.CreatedDate = DateTime.Now; + + dbContext.Database.Insert(highFive); + } } [HttpGet] public string GetHighFiveFeed() @@ -53,10 +72,11 @@ public string GetHighFiveFeed() var fromMember = Members.GetById(dbEntry.FromMemberId); var toAvatar = avatarService.GetMemberAvatar(toMember); var fromAvatar = avatarService.GetMemberAvatar(toMember); + var type = GetActionType(dbEntry.ActionId); var highFive = new HighFiveResponse() { Url = dbEntry.Link, - Type = dbEntry.ActionId.ToString(), + Type = type, From = fromMember.Name, FromAvatarUrl = fromAvatar, To = toMember.Name, @@ -75,25 +95,16 @@ public string GetHighFiveFeed() } + private string GetActionType(int actionId) + { + return ""; + } public string GetCategories() { - var categories = new List(); - categories.Add(new HighFiveCategory(1, "A Package")); - categories.Add(new HighFiveCategory(2, "A Talk")); - categories.Add(new HighFiveCategory(3, "A Blog Post")); - categories.Add(new HighFiveCategory(4, "A Meetup")); - categories.Add(new HighFiveCategory(5, "A Skrift Article")); - categories.Add(new HighFiveCategory(6, "A Tutorial")); - categories.Add(new HighFiveCategory(7, "Advice")); - categories.Add(new HighFiveCategory(8, "A Video")); - categories.Add(new HighFiveCategory(9, "A PR")); - var rawJson = JsonConvert.SerializeObject(categories, Formatting.Indented); - - + + var rawJson = JsonConvert.SerializeObject(Categories, Formatting.Indented); return rawJson; - - } public List GetUmbracians(string name) From c4a67c7078c3891f5b91fc8e09e73a4aab3d11c5 Mon Sep 17 00:00:00 2001 From: Mike Masey Date: Mon, 21 May 2018 15:51:42 +0100 Subject: [PATCH 35/60] Fixed to highfives.js --- OurUmbraco.Site/Assets/js/components/highfives.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/OurUmbraco.Site/Assets/js/components/highfives.js b/OurUmbraco.Site/Assets/js/components/highfives.js index aa698b372e..f5f2fb93a3 100644 --- a/OurUmbraco.Site/Assets/js/components/highfives.js +++ b/OurUmbraco.Site/Assets/js/components/highfives.js @@ -16,9 +16,12 @@ HighFives.bindOnSubmitForm(); HighFives.getRandomUmbracians(function(people) { HighFives.printPhrases(HighFives.shuffle(_.map(people, 'Username')), $('#high-five-mention')); - HighFives.getCategories(function(categories) { + HighFives.getCategories(function(response) { + var categories = JSON.parse(response); + HighFives.buildCategoryDropdown(categories); - HighFives.getRecentHighFiveActivity(0, function(activity) { + HighFives.getRecentHighFiveActivity(0, function(response) { + var activity = JSON.parse(response); HighFives.list = activity.highFives; HighFives.buildActivityList(HighFives.list); HighFives.checkForNewHighFivesPeriodically(30); @@ -142,7 +145,7 @@ if (useMockApi) { onSuccess(ApiMock.getCategories()); } else { - jQuery.get('/umbraco/api/HighFiveFeedAPI/GetCategories', onSuccess); + jQuery.getJSON('/umbraco/api/HighFiveFeedAPI/GetCategories', onSuccess); } }, @@ -152,7 +155,7 @@ HighFives.suggestions = ApiMock.getUmbracians(); HighFives.buildSuggestionsList(); } else { - jquery.get('/Umbraco/Api/highFiveFeedApi/GetUmbracians?name=' + member, function (umbracians) { + jQuery.get('/Umbraco/Api/highFiveFeedApi/GetUmbracians?name=' + member, function (umbracians) { HighFives.suggestions = umbracians; HighFives.buildSuggestionsList(); }); @@ -257,7 +260,7 @@ if (useMockApi) { onSuccess(ApiMock.submitHighFive()); } else { - jQuery.get('/umbraco/api/HighFiveFeedAPI/SubmitHighFive?toUserId=' + to + '&action=' + action + '&url=' + url, onSuccess); + jQuery.post('/umbraco/api/HighFiveFeedAPI/SubmitHighFive?toUserId=' + to + '&action=' + action + '&url=' + url, onSuccess); } }, From 1be9ea9fb0164b110d0554a0b80b14b29a872441 Mon Sep 17 00:00:00 2001 From: Kyle Weems Date: Mon, 21 May 2018 17:05:00 +0200 Subject: [PATCH 36/60] Polyfill for unionBy functionality due to version of lodash being too low. --- .../Assets/js/components/highfives.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/OurUmbraco.Site/Assets/js/components/highfives.js b/OurUmbraco.Site/Assets/js/components/highfives.js index f5f2fb93a3..86486d5976 100644 --- a/OurUmbraco.Site/Assets/js/components/highfives.js +++ b/OurUmbraco.Site/Assets/js/components/highfives.js @@ -120,7 +120,7 @@ checkForNewHighFivesPeriodically: function (seconds) { window.setTimeout(function() { HighFives.getRecentHighFiveActivity(0, function(response) { - HighFives.list = _.unionBy(HighFives.list, response.highFives, 'id').slice(0, 10); + HighFives.list = HighFives.unionBy(HighFives.list, response.highFives).slice(0, 10); HighFives.buildActivityList(HighFives.list); HighFives.checkForNewHighFivesPeriodically(30); }); @@ -281,6 +281,23 @@ } return array; + }, + + unionBy: function(oldArray, newArray) { + for (var n = 0; n < newArray.length; n++) { + var itemToAdd = newArray[n]; + var isUnique = true; + for (var o = 0; o < oldArray.length; o++) { + var oldItem = oldArray[o]; + if (oldItem.id === itemToAdd.id) { + isUnique = false; + } + } + if (isUnique) { + oldArray.unshift(itemToAdd); + } + } + return oldArray; } }; From cbd737a9b85f2f6c71cbc14a042668eff8ffd2ec Mon Sep 17 00:00:00 2001 From: Mike Masey Date: Mon, 21 May 2018 16:14:13 +0100 Subject: [PATCH 37/60] Fix hight five feed bugs. --- OurUmbraco.Site/Assets/js/components/highfives.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/OurUmbraco.Site/Assets/js/components/highfives.js b/OurUmbraco.Site/Assets/js/components/highfives.js index 86486d5976..3e829c2160 100644 --- a/OurUmbraco.Site/Assets/js/components/highfives.js +++ b/OurUmbraco.Site/Assets/js/components/highfives.js @@ -22,7 +22,7 @@ HighFives.buildCategoryDropdown(categories); HighFives.getRecentHighFiveActivity(0, function(response) { var activity = JSON.parse(response); - HighFives.list = activity.highFives; + HighFives.list = activity.HighFives; HighFives.buildActivityList(HighFives.list); HighFives.checkForNewHighFivesPeriodically(30); }); @@ -79,12 +79,12 @@ for (var i = 0; i < highFives.length; i++) { var highFive = highFives[i]; list.innerHTML += '
          • ' + - '
             + highFive.to +
            ' + + '
             + highFive.To +
            ' + '
            ' + - '

            Lovely ' + highFive.to + '

            ' + - '

            ' + highFive.from + ' High Fived you for ' + highFive.type + '' + /*, 2 minutes ago*/ '

            ' + + '

            Lovely ' + highFive.To + '

            ' + + '

            ' + highFive.From + ' High Fived you for ' + highFive.Type + '' + /*, 2 minutes ago*/ '

            ' + '
          • '; } } @@ -120,7 +120,8 @@ checkForNewHighFivesPeriodically: function (seconds) { window.setTimeout(function() { HighFives.getRecentHighFiveActivity(0, function(response) { - HighFives.list = HighFives.unionBy(HighFives.list, response.highFives).slice(0, 10); + var feed = JSON.parse(response); + HighFives.list = HighFives.unionBy(HighFives.list, feed.HighFives).slice(0, 10); HighFives.buildActivityList(HighFives.list); HighFives.checkForNewHighFivesPeriodically(30); }); From ef72dbbd9ff4ff9c5a449dc1ae530a8108d1f7f5 Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Mon, 21 May 2018 16:23:50 +0100 Subject: [PATCH 38/60] fixing categories --- OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index d9f1b0490d..a75426ac78 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -97,7 +97,7 @@ public string GetHighFiveFeed() private string GetActionType(int actionId) { - return ""; + return Categories.Where(x => x.Id == actionId).FirstOrDefault().CategoryText; } public string GetCategories() From 75e11429afd72b21707c7c12e7fabb143958cbe0 Mon Sep 17 00:00:00 2001 From: Kyle Weems Date: Mon, 21 May 2018 17:42:44 +0200 Subject: [PATCH 39/60] Randomized compliments and re-load high fives after submission. --- .../Assets/js/components/highfives.js | 64 ++++++++++++++----- 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/OurUmbraco.Site/Assets/js/components/highfives.js b/OurUmbraco.Site/Assets/js/components/highfives.js index 3e829c2160..f59bf742da 100644 --- a/OurUmbraco.Site/Assets/js/components/highfives.js +++ b/OurUmbraco.Site/Assets/js/components/highfives.js @@ -17,12 +17,12 @@ HighFives.getRandomUmbracians(function(people) { HighFives.printPhrases(HighFives.shuffle(_.map(people, 'Username')), $('#high-five-mention')); HighFives.getCategories(function(response) { - var categories = JSON.parse(response); + var categories = typeof response == 'string' ? JSON.parse(response) : response; HighFives.buildCategoryDropdown(categories); HighFives.getRecentHighFiveActivity(0, function(response) { - var activity = JSON.parse(response); - HighFives.list = activity.HighFives; + var activity = typeof response == 'string' ? JSON.parse(response): response; + HighFives.list = HighFives.addComplimentsToList(activity.HighFives); HighFives.buildActivityList(HighFives.list); HighFives.checkForNewHighFivesPeriodically(30); }); @@ -32,6 +32,13 @@ }); }, + addComplimentsToList: function (list) { + for (var i = 0; i < list.length; i++) { + list[i].To = HighFives.getRandomCompliment() + ' ' + list[i].To; + } + return list; + }, + addToPlaceholder: function (toAdd, el) { el.attr('placeholder', el.attr('placeholder') + toAdd); // Delay between symbols "typing" @@ -65,6 +72,11 @@ if (HighFives.isFormValid()) { HighFives.submitHighFive(HighFives.selectedMember.id, jQuery('#high-five-task').val(), jQuery('#high-five-url').val(), function() { HighFives.resetForm(); + HighFives.getRecentHighFiveActivity(0, function(response) { + var activity = typeof response == 'string' ? JSON.parse(response): response; + HighFives.list = HighFives.unionBy(HighFives.list, HighFives.addComplimentsToList(activity.HighFives)).slice(0, 10); + HighFives.buildActivityList(HighFives.list); + }); }); } }); @@ -83,7 +95,7 @@ 'srcset="' + highFive.ToAvatarUrl + '?v=test&width=200&height=200&mode=crop&upscale=true 2x, ' + highFive.ToAvatarUrl + '?v=test&width=300&height=300&mode=crop&upscale=true 3x" alt=' + highFive.To + '">
            ' + '
            ' + - '

            Lovely ' + highFive.To + '

            ' + + '

            ' + highFive.To + '

            ' + '

            ' + highFive.From + ' High Fived you for ' + highFive.Type + '' + /*, 2 minutes ago*/ '

            ' + '
            '; } @@ -120,8 +132,8 @@ checkForNewHighFivesPeriodically: function (seconds) { window.setTimeout(function() { HighFives.getRecentHighFiveActivity(0, function(response) { - var feed = JSON.parse(response); - HighFives.list = HighFives.unionBy(HighFives.list, feed.HighFives).slice(0, 10); + var feed = typeof response == 'string' ? JSON.parse(response) : response; + HighFives.list = HighFives.unionBy(HighFives.list, HighFives.addComplimentsToList(feed.HighFives)).slice(0, 10); HighFives.buildActivityList(HighFives.list); HighFives.checkForNewHighFivesPeriodically(30); }); @@ -164,6 +176,24 @@ } }, + getRandomCompliment: function() { + var compliments = [ + 'Lovely', + 'Woohoo!', + '#h5yr!', + 'Go', + 'Awesome!', + 'Rockstar', + 'Yass!', + 'Most excellent', + 'Excellent!', + 'Supertak!', + 'Cheers!' + ]; + var rnd = Math.floor(Math.random() * compliments.length); + return compliments[rnd]; + }, + // getRandomUmbracians - Get a random list of Umbracians to use for placeholder. getRandomUmbracians: function(onSuccess) { if (useMockApi) { @@ -320,18 +350,18 @@ }, getHighFiveFeed: function() { return { - count: 100, - pageCount: 10, - currentPage: 0, - highFives: [ + Count: 100, + PageCount: 10, + CurrentPage: 0, + HighFives: [ { - id: '123', - from: 'Name of High Fiver', - to: 'Name of High Fivee', - fromAvatarUrl: '/avatar_of_high_fiver.jpg', - toAvatarUrl: '/avatar_of_high_fivee.jpg', - type: 'Blog post', - url: 'http://optional.url.for.high.five.com' + Id: '123', + From: 'Name of High Fiver', + To: 'Name of High Fivee', + FromAvatarUrl: '/avatar_of_high_fiver.jpg', + ToAvatarUrl: '/avatar_of_high_fivee.jpg', + Type: 'Blog post', + Url: 'http://optional.url.for.high.five.com' } ] }; From 04247c3cfbc6b061132b93f74716fd6d1e2f8da2 Mon Sep 17 00:00:00 2001 From: Mike Masey Date: Mon, 21 May 2018 17:00:49 +0100 Subject: [PATCH 40/60] Remove logged in user from results. --- OurUmbraco/Community/People/PeopleService.cs | 2 -- .../API/HighFiveFeedAPIController.cs | 18 +++++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/OurUmbraco/Community/People/PeopleService.cs b/OurUmbraco/Community/People/PeopleService.cs index 514af357b9..f68220a3d2 100644 --- a/OurUmbraco/Community/People/PeopleService.cs +++ b/OurUmbraco/Community/People/PeopleService.cs @@ -250,7 +250,6 @@ public List GetPeopleByName(string name) examineQuery.And().GroupedAnd(searchTerms, term.MultipleCharacterWildcard()); } - examineQuery.And().OrderByDescending(MemberNameField); var results = memberSearcher.Search(examineQuery.Compile()); @@ -280,7 +279,6 @@ public List GetRandomPeople() var memberSearcher = ExamineManager.Instance.SearchProviderCollection["InternalMemberSearcher"]; var criteria = memberSearcher.CreateSearchCriteria(IndexTypes.Member); - var examineQuery = criteria.Field("blocked", 0.ToString()); criteria.Range("updateDate", DateTime.MinValue, DateTime.MaxValue); diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index a75426ac78..d87a1c36c1 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -111,8 +111,14 @@ public List GetUmbracians(string name) { var peopleService = new PeopleService(); - var people = peopleService.GetPeopleByName(name); - + var people = peopleService.GetPeopleByName(name); + + var currentMember = Members.GetCurrentMember(); + if (currentMember != null && currentMember.Id != 0) + { + return people.Where(p => p.MemberId != currentMember.Id).ToList(); + } + return people; } @@ -120,7 +126,13 @@ public List GetRandomUmbracians() { var peopleService = new PeopleService(); - var people = peopleService.GetRandomPeople(); + var people = peopleService.GetRandomPeople(); + + var currentMember = Members.GetCurrentMember(); + if (currentMember != null && currentMember.Id != 0) + { + return people.Where(p => p.MemberId != currentMember.Id).ToList(); + } return people; } From e82a3cdd3cdf632aa6b5ec453113aa4dab2645cb Mon Sep 17 00:00:00 2001 From: Kyle Weems Date: Mon, 21 May 2018 18:06:51 +0200 Subject: [PATCH 41/60] Added more compliments. --- .../Assets/js/components/highfives.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/OurUmbraco.Site/Assets/js/components/highfives.js b/OurUmbraco.Site/Assets/js/components/highfives.js index f59bf742da..15a2845f17 100644 --- a/OurUmbraco.Site/Assets/js/components/highfives.js +++ b/OurUmbraco.Site/Assets/js/components/highfives.js @@ -188,7 +188,22 @@ 'Most excellent', 'Excellent!', 'Supertak!', - 'Cheers!' + 'Cheers!', + 'Wow!', + 'Yahoo!', + 'Yee haw!', + 'Boo ya!', + 'Hoorah!', + 'Huzzah!', + 'Tada!', + 'Yippee!', + 'Squeee!', + 'Yowza!', + 'Damn Skippy!', + 'Hells yeah!', + 'Bingo!', + 'KAPOW!', + 'Bravo!' ]; var rnd = Math.floor(Math.random() * compliments.length); return compliments[rnd]; From 70cb32aa4eea9519464347dac78710442f7357ae Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Mon, 21 May 2018 23:15:02 +0100 Subject: [PATCH 42/60] DB Id migration update --- OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs | 1 - OurUmbraco/HighFiveFeed/Models/HighFiveFeed.cs | 2 +- OurUmbraco/Our/MigrationsHandler.cs | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index a75426ac78..40c7aa68d4 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -46,7 +46,6 @@ public void SubmitHighFive(int toUserId, int action, String url) if (currentMember != null && currentMember.Id != 0) { var fromUserId = currentMember.Id; - var dbContext = ApplicationContext.Current.DatabaseContext; var highFive = new OurUmbraco.HighFiveFeed.Models.HighFiveFeed(); highFive.FromMemberId = fromUserId; diff --git a/OurUmbraco/HighFiveFeed/Models/HighFiveFeed.cs b/OurUmbraco/HighFiveFeed/Models/HighFiveFeed.cs index 27641cda4c..79591756e8 100644 --- a/OurUmbraco/HighFiveFeed/Models/HighFiveFeed.cs +++ b/OurUmbraco/HighFiveFeed/Models/HighFiveFeed.cs @@ -4,7 +4,7 @@ namespace OurUmbraco.HighFiveFeed.Models { [TableName("highFivePosts")] - [PrimaryKey("id", autoIncrement = false)] + [PrimaryKey("id")] [ExplicitColumns] public class HighFiveFeed { diff --git a/OurUmbraco/Our/MigrationsHandler.cs b/OurUmbraco/Our/MigrationsHandler.cs index ce9e9a397e..8941cc86ec 100644 --- a/OurUmbraco/Our/MigrationsHandler.cs +++ b/OurUmbraco/Our/MigrationsHandler.cs @@ -1474,7 +1474,7 @@ private void AddHighFiveTable() } //locic var db = ApplicationContext.Current.DatabaseContext.Database; - db.Execute("CREATE TABLE [dbo].[highFivePosts]([Id][int] NULL,[FromMemberId] [int] NULL,[ToMemberId] [int] NULL,[ActionId] [varchar] (50) NULL,[Link][nvarchar](max) NULL,[Count] [int] NULL, [CreatedDate] [datetime] NULL) ON[PRIMARY] TEXTIMAGE_ON[PRIMARY]"); + db.Execute("CREATE TABLE [dbo].[highFivePosts]([id] [int] IDENTITY(1,1) NOT NULL,[FromMemberId] [int] NULL,[ToMemberId] [int] NULL,[ActionId] [varchar] (50) NULL,[Link][nvarchar](max) NULL,[Count] [int] NULL, [CreatedDate] [datetime] NULL) ON[PRIMARY] TEXTIMAGE_ON[PRIMARY]"); string[] lines = { "" }; File.WriteAllLines(path, lines); From 848276972e8ab1d86d1495bfa7c67160758b5b3a Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Tue, 22 May 2018 11:54:22 +0100 Subject: [PATCH 43/60] avatar checks --- .../API/HighFiveFeedAPIController.cs | 264 +++++++++--------- 1 file changed, 136 insertions(+), 128 deletions(-) diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index 72c469ff37..6727ea030c 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -1,139 +1,147 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Umbraco.Web.WebApi; -using Umbraco.Core; -using OurUmbraco.HighFiveFeed.Models; -using System.Web.Mvc; -using Newtonsoft.Json; -using System.Net.Http; -using Newtonsoft.Json.Serialization; -using Umbraco.Core.Persistence; -using OurUmbraco.Community.People.Models; -using OurUmbraco.Community.People; -using OurUmbraco.Forum.Services; -using Umbraco.Web.Mvc; - -namespace OurUmbraco.HighFiveFeed.API -{ - public class HighFiveFeedAPIController : UmbracoApiController - { - public List Categories; - public HighFiveFeedAPIController() - { - Categories = new List(); - Categories.Add(new HighFiveCategory(1, "A Package")); - Categories.Add(new HighFiveCategory(2, "A Talk")); - Categories.Add(new HighFiveCategory(3, "A Blog Post")); - Categories.Add(new HighFiveCategory(4, "A Meetup")); - Categories.Add(new HighFiveCategory(5, "A Skrift Article")); - Categories.Add(new HighFiveCategory(6, "A Tutorial")); - Categories.Add(new HighFiveCategory(7, "Advice")); - Categories.Add(new HighFiveCategory(8, "A Video")); - Categories.Add(new HighFiveCategory(9, "A PR")); - } - - //this will be for authorized members only - [HttpPost] - public void SubmitHighFive(int toUserId, int action, String url) - { - - var memberService = ApplicationContext.Current.Services.MemberService; - - var currentMember = Members.GetCurrentMember(); - if (currentMember != null && currentMember.Id != 0) - { - var fromUserId = currentMember.Id; - var dbContext = ApplicationContext.Current.DatabaseContext; - var highFive = new OurUmbraco.HighFiveFeed.Models.HighFiveFeed(); - highFive.FromMemberId = fromUserId; - highFive.ToMemberId = toUserId; - highFive.ActionId = action; - highFive.Link = url; - highFive.CreatedDate = DateTime.Now; - - dbContext.Database.Insert(highFive); - } - } - [HttpGet] - public string GetHighFiveFeed() - { - var dbContext = ApplicationContext.Current.DatabaseContext; - var sql = new Sql().Select("*").From("highFivePosts"); - var result = dbContext.Database.Fetch(sql).OrderByDescending(x=>x.CreatedDate); - var avatarService = new AvatarService(); - var response = new HighFiveFeedResponse(); - foreach (var dbEntry in result.Take(10)) - { - var toMember = Members.GetById(dbEntry.ToMemberId); - var fromMember = Members.GetById(dbEntry.FromMemberId); - var toAvatar = avatarService.GetMemberAvatar(toMember); - var fromAvatar = avatarService.GetMemberAvatar(toMember); - var type = GetActionType(dbEntry.ActionId); - var highFive = new HighFiveResponse() - { - Url = dbEntry.Link, - Type = type, - From = fromMember.Name, - FromAvatarUrl = fromAvatar, - To = toMember.Name, - ToAvatarUrl = toAvatar, - Id = dbEntry.Id, - CreatedDate = dbEntry.CreatedDate - - - }; - response.HighFives.Add(highFive); - } - var rawJson = JsonConvert.SerializeObject(response, Formatting.Indented); - - - return rawJson; - - } - - private string GetActionType(int actionId) - { - return Categories.Where(x => x.Id == actionId).FirstOrDefault().CategoryText; - } - - public string GetCategories() - { - - var rawJson = JsonConvert.SerializeObject(Categories, Formatting.Indented); - return rawJson; - } - - public List GetUmbracians(string name) - { - var peopleService = new PeopleService(); - +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Umbraco.Web.WebApi; +using Umbraco.Core; +using OurUmbraco.HighFiveFeed.Models; +using System.Web.Mvc; +using Newtonsoft.Json; +using System.Net.Http; +using Newtonsoft.Json.Serialization; +using Umbraco.Core.Persistence; +using OurUmbraco.Community.People.Models; +using OurUmbraco.Community.People; +using OurUmbraco.Forum.Services; +using Umbraco.Web.Mvc; + +namespace OurUmbraco.HighFiveFeed.API +{ + public class HighFiveFeedAPIController : UmbracoApiController + { + public List Categories; + public HighFiveFeedAPIController() + { + Categories = new List(); + Categories.Add(new HighFiveCategory(1, "A Package")); + Categories.Add(new HighFiveCategory(2, "A Talk")); + Categories.Add(new HighFiveCategory(3, "A Blog Post")); + Categories.Add(new HighFiveCategory(4, "A Meetup")); + Categories.Add(new HighFiveCategory(5, "A Skrift Article")); + Categories.Add(new HighFiveCategory(6, "A Tutorial")); + Categories.Add(new HighFiveCategory(7, "Advice")); + Categories.Add(new HighFiveCategory(8, "A Video")); + Categories.Add(new HighFiveCategory(9, "A PR")); + } + + //this will be for authorized members only + [HttpPost] + public void SubmitHighFive(int toUserId, int action, String url) + { + + var memberService = ApplicationContext.Current.Services.MemberService; + + var currentMember = Members.GetCurrentMember(); + if (currentMember != null && currentMember.Id != 0) + { + var fromUserId = currentMember.Id; + var dbContext = ApplicationContext.Current.DatabaseContext; + var highFive = new OurUmbraco.HighFiveFeed.Models.HighFiveFeed(); + highFive.FromMemberId = fromUserId; + highFive.ToMemberId = toUserId; + highFive.ActionId = action; + highFive.Link = url; + highFive.CreatedDate = DateTime.Now; + + dbContext.Database.Insert(highFive); + } + } + [HttpGet] + public string GetHighFiveFeed() + { + var dbContext = ApplicationContext.Current.DatabaseContext; + var sql = new Sql().Select("*").From("highFivePosts"); + var result = dbContext.Database.Fetch(sql).OrderByDescending(x=>x.CreatedDate); + var avatarService = new AvatarService(); + var response = new HighFiveFeedResponse(); + foreach (var dbEntry in result.Take(10)) + { + var toAvatar = ""; + var fromAvatar = ""; + var toMember = Members.GetById(dbEntry.ToMemberId); + var fromMember = Members.GetById(dbEntry.FromMemberId); + if (!String.IsNullOrEmpty(toAvatar)) + { + toAvatar = avatarService.GetMemberAvatar(toMember); + } + if (!String.IsNullOrEmpty(fromAvatar)) + { + fromAvatar = avatarService.GetMemberAvatar(toMember); + } + var type = GetActionType(dbEntry.ActionId); + var highFive = new HighFiveResponse() + { + Url = dbEntry.Link, + Type = type, + From = fromMember.Name, + FromAvatarUrl = fromAvatar, + To = toMember.Name, + ToAvatarUrl = toAvatar, + Id = dbEntry.Id, + CreatedDate = dbEntry.CreatedDate + + + }; + response.HighFives.Add(highFive); + } + var rawJson = JsonConvert.SerializeObject(response, Formatting.Indented); + + + return rawJson; + + } + + private string GetActionType(int actionId) + { + return Categories.Where(x => x.Id == actionId).FirstOrDefault().CategoryText; + } + + public string GetCategories() + { + + var rawJson = JsonConvert.SerializeObject(Categories, Formatting.Indented); + return rawJson; + } + + public List GetUmbracians(string name) + { + var peopleService = new PeopleService(); + var people = peopleService.GetPeopleByName(name); - var currentMember = Members.GetCurrentMember(); - if (currentMember != null && currentMember.Id != 0) + var currentMember = Members.GetCurrentMember(); + if (currentMember != null && currentMember.Id != 0) { return people.Where(p => p.MemberId != currentMember.Id).ToList(); } - return people; - } - - public List GetRandomUmbracians() - { - var peopleService = new PeopleService(); - + return people; + } + + public List GetRandomUmbracians() + { + var peopleService = new PeopleService(); + var people = peopleService.GetRandomPeople(); - var currentMember = Members.GetCurrentMember(); - if (currentMember != null && currentMember.Id != 0) + var currentMember = Members.GetCurrentMember(); + if (currentMember != null && currentMember.Id != 0) { return people.Where(p => p.MemberId != currentMember.Id).ToList(); - } - - return people; - } - } + } + + return people; + } + } } \ No newline at end of file From 8729eb40abc98738944c91bbde49550d0c1c21a8 Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Tue, 22 May 2018 16:42:30 +0100 Subject: [PATCH 44/60] fixing null check --- OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index 6727ea030c..82d8dc68b2 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -71,11 +71,11 @@ public string GetHighFiveFeed() var fromAvatar = ""; var toMember = Members.GetById(dbEntry.ToMemberId); var fromMember = Members.GetById(dbEntry.FromMemberId); - if (!String.IsNullOrEmpty(toAvatar)) + if (toMember != null) { toAvatar = avatarService.GetMemberAvatar(toMember); } - if (!String.IsNullOrEmpty(fromAvatar)) + if (fromMember !=null) { fromAvatar = avatarService.GetMemberAvatar(toMember); } From 351347d7dcf035fc56360cd3e2bd62ec42b37054 Mon Sep 17 00:00:00 2001 From: Mike Masey Date: Wed, 23 May 2018 07:01:29 +0100 Subject: [PATCH 45/60] Add a little FE love. --- .../src/scss/sections/_highFive.scss | 48 +- .../Assets/js/components/highfives.js | 871 +++++++++--------- .../API/HighFiveFeedAPIController.cs | 8 +- 3 files changed, 481 insertions(+), 446 deletions(-) diff --git a/OurUmbraco.Client/src/scss/sections/_highFive.scss b/OurUmbraco.Client/src/scss/sections/_highFive.scss index fd78a27d21..053973bf65 100644 --- a/OurUmbraco.Client/src/scss/sections/_highFive.scss +++ b/OurUmbraco.Client/src/scss/sections/_highFive.scss @@ -70,20 +70,23 @@ justify-content: space-between; } + .high-five-activity-list { + display: grid; + grid-template-columns: 1fr 1fr; + grid-column-gap: 20px; + + @media (min-width: $md) { + grid-template-columns: 1fr 1fr 1fr; + } + } + + .high-five-item { - flex: 0 0 100%; + // flex: 0 0 100%; display: flex; overflow: hidden; - @media (min-width: $md) { - flex: 1 0 49%; - - &:nth-child(odd) { - margin-right: 2%; - } - } - .avatar { flex: 0 0 23%; margin-right: 20px; @@ -127,11 +130,36 @@ } } +#high-five-form { + position: relative; +} + +.suggestions-list { + position: absolute; + top: 100%; + left: 21.7%; + list-style: none; + z-index: 10; + + button { + background: #a3db78; + border: 0; + min-width: 200px; + text-align: left; + + transition: .2s ease-in-out; + + &:hover { + background-color: #2EB369; + color: #FFFFFF; + } + } +} .high-five-item { background: #fff; padding: 25px; - margin-bottom: 30px; + margin-bottom: 20px; border: 1px solid darken(#f6f6f6, 5%); transition: box-shadow .2s ease, border-color .2s ease; text-decoration: none; diff --git a/OurUmbraco.Site/Assets/js/components/highfives.js b/OurUmbraco.Site/Assets/js/components/highfives.js index 15a2845f17..4567f6dbfd 100644 --- a/OurUmbraco.Site/Assets/js/components/highfives.js +++ b/OurUmbraco.Site/Assets/js/components/highfives.js @@ -1,435 +1,438 @@ -(function() { - - var useMockApi = false; - - // HighFives - JS functionality for the high fives module. - var HighFives = { - list: [], - selectedMember: false, - suggestions: [], - // init - Starts the high fives app functionality. - init: function() { - $(document).ready(function () { - if (HighFives.doesHaveHighFive()) { - HighFives.bindOnMentionChange(); - HighFives.bindOnMemberSelect(); - HighFives.bindOnSubmitForm(); - HighFives.getRandomUmbracians(function(people) { - HighFives.printPhrases(HighFives.shuffle(_.map(people, 'Username')), $('#high-five-mention')); - HighFives.getCategories(function(response) { - var categories = typeof response == 'string' ? JSON.parse(response) : response; - - HighFives.buildCategoryDropdown(categories); - HighFives.getRecentHighFiveActivity(0, function(response) { - var activity = typeof response == 'string' ? JSON.parse(response): response; - HighFives.list = HighFives.addComplimentsToList(activity.HighFives); - HighFives.buildActivityList(HighFives.list); - HighFives.checkForNewHighFivesPeriodically(30); - }); - }); - }); - } - }); - }, - - addComplimentsToList: function (list) { - for (var i = 0; i < list.length; i++) { - list[i].To = HighFives.getRandomCompliment() + ' ' + list[i].To; - } - return list; - }, - - addToPlaceholder: function (toAdd, el) { - el.attr('placeholder', el.attr('placeholder') + toAdd); - // Delay between symbols "typing" - return new Promise(resolve => setTimeout(resolve, 100)); - }, - - bindOnMentionChange: function () { - jQuery('#high-five-mention').keyup(function(e) { - HighFives.selectedMember = false; - HighFives.getMember(e.target.value); - HighFives.selectMemberIfMatches(e.target.value); - }); - }, - - bindOnMemberSelect: function() { - jQuery('#high-five-form .suggestions-list button').unbind('click'); - jQuery('#high-five-form .suggestions-list button').click(function(e) { - var id = e.target.getAttribute('data-id'); - HighFives.selectedMember = { - id: e.target.getAttribute('data-id'), - name: e.target.innerHTML - }; - HighFives.selectMember(HighFives.selectedMember); - }); - // unbind from previous versions just in case - }, - - bindOnSubmitForm: function() { - jQuery('#high-five-form').submit(function(e) { - e.preventDefault(); - if (HighFives.isFormValid()) { - HighFives.submitHighFive(HighFives.selectedMember.id, jQuery('#high-five-task').val(), jQuery('#high-five-url').val(), function() { - HighFives.resetForm(); - HighFives.getRecentHighFiveActivity(0, function(response) { - var activity = typeof response == 'string' ? JSON.parse(response): response; - HighFives.list = HighFives.unionBy(HighFives.list, HighFives.addComplimentsToList(activity.HighFives)).slice(0, 10); - HighFives.buildActivityList(HighFives.list); - }); - }); - } - }); - }, - - // buildActivityList - Builds a list of list items that represent the activity list and adds them to an activity list for users to view. - buildActivityList: function () { - var highFives = HighFives.list; - if (highFives && highFives.length > 0) { - var list = document.querySelector("#high-five-activity .high-five-activity-list"); - list.innerHTML = ''; - for (var i = 0; i < highFives.length; i++) { - var highFive = highFives[i]; - list.innerHTML += '
          • ' + - '
             + highFive.To +
            ' + - '
            ' + - '

            ' + highFive.To + '

            ' + - '

            ' + highFive.From + ' High Fived you for ' + highFive.Type + '' + /*, 2 minutes ago*/ '

            ' + - '
          • '; - } - } - }, - - buildSuggestionsList: function () { - var suggestions = HighFives.suggestions; - var list = document.querySelector("#high-five-form .suggestions-list"); - list.innerHTML = ''; - for (var i = 0; i < suggestions.length; i++) { - var suggestion = suggestions[i]; - list.innerHTML += '
          • ' + - '
          • '; - } - HighFives.bindOnMemberSelect(); - }, - - // buildCategoryDropdown - Builds a list of options for the category dropdown. - buildCategoryDropdown: function(categories) { - if (categories && categories.length > 0) { - var dropdown = jQuery('#high-five-task'); - var options = ''; - for (var i = 0; i < categories.length; i++) { - var category = categories[i]; - options += ''; - } - dropdown.html(options); - } - }, - - // checkForNewHighFivesPeriodically - Polls the API endpoint for new high fives periodically - checkForNewHighFivesPeriodically: function (seconds) { - window.setTimeout(function() { - HighFives.getRecentHighFiveActivity(0, function(response) { - var feed = typeof response == 'string' ? JSON.parse(response) : response; - HighFives.list = HighFives.unionBy(HighFives.list, HighFives.addComplimentsToList(feed.HighFives)).slice(0, 10); - HighFives.buildActivityList(HighFives.list); - HighFives.checkForNewHighFivesPeriodically(30); - }); - }, (seconds * 1000)); - }, - - clearPlaceholder: function (el) { - el.attr("placeholder", ""); - }, - - // doesHaveHighFive - returns true if highFive element exists - doesHaveHighFive: function() { - var highFive = document.querySelector('section[data-high-five]'); - if (highFive && typeof highFive !== 'null' && typeof highFive !== 'undefined') { - return true; - } - return false; - }, - - // getCategories - Get the categories for the high fives. - getCategories: function(onSuccess) { - if (useMockApi) { - onSuccess(ApiMock.getCategories()); - } else { - jQuery.getJSON('/umbraco/api/HighFiveFeedAPI/GetCategories', onSuccess); - } - }, - - getMember: function(member) { - if (member.length > 2) { - if (useMockApi) { - HighFives.suggestions = ApiMock.getUmbracians(); - HighFives.buildSuggestionsList(); - } else { - jQuery.get('/Umbraco/Api/highFiveFeedApi/GetUmbracians?name=' + member, function (umbracians) { - HighFives.suggestions = umbracians; - HighFives.buildSuggestionsList(); - }); - } - } - }, - - getRandomCompliment: function() { - var compliments = [ - 'Lovely', - 'Woohoo!', - '#h5yr!', - 'Go', - 'Awesome!', - 'Rockstar', - 'Yass!', - 'Most excellent', - 'Excellent!', - 'Supertak!', - 'Cheers!', - 'Wow!', - 'Yahoo!', - 'Yee haw!', - 'Boo ya!', - 'Hoorah!', - 'Huzzah!', - 'Tada!', - 'Yippee!', - 'Squeee!', - 'Yowza!', - 'Damn Skippy!', - 'Hells yeah!', - 'Bingo!', - 'KAPOW!', - 'Bravo!' - ]; - var rnd = Math.floor(Math.random() * compliments.length); - return compliments[rnd]; - }, - - // getRandomUmbracians - Get a random list of Umbracians to use for placeholder. - getRandomUmbracians: function(onSuccess) { - if (useMockApi) { - onSuccess(ApiMock.getRandomUmbracians()); - } else { - jQuery.get('/umbraco/api/HighFiveFeedAPI/getRandomUmbracians', onSuccess); - } - }, - - // getRecentHighFiveActivity - Gets the most recent high fives via API. - getRecentHighFiveActivity: function(page, onSuccess) { - page = typeof page === 'undefined' ? 0 : page; - if (useMockApi) { - onSuccess(ApiMock.getHighFiveFeed()); - } else { - jQuery.get('/umbraco/api/HighFiveFeedAPI/GetHighFiveFeed?page=' + page, onSuccess); - } - }, - - isFormValid: function() { - if (HighFives.selectedMember) { - if (jQuery('#high-five-url').val() !== '') { - if (typeof jQuery('#high-five-task').val() !== 'object') { - return true; - } - } - } - return false; - }, - - printPhrase: function (phrase, el) { - return new Promise(resolve => { - // Clear placeholder before typing next phrase - HighFives.clearPlaceholder(el); - let letters = phrase.split(''); - // For each letter in phrase - letters.reduce( - (promise, letter, index) => promise.then(_ => { - // Resolve promise when all letters are typed - if (index === letters.length - 1) { - // Delay before start next phrase "typing" - setTimeout(resolve, 1000); - } - return HighFives.addToPlaceholder(letter, el); - }), - Promise.resolve() - ); - }); - }, - - printPhrases: function (phrases, el) { - // For each phrase - // wait for phrase to be typed - // before start typing next - phrases.reduce( - (promise, phrase) => promise.then(_ => HighFives.printPhrase(phrase, el)), - Promise.resolve() - ); - }, - - resetForm: function () { - HighFives.selectedMember = false; - HighFives.suggestions = []; - jQuery('#high-five-url').val(''); - jQuery('#high-five-mention').val(''); - HighFives.buildSuggestionsList(); - }, - - // selectMember - selectMember: function (member) { - var list = document.querySelector("#high-five-form .suggestions-list"); - list.innerHTML = ''; - jQuery('#high-five-mention').val(member.name); - }, - - // selectMemberIfMatches - If the `value` matches the name of a user in the suggestions list, select them. - selectMemberIfMatches: function(value) { - var suggestions = HighFives.suggestions; - if (suggestions && suggestions.length > 0) { - for (var i = 0; i < suggestions.length; i++) { - var suggestion = suggestions[i]; - if (suggestion.Username.toLowerCase() == value.toLowerCase()) { - HighFives.selectedMember = { - id: suggestion.MemberId, - name: suggestion.Username - }; - HighFives.selectMember(HighFives.selectedMember); - } - } - } - }, - - // submitHighFive - submitHighFive: function(to, action, url, onSuccess) { - if (useMockApi) { - onSuccess(ApiMock.submitHighFive()); - } else { - jQuery.post('/umbraco/api/HighFiveFeedAPI/SubmitHighFive?toUserId=' + to + '&action=' + action + '&url=' + url, onSuccess); - } - }, - - shuffle: function(array) { - var currentIndex = array.length, temporaryValue, randomIndex; - - // While there remain elements to shuffle... - while (0 !== currentIndex) { - - // Pick a remaining element... - randomIndex = Math.floor(Math.random() * currentIndex); - currentIndex -= 1; - - // And swap it with the current element. - temporaryValue = array[currentIndex]; - array[currentIndex] = array[randomIndex]; - array[randomIndex] = temporaryValue; - } - - return array; - }, - - unionBy: function(oldArray, newArray) { - for (var n = 0; n < newArray.length; n++) { - var itemToAdd = newArray[n]; - var isUnique = true; - for (var o = 0; o < oldArray.length; o++) { - var oldItem = oldArray[o]; - if (oldItem.id === itemToAdd.id) { - isUnique = false; - } - } - if (isUnique) { - oldArray.unshift(itemToAdd); - } - } - return oldArray; - } - }; - - var memberSearch = _.debounce(HighFives.getMember, 300); - - var ApiMock = { - getCategories: function() { - return [ - { "Id": 1, "CategoryText": "A Package" }, - { "Id": 2, "CategoryText": "A Talk" }, - { "Id": 3, "CategoryText": "A Blog Post" }, - { "Id": 4, "CategoryText": "A Meetup" }, - { "Id": 5, "CategoryText": "A Skrift Article" }, - { "Id": 6, "CategoryText": "A Tutorial" }, - { "Id": 7, "CategoryText": "Advice" }, - { "Id": 8, "CategoryText": "A Video" }, - { "Id": 9, "CategoryText": "A PR" } - ]; - }, - getHighFiveFeed: function() { - return { - Count: 100, - PageCount: 10, - CurrentPage: 0, - HighFives: [ - { - Id: '123', - From: 'Name of High Fiver', - To: 'Name of High Fivee', - FromAvatarUrl: '/avatar_of_high_fiver.jpg', - ToAvatarUrl: '/avatar_of_high_fivee.jpg', - Type: 'Blog post', - Url: 'http://optional.url.for.high.five.com' - } - ] - }; - }, - getUmbracians: function() { - return [ - { - MemberId: '123', - Username: 'Fred Johnson', - }, - { - MemberId: '124', - Username: 'Fred Samson', - }, - { - MemberId: '125', - Username: 'Fredina Hartvig' - } - ]; - }, - getRandomUmbracians: function() { - return [ - {MemberId: '0001', Username: "Marcin Zajkowski"}, - {MemberId: '0002', Username: "Callum Whyte"}, - {MemberId: '0003', Username: "Anders Bjerner"}, - {MemberId: '0004', Username: "Emma Garland"}, - {MemberId: '0005', Username: "Lars - Erik Aabech"}, - {MemberId: '0006', Username: "Matt Brailsford"}, - {MemberId: '0007', Username: "Carole Rennie Logan"}, - {MemberId: '0008', Username: "Emma Burstow"}, - {MemberId: '0009', Username: "Lee Kelleher"}, - {MemberId: '0010', Username: "Jeffrey Schoemaker"}, - {MemberId: '0011', Username: "Erica Quessenberry"}, - {MemberId: '0012', Username: "Kyle Weems"}, - {MemberId: '0013', Username: "Mike Masey"}, - {MemberId: '0014', Username: "Niels Hartvig"}, - {MemberId: '0015', Username: "Jeavon Leopold"}, - {MemberId: '0016', Username: "Damiaan Peeters"}, - {MemberId: '0017', Username: "Marc Goodson"}, - {MemberId: '0018', Username: "Mads Rasmussen"}, - {MemberId: '0019', Username: "Shannon Deminick"}, - {MemberId: '0020', Username: "Stéphane Gay"}, - {MemberId: '0021', Username: "Sebastiaan Janssen"}, - {MemberId: '0022', Username: "Jacob Midtgaard - Olesen"}, - {MemberId: '0023', Username: "Ilham Boulghallat"} - ] - }, - submitHighFive: function() { - return {}; - } - }; - - // Init - HighFives.init(); - +(function() { + + var useMockApi = false; + + // HighFives - JS functionality for the high fives module. + var HighFives = { + list: [], + selectedMember: false, + suggestions: [], + // init - Starts the high fives app functionality. + init: function() { + $(document).ready(function () { + if (HighFives.doesHaveHighFive()) { + HighFives.bindOnMentionChange(); + HighFives.bindOnMemberSelect(); + HighFives.bindOnSubmitForm(); + HighFives.getRandomUmbracians(function(people) { + HighFives.printPhrases(HighFives.shuffle(_.map(people, 'Username')), $('#high-five-mention')); + HighFives.getCategories(function(response) { + var categories = typeof response == 'string' ? JSON.parse(response) : response; + + HighFives.buildCategoryDropdown(categories); + HighFives.getRecentHighFiveActivity(0, function(response) { + var activity = typeof response == 'string' ? JSON.parse(response): response; + HighFives.list = HighFives.addComplimentsToList(activity.HighFives); + HighFives.buildActivityList(HighFives.list); + HighFives.checkForNewHighFivesPeriodically(30); + }); + }); + }); + } + }); + }, + + addComplimentsToList: function (list) { + for (var i = 0; i < list.length; i++) { + list[i].To = HighFives.getRandomCompliment() + ' ' + list[i].To; + } + return list; + }, + + addToPlaceholder: function (toAdd, el) { + el.attr('placeholder', el.attr('placeholder') + toAdd); + // Delay between symbols "typing" + return new Promise(resolve => setTimeout(resolve, 100)); + }, + + bindOnMentionChange: function () { + jQuery('#high-five-mention').keyup(function(e) { + HighFives.selectedMember = false; + HighFives.getMember(e.target.value); + HighFives.selectMemberIfMatches(e.target.value); + }); + }, + + bindOnMemberSelect: function() { + jQuery('#high-five-form .suggestions-list button').unbind('click'); + jQuery('#high-five-form .suggestions-list button').click(function(e) { + var id = e.target.getAttribute('data-id'); + HighFives.selectedMember = { + id: e.target.getAttribute('data-id'), + name: e.target.innerHTML + }; + HighFives.selectMember(HighFives.selectedMember); + }); + // unbind from previous versions just in case + }, + + bindOnSubmitForm: function() { + jQuery('#high-five-form').submit(function(e) { + e.preventDefault(); + if (HighFives.isFormValid()) { + HighFives.submitHighFive(HighFives.selectedMember.id, jQuery('#high-five-task').val(), jQuery('#high-five-url').val(), function() { + HighFives.resetForm(); + + setTimeout(function() { + HighFives.getRecentHighFiveActivity(0, function(response) { + var activity = typeof response == 'string' ? JSON.parse(response): response; + HighFives.list = HighFives.unionBy(HighFives.list, HighFives.addComplimentsToList(activity.HighFives)).slice(0, 10); + HighFives.buildActivityList(HighFives.list); + }); + }, 1500); + }); + } + }); + }, + + // buildActivityList - Builds a list of list items that represent the activity list and adds them to an activity list for users to view. + buildActivityList: function () { + var highFives = HighFives.list; + if (highFives && highFives.length > 0) { + var list = document.querySelector("#high-five-activity .high-five-activity-list"); + list.innerHTML = ''; + for (var i = 0; i < highFives.length; i++) { + var highFive = highFives[i]; + list.innerHTML += '
          • ' + + '
             + highFive.To +
            ' + + '
            ' + + '

            ' + highFive.To + '

            ' + + '

            ' + highFive.From + ' High Fived you for ' + highFive.Type + '' + /*, 2 minutes ago*/ '

            ' + + '
          • '; + } + } + }, + + buildSuggestionsList: function () { + var suggestions = HighFives.suggestions; + var list = document.querySelector("#high-five-form .suggestions-list"); + list.innerHTML = ''; + for (var i = 0; i < suggestions.length; i++) { + var suggestion = suggestions[i]; + list.innerHTML += '
          • ' + + '
          • '; + } + HighFives.bindOnMemberSelect(); + }, + + // buildCategoryDropdown - Builds a list of options for the category dropdown. + buildCategoryDropdown: function(categories) { + if (categories && categories.length > 0) { + var dropdown = jQuery('#high-five-task'); + var options = ''; + for (var i = 0; i < categories.length; i++) { + var category = categories[i]; + options += ''; + } + dropdown.html(options); + } + }, + + // checkForNewHighFivesPeriodically - Polls the API endpoint for new high fives periodically + checkForNewHighFivesPeriodically: function (seconds) { + window.setTimeout(function() { + HighFives.getRecentHighFiveActivity(0, function(response) { + var feed = typeof response == 'string' ? JSON.parse(response) : response; + HighFives.list = HighFives.unionBy(HighFives.list, HighFives.addComplimentsToList(feed.HighFives)).slice(0, 10); + HighFives.buildActivityList(HighFives.list); + HighFives.checkForNewHighFivesPeriodically(30); + }); + }, (seconds * 1000)); + }, + + clearPlaceholder: function (el) { + el.attr("placeholder", ""); + }, + + // doesHaveHighFive - returns true if highFive element exists + doesHaveHighFive: function() { + var highFive = document.querySelector('section[data-high-five]'); + if (highFive && typeof highFive !== 'null' && typeof highFive !== 'undefined') { + return true; + } + return false; + }, + + // getCategories - Get the categories for the high fives. + getCategories: function(onSuccess) { + if (useMockApi) { + onSuccess(ApiMock.getCategories()); + } else { + jQuery.getJSON('/umbraco/api/HighFiveFeedAPI/GetCategories', onSuccess); + } + }, + + getMember: function(member) { + if (member.length > 2) { + if (useMockApi) { + HighFives.suggestions = ApiMock.getUmbracians(); + HighFives.buildSuggestionsList(); + } else { + jQuery.get('/Umbraco/Api/highFiveFeedApi/GetUmbracians?name=' + member, function (umbracians) { + HighFives.suggestions = umbracians; + HighFives.buildSuggestionsList(); + }); + } + } + }, + + getRandomCompliment: function() { + var compliments = [ + 'Lovely', + 'Woohoo!', + '#h5yr!', + 'Go', + 'Awesome!', + 'Rockstar', + 'Yass!', + 'Most excellent', + 'Excellent!', + 'Supertak!', + 'Cheers!', + 'Wow!', + 'Yahoo!', + 'Yee haw!', + 'Boo ya!', + 'Hoorah!', + 'Huzzah!', + 'Tada!', + 'Yippee!', + 'Squeee!', + 'Yowza!', + 'Damn Skippy!', + 'Hells yeah!', + 'Bingo!', + 'KAPOW!', + 'Bravo!' + ]; + var rnd = Math.floor(Math.random() * compliments.length); + return compliments[rnd]; + }, + + // getRandomUmbracians - Get a random list of Umbracians to use for placeholder. + getRandomUmbracians: function(onSuccess) { + if (useMockApi) { + onSuccess(ApiMock.getRandomUmbracians()); + } else { + jQuery.get('/umbraco/api/HighFiveFeedAPI/getRandomUmbracians', onSuccess); + } + }, + + // getRecentHighFiveActivity - Gets the most recent high fives via API. + getRecentHighFiveActivity: function(page, onSuccess) { + page = typeof page === 'undefined' ? 0 : page; + if (useMockApi) { + onSuccess(ApiMock.getHighFiveFeed()); + } else { + jQuery.get('/umbraco/api/HighFiveFeedAPI/GetHighFiveFeed?page=' + page, onSuccess); + } + }, + + isFormValid: function() { + if (HighFives.selectedMember) { + if (jQuery('#high-five-url').val() !== '') { + if (typeof jQuery('#high-five-task').val() !== 'object') { + return true; + } + } + } + return false; + }, + + printPhrase: function (phrase, el) { + return new Promise(resolve => { + // Clear placeholder before typing next phrase + HighFives.clearPlaceholder(el); + let letters = phrase.split(''); + // For each letter in phrase + letters.reduce( + (promise, letter, index) => promise.then(_ => { + // Resolve promise when all letters are typed + if (index === letters.length - 1) { + // Delay before start next phrase "typing" + setTimeout(resolve, 1000); + } + return HighFives.addToPlaceholder(letter, el); + }), + Promise.resolve() + ); + }); + }, + + printPhrases: function (phrases, el) { + // For each phrase + // wait for phrase to be typed + // before start typing next + phrases.reduce( + (promise, phrase) => promise.then(_ => HighFives.printPhrase(phrase, el)), + Promise.resolve() + ); + }, + + resetForm: function () { + HighFives.selectedMember = false; + HighFives.suggestions = []; + jQuery('#high-five-url').val(''); + jQuery('#high-five-mention').val(''); + HighFives.buildSuggestionsList(); + }, + + // selectMember + selectMember: function (member) { + var list = document.querySelector("#high-five-form .suggestions-list"); + list.innerHTML = ''; + jQuery('#high-five-mention').val(member.name); + }, + + // selectMemberIfMatches - If the `value` matches the name of a user in the suggestions list, select them. + selectMemberIfMatches: function(value) { + var suggestions = HighFives.suggestions; + if (suggestions && suggestions.length > 0) { + for (var i = 0; i < suggestions.length; i++) { + var suggestion = suggestions[i]; + if (suggestion.Username.toLowerCase() == value.toLowerCase()) { + HighFives.selectedMember = { + id: suggestion.MemberId, + name: suggestion.Username + }; + HighFives.selectMember(HighFives.selectedMember); + } + } + } + }, + + // submitHighFive + submitHighFive: function(to, action, url, onSuccess) { + if (useMockApi) { + onSuccess(ApiMock.submitHighFive()); + } else { + jQuery.post('/umbraco/api/HighFiveFeedAPI/SubmitHighFive?toUserId=' + to + '&action=' + action + '&url=' + url, onSuccess); + } + }, + + shuffle: function(array) { + var currentIndex = array.length, temporaryValue, randomIndex; + + // While there remain elements to shuffle... + while (0 !== currentIndex) { + + // Pick a remaining element... + randomIndex = Math.floor(Math.random() * currentIndex); + currentIndex -= 1; + + // And swap it with the current element. + temporaryValue = array[currentIndex]; + array[currentIndex] = array[randomIndex]; + array[randomIndex] = temporaryValue; + } + + return array; + }, + + unionBy: function(oldArray, newArray) { + for (var n = 0; n < newArray.length; n++) { + var itemToAdd = newArray[n]; + var isUnique = true; + for (var o = 0; o < oldArray.length; o++) { + var oldItem = oldArray[o]; + if (oldItem.id === itemToAdd.id) { + isUnique = false; + } + } + if (isUnique) { + oldArray.unshift(itemToAdd); + } + } + return oldArray; + } + }; + + var memberSearch = _.debounce(HighFives.getMember, 300); + + var ApiMock = { + getCategories: function() { + return [ + { "Id": 1, "CategoryText": "A Package" }, + { "Id": 2, "CategoryText": "A Talk" }, + { "Id": 3, "CategoryText": "A Blog Post" }, + { "Id": 4, "CategoryText": "A Meetup" }, + { "Id": 5, "CategoryText": "A Skrift Article" }, + { "Id": 6, "CategoryText": "A Tutorial" }, + { "Id": 7, "CategoryText": "Advice" }, + { "Id": 8, "CategoryText": "A Video" }, + { "Id": 9, "CategoryText": "A PR" } + ]; + }, + getHighFiveFeed: function() { + return { + Count: 100, + PageCount: 10, + CurrentPage: 0, + HighFives: [ + { + Id: '123', + From: 'Name of High Fiver', + To: 'Name of High Fivee', + FromAvatarUrl: '/avatar_of_high_fiver.jpg', + ToAvatarUrl: '/avatar_of_high_fivee.jpg', + Type: 'Blog post', + Url: 'http://optional.url.for.high.five.com' + } + ] + }; + }, + getUmbracians: function() { + return [ + { + MemberId: '123', + Username: 'Fred Johnson', + }, + { + MemberId: '124', + Username: 'Fred Samson', + }, + { + MemberId: '125', + Username: 'Fredina Hartvig' + } + ]; + }, + getRandomUmbracians: function() { + return [ + {MemberId: '0001', Username: "Marcin Zajkowski"}, + {MemberId: '0002', Username: "Callum Whyte"}, + {MemberId: '0003', Username: "Anders Bjerner"}, + {MemberId: '0004', Username: "Emma Garland"}, + {MemberId: '0005', Username: "Lars - Erik Aabech"}, + {MemberId: '0006', Username: "Matt Brailsford"}, + {MemberId: '0007', Username: "Carole Rennie Logan"}, + {MemberId: '0008', Username: "Emma Burstow"}, + {MemberId: '0009', Username: "Lee Kelleher"}, + {MemberId: '0010', Username: "Jeffrey Schoemaker"}, + {MemberId: '0011', Username: "Erica Quessenberry"}, + {MemberId: '0012', Username: "Kyle Weems"}, + {MemberId: '0013', Username: "Mike Masey"}, + {MemberId: '0014', Username: "Niels Hartvig"}, + {MemberId: '0015', Username: "Jeavon Leopold"}, + {MemberId: '0016', Username: "Damiaan Peeters"}, + {MemberId: '0017', Username: "Marc Goodson"}, + {MemberId: '0018', Username: "Mads Rasmussen"}, + {MemberId: '0019', Username: "Shannon Deminick"}, + {MemberId: '0020', Username: "Stéphane Gay"}, + {MemberId: '0021', Username: "Sebastiaan Janssen"}, + {MemberId: '0022', Username: "Jacob Midtgaard - Olesen"}, + {MemberId: '0023', Username: "Ilham Boulghallat"} + ] + }, + submitHighFive: function() { + return {}; + } + }; + + // Init + HighFives.init(); + })(); \ No newline at end of file diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index 82d8dc68b2..b52963a831 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -37,7 +37,7 @@ public HighFiveFeedAPIController() //this will be for authorized members only [HttpPost] - public void SubmitHighFive(int toUserId, int action, String url) + public bool SubmitHighFive(int toUserId, int action, String url) { var memberService = ApplicationContext.Current.Services.MemberService; @@ -55,8 +55,12 @@ public void SubmitHighFive(int toUserId, int action, String url) highFive.CreatedDate = DateTime.Now; dbContext.Database.Insert(highFive); + return true; } + + return false; } + [HttpGet] public string GetHighFiveFeed() { @@ -77,7 +81,7 @@ public string GetHighFiveFeed() } if (fromMember !=null) { - fromAvatar = avatarService.GetMemberAvatar(toMember); + fromAvatar = avatarService.GetMemberAvatar(fromMember); } var type = GetActionType(dbEntry.ActionId); var highFive = new HighFiveResponse() From f538b71d667928f72a348fd282ec540138f08b02 Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Mon, 28 May 2018 22:28:01 +0100 Subject: [PATCH 46/60] Refactoring to service to be reusable --- .../API/HighFiveFeedAPIController.cs | 60 ++----------- .../Services/HighFiveFeedService.cs | 88 +++++++++++++++++++ OurUmbraco/OurUmbraco.csproj | 1 + 3 files changed, 97 insertions(+), 52 deletions(-) create mode 100644 OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index b52963a831..4678d05931 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -15,24 +15,18 @@ using OurUmbraco.Community.People; using OurUmbraco.Forum.Services; using Umbraco.Web.Mvc; +using OurUmbraco.HighFiveFeed.Services; namespace OurUmbraco.HighFiveFeed.API { public class HighFiveFeedAPIController : UmbracoApiController { - public List Categories; + + public HighFiveFeedService _highFiveService; + public HighFiveFeedAPIController() { - Categories = new List(); - Categories.Add(new HighFiveCategory(1, "A Package")); - Categories.Add(new HighFiveCategory(2, "A Talk")); - Categories.Add(new HighFiveCategory(3, "A Blog Post")); - Categories.Add(new HighFiveCategory(4, "A Meetup")); - Categories.Add(new HighFiveCategory(5, "A Skrift Article")); - Categories.Add(new HighFiveCategory(6, "A Tutorial")); - Categories.Add(new HighFiveCategory(7, "Advice")); - Categories.Add(new HighFiveCategory(8, "A Video")); - Categories.Add(new HighFiveCategory(9, "A PR")); + _highFiveService = new HighFiveFeedService(); } //this will be for authorized members only @@ -64,41 +58,7 @@ public bool SubmitHighFive(int toUserId, int action, String url) [HttpGet] public string GetHighFiveFeed() { - var dbContext = ApplicationContext.Current.DatabaseContext; - var sql = new Sql().Select("*").From("highFivePosts"); - var result = dbContext.Database.Fetch(sql).OrderByDescending(x=>x.CreatedDate); - var avatarService = new AvatarService(); - var response = new HighFiveFeedResponse(); - foreach (var dbEntry in result.Take(10)) - { - var toAvatar = ""; - var fromAvatar = ""; - var toMember = Members.GetById(dbEntry.ToMemberId); - var fromMember = Members.GetById(dbEntry.FromMemberId); - if (toMember != null) - { - toAvatar = avatarService.GetMemberAvatar(toMember); - } - if (fromMember !=null) - { - fromAvatar = avatarService.GetMemberAvatar(fromMember); - } - var type = GetActionType(dbEntry.ActionId); - var highFive = new HighFiveResponse() - { - Url = dbEntry.Link, - Type = type, - From = fromMember.Name, - FromAvatarUrl = fromAvatar, - To = toMember.Name, - ToAvatarUrl = toAvatar, - Id = dbEntry.Id, - CreatedDate = dbEntry.CreatedDate - - - }; - response.HighFives.Add(highFive); - } + var response = _highFiveService.GetHighFiveFeed(); var rawJson = JsonConvert.SerializeObject(response, Formatting.Indented); @@ -106,14 +66,10 @@ public string GetHighFiveFeed() } - private string GetActionType(int actionId) - { - return Categories.Where(x => x.Id == actionId).FirstOrDefault().CategoryText; - } - + public string GetCategories() { - + var Categories = _highFiveService.GetCategories(); var rawJson = JsonConvert.SerializeObject(Categories, Formatting.Indented); return rawJson; } diff --git a/OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs b/OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs new file mode 100644 index 0000000000..e67b641017 --- /dev/null +++ b/OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs @@ -0,0 +1,88 @@ +using OurUmbraco.Community.People; +using OurUmbraco.HighFiveFeed.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Umbraco.Core; +using OurUmbraco.Community.People.Models; +using OurUmbraco.Forum.Services; +using Umbraco.Web.Mvc; +using OurUmbraco.HighFiveFeed.Services; +using Umbraco.Core.Persistence; +using Umbraco.Core.Services; + +namespace OurUmbraco.HighFiveFeed.Services +{ + public class HighFiveFeedService + { + public List Categories; + public HighFiveFeedService() + { + Categories = new List(); + Categories.Add(new HighFiveCategory(1, "A Package")); + Categories.Add(new HighFiveCategory(2, "A Talk")); + Categories.Add(new HighFiveCategory(3, "A Blog Post")); + Categories.Add(new HighFiveCategory(4, "A Meetup")); + Categories.Add(new HighFiveCategory(5, "A Skrift Article")); + Categories.Add(new HighFiveCategory(6, "A Tutorial")); + Categories.Add(new HighFiveCategory(7, "Advice")); + Categories.Add(new HighFiveCategory(8, "A Video")); + Categories.Add(new HighFiveCategory(9, "A PR")); + } + + public HighFiveFeedResponse GetHighFiveFeed() + { + var Members = ApplicationContext.Current.Services.MemberService; + var dbContext = ApplicationContext.Current.DatabaseContext; + var sql = new Sql().Select("*").From("highFivePosts"); + var result = dbContext.Database.Fetch(sql).OrderByDescending(x => x.CreatedDate); + var avatarService = new AvatarService(); + var response = new HighFiveFeedResponse(); + + foreach (var dbEntry in result.Take(10)) + { + var toAvatar = ""; + var fromAvatar = ""; + var toMember = Members.GetById(dbEntry.ToMemberId); + var fromMember = Members.GetById(dbEntry.FromMemberId); + if (toMember != null) + { + toAvatar = avatarService.GetMemberAvatar(toMember); + } + if (fromMember != null) + { + fromAvatar = avatarService.GetMemberAvatar(fromMember); + } + var type = GetActionType(dbEntry.ActionId); + var highFive = new HighFiveResponse() + { + Url = dbEntry.Link, + Type = type, + From = fromMember.Name, + FromAvatarUrl = fromAvatar, + To = toMember.Name, + ToAvatarUrl = toAvatar, + Id = dbEntry.Id, + CreatedDate = dbEntry.CreatedDate + + + }; + response.HighFives.Add(highFive); + } + return response; + } + + private string GetActionType(int actionId) + { + return Categories.Where(x => x.Id == actionId).FirstOrDefault().CategoryText; + } + + public List GetCategories() + { + return Categories; + + } + } +} diff --git a/OurUmbraco/OurUmbraco.csproj b/OurUmbraco/OurUmbraco.csproj index 78b9ebb762..2e939de816 100644 --- a/OurUmbraco/OurUmbraco.csproj +++ b/OurUmbraco/OurUmbraco.csproj @@ -522,6 +522,7 @@ + From 6d5dad9d120427a4eb4f3b0955f53d74fd253cd7 Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Tue, 29 May 2018 21:08:10 +0100 Subject: [PATCH 47/60] fixing profile high five feed --- .../Partials/Members/PublicProfile.cshtml | 372 ++++++++++-------- .../API/HighFiveFeedAPIController.cs | 4 +- .../Services/HighFiveFeedService.cs | 41 ++ 3 files changed, 246 insertions(+), 171 deletions(-) diff --git a/OurUmbraco.Site/Views/Partials/Members/PublicProfile.cshtml b/OurUmbraco.Site/Views/Partials/Members/PublicProfile.cshtml index 6e338cec94..ac9e46465f 100644 --- a/OurUmbraco.Site/Views/Partials/Members/PublicProfile.cshtml +++ b/OurUmbraco.Site/Views/Partials/Members/PublicProfile.cshtml @@ -6,6 +6,7 @@ @using OurUmbraco.MarketPlace.NodeListing @using OurUmbraco.Our @using OurUmbraco.Our.Extensions +@using OurUmbraco.HighFiveFeed.Services @{ var memberId = Request["id"]; int id = 0; @@ -19,6 +20,8 @@ } else { + var highFiveService = new HighFiveFeedService(); + var highFives = highFiveService.GetHighFiveFeedForMember(member.Id); var ts = new TopicService(ApplicationContext.DatabaseContext); var topics = ts.GetLatestTopicsForMember(member.Id); @@ -38,14 +41,14 @@ contribProjects.Add(Umbraco.TypedContent(contribPackageId)); } } - + var reputationCurrent = member.GetPropertyValue("reputationCurrent"); var nodeListingProvider = new NodeListingProvider(); var votedProjects = nodeListingProvider.GetVotedProjectsForMember(member.Id); var rolesForUser = Roles.GetRolesForUser(member.GetPropertyValue("UserName")); - + var avatarService = new AvatarService(); var avatarPath = avatarService.GetMemberAvatar(member); var img = avatarService.GetImgWithSrcSet(avatarPath, member.Name, 125); @@ -120,206 +123,237 @@ { works at @member.GetPropertyValue("company") } - and has @member.GetPropertyValue("forumPosts") @if (member.ForumPosts() == 0 || member.ForumPosts() > 1){posts}else{post} and @member.GetPropertyValue("reputationCurrent") karma points - - -
            -

            @member.GetPropertyValue("profileText")

            -
            + and has @member.GetPropertyValue("forumPosts") @if (member.ForumPosts() == 0 || member.ForumPosts() > 1) + {posts} + else + {post} and @member.GetPropertyValue("reputationCurrent") karma points + + +
            +

            @member.GetPropertyValue("profileText")

            -
            -
            -
            -

            Activity

            - @foreach (var topic in topics) +
            +
            +
            +
            +

            Activity

            + @foreach (var topic in topics) + { + var cat = Umbraco.TypedContent(topic.ParentId); + // if cat == null then it's been hidden/unpublished (example: v5 forum) + // if this is the case: don't show forum post in list + if (cat != null) { - var cat = Umbraco.TypedContent(topic.ParentId); - // if cat == null then it's been hidden/unpublished (example: v5 forum) - // if this is the case: don't show forum post in list - if (cat != null) - { - var mem = Members.GetById(topic.LatestReplyAuthor) ?? Members.GetById(topic.MemberId); - var memImg = avatarService.GetImgWithSrcSet(mem, mem.Name, 75); - - -
            - @if (projects.Any()) - { -
            -
            - + @if (highFives.HighFives.ToList().Any()) + { +
            +
            +
            +

            High Five Feed

            + @foreach (var highFive in highFives.HighFives.ToList().OrderByDescending(x => x.CreatedDate)) + { +
            +
            + @highFive.From +
            + +
            +
            +

            High Five @highFive.To!!

            +

            + @highFive.From High Fived you for @highFive.Type, @highFive.CreatedDate.ToShortDateString() +

            +
            +
            +
            }
            -
            - } - @if (contribProjects.Any()) - { -
            -
            -
            -

            Packages contributed to

            - @foreach (var project in contribProjects.Where(x => x.GetPropertyValue("projectLive")).OrderByDescending(x => x.CreateDate)) - { - -
            -
            - @if (string.IsNullOrWhiteSpace(project.GetPropertyValue("defaultScreenshotPath").Trim())) - { - - } - else - { - @project.Name - } +
            + } + + @if (projects.Any()) + { +
            + } - @if (votedProjects.Any()) - { - + + if (MemberData != null && MemberData.IsAdmin) + { + var allTopics = ts.GetLatestTopicsForMember(member.Id, false, 1000); -
            -

            Moderator Tools (also known as "with great power comes great responsibility"):


            - @if (member.GetPropertyValue("blocked") == false) +
            +

            Moderator Tools (also known as "with great power comes great responsibility"):


            + @if (member.GetPropertyValue("blocked") == false) + { + Block this member
            + } + else + { + Unblock this member
            + Member is blocked
            + } +

            + @if (reputationCurrent < 71 || rolesForUser.Contains("potentialspam") || rolesForUser.Contains("newaccount")) + { + Approve member (careful now! if you approve this member, EVERYTHING that they posted and is marked as spam will be marked as ham.. )
            + } +

            +

            All threads this member was involved in (created or commented)

            + +
            + } +

            + var currentMember = MemberData != null ? MemberData.Member : null; + if (currentMember != null && currentMember.IsHq()) + { +
            +

            HQ Tools (also known as "with great power comes great responsibility"):


            + @{ + if (rolesForUser.Contains("potentialspam")) { - Unblock this member
            - Member is blocked
            + Member is in role "potentialspam"
            } -

            - @if (reputationCurrent < 71 || rolesForUser.Contains("potentialspam") || rolesForUser.Contains("newaccount")) + if (rolesForUser.Contains("newaccount")) { - Approve member (careful now! if you approve this member, EVERYTHING that they posted and is marked as spam will be marked as ham.. )
            - } -

            -

            All threads this member was involved in (created or commented)

            - -
            - } -

            - var currentMember = MemberData != null ? MemberData.Member : null; - if (currentMember != null && currentMember.IsHq()) - { -
            -

            HQ Tools (also known as "with great power comes great responsibility"):


            - @{ - if (rolesForUser.Contains("potentialspam")) - { - Member is in role "potentialspam"
            - } - if (rolesForUser.Contains("newaccount")) - { - Member is in role "newaccount"
            - } + Member is in role "newaccount"
            } -

            - Delete this member including all their topics and comments
            -
            - } + } +

            + Delete this member including all their topics and comments
            +
            } } +} \ No newline at end of file diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index 4678d05931..6dbb32c3a1 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -29,13 +29,13 @@ public HighFiveFeedAPIController() _highFiveService = new HighFiveFeedService(); } - //this will be for authorized members only + [Authorize] [HttpPost] public bool SubmitHighFive(int toUserId, int action, String url) { var memberService = ApplicationContext.Current.Services.MemberService; - + //you need to be logged in! var currentMember = Members.GetCurrentMember(); if (currentMember != null && currentMember.Id != 0) { diff --git a/OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs b/OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs index e67b641017..c570bff35c 100644 --- a/OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs +++ b/OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs @@ -32,6 +32,47 @@ public HighFiveFeedService() Categories.Add(new HighFiveCategory(9, "A PR")); } + public HighFiveFeedResponse GetHighFiveFeedForMember(int memberId) + { + var Members = ApplicationContext.Current.Services.MemberService; + var dbContext = ApplicationContext.Current.DatabaseContext; + var sql = new Sql().Select("*").From("highFivePosts").Where(x=>x.ToMemberId== memberId); + var result = dbContext.Database.Fetch(sql).OrderByDescending(x => x.CreatedDate); + var avatarService = new AvatarService(); + var response = new HighFiveFeedResponse(); + foreach (var dbEntry in result.Take(10)) + { + var toAvatar = ""; + var fromAvatar = ""; + var toMember = Members.GetById(dbEntry.ToMemberId); + var fromMember = Members.GetById(dbEntry.FromMemberId); + if (toMember != null) + { + toAvatar = avatarService.GetMemberAvatar(toMember); + } + if (fromMember != null) + { + fromAvatar = avatarService.GetMemberAvatar(fromMember); + } + var type = GetActionType(dbEntry.ActionId); + var highFive = new HighFiveResponse() + { + Url = dbEntry.Link, + Type = type, + From = fromMember.Name, + FromAvatarUrl = fromAvatar, + To = toMember.Name, + ToAvatarUrl = toAvatar, + Id = dbEntry.Id, + CreatedDate = dbEntry.CreatedDate + + + }; + response.HighFives.Add(highFive); + } + return response; + } + public HighFiveFeedResponse GetHighFiveFeed() { var Members = ApplicationContext.Current.Services.MemberService; From b556c43b1d6150f63578f566d09a4036bae90963 Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Wed, 30 May 2018 23:15:59 +0100 Subject: [PATCH 48/60] Adding title tag for high five link. --- .../Assets/js/components/highfives.js | 33 +++++++++++++++---- OurUmbraco.Site/OurUmbraco.Site.csproj | 3 +- .../Views/Partials/Community/Scripts.cshtml | 2 +- .../Partials/Members/PublicProfile.cshtml | 2 +- .../API/HighFiveFeedAPIController.cs | 16 +++++++-- .../HighFiveFeed/Models/HighFiveFeed.cs | 3 ++ .../HighFiveFeed/Models/HighFiveResponse.cs | 1 + .../Services/HighFiveFeedService.cs | 2 ++ OurUmbraco/Our/MigrationsHandler.cs | 2 +- 9 files changed, 51 insertions(+), 13 deletions(-) diff --git a/OurUmbraco.Site/Assets/js/components/highfives.js b/OurUmbraco.Site/Assets/js/components/highfives.js index 4567f6dbfd..5e29cf0206 100644 --- a/OurUmbraco.Site/Assets/js/components/highfives.js +++ b/OurUmbraco.Site/Assets/js/components/highfives.js @@ -14,6 +14,7 @@ HighFives.bindOnMentionChange(); HighFives.bindOnMemberSelect(); HighFives.bindOnSubmitForm(); + HighFives.bindOnLinkChange(); HighFives.getRandomUmbracians(function(people) { HighFives.printPhrases(HighFives.shuffle(_.map(people, 'Username')), $('#high-five-mention')); HighFives.getCategories(function(response) { @@ -52,7 +53,12 @@ HighFives.selectMemberIfMatches(e.target.value); }); }, - + bindOnLinkChange: function () { + jQuery('#high-five-url').keyup(function (e) { + HighFives.getUrlTitle(e.target.value); + HighFives.preview = false; + }); + }, bindOnMemberSelect: function() { jQuery('#high-five-form .suggestions-list button').unbind('click'); jQuery('#high-five-form .suggestions-list button').click(function(e) { @@ -70,7 +76,7 @@ jQuery('#high-five-form').submit(function(e) { e.preventDefault(); if (HighFives.isFormValid()) { - HighFives.submitHighFive(HighFives.selectedMember.id, jQuery('#high-five-task').val(), jQuery('#high-five-url').val(), function() { + HighFives.submitHighFive(HighFives.selectedMember.id, jQuery('#high-five-task').val(), jQuery('#high-five-url').val(), HighFives.linkTitle, function () { HighFives.resetForm(); setTimeout(function() { @@ -99,7 +105,7 @@ highFive.ToAvatarUrl + '?v=test&width=300&height=300&mode=crop&upscale=true 3x" alt=' + highFive.To + '">
            ' + '
            ' + '

            ' + highFive.To + '

            ' + - '

            ' + highFive.From + ' High Fived you for ' + highFive.Type + '' + /*, 2 minutes ago*/ '

            ' + + '

            ' + highFive.From + ' High Fived you for ' + highFive.Type +' : ' + highFive.LinkTitle + '' + /*, 2 minutes ago*/ '

            ' + '
            '; } } @@ -117,6 +123,10 @@ } HighFives.bindOnMemberSelect(); }, + buildPreview: function () + { + var preview = HighFives.preview; + }, // buildCategoryDropdown - Builds a list of options for the category dropdown. buildCategoryDropdown: function(categories) { @@ -178,7 +188,17 @@ } } }, - + getUrlTitle: function (url) { + if (url.length > 10) { + + jQuery.get('/Umbraco/Api/highFiveFeedApi/GetTitleTag?url=' + url, function (title) { + HighFives.linkTitle = title; + HighFives.preview.linkTitle = title; + HighFives.buildPreview(); + }); + + } + }, getRandomCompliment: function() { var compliments = [ 'Lovely', @@ -305,11 +325,11 @@ }, // submitHighFive - submitHighFive: function(to, action, url, onSuccess) { + submitHighFive: function(to, action, url, linkTitle, onSuccess) { if (useMockApi) { onSuccess(ApiMock.submitHighFive()); } else { - jQuery.post('/umbraco/api/HighFiveFeedAPI/SubmitHighFive?toUserId=' + to + '&action=' + action + '&url=' + url, onSuccess); + jQuery.post('/umbraco/api/HighFiveFeedAPI/SubmitHighFive?toUserId=' + to + '&action=' + action + '&url=' + url + '&linkTitle=' + linkTitle, onSuccess); } }, @@ -351,6 +371,7 @@ }; var memberSearch = _.debounce(HighFives.getMember, 300); + var titleSearch = _.debounce(HighFives.getUrlTitle, 300); var ApiMock = { getCategories: function() { diff --git a/OurUmbraco.Site/OurUmbraco.Site.csproj b/OurUmbraco.Site/OurUmbraco.Site.csproj index 8f02dce94c..a7b2e01094 100644 --- a/OurUmbraco.Site/OurUmbraco.Site.csproj +++ b/OurUmbraco.Site/OurUmbraco.Site.csproj @@ -455,6 +455,7 @@ + @@ -4438,7 +4439,7 @@ - True + False True 24292 / diff --git a/OurUmbraco.Site/Views/Partials/Community/Scripts.cshtml b/OurUmbraco.Site/Views/Partials/Community/Scripts.cshtml index ec96f8aac7..365ea2eef2 100644 --- a/OurUmbraco.Site/Views/Partials/Community/Scripts.cshtml +++ b/OurUmbraco.Site/Views/Partials/Community/Scripts.cshtml @@ -44,7 +44,7 @@

            {{compliment}} {{name}}

            - {{highFiver}} High Fived you for {{type}}, {{timestamp}} + {{highFiver}} High Fived you for {{type}}: {{linkTitle}}, {{timestamp}}

            diff --git a/OurUmbraco.Site/Views/Partials/Members/PublicProfile.cshtml b/OurUmbraco.Site/Views/Partials/Members/PublicProfile.cshtml index ac9e46465f..cae24ec2d6 100644 --- a/OurUmbraco.Site/Views/Partials/Members/PublicProfile.cshtml +++ b/OurUmbraco.Site/Views/Partials/Members/PublicProfile.cshtml @@ -187,7 +187,7 @@

            High Five @highFive.To!!

            - @highFive.From High Fived you for @highFive.Type, @highFive.CreatedDate.ToShortDateString() + @highFive.From High Fived you for @highFive.Type : @highFive.LinkTitle, @highFive.CreatedDate.ToShortDateString()

            diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index 6dbb32c3a1..4ca1698448 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -16,6 +16,8 @@ using OurUmbraco.Forum.Services; using Umbraco.Web.Mvc; using OurUmbraco.HighFiveFeed.Services; +using HtmlAgilityPack; +using System.Text.RegularExpressions; namespace OurUmbraco.HighFiveFeed.API { @@ -31,9 +33,9 @@ public HighFiveFeedAPIController() [Authorize] [HttpPost] - public bool SubmitHighFive(int toUserId, int action, String url) + public bool SubmitHighFive(int toUserId, int action, String url, String linkTitle="") { - + var memberService = ApplicationContext.Current.Services.MemberService; //you need to be logged in! var currentMember = Members.GetCurrentMember(); @@ -47,7 +49,7 @@ public bool SubmitHighFive(int toUserId, int action, String url) highFive.ActionId = action; highFive.Link = url; highFive.CreatedDate = DateTime.Now; - + highFive.LinkTitle = linkTitle; dbContext.Database.Insert(highFive); return true; } @@ -103,5 +105,13 @@ public List GetRandomUmbracians() return people; } + + public string GetTitleTag(string url) + { + var webGet = new HtmlWeb(); + var document = webGet.Load(url); + var title = document.DocumentNode.SelectSingleNode("html/head/title").InnerText; + return title; + } } } \ No newline at end of file diff --git a/OurUmbraco/HighFiveFeed/Models/HighFiveFeed.cs b/OurUmbraco/HighFiveFeed/Models/HighFiveFeed.cs index 79591756e8..bd8c06d03e 100644 --- a/OurUmbraco/HighFiveFeed/Models/HighFiveFeed.cs +++ b/OurUmbraco/HighFiveFeed/Models/HighFiveFeed.cs @@ -23,6 +23,9 @@ public class HighFiveFeed [Column("link")] public string Link { get; set; } + [Column("linkTitle")] + public string LinkTitle { get; set; } + [Column("count")] public int Count { get; set; } diff --git a/OurUmbraco/HighFiveFeed/Models/HighFiveResponse.cs b/OurUmbraco/HighFiveFeed/Models/HighFiveResponse.cs index d00a371b02..d37c50b1f6 100644 --- a/OurUmbraco/HighFiveFeed/Models/HighFiveResponse.cs +++ b/OurUmbraco/HighFiveFeed/Models/HighFiveResponse.cs @@ -16,6 +16,7 @@ public class HighFiveResponse public string Type { get; set; } public string Url { get; set; } public DateTime CreatedDate { get; set; } + public string LinkTitle { get; set; } } } diff --git a/OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs b/OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs index c570bff35c..7ca253d63d 100644 --- a/OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs +++ b/OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs @@ -64,6 +64,7 @@ public HighFiveFeedResponse GetHighFiveFeedForMember(int memberId) To = toMember.Name, ToAvatarUrl = toAvatar, Id = dbEntry.Id, + LinkTitle = dbEntry.LinkTitle, CreatedDate = dbEntry.CreatedDate @@ -106,6 +107,7 @@ public HighFiveFeedResponse GetHighFiveFeed() To = toMember.Name, ToAvatarUrl = toAvatar, Id = dbEntry.Id, + LinkTitle = dbEntry.LinkTitle, CreatedDate = dbEntry.CreatedDate diff --git a/OurUmbraco/Our/MigrationsHandler.cs b/OurUmbraco/Our/MigrationsHandler.cs index 8941cc86ec..6de2cabdd7 100644 --- a/OurUmbraco/Our/MigrationsHandler.cs +++ b/OurUmbraco/Our/MigrationsHandler.cs @@ -1474,7 +1474,7 @@ private void AddHighFiveTable() } //locic var db = ApplicationContext.Current.DatabaseContext.Database; - db.Execute("CREATE TABLE [dbo].[highFivePosts]([id] [int] IDENTITY(1,1) NOT NULL,[FromMemberId] [int] NULL,[ToMemberId] [int] NULL,[ActionId] [varchar] (50) NULL,[Link][nvarchar](max) NULL,[Count] [int] NULL, [CreatedDate] [datetime] NULL) ON[PRIMARY] TEXTIMAGE_ON[PRIMARY]"); + db.Execute("CREATE TABLE [dbo].[highFivePosts]([id] [int] IDENTITY(1,1) NOT NULL,[FromMemberId] [int] NULL,[ToMemberId] [int] NULL,[ActionId] [varchar] (50) NULL,[Link][nvarchar](max) NULL,[LinkTitle][nvarchar](max) NULL,[Count] [int] NULL, [CreatedDate] [datetime] NULL) ON[PRIMARY] TEXTIMAGE_ON[PRIMARY]"); string[] lines = { "" }; File.WriteAllLines(path, lines); From 5edeae25770a132c98410050d74dba67bbea2f9f Mon Sep 17 00:00:00 2001 From: Mike Masey Date: Thu, 31 May 2018 22:03:58 +0100 Subject: [PATCH 49/60] Tidy up css & markup. Begin work for updated member suggestion controls. --- .../src/scss/sections/_highFive.scss | 205 +++++++++--------- .../Assets/js/components/highfives.js | 22 +- .../Views/Partials/Community/Home.cshtml | 18 +- 3 files changed, 127 insertions(+), 118 deletions(-) diff --git a/OurUmbraco.Client/src/scss/sections/_highFive.scss b/OurUmbraco.Client/src/scss/sections/_highFive.scss index 053973bf65..797c92b623 100644 --- a/OurUmbraco.Client/src/scss/sections/_highFive.scss +++ b/OurUmbraco.Client/src/scss/sections/_highFive.scss @@ -1,4 +1,4 @@ -section.high-five { +.high-five { background: rgba($color-space, .11); background-size: 100%; background-position: center bottom; @@ -8,8 +8,8 @@ h2 { margin: 1rem auto 3.5rem; margin-bottom: 3rem; - line-height: 1.5; - padding: 0 10px; + line-height: 2.5; + padding: 0; font-size: 1.4rem; color: darken($color-space, 15%); text-align: center; @@ -70,156 +70,147 @@ justify-content: space-between; } - .high-five-activity-list { - display: grid; - grid-template-columns: 1fr 1fr; - grid-column-gap: 20px; - - @media (min-width: $md) { - grid-template-columns: 1fr 1fr 1fr; - } + &__member-search { + position: relative; } - + &__field { + min-width: 160px; + } - .high-five-item { - // flex: 0 0 100%; + &__activity-list { display: flex; - overflow: hidden; - - .avatar { - flex: 0 0 23%; - margin-right: 20px; + flex-wrap: wrap; + margin-left: -20px; + .high-five-panel { + width: calc(50% - 20px); + margin-left: 20px; + margin-top: 20px; + } - @media (min-width: $md) { - flex: 0 0 15%; + @media (min-width: $md) { + .high-five-panel { + width: calc(33.33% - 20px); } - - img { - width: 100%; - max-width: 112px; - height: auto; + } + + @supports (display: grid) { + display: grid; + grid-template-columns: 1fr 1fr; + grid-column-gap: 20px; + margin-left: 0; + + .high-five-panel { + margin-top: 0; + margin-left: 0; + width: auto; } - } - - - - .meta { - display: flex; - flex-direction: column; - flex: 1 0 75%; - overflow: hidden; - padding: 0 10px 0 0; - + @media (min-width: $md) { - flex: 1 0 83%; - } - } - + grid-template-columns: 1fr 1fr 1fr; - - .category { - margin: .5rem 0 0; - max-width: 95%; - - span { - font-size: .75rem; + .high-five-panel { + width: auto; + } } } } } -#high-five-form { - position: relative; -} - -.suggestions-list { - position: absolute; - top: 100%; - left: 21.7%; - list-style: none; - z-index: 10; - - button { - background: #a3db78; - border: 0; - min-width: 200px; - text-align: left; - - transition: .2s ease-in-out; - - &:hover { - background-color: #2EB369; - color: #FFFFFF; - } - } -} - -.high-five-item { +.high-five-panel { background: #fff; - padding: 25px; - margin-bottom: 20px; + padding: 15px; border: 1px solid darken(#f6f6f6, 5%); transition: box-shadow .2s ease, border-color .2s ease; text-decoration: none; display: flex; - align-items: center; + overflow: hidden; &:hover { border-color: white; @include box_shadow(2); } - .row { + p { margin: 0; + text-align: left; + font-size: .9rem; + color: $color-space; } - img { - border-radius: 50%; - width: 100%; - max-width: 112px; - height: auto; + &__avatar { + flex: 0 0 23%; + margin-right: 15px; - .package-forum-activity & { - border-radius: 0; - } - - @media (min-width: $md) { - width: 58px; + img { + width: 100%; + max-width: 112px; + height: auto; + border-radius: 50%; } + } - + &__meta { + display: flex; + flex-direction: column; + overflow: hidden; + padding: 0; } - .high-five-header { + &__header { margin-bottom: 2px; font-weight: normal; color: #000; line-height: 1.3; font-size: 1rem; + } - @media (min-width: $md) { + @media (min-width: $xs) { + align-items: center; + } + + @media (min-width: $md) { + padding: 25px; + + &__header { font-size: 1.1rem; } - } - p { - margin: 0; - text-align: left; - font-size: .9rem; - color: $color-space; - } + &__avatar { + flex: 0 0 15%; + margin-right: 20px; - small { - font-size: .8rem; + img { + width: 58px; + } + } } +} - .col-xs-2 { - padding: 0 .1rem; +#high-five-form { + position: relative; +} - @media (min-width: $md) { - padding: 0 .3rem; +.suggestions-list { + position: absolute; + top: calc(100% + 7px); + left: 0; + list-style: none; + z-index: 10; + + button { + background: #a3db78; + border: 0; + min-width: 200px; + text-align: left; + + transition: .2s ease-in-out; + + &:hover { + background-color: #2EB369; + color: #FFFFFF; } } -} \ No newline at end of file +} + diff --git a/OurUmbraco.Site/Assets/js/components/highfives.js b/OurUmbraco.Site/Assets/js/components/highfives.js index 5e29cf0206..2e4f22827e 100644 --- a/OurUmbraco.Site/Assets/js/components/highfives.js +++ b/OurUmbraco.Site/Assets/js/components/highfives.js @@ -95,16 +95,16 @@ buildActivityList: function () { var highFives = HighFives.list; if (highFives && highFives.length > 0) { - var list = document.querySelector("#high-five-activity .high-five-activity-list"); + var list = document.querySelector("#high-five-activity .high-five__activity-list"); list.innerHTML = ''; for (var i = 0; i < highFives.length; i++) { var highFive = highFives[i]; - list.innerHTML += '
          • ' + - '
             + highFive.To +
            ' + - '
            ' + - '

            ' + highFive.To + '

            ' + + '
            ' + + '

            ' + highFive.To + '

            ' + '

            ' + highFive.From + ' High Fived you for ' + highFive.Type +' : ' + highFive.LinkTitle + '' + /*, 2 minutes ago*/ '

            ' + '
          • '; } @@ -112,6 +112,7 @@ }, buildSuggestionsList: function () { + console.log("builds") var suggestions = HighFives.suggestions; var list = document.querySelector("#high-five-form .suggestions-list"); list.innerHTML = ''; @@ -123,6 +124,14 @@ } HighFives.bindOnMemberSelect(); }, + + clearSuggestionsList: function () { + console.log("clear") + jQuery('#high-five-form .suggestions-list button').unbind('click'); + var list = document.querySelector("#high-five-form .suggestions-list"); + list.innerHTML = ''; + }, + buildPreview: function () { var preview = HighFives.preview; @@ -182,10 +191,13 @@ HighFives.buildSuggestionsList(); } else { jQuery.get('/Umbraco/Api/highFiveFeedApi/GetUmbracians?name=' + member, function (umbracians) { + console.log(umbracians); HighFives.suggestions = umbracians; HighFives.buildSuggestionsList(); }); } + } else { + HighFives.clearSuggestionsList(); } }, getUrlTitle: function (url) { diff --git a/OurUmbraco.Site/Views/Partials/Community/Home.cshtml b/OurUmbraco.Site/Views/Partials/Community/Home.cshtml index dcc9b37e24..f59bcfd6fd 100644 --- a/OurUmbraco.Site/Views/Partials/Community/Home.cshtml +++ b/OurUmbraco.Site/Views/Partials/Community/Home.cshtml @@ -91,20 +91,26 @@ else

            - High Five - for +
              + + + + for at - -

              -
                -
                  +
                    -
                    +
                    +
                      +
                        + +
                        diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index 4ca1698448..54bcbf758a 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -68,7 +68,25 @@ public string GetHighFiveFeed() } - + [Authorize] + [HttpGet] + public Person GetCurrentMember() + { + var currentMember = Members.GetCurrentMember(); + var memberService = ApplicationContext.Current.Services.MemberService; + + if (currentMember != null && currentMember.Id != 0) + { + var member = memberService.GetById(currentMember.Id); + // var rawJson = JsonConvert.SerializeObject(currentMember, Formatting.Indented); + var returnItem = new Person(member); + + return returnItem; + } + return null; + } + + public string GetCategories() { var Categories = _highFiveService.GetCategories(); From 3a941ad75fc8fada145242dcaff34f0b962dd78f Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Sun, 10 Jun 2018 18:21:23 +0100 Subject: [PATCH 53/60] fixing preview high five styles --- .../src/scss/sections/_highFive.scss | 47 +++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/OurUmbraco.Client/src/scss/sections/_highFive.scss b/OurUmbraco.Client/src/scss/sections/_highFive.scss index 0d0d7e11df..46cf0cacd7 100644 --- a/OurUmbraco.Client/src/scss/sections/_highFive.scss +++ b/OurUmbraco.Client/src/scss/sections/_highFive.scss @@ -93,7 +93,47 @@ .high-five-panel { width: calc(33.33% - 20px); } - } + } + + @supports (display: grid) { + display: grid; + grid-template-columns: 1fr 1fr; + grid-gap: 20px; + margin-left: 0; + + .high-five-panel { + margin-top: 0; + margin-left: 0; + width: auto; + } + + @media (min-width: $md) { + grid-template-columns: 1fr 1fr 1fr; + + .high-five-panel { + width: auto; + } + } + } + } + + &__activity-preview { + display: flex; + flex-wrap: wrap; + margin-left: -20px; + + .high-five-panel { + width: calc(50% - 20px); + margin-left: 20px; + margin-top: 20px; + margin-bottom: 20px; + } + + @media (min-width: $md) { + .high-five-panel { + width: calc(33.33% - 20px); + } + } @supports (display: grid) { display: grid; @@ -101,18 +141,19 @@ grid-gap: 20px; margin-left: 0; + .high-five-panel { margin-top: 0; margin-left: 0; width: auto; } - + @media (min-width: $md) { grid-template-columns: 1fr 1fr 1fr; .high-five-panel { width: auto; - } + } } } } From d0dadb40ff07967cc64c90b7c5ebc8af52c9935f Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Sun, 10 Jun 2018 19:30:57 +0100 Subject: [PATCH 54/60] show relevant profile in preview --- OurUmbraco.Site/Assets/js/components/highfives.js | 11 ++++++++--- .../HighFiveFeed/API/HighFiveFeedAPIController.cs | 11 +++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/OurUmbraco.Site/Assets/js/components/highfives.js b/OurUmbraco.Site/Assets/js/components/highfives.js index 6d6168ff38..51052359cb 100644 --- a/OurUmbraco.Site/Assets/js/components/highfives.js +++ b/OurUmbraco.Site/Assets/js/components/highfives.js @@ -129,8 +129,7 @@ addPreviewBlock: function () { var list = document.querySelector("#high-five-activity .high-five__activity-preview"); list.innerHTML = ''; - - HighFives.preview.ToAvatarUrl = "/media/avatar/70690.png"; + var highFive = HighFives.preview; list.innerHTML += '

                        Preview of your High Five:

                      • ' + @@ -361,7 +360,13 @@ list.innerHTML = ''; jQuery('#high-five-mention').val(member.name); HighFives.preview.ToName = member.name; - HighFives.addPreviewBlock(); + var avatar = jQuery.get('/Umbraco/Api/highFiveFeedApi/GetMemberAvatar?memberId=' + member.id, function (memberAvatar) { + HighFives.preview.ToAvatarUrl = memberAvatar; + HighFives.addPreviewBlock(); + }); + + + }, // selectMemberIfMatches - If the `value` matches the name of a user in the suggestions list, select them. diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index 54bcbf758a..e261ba0cac 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -93,7 +93,18 @@ public string GetCategories() var rawJson = JsonConvert.SerializeObject(Categories, Formatting.Indented); return rawJson; } + public string GetMemberAvatar(int memberId) + { + var member = Members.GetById(memberId); + if (member != null) + { + var avatarService = new AvatarService(); + var avatar = avatarService.GetMemberAvatar(member); + return avatar; + } + return null; + } public List GetUmbracians(string name) { var peopleService = new PeopleService(); From a1bb8ede684b171397a022eef72478a633e4c7b7 Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Sun, 10 Jun 2018 20:54:11 +0100 Subject: [PATCH 55/60] fix for non http urls --- OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs index e261ba0cac..00b5bed5c6 100644 --- a/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs +++ b/OurUmbraco/HighFiveFeed/API/HighFiveFeedAPIController.cs @@ -137,8 +137,9 @@ public List GetRandomUmbracians() public string GetTitleTag(string url) { + var uri = new UriBuilder(url).Uri.AbsoluteUri; var webGet = new HtmlWeb(); - var document = webGet.Load(url); + var document = webGet.Load(uri.ToString()); var title = document.DocumentNode.SelectSingleNode("html/head/title").InnerText; return title; } From 4928053e262765d123be2a50a627dc69dce0e56f Mon Sep 17 00:00:00 2001 From: Carole Rennie Logan Date: Sat, 16 Jun 2018 17:40:10 +0100 Subject: [PATCH 56/60] high fives for members update hopefully more efficient :) --- OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs b/OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs index 94454cc358..e5e4f89baa 100644 --- a/OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs +++ b/OurUmbraco/HighFiveFeed/Services/HighFiveFeedService.cs @@ -37,10 +37,11 @@ public HighFiveFeedResponse GetHighFiveFeedForMember(int memberId) var Members = ApplicationContext.Current.Services.MemberService; var dbContext = ApplicationContext.Current.DatabaseContext; var sql = new Sql().Select("*").From("highFivePosts").Where(x=>x.ToMemberId== memberId); - var result = dbContext.Database.Fetch(sql).OrderByDescending(x => x.CreatedDate); + sql.OrderByDescending(x => x.CreatedDate); + var result = dbContext.Database.Page(1, 5, sql); var avatarService = new AvatarService(); var response = new HighFiveFeedResponse(); - foreach (var dbEntry in result.Take(10)) + foreach (var dbEntry in result.Items) { var toAvatar = ""; var fromAvatar = ""; From 1ef9f63ee05e426d7019a317d3712b72cfd64d06 Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 16 Jun 2018 16:16:02 +0100 Subject: [PATCH 57/60] Add whatInput library. It is used to help display the focus ring when required, which is great for accessibility. --- OurUmbraco.Client/src/js/vendor/whatInput.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 OurUmbraco.Client/src/js/vendor/whatInput.js diff --git a/OurUmbraco.Client/src/js/vendor/whatInput.js b/OurUmbraco.Client/src/js/vendor/whatInput.js new file mode 100644 index 0000000000..a878b72774 --- /dev/null +++ b/OurUmbraco.Client/src/js/vendor/whatInput.js @@ -0,0 +1,7 @@ +/** + * what-input - A global utility for tracking the current input method (mouse, keyboard or touch). + * @version v5.1.0 + * @link https://github.com/ten1seven/what-input + * @license MIT + */ +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("whatInput",[],t):"object"==typeof exports?exports.whatInput=t():e.whatInput=t()}(this,function(){return function(e){function t(o){if(n[o])return n[o].exports;var i=n[o]={exports:{},id:o,loaded:!1};return e[o].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t){"use strict";e.exports=function(){if("undefined"==typeof document||"undefined"==typeof window)return{ask:function(){return"initial"},element:function(){return null},ignoreKeys:function(){},registerOnChange:function(){},unRegisterOnChange:function(){}};var e=document.documentElement,t=null,n="initial",o=n;window.sessionStorage&&(window.sessionStorage.getItem("what-input")&&(n=window.sessionStorage.getItem("what-input")),window.sessionStorage.getItem("what-intent")&&(o=window.sessionStorage.getItem("what-intent")));var i=null,r=["input","select","textarea"],s=[],u=[16,17,18,91,93],a={keydown:"keyboard",keyup:"keyboard",mousedown:"mouse",mousemove:"mouse",MSPointerDown:"pointer",MSPointerMove:"pointer",pointerdown:"pointer",pointermove:"pointer",touchstart:"touch"},d=!1,w=!1,c={x:null,y:null},p={2:"touch",3:"touch",4:"mouse"},f=!1;try{var l=Object.defineProperty({},"passive",{get:function(){f=!0}});window.addEventListener("test",null,l)}catch(e){}var m=function(){var e=!!f&&{passive:!0};window.PointerEvent?(window.addEventListener("pointerdown",v),window.addEventListener("pointermove",g)):window.MSPointerEvent?(window.addEventListener("MSPointerDown",v),window.addEventListener("MSPointerMove",g)):(window.addEventListener("mousedown",v),window.addEventListener("mousemove",g),"ontouchstart"in window&&(window.addEventListener("touchstart",L,e),window.addEventListener("touchend",v))),window.addEventListener(x(),g,e),window.addEventListener("keydown",L),window.addEventListener("keyup",L),window.addEventListener("focusin",y),window.addEventListener("focusout",E)},v=function(e){if(!d){var t=e.which,i=a[e.type];"pointer"===i&&(i=S(e));var s="keyboard"===i&&t&&-1===u.indexOf(t)||"mouse"===i||"touch"===i;if(n!==i&&s&&(n=i,window.sessionStorage&&window.sessionStorage.setItem("what-input",n),h("input")),o!==i&&s){var w=document.activeElement;w&&w.nodeName&&-1===r.indexOf(w.nodeName.toLowerCase())&&(o=i,window.sessionStorage&&window.sessionStorage.setItem("what-intent",o),h("intent"))}}},h=function(t){e.setAttribute("data-what"+t,"input"===t?n:o),b(t)},g=function(e){if(k(e),!d&&!w){var t=a[e.type];"pointer"===t&&(t=S(e)),o!==t&&(o=t,window.sessionStorage&&window.sessionStorage.setItem("what-intent",o),h("intent"))}},y=function(n){if(!n.target.nodeName)return void E();t=n.target.nodeName.toLowerCase(),e.setAttribute("data-whatelement",t),n.target.classList&&n.target.classList.length&&e.setAttribute("data-whatclasses",n.target.classList.toString().replace(" ",","))},E=function(){t=null,e.removeAttribute("data-whatelement"),e.removeAttribute("data-whatclasses")},L=function(e){v(e),window.clearTimeout(i),d=!0,i=window.setTimeout(function(){d=!1},100)},S=function(e){return"number"==typeof e.pointerType?p[e.pointerType]:"pen"===e.pointerType?"touch":e.pointerType},x=function(){return"onwheel"in document.createElement("div")?"wheel":void 0!==document.onmousewheel?"mousewheel":"DOMMouseScroll"},b=function(e){for(var t=0,i=s.length;t Date: Sun, 17 Jun 2018 00:45:20 +0100 Subject: [PATCH 58/60] Refactor HighFive FE & BE, add WIF for preview, add basic validation for url input, add more compliments from retreat. --- OurUmbraco.Client/package-lock.json | 14 +- OurUmbraco.Client/src/js/app.js | 172 +++++++++--------- .../src/scss/elements/_audio-only.scss | 11 ++ .../src/scss/sections/_highFive.scss | 102 +++++------ OurUmbraco.Client/src/scss/style.scss | 1 + .../Assets/js/components/highfives.js | 144 ++++++++------- .../Views/Partials/Community/Home.cshtml | 35 ++-- .../Views/Partials/Community/Scripts.cshtml | 18 +- .../API/HighFiveFeedAPIController.cs | 6 +- .../HighFiveFeed/Models/HighFiveResponse.cs | 8 +- .../Services/HighFiveFeedService.cs | 22 +-- 11 files changed, 256 insertions(+), 277 deletions(-) create mode 100644 OurUmbraco.Client/src/scss/elements/_audio-only.scss diff --git a/OurUmbraco.Client/package-lock.json b/OurUmbraco.Client/package-lock.json index 51c50ee28f..702bc000b0 100644 --- a/OurUmbraco.Client/package-lock.json +++ b/OurUmbraco.Client/package-lock.json @@ -7,7 +7,7 @@ "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", - "integrity": "sha1-+PLIh60Qv2f2NPAFtph/7TF5qsg=", + "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", "dev": true }, "amdefine": { @@ -55,7 +55,7 @@ "aproba": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", - "integrity": "sha1-aALmJk79GMeQobDVF/DyYnvyyUo=", + "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", "dev": true }, "are-we-there-yet": { @@ -36080,7 +36080,7 @@ "normalize-package-data": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.4.0.tgz", - "integrity": "sha1-EvlaMH1YNSB1oEkHuErIvpisAS8=", + "integrity": "sha512-9jjUFbTPfEy3R/ad/2oNbKtW9Hgovl5O1FvFWKkKblNXoN/Oou6+9+KKohPK13Yc3/TyunyWhJp6gvRNR/PPAw==", "dev": true, "requires": { "hosted-git-info": "2.5.0", @@ -36092,7 +36092,7 @@ "npmlog": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", - "integrity": "sha1-CKfyqL9zRgR3mp76StXMcXq7lUs=", + "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", "dev": true, "requires": { "are-we-there-yet": "1.1.4", @@ -36371,7 +36371,7 @@ "rimraf": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", - "integrity": "sha1-LtgVDSShbqhlHm1u8PR8QVjOejY=", + "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", "dev": true, "requires": { "glob": "7.1.2" @@ -36700,7 +36700,7 @@ "which": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/which/-/which-1.3.0.tgz", - "integrity": "sha1-/wS9/AEO5UfXgL7DjhrBwnd9JTo=", + "integrity": "sha512-xcJpopdamTuY5duC/KnTTNBraPK54YwpenP4lzxU8H91GudWpFv38u0CKjclE1Wi2EH2EDz5LRcHcKbCIzqGyg==", "dev": true, "requires": { "isexe": "2.0.0" @@ -36715,7 +36715,7 @@ "wide-align": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.2.tgz", - "integrity": "sha1-Vx4PGwYEY268DfwhsDObvjE0FxA=", + "integrity": "sha512-ijDLlyQ7s6x1JgCLur53osjm/UXUYD9+0PbYKrBsYisYXzCxN+HC3mYDNy/dWdmf3AwqwU3CXwDCvsNgGK1S0w==", "dev": true, "requires": { "string-width": "1.0.2" diff --git a/OurUmbraco.Client/src/js/app.js b/OurUmbraco.Client/src/js/app.js index 905bfd40b1..7f19bc306d 100644 --- a/OurUmbraco.Client/src/js/app.js +++ b/OurUmbraco.Client/src/js/app.js @@ -7,96 +7,96 @@ _.templateSettings = { jQuery(document).ready(function (){ - // Quick menu - var bodyVar = $('body'), - searchAll = $('.search-all'); - - $( ".user, .close" ).click(function(e) { - e.preventDefault(); - e.stopPropagation(); - bodyVar.toggleClass( "quickmenu" ); - }); - - $('.wrapper').on('click', function () { - bodyVar.removeClass('quickmenu'); - }); - - - // Mobile navigation - $("#toggle").click(function(e) { - e.preventDefault(); - $(".cross").toggleClass("open"); - $("nav").toggleClass("open"); - $("body").toggleClass("navopen"); - }); - - $('.pm-nuget').on('click', '.nuget', function(){ - $(this).focus(); - $(this).select(); - }); - - // Tab - $('.tabs li').click(function(){ - var tab_id = $(this).attr('data-tab'); - - $('.tabs li').removeClass('current'); - $('.tab-content').removeClass('current'); - - $(this).addClass('current'); - $("#"+tab_id).addClass('current'); - }); - - // Click effect - var ink, d, x, y; - $(".button, .inked").click(function(e){ - - if($(this).find(".ink").length === 0){ - $(this).prepend("
                        "); - } - - ink = $(this).find(".ink"); - ink.removeClass("animate"); - - if(!ink.height() && !ink.width()){ - d = Math.max($(this).outerWidth(), $(this).outerHeight()); - ink.css({height: d, width: d}); - } - - x = e.pageX - $(this).offset().left - ink.width()/2; - y = e.pageY - $(this).offset().top - ink.height()/2; - - ink.css({top: y+'px', left: x+'px'}).addClass("animate"); - }); + // Quick menu + var bodyVar = $('body'), + searchAll = $('.search-all'); + + $( ".user, .close" ).click(function(e) { + e.preventDefault(); + e.stopPropagation(); + bodyVar.toggleClass( "quickmenu" ); }); - var classOnScrollObject = function (selector, className, scrollDistance) { - this.item = $(selector); - this.itemClass = className; - this.scrollDistance = scrollDistance; - this.classApplied = false; - this.scrollContainer = $(window); - this.fromTop = this.scrollContainer.scrollTop(); - }; - - classOnScrollObject.prototype.applyClass = function() { - this.fromTop = this.scrollContainer.scrollTop(); + $('.wrapper').on('click', function () { + bodyVar.removeClass('quickmenu'); + }); + + + // Mobile navigation + $("#toggle").click(function(e) { + e.preventDefault(); + $(".cross").toggleClass("open"); + $("nav").toggleClass("open"); + $("body").toggleClass("navopen"); + }); + + $('.pm-nuget').on('click', '.nuget', function(){ + $(this).focus(); + $(this).select(); + }); + + // Tab + $('.tabs li').click(function(){ + var tab_id = $(this).attr('data-tab'); + + $('.tabs li').removeClass('current'); + $('.tab-content').removeClass('current'); + + $(this).addClass('current'); + $("#"+tab_id).addClass('current'); + }); + + // Click effect + var ink, d, x, y; + $(".button, .inked").click(function(e){ + + if($(this).find(".ink").length === 0){ + $(this).prepend("
                        "); + } + + ink = $(this).find(".ink"); + ink.removeClass("animate"); + + if(!ink.height() && !ink.width()){ + d = Math.max($(this).outerWidth(), $(this).outerHeight()); + ink.css({height: d, width: d}); + } + + x = e.pageX - $(this).offset().left - ink.width()/2; + y = e.pageY - $(this).offset().top - ink.height()/2; - if (this.fromTop > this.scrollDistance && this.classApplied === false) { - this.classApplied = true; - this.item.addClass(this.itemClass); - } else if (this.fromTop < this.scrollDistance && this.classApplied === true) { - this.classApplied = false; - this.item.removeClass(this.itemClass); - } - }; + ink.css({top: y+'px', left: x+'px'}).addClass("animate"); + }); +}); + +var classOnScrollObject = function (selector, className, scrollDistance) { + this.item = $(selector); + this.itemClass = className; + this.scrollDistance = scrollDistance; + this.classApplied = false; + this.scrollContainer = $(window); + this.fromTop = this.scrollContainer.scrollTop(); +}; + +classOnScrollObject.prototype.applyClass = function() { + this.fromTop = this.scrollContainer.scrollTop(); + + if (this.fromTop > this.scrollDistance && this.classApplied === false) { + this.classApplied = true; + this.item.addClass(this.itemClass); + } else if (this.fromTop < this.scrollDistance && this.classApplied === true) { + this.classApplied = false; + this.item.removeClass(this.itemClass); + } +}; - function classOnScroll (selector, className, scrollDistance) { - var newClassOnScroll = new classOnScrollObject(selector, className, scrollDistance); +function classOnScroll (selector, className, scrollDistance) { + var newClassOnScroll = new classOnScrollObject(selector, className, scrollDistance); - newClassOnScroll.applyClass(); + newClassOnScroll.applyClass(); - newClassOnScroll.scrollContainer.scroll(function () { - newClassOnScroll.applyClass(); - }); + newClassOnScroll.scrollContainer.scroll(function () { + newClassOnScroll.applyClass(); + }); - } \ No newline at end of file +} \ No newline at end of file diff --git a/OurUmbraco.Client/src/scss/elements/_audio-only.scss b/OurUmbraco.Client/src/scss/elements/_audio-only.scss new file mode 100644 index 0000000000..eab971c560 --- /dev/null +++ b/OurUmbraco.Client/src/scss/elements/_audio-only.scss @@ -0,0 +1,11 @@ +// Hides an element, but keeps it accessable to screen readers. +.audio-only { + position: absolute; + overflow: hidden; + padding: 0; + width: 1px; + height: 1px; + margin: -1px; + border: 0; + clip: rect(0, 0, 0, 0); +} \ No newline at end of file diff --git a/OurUmbraco.Client/src/scss/sections/_highFive.scss b/OurUmbraco.Client/src/scss/sections/_highFive.scss index 46cf0cacd7..1b8aba40be 100644 --- a/OurUmbraco.Client/src/scss/sections/_highFive.scss +++ b/OurUmbraco.Client/src/scss/sections/_highFive.scss @@ -5,25 +5,12 @@ background-repeat: no-repeat; position: relative; - h2 { - margin: 1rem auto 3.5rem; - margin-bottom: 3rem; - line-height: 2.5; - padding: 0; - font-size: 1.4rem; - color: darken($color-space, 15%); - text-align: center; - } - h1 { font-size: 1.8rem; text-align: center; position: relative; z-index: 30; //margin-bottom: 3.5rem; // Remove me when text is ready under this - @media (min-width: $md) { - font-size: 2.4rem; - } + p { max-width: 700px; @@ -34,21 +21,36 @@ font-size: 1rem; color: darken($color-space, 15%); text-align: center; - - @media (min-width: $md) { - padding: 0; - font-size: 1.2rem; - } } } + + h2 { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: center; + margin: 1rem auto 3.5rem; + margin-bottom: 3rem; + line-height: 2.5; + padding: 0; + font-size: 1rem; + color: darken($color-space, 15%); + text-align: center; + } - input[type=text], select { + input, select { border: 0; padding: 3px; border-bottom: 2px solid #ccc; background: none; - font-size: 1.4rem; + font-size: 1rem; max-width: 200px; + margin-left: .7em; + margin-right: .7em; + + [data-whatintent="mouse"] &:focus { + outline: none; + } } button { @@ -81,7 +83,12 @@ &__activity-list { display: flex; flex-wrap: wrap; + width: 100%; margin-left: -20px; + + &--preview { + margin-bottom: 20px; + } .high-five-panel { width: calc(50% - 20px); @@ -89,12 +96,6 @@ margin-top: 20px; } - @media (min-width: $md) { - .high-five-panel { - width: calc(33.33% - 20px); - } - } - @supports (display: grid) { display: grid; grid-template-columns: 1fr 1fr; @@ -106,49 +107,30 @@ margin-left: 0; width: auto; } - - @media (min-width: $md) { - grid-template-columns: 1fr 1fr 1fr; - - .high-five-panel { - width: auto; - } - } } } - &__activity-preview { - display: flex; - flex-wrap: wrap; - margin-left: -20px; - - .high-five-panel { - width: calc(50% - 20px); - margin-left: 20px; - margin-top: 20px; - margin-bottom: 20px; - } + @media (min-width: $md) { + h1 { + font-size: 2.4rem; - @media (min-width: $md) { - .high-five-panel { - width: calc(33.33% - 20px); + + p { + padding: 0; + font-size: 1.2rem; } } - @supports (display: grid) { - display: grid; - grid-template-columns: 1fr 1fr; - grid-gap: 20px; - margin-left: 0; - + h2, + input, select { + font-size: 1.4rem; + } + &__activity-list { .high-five-panel { - margin-top: 0; - margin-left: 0; - width: auto; + width: calc(33.33% - 20px); } - @media (min-width: $md) { + @supports (display: grid) { grid-template-columns: 1fr 1fr 1fr; .high-five-panel { @@ -160,12 +142,12 @@ } .high-five-panel { + display: flex; background: #fff; padding: 15px; border: 1px solid darken(#f6f6f6, 5%); transition: box-shadow .2s ease, border-color .2s ease; text-decoration: none; - display: flex; overflow: hidden; &:hover { @@ -236,7 +218,7 @@ .suggestions-list { position: absolute; top: calc(100% + 7px); - left: 0; + left: .7em; list-style: none; z-index: 10; diff --git a/OurUmbraco.Client/src/scss/style.scss b/OurUmbraco.Client/src/scss/style.scss index 11c7f82d7e..f96636500e 100644 --- a/OurUmbraco.Client/src/scss/style.scss +++ b/OurUmbraco.Client/src/scss/style.scss @@ -54,6 +54,7 @@ @import 'elements/videos'; @import 'elements/overlay'; @import 'elements/umb-load-indicator'; +@import 'elements/audio-only'; /** /* Sections diff --git a/OurUmbraco.Site/Assets/js/components/highfives.js b/OurUmbraco.Site/Assets/js/components/highfives.js index 51052359cb..3b03bec1bb 100644 --- a/OurUmbraco.Site/Assets/js/components/highfives.js +++ b/OurUmbraco.Site/Assets/js/components/highfives.js @@ -5,8 +5,10 @@ // HighFives - JS functionality for the high fives module. var HighFives = { list: [], + rawList: [], selectedMember: false, suggestions: [], + prevLinkUrl: "", // init - Starts the high fives app functionality. init: function() { $(document).ready(function () { @@ -16,11 +18,14 @@ HighFives.bindOnSubmitForm(); HighFives.bindOnLinkChange(); HighFives.preview = {}; - HighFives.preview.ToName = ""; + HighFives.preview.To = ""; HighFives.preview.ToAvatarUrl = ""; HighFives.preview.Category = ""; - HighFives.preview.Link = ""; + HighFives.preview.LinkUrl = ""; HighFives.preview.LinkTitle = ""; + HighFives.previewNode = HighFives.createPreviewNode(), + HighFives.activityListNode = document.querySelector("#high-five-activity .high-five__activity-list"); + HighFives.highFiveActivityNode = document.querySelector("#high-five-activity"); HighFives.getCurrentMember(); HighFives.getRandomUmbracians(function(people) { HighFives.printPhrases(HighFives.shuffle(_.map(people, 'Username')), $('#high-five-mention')); @@ -30,8 +35,7 @@ HighFives.buildCategoryDropdown(categories); HighFives.getRecentHighFiveActivity(0, function(response) { var activity = typeof response == 'string' ? JSON.parse(response): response; - HighFives.list = HighFives.addComplimentsToList(activity.HighFives.slice(0, 6)); - HighFives.buildActivityList(HighFives.list); + HighFives.updateHighFiveList(activity.HighFives); HighFives.checkForNewHighFivesPeriodically(30); }); }); @@ -40,7 +44,16 @@ }); }, + updateHighFiveList(newHighFives) { + if(_.isEqual(HighFives.rawList, newHighFives) === false) { + HighFives.rawList = _.clone(newHighFives, true); + HighFives.list = HighFives.addComplimentsToList(newHighFives.slice(0, 6)); + HighFives.buildactivityListNode(HighFives.list); + } + }, + addComplimentsToList: function (list) { + var complimentedList = []; for (var i = 0; i < list.length; i++) { list[i].To = HighFives.getRandomCompliment() + ' ' + list[i].To; } @@ -61,10 +74,7 @@ }); }, bindOnLinkChange: function () { - jQuery('#high-five-url').keyup(function (e) { - HighFives.getUrlTitle(e.target.value); - - }); + jQuery('#high-five-url').keyup(_.debounce(HighFives.getUrlTitle, 300)); }, bindOnMemberSelect: function() { jQuery('#high-five-form .suggestions-list button').unbind('click'); @@ -80,11 +90,9 @@ }, bindOnCategorySelect: function () { - var categorySeleted = jQuery('#high-five-task option:selected').text(); HighFives.preview.Category = categorySeleted; - HighFives.addPreviewBlock(); - + HighFives.updatePreviewNode(); }, bindOnSubmitForm: function() { @@ -93,60 +101,60 @@ if (HighFives.isFormValid()) { HighFives.submitHighFive(HighFives.selectedMember.id, jQuery('#high-five-task').val(), jQuery('#high-five-url').val(), HighFives.linkTitle, function () { HighFives.resetForm(); - HighFives.clearPreviewBlock(); + HighFives.removePreviewNode(); HighFives.getRecentHighFiveActivity(0, function(response) { var activity = typeof response == 'string' ? JSON.parse(response): response; - // HighFives.list = HighFives.unionBy(HighFives.list, HighFives.addComplimentsToList(activity.HighFives)).slice(0, 6); - HighFives.list = HighFives.addComplimentsToList(activity.HighFives).slice(0, 6); - HighFives.buildActivityList(HighFives.list); + HighFives.updateHighFiveList(activity.HighFives); + HighFives.buildactivityListNode(HighFives.list); }); }); } }); }, - // buildActivityList - Builds a list of list items that represent the activity list and adds them to an activity list for users to view. - buildActivityList: function () { + // buildactivityListNode - Builds a list of list items that represent the activity list and adds them to an activity list for users to view. + buildactivityListNode: function () { var highFives = HighFives.list; if (highFives && highFives.length > 0) { - var list = document.querySelector("#high-five-activity .high-five__activity-list"); - list.innerHTML = ''; + HighFives.activityListNode.innerHTML = ''; for (var i = 0; i < highFives.length; i++) { var highFive = highFives[i]; - list.innerHTML += '
                      • ' + - '
                         + highFive.To +
                        ' + - '
                        ' + - '

                        ' + highFive.To + '

                        ' + - '

                        ' + highFive.From + ' High Fived you for ' + highFive.Type +' : ' + highFive.LinkTitle + '' + /*, 2 minutes ago*/ '

                        ' + - '
                      • '; + HighFives.activityListNode.innerHTML += HighFives.createHighFivePanelHtml(highFive); } } }, - addPreviewBlock: function () { - var list = document.querySelector("#high-five-activity .high-five__activity-preview"); - list.innerHTML = ''; - - + createPreviewNode() { + var preview = document.createElement("ul"); + preview.classList.add("high-five__activity-list"); + preview.classList.add("high-five__activity-list--preview"); + return preview; + }, + updatePreviewNode: function() { + HighFives.previewNode.innerHTML = ''; var highFive = HighFives.preview; - list.innerHTML += '

                        Preview of your High Five:

                      • ' + - '
                         + highFive.ToName +
                        ' + - '
                        ' + - '

                        ' + highFive.ToName + '

                        ' + - '

                        ' + highFive.FromMember + ' High Fived you for ' + highFive.Category + ' : ' + highFive.LinkTitle + '' + /*, 2 minutes ago*/ '

                        ' + - '
                      • '; - }, - - clearPreviewBlock: function () { - var list = document.querySelector("#high-five-activity .high-five__activity-preview"); - list.innerHTML = ''; + HighFives.previewNode.innerHTML += '

                        Preview of your High Five:

                        '; + HighFives.previewNode.innerHTML += HighFives.createHighFivePanelHtml(highFive); + if(document.body.contains(HighFives.previewNode) === false) { + HighFives.highFiveActivityNode.prepend(HighFives.previewNode); + } }, + removePreviewNode: function () { + HighFives.previewNode.remove(); + }, + createHighFivePanelHtml(highFive) { + return '
                      • ' + + '
                        ' + highFive.To + '
                        ' + + '
                        ' + + '

                        ' + highFive.To + '

                        ' + + '

                        ' + highFive.From + ' High Fived you for ' + highFive.Category +' : ' + highFive.LinkTitle + '' + /*, 2 minutes ago*/ '

                        ' + + '
                      • '; + }, + buildSuggestionsList: function () { var suggestions = HighFives.suggestions; var list = document.querySelector("#high-five-form .suggestions-list"); @@ -166,8 +174,6 @@ list.innerHTML = ''; }, - - // buildCategoryDropdown - Builds a list of options for the category dropdown. buildCategoryDropdown: function(categories) { if (categories && categories.length > 0) { @@ -190,8 +196,7 @@ HighFives.getRecentHighFiveActivity(0, function(response) { var feed = typeof response == 'string' ? JSON.parse(response) : response; // HighFives.list = HighFives.unionBy(HighFives.list, HighFives.addComplimentsToList(feed.HighFives)).slice(0, 6); - HighFives.list = HighFives.addComplimentsToList(feed.HighFives).slice(0, 6); - HighFives.buildActivityList(HighFives.list); + HighFives.updateHighFiveList(feed.HighFives); HighFives.checkForNewHighFivesPeriodically(30); }); }, (seconds * 1000)); @@ -234,22 +239,23 @@ HighFives.clearSuggestionsList(); } }, - getUrlTitle: function (url) { - if (url.length > 10) { - - jQuery.get('/Umbraco/Api/highFiveFeedApi/GetTitleTag?url=' + url, function (title) { + getUrlTitle: function (event) { + var url = event.target.value || ""; + + if (event.target.validity.valid === true && url.length > 10 && HighFives.prevLinkUrl !== url) { + HighFives.prevLinkUrl = url; + jQuery.get('/Umbraco/Api/highFiveFeedApi/GetTitleTag?url=' + encodeURIComponent(url), function (title) { HighFives.linkTitle = title; HighFives.preview.LinkTitle = title; - HighFives.preview.Link = url; - HighFives.addPreviewBlock(); - }); - + HighFives.preview.LinkUrl = url; + HighFives.updatePreviewNode(); + }); } }, getCurrentMember: function () { jQuery.get('/Umbraco/Api/highFiveFeedApi/GetCurrentMember', function (member) { HighFives.currentMember = member; - HighFives.preview.FromMember = HighFives.currentMember.Username; + HighFives.preview.From = HighFives.currentMember.Username; }); }, @@ -280,7 +286,16 @@ 'Hells yeah!', 'Bingo!', 'KAPOW!', - 'Bravo!' + 'Bravo!', + 'That\'s magic!', + 'Wizard!', + 'Nailed it!', + 'Well done!', + 'Like a boss!', + 'Congrats!', + 'Go you!', + 'Get you!', + 'Yay!' ]; var rnd = Math.floor(Math.random() * compliments.length); return compliments[rnd]; @@ -359,14 +374,12 @@ var list = document.querySelector("#high-five-form .suggestions-list"); list.innerHTML = ''; jQuery('#high-five-mention').val(member.name); - HighFives.preview.ToName = member.name; - var avatar = jQuery.get('/Umbraco/Api/highFiveFeedApi/GetMemberAvatar?memberId=' + member.id, function (memberAvatar) { + HighFives.preview.To = member.name; + + jQuery.get('/Umbraco/Api/highFiveFeedApi/GetMemberAvatar?memberId=' + member.id, function (memberAvatar) { HighFives.preview.ToAvatarUrl = memberAvatar; - HighFives.addPreviewBlock(); + HighFives.updatePreviewNode(); }); - - - }, // selectMemberIfMatches - If the `value` matches the name of a user in the suggestions list, select them. @@ -434,7 +447,6 @@ }; var memberSearch = _.debounce(HighFives.getMember, 300); - var titleSearch = _.debounce(HighFives.getUrlTitle, 300); var ApiMock = { getCategories: function() { diff --git a/OurUmbraco.Site/Views/Partials/Community/Home.cshtml b/OurUmbraco.Site/Views/Partials/Community/Home.cshtml index eaea6be1a7..46d17327c1 100644 --- a/OurUmbraco.Site/Views/Partials/Community/Home.cshtml +++ b/OurUmbraco.Site/Views/Partials/Community/Home.cshtml @@ -90,27 +90,28 @@ else
                        -

                        - High Five - - - -
                          -
                          - - - for at - - +

                          + High Five + + + + +
                            +
                            +
                            + + for at + +

                            -
                              +