Sorting options in module config
authorJamie Cameron <jcameron@webmin.com>
Mon, 14 Dec 2009 22:18:42 +0000 (14:18 -0800)
committerJamie Cameron <jcameron@webmin.com>
Mon, 14 Dec 2009 22:18:42 +0000 (14:18 -0800)
custom/CHANGELOG
custom/acl_security.pl
custom/config.info
custom/custom-lib.pl
custom/index.cgi

index 3342d3d..063edfb 100644 (file)
@@ -26,3 +26,4 @@ All links to commands are via an ID number rather than an index, which makes the
 Added a parameter-level option to make the parameter mandatory.
 ---- Changes since 1.500 ----
 Added a button to clone an existing command when editing.
+The sort order of commands can now be set on the Module Config page, and is respected in the Webmin Users module.
index e33e0f0..708cd26 100755 (executable)
@@ -14,8 +14,8 @@ printf "<input type=radio name=cmds_def value=0 %s> %s\n",
        $mode == 0 ? 'checked' : '', $text{'acl_csel'};
 printf "<input type=radio name=cmds_def value=2 %s> %s<br>\n",
        $mode == 2 ? 'checked' : '', $text{'acl_cexcept'};
-print "<select name=cmds size=5 multiple width=200>\n";
-local @cmds = &list_commands();
+print "<select name=cmds size=10 multiple width=200>\n";
+local @cmds = &sort_commands(&list_commands());
 local ($c, %ccan);
 map { $ccan{$_}++ } split(/\s+/, $_[0]->{'cmds'});
 foreach $c (@cmds) {
index 545c80d..53bd8aa 100644 (file)
@@ -4,4 +4,4 @@ width=Width of file editor window,3,Default (80 chars)
 height=Height of file editor window,3,Default (20 chars)
 wrap=File editor wrap mode,1,-Default (Soft),hard-Hard,off-Off
 columns=Columns to display commands in,1,2-2,1-1
-line2=System configuration,11
+sort=Sort commands by,1,desc-Command name,html-Description,-Command ordering
index 38c89c3..a5ebb85 100755 (executable)
@@ -100,6 +100,22 @@ closedir(DIR);
 return @rv;
 }
 
+# sort_commands(&command, ...)
+# Sorts a list of custom commands by the user-defined order
+sub sort_commands
+{
+local @cust = @_;
+if ($config{'sort'}) {
+       @cust = sort { lc($a->{$config{'sort'}}) cmp
+                      lc($b->{$config{'sort'}}) } @cust;
+       }
+else {
+       @cust = sort { local $o = $b->{'order'} <=> $a->{'order'};
+                      $o ? $o : $a->{'id'} <=> $b->{'id'} } @cust;
+       }
+return @cust;
+}
+
 # get_command(id)
 # Returns the command with some ID
 sub get_command
index 6955f4c..de16ae5 100755 (executable)
@@ -6,8 +6,7 @@ require './custom-lib.pl';
 &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1);
 
 @cust = grep { &can_run_command($_) } &list_commands();
-@cust = sort { local $o = $b->{'order'} <=> $a->{'order'};
-              $o ? $o : $a->{'id'} <=> $b->{'id'} } @cust;
+@cust = &sort_commands(@cust);
 
 # Build links
 @links = ( );