Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix Tags in PHP version & add natural sort in ScriptSharp

  • Loading branch information...
commit ed134d60992b1d33980eeb2f8c7f13fadd7ace9d 1 parent 508cc11
@a-fung authored
View
46 source/aspnetserver/CollectionUser.cs
@@ -1,4 +1,8 @@
-using System;
+// CollectionUser.cs
+// MangaWeb3 Project
+// Copyright 2012 Man Kwan Liu
+
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
@@ -6,32 +10,57 @@
namespace afung.MangaWeb3.Server
{
+ /// <summary>
+ /// The CollectionUser class
+ /// </summary>
public class CollectionUser
{
+ /// <summary>
+ /// Whether this object is new (not yet saved to database)
+ /// </summary>
private bool isNew = false;
+ /// <summary>
+ /// Collection ID
+ /// </summary>
public int CollectionId
{
get;
private set;
}
+ /// <summary>
+ /// User ID
+ /// </summary>
public int UserId
{
get;
private set;
}
+ /// <summary>
+ /// Allow/deny access
+ /// </summary>
public bool Access
{
get;
private set;
}
+ /// <summary>
+ /// Instantiate a new instance of CollectionUser class
+ /// </summary>
private CollectionUser()
{
}
+ /// <summary>
+ /// Create a new CollectionUser object
+ /// </summary>
+ /// <param name="collection">The collection</param>
+ /// <param name="user">The user</param>
+ /// <param name="access">Allow/deny access</param>
+ /// <returns>The new CollectionUser object</returns>
public static CollectionUser CreateNew(Collection collection, User user, bool access)
{
CollectionUser cu = new CollectionUser();
@@ -42,6 +71,11 @@ public static CollectionUser CreateNew(Collection collection, User user, bool ac
return cu;
}
+ /// <summary>
+ /// Create a new instance of CollectionUser using data from database
+ /// </summary>
+ /// <param name="data">The data</param>
+ /// <returns>A CollectionUser object from data</returns>
private static CollectionUser FromData(Dictionary<string, object> data)
{
CollectionUser cu = new CollectionUser();
@@ -51,6 +85,11 @@ private static CollectionUser FromData(Dictionary<string, object> data)
return cu;
}
+ /// <summary>
+ /// Get all CollectionUser objects associated to a collection
+ /// </summary>
+ /// <param name="collection">The collection</param>
+ /// <returns>An array of CollectionUser objects</returns>
public static CollectionUser[] GetByCollection(Collection collection)
{
if (collection != null && collection.Id != -1)
@@ -61,6 +100,11 @@ public static CollectionUser[] GetByCollection(Collection collection)
return new CollectionUser[] { };
}
+ /// <summary>
+ /// Get all CollectionUser objects associated to a user
+ /// </summary>
+ /// <param name="user">The user</param>
+ /// <returns>An array of CollectionUser objects</returns>
public static CollectionUser[] GetByUser(User user)
{
if (user != null && user.Id != -1)
View
4 source/haxe/afung/mangaWeb3/server/Manga.hx
@@ -605,7 +605,7 @@ class Manga
tag = Utf8.sub(tag, 0, 100);
}
- if (Utility.ArrayStringContains(oldTags, tag))
+ if (!Utility.ArrayStringContains(oldTags, tag))
{
if (Utility.ArrayStringContains(allTags, tag))
{
@@ -627,7 +627,7 @@ class Manga
for (tag in oldTags)
{
- if (Utility.ArrayStringContains(tags, tag))
+ if (!Utility.ArrayStringContains(tags, tag))
{
id = Std.parseInt(Database.Select("tag", "`name`=" + Database.Quote(tag))[0].get("id"));
Database.Delete("mangatag", "`tid`=" + Database.Quote(Std.string(id)) + " AND `mid`=" + Database.Quote(Std.string(Id)));
View
2  source/scriptsharp/Module/MangasModule.cs
@@ -215,7 +215,7 @@ public void SortItems()
default:
compare = delegate(MangaListItemJson a, MangaListItemJson b)
{
- return a.title.CompareTo(b.title);
+ return Utility.NaturalCompare(a.title, b.title);
};
break;
}
View
38 source/scriptsharp/Utility.cs
@@ -3,7 +3,9 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Html;
+using System.Runtime.CompilerServices;
using jQueryApi;
namespace afung.MangaWeb3.Client
@@ -46,5 +48,41 @@ public static void OnTransitionEnd(jQueryObject obj, Action trigger)
trigger();
}
}
+
+ [AlternateSignature]
+ public extern static int NaturalCompare(object a, object b);
+ public static int NaturalCompare(string a, string b)
+ {
+ RegularExpression regex = new RegularExpression("[0-9]+");
+
+ string[] aa = regex.Exec(a), bb = regex.Exec(b);
+
+ if (aa != null && bb != null)
+ {
+ string aaa = a.Substr(0, a.IndexOf(aa[0])), bbb = b.Substr(0, b.IndexOf(bb[0]));
+
+ if (aaa == bbb)
+ {
+ if (aa[0] == bb[0])
+ {
+ return NaturalCompare(a.Substr(aaa.Length + aa[0].Length), b.Substr(bbb.Length + bb[0].Length));
+ }
+ else
+ {
+ int ia = int.Parse(aa[0], 10), ib = int.Parse(bb[0], 10);
+ if (ia == ib)
+ {
+ return bb[0].Length - aa[0].Length;
+ }
+ else
+ {
+ return ia - ib;
+ }
+ }
+ }
+ }
+
+ return a.CompareTo(b);
+ }
}
}
View
2  source/scriptsharp/Widget/FoldersWidget.cs
@@ -23,7 +23,7 @@ public FoldersWidget(jQueryObject parent, FolderJson[] folders, string folderPat
((List<FolderJson>)(object)folders).Sort(delegate(FolderJson a, FolderJson b)
{
- return a.name.CompareTo(b.name); ;
+ return Utility.NaturalCompare(a.name, b.name);
});
foreach (FolderJson folder in folders)
Please sign in to comment.
Something went wrong with that request. Please try again.