From 5d7f32a3d87bccebe64219eb12a50afc8760649e Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Tue, 29 Jun 2010 07:39:40 +0000 Subject: [PATCH] Settings edit interface implemented; tested --- Builder/IISMainHandler/build.txt | 2 +- Builder/IISUploadHandler/build.txt | 2 +- Common/actions/ChangeSet.cs | 1 + Common/dataobjects/AccountSettings.cs | 35 +++++++- Common/dataobjects/IUserSettings.cs | 15 ++++ IISMainHandler/HandlersFactory.cs | 4 + IISMainHandler/IISMainHandler.csproj | 2 + .../handlers/request/AbstractPostHandler.cs | 1 + .../handlers/request/SettingsHandler.cs | 36 +++++++++ .../handlers/response/SettingsHandler.cs | 31 +++++++ templates/Full/Settings.xslt | 80 +++++++++++++++++++ templates/Full/elems/Header.xslt | 7 +- templates/Full/result/Login.xslt | 5 ++ templates/Full/result/Logout.xslt | 5 ++ templates/Full/result/SettingsSaved.xslt | 30 +++++++ 15 files changed, 252 insertions(+), 4 deletions(-) create mode 100644 IISMainHandler/handlers/request/SettingsHandler.cs create mode 100644 IISMainHandler/handlers/response/SettingsHandler.cs create mode 100644 templates/Full/Settings.xslt create mode 100644 templates/Full/result/SettingsSaved.xslt diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index b14de3a..00c22e5 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -421 \ No newline at end of file +429 \ No newline at end of file diff --git a/Builder/IISUploadHandler/build.txt b/Builder/IISUploadHandler/build.txt index 2bab422..59f3135 100644 --- a/Builder/IISUploadHandler/build.txt +++ b/Builder/IISUploadHandler/build.txt @@ -1 +1 @@ -157 \ No newline at end of file +165 \ No newline at end of file diff --git a/Common/actions/ChangeSet.cs b/Common/actions/ChangeSet.cs index 9af2eaa..3622927 100644 --- a/Common/actions/ChangeSet.cs +++ b/Common/actions/ChangeSet.cs @@ -25,6 +25,7 @@ namespace FLocal.Common.actions { dataobjects.Post.RevisionTableSpec.TABLE, dataobjects.Account.TableSpec.TABLE, dataobjects.User.TableSpec.TABLE, + dataobjects.AccountSettings.TableSpec.TABLE, dataobjects.Thread.ReadMarkerTableSpec.TABLE, dataobjects.Board.ReadMarkerTableSpec.TABLE, dataobjects.Session.TableSpec.TABLE, diff --git a/Common/dataobjects/AccountSettings.cs b/Common/dataobjects/AccountSettings.cs index 58e7cc2..cb50255 100644 --- a/Common/dataobjects/AccountSettings.cs +++ b/Common/dataobjects/AccountSettings.cs @@ -6,6 +6,7 @@ using System.Xml.Linq; using FLocal.Core; using FLocal.Core.DB; using FLocal.Core.DB.conditions; +using FLocal.Common.actions; namespace FLocal.Common.dataobjects { public class AccountSettings : SqlObject, IUserSettings { @@ -68,7 +69,7 @@ namespace FLocal.Common.dataobjects { private int _usersPerPage; public int usersPerPage { get { - this.Load(); + this.LoadIfNotLoaded(); return this._usersPerPage; } } @@ -127,6 +128,38 @@ namespace FLocal.Common.dataobjects { return AccountSettings.LoadById(accountid2id[account.id].Value); } else { return new AnonymousUserSettings(); + //If cache for this account was just cleared, we will return AnonymousUserSettings. It is ok. + } + } + private static void ClearCacheByAccount(Account account) { + lock(accountid2id) { + accountid2id.Remove(account.id); + } + } + + public static void Save(Account account, int postsPerPage, int threadsPerPage, int usersPerPage, int uploadsPerPage, Skin skin) { + Dictionary data = new Dictionary { + { TableSpec.FIELD_ACCOUNTID, new ScalarFieldValue(account.id.ToString()) }, + { TableSpec.FIELD_POSTSPERPAGE, new ScalarFieldValue(postsPerPage.ToString()) }, + { TableSpec.FIELD_THREADSPERPAGE, new ScalarFieldValue(threadsPerPage.ToString()) }, + { TableSpec.FIELD_USERSPERPAGE, new ScalarFieldValue(usersPerPage.ToString()) }, + { TableSpec.FIELD_UPLOADSPERPAGE, new ScalarFieldValue(uploadsPerPage.ToString()) }, + { TableSpec.FIELD_SKINID, new ScalarFieldValue(skin.id.ToString()) }, + }; + ChangeSetUtil.ApplyChanges( + new InsertOrUpdateChange( + TableSpec.instance, + data, + data, + new ComparisonCondition( + TableSpec.instance.getColumnSpec(TableSpec.FIELD_ACCOUNTID), + ComparisonType.EQUAL, + account.id.ToString() + ) + ) + ); + if(LoadByAccount(account) is AnonymousUserSettings) { + ClearCacheByAccount(account); } } diff --git a/Common/dataobjects/IUserSettings.cs b/Common/dataobjects/IUserSettings.cs index 7669d4e..6daf333 100644 --- a/Common/dataobjects/IUserSettings.cs +++ b/Common/dataobjects/IUserSettings.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Xml.Linq; namespace FLocal.Common.dataobjects { public interface IUserSettings { @@ -27,4 +28,18 @@ namespace FLocal.Common.dataobjects { } } + + public static class IUserSettings_Extension { + + public static XElement exportToXml(this IUserSettings settings, UserContext context) { + return new XElement("settings", + new XElement("postsPerPage", settings.postsPerPage), + new XElement("threadsPerPage", settings.threadsPerPage), + new XElement("usersPerPage", settings.usersPerPage), + new XElement("uploadsPerPage", settings.uploadsPerPage), + new XElement("skinId", settings.skin.id) + ); + } + + } } diff --git a/IISMainHandler/HandlersFactory.cs b/IISMainHandler/HandlersFactory.cs index 954ffcd..52bd72d 100644 --- a/IISMainHandler/HandlersFactory.cs +++ b/IISMainHandler/HandlersFactory.cs @@ -62,6 +62,8 @@ namespace FLocal.IISHandler { return new handlers.response.UserListHandler(); case "user": return new handlers.response.UserInfoHandler(); + case "settings": + return new handlers.response.SettingsHandler(); case "upload": if(context.requestParts.Length < 2) { return new handlers.WrongUrlHandler(); @@ -93,6 +95,8 @@ namespace FLocal.IISHandler { return new handlers.request.ReplyHandler(); case "newthread": return new handlers.request.CreateThreadHandler(); + case "settings": + return new handlers.request.SettingsHandler(); case "upload": return new handlers.request.UploadHandler(); default: diff --git a/IISMainHandler/IISMainHandler.csproj b/IISMainHandler/IISMainHandler.csproj index 8d1f8a5..4a3caca 100644 --- a/IISMainHandler/IISMainHandler.csproj +++ b/IISMainHandler/IISMainHandler.csproj @@ -65,6 +65,7 @@ + @@ -72,6 +73,7 @@ + diff --git a/IISMainHandler/handlers/request/AbstractPostHandler.cs b/IISMainHandler/handlers/request/AbstractPostHandler.cs index 6e3d6dc..8e75f94 100644 --- a/IISMainHandler/handlers/request/AbstractPostHandler.cs +++ b/IISMainHandler/handlers/request/AbstractPostHandler.cs @@ -32,6 +32,7 @@ namespace FLocal.IISHandler.handlers.request { new XElement("root", new XElement("title", Config.instance.AppInfo), this.Do(context), + context.userSettings.skin.exportToXml(), context.exportSession() ) ); diff --git a/IISMainHandler/handlers/request/SettingsHandler.cs b/IISMainHandler/handlers/request/SettingsHandler.cs new file mode 100644 index 0000000..1f3aaa8 --- /dev/null +++ b/IISMainHandler/handlers/request/SettingsHandler.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml.Linq; +using FLocal.Core; +using FLocal.Common.dataobjects; + +namespace FLocal.IISHandler.handlers.request { + class SettingsHandler : AbstractPostHandler { + + protected override string templateName { + get { + return "result/SettingsSaved.xslt"; + } + } + + protected override XElement[] Do(WebContext context) { + int postsPerPage = int.Parse(context.httprequest.Form["postsPerPage"]); + int threadsPerPage = int.Parse(context.httprequest.Form["threadsPerPage"]); + int usersPerPage = int.Parse(context.httprequest.Form["usersPerPage"]); + int uploadsPerPage = int.Parse(context.httprequest.Form["uploadsPerPage"]); + Skin skin = Skin.LoadById(int.Parse(context.httprequest.Form["skinId"])); + + if((postsPerPage < 1) || (postsPerPage > 200)) throw new FLocalException("wrong number for postsPerPage"); + if((threadsPerPage < 1) || (threadsPerPage > 200)) throw new FLocalException("wrong number for threadsPerPage"); + if((usersPerPage < 1) || (usersPerPage > 200)) throw new FLocalException("wrong number for usersPerPage"); + if((uploadsPerPage < 1) || (uploadsPerPage > 200)) throw new FLocalException("wrong number for uploadsPerPage"); + + AccountSettings.Save(context.session.account, postsPerPage, threadsPerPage, usersPerPage, uploadsPerPage, skin); + + return new XElement[0]; + } + + } +} diff --git a/IISMainHandler/handlers/response/SettingsHandler.cs b/IISMainHandler/handlers/response/SettingsHandler.cs new file mode 100644 index 0000000..08b693d --- /dev/null +++ b/IISMainHandler/handlers/response/SettingsHandler.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Web; +using System.Xml.Linq; +using FLocal.Core; +using FLocal.Common; +using FLocal.Common.dataobjects; + +namespace FLocal.IISHandler.handlers.response { + + class SettingsHandler : AbstractGetHandler { + + override protected string templateName { + get { + return "Settings.xslt"; + } + } + + override protected XElement[] getSpecificData(WebContext context) { + IUserSettings settings = AccountSettings.LoadByAccount(context.session.account); + + return new XElement[] { + settings.exportToXml(context), + new XElement("skins", from skin in Skin.allSkins select skin.exportToXml()), + }; + } + } + +} \ No newline at end of file diff --git a/templates/Full/Settings.xslt b/templates/Full/Settings.xslt new file mode 100644 index 0000000..8a86d70 --- /dev/null +++ b/templates/Full/Settings.xslt @@ -0,0 +1,80 @@ + + + + + + + + +
+ + + + + + + + + + +
+ Èçìåíåíèå íàñòðîåê +
+ ??? +
+
+

+ Ïîñòîâ íà ñòðàíèöó: +
+ + + +

+

+ Òðåäîâ íà ñòðàíèöó: +
+ + + +

+

+ Ïîëüçîâàòåëåé íà ñòðàíèöó: +
+ + + +

+

+ Êàðòèíîê íà ñòðàíèöó: +
+ + + +

+

+ Öâåòîâàÿ ñõåìà: +
+ +

+ +
+
+
+
+ + + + + + +
\ No newline at end of file diff --git a/templates/Full/elems/Header.xslt b/templates/Full/elems/Header.xslt index 6254cf9..8d39fd9 100644 --- a/templates/Full/elems/Header.xslt +++ b/templates/Full/elems/Header.xslt @@ -45,7 +45,12 @@ Àïëîàä | - My Home + + + /Settings/ + + Íàñòðîéêè + | diff --git a/templates/Full/result/Login.xslt b/templates/Full/result/Login.xslt index 9c429e3..f291f7f 100644 --- a/templates/Full/result/Login.xslt +++ b/templates/Full/result/Login.xslt @@ -14,6 +14,11 @@ Àâòîðèçàöèÿ ïðîøëà óñïåøíî +
+
+ /Boards/ + Íà ãëàâíóþ + diff --git a/templates/Full/result/Logout.xslt b/templates/Full/result/Logout.xslt index 6da221d..8ee7717 100644 --- a/templates/Full/result/Logout.xslt +++ b/templates/Full/result/Logout.xslt @@ -14,6 +14,11 @@ Ñåññèÿ óäàëåíà +
+ + /Boards/ + Íà ãëàâíóþ + diff --git a/templates/Full/result/SettingsSaved.xslt b/templates/Full/result/SettingsSaved.xslt new file mode 100644 index 0000000..3b93fc7 --- /dev/null +++ b/templates/Full/result/SettingsSaved.xslt @@ -0,0 +1,30 @@ + + + + + + + + +
+ + + + + + + +
+ Ñîõðàíåíèå íàñòðîåê +
+ Íàñòðîéêè ñîõðàíåíû +
+ + /Boards/ + Íà ãëàâíóþ + +
+
+
+ +
\ No newline at end of file