コード例 #1
0
ファイル: WallController.cs プロジェクト: maxpavlov/FlexNet
        public ActionResult CreatePost(string contextPath, string text, string rnd)
        {
            if (string.IsNullOrEmpty(text))
                return null;

            AssertPermission();

            var post = DataLayer.CreateManualPost(contextPath, text);
            var postInfo = new PostInfo(post);
            var postMarkup = WallHelper.GetPostMarkup(postInfo, contextPath);
            return Json(postMarkup, JsonRequestBehavior.AllowGet);
        }
コード例 #2
0
ファイル: WallController.cs プロジェクト: pchaozhong/FlexNet
        public ActionResult CreatePost(string contextPath, string text, string rnd)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            AssertPermission();

            var post       = DataLayer.CreateManualPost(contextPath, text);
            var postInfo   = new PostInfo(post);
            var postMarkup = WallHelper.GetPostMarkup(postInfo, contextPath);

            return(Json(postMarkup, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public static string CreatePost(Content content, string text)
        {
            AssertPermission(PlaceholderPath);
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            SetCurrentWorkspace(content.Path);
            var post       = DataLayer.CreateManualPost(content.Path, text);
            var postInfo   = new PostInfo(post);
            var postMarkup = WallHelper.GetPostMarkup(postInfo, content.Path);

            return(postMarkup);
        }
コード例 #4
0
ファイル: PostInfo.cs プロジェクト: maxpavlov/FlexNet
        // =============================================================================== Constructors
        public static PostInfo CreateFromCommentOrLike(Node commentOrLike)
        {
            var targetContent = commentOrLike.Parent.Parent;

            // comment likes should not appear, only content likes
            if (targetContent.NodeType.Name == "Comment")
                return null;

            var postInfo = new PostInfo();
            postInfo.CreationDate = commentOrLike.CreationDate;
            postInfo.CreatedBy = commentOrLike.CreatedBy as User;
            postInfo.Action = commentOrLike.NodeType.Name == "Comment" ? "commented on a Content" : "likes a Content";
            postInfo.Id = targetContent.Id;
            postInfo.Path = targetContent.Path; 
            postInfo.ClientId = postInfo.Id.ToString();
            postInfo.Type = PostType.BigPost;
            postInfo.SharedContent = targetContent;
            return postInfo;
        }
コード例 #5
0
ファイル: WallController.cs プロジェクト: pchaozhong/FlexNet
        public ActionResult GetLikeList(string itemId, string rnd)
        {
            if (!HasPermission())
            {
                return(Json("Please log in to see who liked this item!", JsonRequestBehavior.AllowGet));
            }

            var id = PostInfo.GetIdFromClientId(itemId);

            // create like markup
            var likeInfo = new LikeInfo(id);
            var likelist = new StringBuilder();

            foreach (var likeitem in likeInfo.LikeUsers)
            {
                var likeuser = likeitem as User;
                likelist.Append(WallHelper.GetLikeListItemMarkup(likeuser));
            }

            return(Json(likelist.ToString(), JsonRequestBehavior.AllowGet));
        }
コード例 #6
0
ファイル: WallController.cs プロジェクト: vlslavik/SenseNet
        public ActionResult GetLikeList(string itemId, string contextPath, string rnd)
        {
            if (!HasPermission())
            {
                return(Json(SNSR.GetString(SNSR.Wall.PleaseLogIn), JsonRequestBehavior.AllowGet));
            }

            SetCurrentWorkspace(contextPath);
            var id = PostInfo.GetIdFromClientId(itemId);

            // create like markup
            var likeInfo = new LikeInfo(id);
            var likelist = new StringBuilder();

            foreach (var likeitem in likeInfo.LikeUsers)
            {
                var likeuser = likeitem as User;
                likelist.Append(WallHelper.GetLikeListItemMarkup(likeuser));
            }

            return(Json(likelist.ToString(), JsonRequestBehavior.AllowGet));
        }
コード例 #7
0
ファイル: PostInfo.cs プロジェクト: pchaozhong/FlexNet
        // =============================================================================== Constructors
        public static PostInfo CreateFromCommentOrLike(Node commentOrLike)
        {
            var targetContent = commentOrLike.Parent.Parent;

            // comment likes should not appear, only content likes
            if (targetContent.NodeType.Name == "Comment")
            {
                return(null);
            }

            var postInfo = new PostInfo();

            postInfo.CreationDate  = commentOrLike.CreationDate;
            postInfo.CreatedBy     = commentOrLike.CreatedBy as User;
            postInfo.Action        = commentOrLike.NodeType.Name == "Comment" ? "commented on a Content" : "likes a Content";
            postInfo.Id            = targetContent.Id;
            postInfo.Path          = targetContent.Path;
            postInfo.ClientId      = postInfo.Id.ToString();
            postInfo.Type          = PostType.BigPost;
            postInfo.SharedContent = targetContent;
            return(postInfo);
        }
コード例 #8
0
        public static string GetLikeList(Content content, string itemId, string rnd)
        {
            if (!HasPermission())
            {
                return(JsonConvert.SerializeObject(SNSR.GetString(Compatibility.SR.Wall.PleaseLogIn)));
            }

            SetCurrentWorkspace(content.Path);
            var id = PostInfo.GetIdFromClientId(itemId);

            // create like markup
            var likeInfo = new LikeInfo(id);
            var likelist = new StringBuilder();

            foreach (var likeitem in likeInfo.LikeUsers)
            {
                var likeuser = likeitem as User;
                likelist.Append(WallHelper.GetLikeListItemMarkup(likeuser));
            }

            return(likelist.ToString());
        }
コード例 #9
0
 /// <summary>
 /// Gets markup for a new post, when there are no comments and likes yet.
 /// </summary>
 /// <returns></returns>
 public static string GetPostMarkup(PostInfo postInfo, string contextPath)
 {
     return(WallHelper.GetPostMarkup(postInfo, contextPath, string.Empty, string.Empty, 0, new LikeInfo(), false));
 }
コード例 #10
0
        public static string GetWallPostsMarkup(string contextPath, List <PostInfo> posts)
        {
            if (posts.Count == 0)
            {
                return(string.Empty);
            }

            // create query for comments and likes
            var csb   = new StringBuilder();
            var paths = new List <string>();

            foreach (var postInfo in posts)
            {
                if (postInfo.IsJournal)
                {
                    continue;
                }
                paths.Add(postInfo.Path);
            }

            List <Node> allComments;
            List <Node> allLikes;

            if (paths.Count == 0)    // only non-persisted journal posts are there to show (no comments or likes)
            {
                allComments = new List <Node>();
                allLikes    = new List <Node>();
            }
            else
            {
                var settings = new QuerySettings()
                {
                    EnableAutofilters = FilterStatus.Disabled
                };
                var allCommentsAndLikes = ContentQuery.Query(ContentRepository.SafeQueries.InTreeAndTypeIs, settings,
                                                             paths, new[] { "Comment", "Like" }).Nodes.ToList();

                var commentNodeTypeId = NodeType.GetByName("Comment").Id;
                var likeTypeId        = NodeType.GetByName("Like").Id;

                allComments = allCommentsAndLikes.Where(c => c.NodeTypeId == commentNodeTypeId).ToList();
                allLikes    = allCommentsAndLikes.Where(l => l.NodeTypeId == likeTypeId).ToList();
            }

            var bigPostMarkupStr   = GetBigPostMarkupStr();
            var smallPostMarkupStr = GetSmallPostMarkupStr();
            var commentMarkupStr   = GetCommentMarkupStr();
            var commentSectionStr  = GetCommentSectionMarkupStr();

            PostInfo prevPost = null;
            var      sb       = new StringBuilder();

            foreach (var postInfo in posts)
            {
                // get comments and likes for post
                CommentInfo commentInfo;
                LikeInfo    likeInfo;

                if (postInfo.IsJournal)
                {
                    commentInfo = new CommentInfo();
                    likeInfo    = new LikeInfo();
                }
                else
                {
                    var commentsForPost         = allComments.Where(c => RepositoryPath.GetParentPath(RepositoryPath.GetParentPath(c.Path)) == postInfo.Path).ToList();
                    var likesForPostAndComments = allLikes.Where(l => l.Path.StartsWith(postInfo.Path)).ToList();
                    var likesForPost            = likesForPostAndComments.Where(l => RepositoryPath.GetParentPath(RepositoryPath.GetParentPath(l.Path)) == postInfo.Path).ToList();

                    commentInfo = new CommentInfo(commentsForPost, likesForPostAndComments, commentMarkupStr);
                    likeInfo    = new LikeInfo(likesForPost, postInfo.Id);
                }

                var drawBoundary = (prevPost != null) && (prevPost.Type != PostType.BigPost) && (postInfo.Type == PostType.BigPost);

                var markup = WallHelper.GetPostMarkup(
                    postInfo.Type == PostType.BigPost ? bigPostMarkupStr : smallPostMarkupStr,
                    commentSectionStr,
                    postInfo,
                    contextPath,
                    commentInfo.HiddenCommentsMarkup,
                    commentInfo.CommentsMarkup,
                    commentInfo.CommentCount,
                    likeInfo, drawBoundary);

                prevPost = postInfo;

                sb.Append(markup);
            }
            return(sb.ToString());
        }
コード例 #11
0
        public static string GetPostMarkup(string markupStr, string commentSectionStr, PostInfo postInfo, string contextPath, string hiddenCommentsMarkup, string commentsMarkup, int commentCount, LikeInfo likeInfo, bool drawBoundary)
        {
            if (markupStr == null)
            {
                return(null);
            }

            if (commentSectionStr == null)
            {
                return(null);
            }

            markupStr = ReplaceResources(markupStr);

            markupStr = markupStr.Replace("{{commentsection}}", commentSectionStr);
            markupStr = markupStr.Replace("{{postid}}", postInfo.ClientId.ToString());
            markupStr = markupStr.Replace("{{avatar}}", UITools.GetAvatarUrl(postInfo.CreatedBy));
            markupStr = markupStr.Replace("{{username}}", postInfo.CreatedBy.FullName);
            markupStr = markupStr.Replace("{{userlink}}", Actions.ActionUrl(Content.Create(postInfo.CreatedBy), "Profile"));

            var text = postInfo.Text;

            if (text != null)
            {
                text = text.Replace("{{path}}", postInfo.LastPath ?? string.Empty);
            }

            var haspermission = WallHelper.HasWallPermission(contextPath);

            markupStr = markupStr.Replace("{{text}}", text);
            markupStr = markupStr.Replace("{{date}}", postInfo.CreationDate.ToString());
            markupStr = markupStr.Replace("{{friendlydate}}", UITools.GetFriendlyDate(postInfo.CreationDate));
            markupStr = markupStr.Replace("{{hiddencomments}}", hiddenCommentsMarkup);
            markupStr = markupStr.Replace("{{comments}}", commentsMarkup);
            markupStr = markupStr.Replace("{{commentboxdisplay}}", (commentCount > 0) && haspermission ? "block" : "none");
            markupStr = markupStr.Replace("{{hiddencommentboxdisplay}}", commentCount > 2 ? "block" : "none");
            markupStr = markupStr.Replace("{{commentcount}}", commentCount.ToString());
            markupStr = markupStr.Replace("{{likeboxdisplay}}", likeInfo.Count > 0 ? "block" : "none");
            markupStr = markupStr.Replace("{{likes}}", likeInfo.GetLongMarkup());
            markupStr = markupStr.Replace("{{ilikedisplay}}", !likeInfo.iLike ? "inline" : "none");
            markupStr = markupStr.Replace("{{iunlikedisplay}}", likeInfo.iLike ? "inline" : "none");

            // content card - only manualposts count here, journals don't have this markup
            if (postInfo.Type == PostType.BigPost && postInfo.SharedContent != null)
            {
                markupStr = markupStr.Replace("{{contentcard}}", WallHelper.GetContentCardMarkup(postInfo.SharedContent, contextPath));
            }
            else
            {
                markupStr = markupStr.Replace("{{contentcard}}", string.Empty);
            }

            // small post icon
            var smallposticon = "/Root/Global/images/icons/16/add.png";

            if (postInfo.Type == PostType.JournalModified)
            {
                smallposticon = "/Root/Global/images/icons/16/edit.png";
            }
            if (postInfo.Type == PostType.JournalDeletedPhysically)
            {
                smallposticon = "/Root/Global/images/icons/16/delete.png";
            }
            if (postInfo.Type == PostType.JournalMoved)
            {
                smallposticon = "/Root/Global/images/icons/16/move.png";
            }
            if (postInfo.Type == PostType.JournalCopied)
            {
                smallposticon = "/Root/Global/images/icons/16/copy.png";
            }
            markupStr = markupStr.Replace("{{smallposticon}}", smallposticon);

            markupStr = markupStr.Replace("{{postboundaryclass}}", drawBoundary ? "sn-post-boundary" : string.Empty);

            markupStr = markupStr.Replace("{{action}}", postInfo.Action);

            // small post details
            markupStr = markupStr.Replace("{{detailsdisplay}}", string.IsNullOrEmpty(postInfo.Details) ? "none" : "inline");
            markupStr = markupStr.Replace("{{detailssection}}", ReplaceResources(postInfo.Details));

            // user interaction allowed
            markupStr = markupStr.Replace("{{interactdisplay}}", haspermission ? "inline" : "none");

            return(markupStr);
        }
コード例 #12
0
ファイル: DataLayer.cs プロジェクト: pchaozhong/FlexNet
        // ================================================================================================ Public methods
        /// <summary>
        /// Retrieves all posts under given contextPath.
        /// </summary>
        /// <param name="contextPath">Path of context, ie. workspace.</param>
        /// <returns></returns>
        public static IEnumerable <PostInfo> GetPostsForWorkspace(string contextPath)
        {
            var queryText = string.Format("+InTree:\"{0}\" +Type:Post", contextPath);
            var settings  = new QuerySettings {
                EnableAutofilters = false, Sort = new SortInfo[] { new SortInfo {
                                                                       FieldName = "CreationDate", Reverse = true
                                                                   } }
            };
            var posts = ContentQuery.Query(queryText, settings).Nodes.Select(n => new PostInfo(n));

            // gather all journalid-s: these are ids to which post has already been created in the Content Repository
            var journalIds = posts.Select(p => p.JournalId).Distinct();

            var journalItems = Journals.GetItemsForWorkspace(contextPath);

            // get last paths of journals. Get all journals grouped by nodeids
            var lastPaths = (from j in journalItems
                             group j by j.NodeId into grp
                             select grp.First()).ToDictionary(j => j.NodeId, j => j.Wherewith);

            // gather crudposts, where createdby is a valid user (not SYSTEMUSER)
            // and it has not been persisted to the content repository yet (journalid is not contained in journalids above)
            var crudPosts = journalItems.Select(j => new PostInfo(j, lastPaths[j.NodeId])).Where(p => p.CreatedBy != null && !journalIds.Contains(p.JournalId));

            // gather likes and comments corresponding to content under this workspace
            var postsFolderPath = RepositoryPath.Combine(contextPath, "Posts");

            queryText = string.Format("+InTree:\"{0}\" +(Type:Comment Type:Like) -InTree:\"{1}\"", contextPath, postsFolderPath);
            var contentComments = ContentQuery.Query(queryText, settings).Nodes.Select(n => PostInfo.CreateFromCommentOrLike(n)).Where(p => p != null).Distinct(new CommentsLikesComparer());

            return(posts.Union(crudPosts).Union(contentComments).OrderByDescending(p => p.CreationDate));
        }
コード例 #13
0
ファイル: WallHelper.cs プロジェクト: maxpavlov/FlexNet
        public static string GetPostMarkup(string markupStr, string commentSectionStr, PostInfo postInfo, string contextPath, string hiddenCommentsMarkup, string commentsMarkup, int commentCount, LikeInfo likeInfo, bool drawBoundary)
        {
            if (markupStr == null)
                return null;

            if (commentSectionStr == null)
                return null;

            markupStr = markupStr.Replace("{{commentsection}}", commentSectionStr);
            markupStr = markupStr.Replace("{{postid}}", postInfo.ClientId.ToString());
            markupStr = markupStr.Replace("{{avatar}}", UITools.GetAvatarUrl(postInfo.CreatedBy));
            markupStr = markupStr.Replace("{{username}}", postInfo.CreatedBy.Name);
            markupStr = markupStr.Replace("{{userlink}}", Actions.ActionUrl(Content.Create(postInfo.CreatedBy), "Profile"));

            var text = postInfo.Text;
            if (text != null)
                text = text.Replace("{{path}}", postInfo.LastPath ?? string.Empty);

            var haspermission = WallHelper.HasWallPermission(contextPath);

            markupStr = markupStr.Replace("{{text}}", text);
            markupStr = markupStr.Replace("{{date}}", postInfo.CreationDate.ToString());
            markupStr = markupStr.Replace("{{friendlydate}}", UITools.GetFriendlyDate(postInfo.CreationDate));
            markupStr = markupStr.Replace("{{hiddencomments}}", hiddenCommentsMarkup);
            markupStr = markupStr.Replace("{{comments}}", commentsMarkup);
            markupStr = markupStr.Replace("{{commentboxdisplay}}", (commentCount > 0) && haspermission ? "block" : "none");
            markupStr = markupStr.Replace("{{hiddencommentboxdisplay}}", commentCount > 2 ? "block" : "none");
            markupStr = markupStr.Replace("{{commentcount}}", commentCount.ToString());
            markupStr = markupStr.Replace("{{likeboxdisplay}}", likeInfo.Count > 0 ? "block" : "none");
            markupStr = markupStr.Replace("{{likes}}", likeInfo.GetLongMarkup());
            markupStr = markupStr.Replace("{{ilikedisplay}}", !likeInfo.iLike ? "inline" : "none");
            markupStr = markupStr.Replace("{{iunlikedisplay}}", likeInfo.iLike ? "inline" : "none");

            // content card - only manualposts count here, journals don't have this markup
            if (postInfo.Type == PostType.BigPost && postInfo.SharedContent != null)
                markupStr = markupStr.Replace("{{contentcard}}", WallHelper.GetContentCardMarkup(postInfo.SharedContent, contextPath));
            else
                markupStr = markupStr.Replace("{{contentcard}}", string.Empty);

            // small post icon
            var smallposticon = "/Root/Global/images/icons/16/add.png";
            if (postInfo.Type == PostType.JournalModified)
                smallposticon = "/Root/Global/images/icons/16/edit.png";
            if (postInfo.Type == PostType.JournalDeletedPhysically)
                smallposticon = "/Root/Global/images/icons/16/delete.png";
            if (postInfo.Type == PostType.JournalMoved)
                smallposticon = "/Root/Global/images/icons/16/move.png";
            if (postInfo.Type == PostType.JournalCopied)
                smallposticon = "/Root/Global/images/icons/16/copy.png";
            markupStr = markupStr.Replace("{{smallposticon}}", smallposticon);

            markupStr = markupStr.Replace("{{postboundaryclass}}", drawBoundary ? "sn-post-boundary" : string.Empty);

            markupStr = markupStr.Replace("{{action}}", postInfo.Action);

            // small post details
            markupStr = markupStr.Replace("{{detailsdisplay}}", string.IsNullOrEmpty(postInfo.Details) ? "none" : "inline");
            markupStr = markupStr.Replace("{{detailssection}}", postInfo.Details);

            // user interaction allowed
            markupStr = markupStr.Replace("{{interactdisplay}}", haspermission ? "inline" : "none");

            return markupStr;
        }
コード例 #14
0
ファイル: WallHelper.cs プロジェクト: maxpavlov/FlexNet
 /// <summary>
 /// Gets markup for a Post.
 /// </summary>
 /// <returns></returns>
 public static string GetPostMarkup(PostInfo postInfo, string contextPath, string hiddenCommentsMarkup, string commentsMarkup, int commentCount, LikeInfo likeInfo, bool drawBoundary)
 {
     var markupStr = postInfo.Type == PostType.BigPost ? GetBigPostMarkupStr() : GetSmallPostMarkupStr();
     var commentSectionStr = GetCommentSectionMarkupStr();
     return GetPostMarkup(markupStr, commentSectionStr, postInfo, contextPath, hiddenCommentsMarkup, commentsMarkup, commentCount, likeInfo, drawBoundary);
 }
コード例 #15
0
ファイル: WallHelper.cs プロジェクト: maxpavlov/FlexNet
 /// <summary>
 /// Gets markup for a new post, when there are no comments and likes yet.
 /// </summary>
 /// <returns></returns>
 public static string GetPostMarkup(PostInfo postInfo, string contextPath)
 {
     return WallHelper.GetPostMarkup(postInfo, contextPath, string.Empty, string.Empty, 0, new LikeInfo(), false);
 }