Settings edit interface implemented; tested

main
Inga 🏳‍🌈 15 years ago
parent e58cb88d98
commit 5d7f32a3d8
  1. 2
      Builder/IISMainHandler/build.txt
  2. 2
      Builder/IISUploadHandler/build.txt
  3. 1
      Common/actions/ChangeSet.cs
  4. 35
      Common/dataobjects/AccountSettings.cs
  5. 15
      Common/dataobjects/IUserSettings.cs
  6. 4
      IISMainHandler/HandlersFactory.cs
  7. 2
      IISMainHandler/IISMainHandler.csproj
  8. 1
      IISMainHandler/handlers/request/AbstractPostHandler.cs
  9. 36
      IISMainHandler/handlers/request/SettingsHandler.cs
  10. 31
      IISMainHandler/handlers/response/SettingsHandler.cs
  11. 80
      templates/Full/Settings.xslt
  12. 7
      templates/Full/elems/Header.xslt
  13. 5
      templates/Full/result/Login.xslt
  14. 5
      templates/Full/result/Logout.xslt
  15. 30
      templates/Full/result/SettingsSaved.xslt

@ -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,

@ -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<AccountSettings>, 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<string, AbstractFieldValue> data = new Dictionary<string,AbstractFieldValue> {
{ 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);
}
}

@ -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)
);
}
}
}

@ -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:

@ -65,6 +65,7 @@
<Compile Include="handlers\request\LogoutHandler.cs" />
<Compile Include="handlers\request\MigrateAccountHandler.cs" />
<Compile Include="handlers\request\ReplyHandler.cs" />
<Compile Include="handlers\request\SettingsHandler.cs" />
<Compile Include="handlers\request\UploadHandler.cs" />
<Compile Include="handlers\response\BoardAsThread.cs" />
<Compile Include="handlers\response\CreateThreadHandler.cs" />
@ -72,6 +73,7 @@
<Compile Include="handlers\response\LoginHandler.cs" />
<Compile Include="handlers\response\MigrateAccountHandler.cs" />
<Compile Include="handlers\response\ReplyHandler.cs" />
<Compile Include="handlers\response\SettingsHandler.cs" />
<Compile Include="handlers\response\UploadHandler.cs" />
<Compile Include="handlers\response\UploadListHandler.cs" />
<Compile Include="handlers\response\UploadNewHandler.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()
)
);

@ -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];
}
}
}

@ -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()),
};
}
}
}

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="Windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:import href="elems\Main.xslt"/>
<xsl:template name="specific">
<table width="95%" align="center" cellpadding="1" cellspacing="1" class="tablesurround">
<tr>
<td>
<table cellpadding="3" cellspacing="1" width="100%" class="tableborders">
<tr>
<td class="tdheader">
<xsl:text>Èçìåíåíèå íàñòðîåê</xsl:text>
</td>
</tr>
<tr class="darktable">
<td>
<xsl:text>???</xsl:text>
</td>
</tr>
<tr>
<td class="lighttable">
<form method="post" action="/do/Settings/">
<p>
<xsl:text>Ïîñòîâ íà ñòðàíèöó:</xsl:text>
<br/>
<input type="text" name="postsPerPage">
<xsl:attribute name="value"><xsl:value-of select="settings/postsPerPage"/></xsl:attribute>
</input>
</p>
<p>
<xsl:text>Òðåäîâ íà ñòðàíèöó:</xsl:text>
<br/>
<input type="text" name="threadsPerPage">
<xsl:attribute name="value"><xsl:value-of select="settings/threadsPerPage"/></xsl:attribute>
</input>
</p>
<p>
<xsl:text>Ïîëüçîâàòåëåé íà ñòðàíèöó:</xsl:text>
<br/>
<input type="text" name="usersPerPage">
<xsl:attribute name="value"><xsl:value-of select="settings/usersPerPage"/></xsl:attribute>
</input>
</p>
<p>
<xsl:text>Êàðòèíîê íà ñòðàíèöó:</xsl:text>
<br/>
<input type="text" name="uploadsPerPage">
<xsl:attribute name="value"><xsl:value-of select="settings/uploadsPerPage"/></xsl:attribute>
</input>
</p>
<p>
<xsl:text>Öâåòîâàÿ ñõåìà:</xsl:text>
<br/>
<select name="skinId">
<xsl:apply-templates select="skins/skin" mode="skinOption">
<xsl:with-param name="currentSkin"><xsl:value-of select="settings/skinId"/></xsl:with-param>
</xsl:apply-templates>
</select>
</p>
<input type="submit" name="buttlogin" value="Îòïðàâèòü!" class="buttons" />
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</xsl:template>
<xsl:template match="skin" mode="skinOption">
<xsl:param name="currentSkin"/>
<option>
<xsl:attribute name="value"><xsl:value-of select="id"/></xsl:attribute>
<xsl:if test="id=$currentSkin">
<xsl:attribute name="selected">selected</xsl:attribute>
</xsl:if>
<xsl:value-of select="name"/>
</option>
</xsl:template>
</xsl:stylesheet>

@ -45,7 +45,12 @@
<xsl:text>Ŕďëîŕä</xsl:text>
</a>
<xsl:text> | </xsl:text>
<a target="_top">My Home</a>
<a target="_top">
<xsl:if test="session/sessionKey">
<xsl:attribute name="href">/Settings/</xsl:attribute>
</xsl:if>
<xsl:text>Íàñòðîéêè</xsl:text>
</a>
<xsl:text> | </xsl:text>
<a target="_top">
<xsl:if test="session/notLoggedIn">

@ -14,6 +14,11 @@
<tr>
<td class="lighttable">
<xsl:text>Авторизация прошла успешно</xsl:text>
<br/>
<a>
<xsl:attribute name="href">/Boards/</xsl:attribute>
<xsl:text>Íà ãëàâíóþ</xsl:text>
</a>
</td>
</tr>
</table>

@ -14,6 +14,11 @@
<tr>
<td class="lighttable">
<xsl:text>Ñåññèÿ óäàëåíà</xsl:text>
<br/>
<a>
<xsl:attribute name="href">/Boards/</xsl:attribute>
<xsl:text>Íà ãëàâíóþ</xsl:text>
</a>
</td>
</tr>
</table>

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="Windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:import href="..\elems\Main.xslt"/>
<xsl:template name="specific">
<table width="95%" align="center" cellpadding="1" cellspacing="1" class="tablesurround">
<tr>
<td>
<table cellpadding="3" cellspacing="1" width="100%" class="tableborders">
<tr>
<td class="tdheader">
<xsl:text>Ñîõðàíåíèå íàñòðîåê</xsl:text>
</td>
</tr>
<tr>
<td class="lighttable">
<xsl:text>Íàñòðîéêè ñîõðàíåíû</xsl:text>
<br/>
<a>
<xsl:attribute name="href">/Boards/</xsl:attribute>
<xsl:text>Íà ãëàâíóþ</xsl:text>
</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
Loading…
Cancel
Save