From a6208a90eba6ec4f0e8349681dda1b99e03862d6 Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Thu, 9 Sep 2010 17:22:28 +0000 Subject: [PATCH] UserInfo handlers refactored; UserHeader improved --- Builder/IISMainHandler/build.txt | 2 +- IISMainHandler/IISMainHandler.csproj | 1 + .../response/AbstractUserGetHandler.cs | 49 +++++++++++++++++++ .../handlers/response/UserInfoHandler.cs | 27 +--------- .../response/UserPollsParticipatedHandler.cs | 10 ++-- .../handlers/response/UserPostsHandler.cs | 10 ++-- .../handlers/response/UserRepliesHandler.cs | 9 ++-- .../handlers/response/UserThreadsHandler.cs | 10 ++-- templates/Full/UserInfo.xslt | 29 ----------- templates/Full/elems/MyHeader.xslt | 3 +- templates/Full/elems/UserHeader.xslt | 18 +++++++ 11 files changed, 85 insertions(+), 83 deletions(-) create mode 100644 IISMainHandler/handlers/response/AbstractUserGetHandler.cs diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 8535dde..c659825 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -1161 \ No newline at end of file +1163 \ No newline at end of file diff --git a/IISMainHandler/IISMainHandler.csproj b/IISMainHandler/IISMainHandler.csproj index bed0671..8245d18 100644 --- a/IISMainHandler/IISMainHandler.csproj +++ b/IISMainHandler/IISMainHandler.csproj @@ -145,6 +145,7 @@ + diff --git a/IISMainHandler/handlers/response/AbstractUserGetHandler.cs b/IISMainHandler/handlers/response/AbstractUserGetHandler.cs new file mode 100644 index 0000000..30bad16 --- /dev/null +++ b/IISMainHandler/handlers/response/AbstractUserGetHandler.cs @@ -0,0 +1,49 @@ +п»їusing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Web; +using System.Xml.Linq; +using FLocal.Common; +using FLocal.Common.dataobjects; +using FLocal.Core; +using FLocal.Core.DB; +using FLocal.Core.DB.conditions; + +namespace FLocal.IISHandler.handlers.response { + + abstract class AbstractUserGetHandler : AbstractGetHandler { + + abstract protected IEnumerable getUserSpecificData(WebContext context, User user); + + sealed override protected IEnumerable getSpecificData(WebContext context) { + User user; + { + int userId; + if(int.TryParse(context.requestParts[2], out userId)) { + user = User.LoadById(userId); + } else { + user = User.LoadByName(context.requestParts[2]); + } + } + Account account = null; + if(context.session != null) { + try { + account = Account.LoadByUser(user); + } catch(NotFoundInDBException) { + } + } + Session lastSession = null; + if(account != null && !account.isDetailedStatusHidden) { + lastSession = Session.GetLastSession(account); + } + return new XElement[] { + user.exportToXmlForViewing(context), + (account == null) ? null : new XElement("accountId", account.id.ToString()), //for PM history, PM send etc + (lastSession == null) ? null : new XElement("lastActivity", lastSession.lastActivity.ToXml()), + }.Union(this.getUserSpecificData(context, user)); + } + + } + +} \ No newline at end of file diff --git a/IISMainHandler/handlers/response/UserInfoHandler.cs b/IISMainHandler/handlers/response/UserInfoHandler.cs index 0c3094a..1f170b2 100644 --- a/IISMainHandler/handlers/response/UserInfoHandler.cs +++ b/IISMainHandler/handlers/response/UserInfoHandler.cs @@ -12,7 +12,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class UserInfoHandler : AbstractGetHandler { + class UserInfoHandler : AbstractUserGetHandler { override protected string templateName { get { @@ -20,31 +20,8 @@ namespace FLocal.IISHandler.handlers.response { } } - override protected IEnumerable getSpecificData(WebContext context) { - User user; - { - int userId; - if(int.TryParse(context.requestParts[2], out userId)) { - user = User.LoadById(userId); - } else { - user = User.LoadByName(context.requestParts[2]); - } - } - Account account = null; - if(context.session != null) { - try { - account = Account.LoadByUser(user); - } catch(NotFoundInDBException) { - } - } - Session lastSession = null; - if(account != null && !account.isDetailedStatusHidden) { - lastSession = Session.GetLastSession(account); - } + override protected IEnumerable getUserSpecificData(WebContext context, User user) { return new XElement[] { - user.exportToXmlForViewing(context), - (account == null) ? null : new XElement("accountId", account.id.ToString()), //for PM history, PM send etc - (lastSession == null) ? null : new XElement("lastActivity", lastSession.lastActivity.ToXml()) }; } diff --git a/IISMainHandler/handlers/response/UserPollsParticipatedHandler.cs b/IISMainHandler/handlers/response/UserPollsParticipatedHandler.cs index c938930..9b7eb92 100644 --- a/IISMainHandler/handlers/response/UserPollsParticipatedHandler.cs +++ b/IISMainHandler/handlers/response/UserPollsParticipatedHandler.cs @@ -12,7 +12,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class UserPollsParticipatedHandler : AbstractGetHandler { + class UserPollsParticipatedHandler : AbstractUserGetHandler { override protected string templateName { get { @@ -20,8 +20,7 @@ namespace FLocal.IISHandler.handlers.response { } } - override protected IEnumerable getSpecificData(WebContext context) { - User user = User.LoadById(int.Parse(context.requestParts[2])); + override protected IEnumerable getUserSpecificData(WebContext context, User user) { PageOuter pageOuter = PageOuter.createFromGet( context.requestParts, context.userSettings.postsPerPage, @@ -46,15 +45,12 @@ namespace FLocal.IISHandler.handlers.response { ) select int.Parse(stringId) ); - XElement[] result = new XElement[] { - user.exportToXmlForViewing(context), + return new XElement[] { new XElement("polls", from vote in votes select vote.poll.exportToXml(context), pageOuter.exportToXml(2, 5, 2) ) }; - - return result; } } diff --git a/IISMainHandler/handlers/response/UserPostsHandler.cs b/IISMainHandler/handlers/response/UserPostsHandler.cs index 4e8566d..be01a75 100644 --- a/IISMainHandler/handlers/response/UserPostsHandler.cs +++ b/IISMainHandler/handlers/response/UserPostsHandler.cs @@ -12,7 +12,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class UserPostsHandler : AbstractGetHandler { + class UserPostsHandler : AbstractUserGetHandler { override protected string templateName { get { @@ -20,8 +20,7 @@ namespace FLocal.IISHandler.handlers.response { } } - override protected IEnumerable getSpecificData(WebContext context) { - User user = User.LoadById(int.Parse(context.requestParts[2])); + override protected IEnumerable getUserSpecificData(WebContext context, User user) { PageOuter pageOuter = PageOuter.createFromGet( context.requestParts, context.userSettings.postsPerPage, @@ -29,15 +28,12 @@ namespace FLocal.IISHandler.handlers.response { ); IEnumerable posts = user.getPosts(pageOuter); - XElement[] result = new XElement[] { - user.exportToXmlForViewing(context), + return new XElement[] { new XElement("posts", from post in posts select post.exportToXml(context), pageOuter.exportToXml(2, 5, 2) ) }; - - return result; } } diff --git a/IISMainHandler/handlers/response/UserRepliesHandler.cs b/IISMainHandler/handlers/response/UserRepliesHandler.cs index 94a9daf..d87ffc0 100644 --- a/IISMainHandler/handlers/response/UserRepliesHandler.cs +++ b/IISMainHandler/handlers/response/UserRepliesHandler.cs @@ -12,7 +12,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class UserRepliesHandler : AbstractGetHandler { + class UserRepliesHandler : AbstractUserGetHandler { override protected string templateName { get { @@ -20,8 +20,7 @@ namespace FLocal.IISHandler.handlers.response { } } - override protected IEnumerable getSpecificData(WebContext context) { - User user = User.LoadById(int.Parse(context.requestParts[2])); + override protected IEnumerable getUserSpecificData(WebContext context, User user) { PageOuter pageOuter = PageOuter.createFromGet( context.requestParts, context.userSettings.postsPerPage, @@ -29,15 +28,13 @@ namespace FLocal.IISHandler.handlers.response { ); IEnumerable posts = user.getReplies(pageOuter); - XElement[] result = new XElement[] { + return new XElement[] { user.exportToXmlForViewing(context), new XElement("posts", from post in posts select post.exportToXml(context), pageOuter.exportToXml(2, 5, 2) ) }; - - return result; } } diff --git a/IISMainHandler/handlers/response/UserThreadsHandler.cs b/IISMainHandler/handlers/response/UserThreadsHandler.cs index 3bb5196..b915f55 100644 --- a/IISMainHandler/handlers/response/UserThreadsHandler.cs +++ b/IISMainHandler/handlers/response/UserThreadsHandler.cs @@ -12,7 +12,7 @@ using FLocal.Core.DB.conditions; namespace FLocal.IISHandler.handlers.response { - class UserThreadsHandler : AbstractGetHandler { + class UserThreadsHandler : AbstractUserGetHandler { override protected string templateName { get { @@ -20,8 +20,7 @@ namespace FLocal.IISHandler.handlers.response { } } - override protected IEnumerable getSpecificData(WebContext context) { - User user = User.LoadById(int.Parse(context.requestParts[2])); + override protected IEnumerable getUserSpecificData(WebContext context, User user) { PageOuter pageOuter = PageOuter.createFromGet( context.requestParts, context.userSettings.postsPerPage, @@ -29,15 +28,12 @@ namespace FLocal.IISHandler.handlers.response { ); IEnumerable threads = user.getThreads(pageOuter); - XElement[] result = new XElement[] { - user.exportToXmlForViewing(context), + return new XElement[] { new XElement("threads", from thread in threads select thread.exportToXml(context), pageOuter.exportToXml(1, 5, 1) ) }; - - return result; } } diff --git a/templates/Full/UserInfo.xslt b/templates/Full/UserInfo.xslt index f0b4c59..85d99d2 100644 --- a/templates/Full/UserInfo.xslt +++ b/templates/Full/UserInfo.xslt @@ -179,35 +179,6 @@ Not implemented - - - - - /My/Conversations/PMSend// - - - Послать личное сообщение - - | - - - /My/Conversations/Conversation// - - - История - - | - - - Добавить в адресную книгу - - | - - - Статистика - - - diff --git a/templates/Full/elems/MyHeader.xslt b/templates/Full/elems/MyHeader.xslt index 0692bb7..b456227 100644 --- a/templates/Full/elems/MyHeader.xslt +++ b/templates/Full/elems/MyHeader.xslt @@ -52,7 +52,7 @@ true - | >> + | /Users/User//Info/ Профиль @@ -60,6 +60,7 @@ true + | diff --git a/templates/Full/elems/UserHeader.xslt b/templates/Full/elems/UserHeader.xslt index f99e00c..38c655b 100644 --- a/templates/Full/elems/UserHeader.xslt +++ b/templates/Full/elems/UserHeader.xslt @@ -33,6 +33,24 @@ PollsParticipated/ Опросы + | + + /My/Conversations/Conversation// + История + + true + + + + | + + /My/Conversations/PMSend// + Написать + + true + + +