From e72dffe3a211d94a123a9a0b6843ae9b4b9838f5 Mon Sep 17 00:00:00 2001 From: pho Date: Fri, 1 Aug 2008 18:18:01 +0900 Subject: [PATCH] More users thingy darcs-hash:20080801091801-62b54-f601f90bf662aeb4061cb7625a0a2fd7fec4fda0.gz --- Rakka/Resource/Users.hs | 55 +++-------- js/Makefile | 4 +- js/jquery-dom.js | 18 ++-- js/systemConfig.js | 203 ++++++++++++++++++++++++++-------------- 4 files changed, 157 insertions(+), 123 deletions(-) diff --git a/Rakka/Resource/Users.hs b/Rakka/Resource/Users.hs index 7eb0e13..a4bf602 100644 --- a/Rakka/Resource/Users.hs +++ b/Rakka/Resource/Users.hs @@ -7,12 +7,9 @@ import Control.Monad import Control.Monad.Trans import Data.Maybe import Network.HTTP.Lucu -import Network.URI hiding (path) import Rakka.Authorization import Rakka.Environment import Rakka.Resource -import Rakka.SystemConfig -import System.FilePath import Text.XML.HXT.Arrow hiding (when) @@ -31,17 +28,11 @@ resUsers env {- [GET /users] - - - - - - - ... - - - - + + + + ... + [GET /users/foo] 204 No Content @@ -63,42 +54,20 @@ handleGet env where returnUserList :: Resource () returnUserList - = do BaseURI baseURI <- getSysConf (envSysConf env) - users <- liftIO $ getUserList $ envAuthDB env + = do users <- liftIO $ getUserList $ envAuthDB env runIdempotentA' $ proc () -> do tree <- ( eelem "/" - += ( eelem "rdf:RDF" - += sattr "xmlns" "http://cielonegro.org/terms/" - += sattr "xmlns:rdf" "http://www.w3.org/1999/02/22-rdf-syntax-ns#" - += ( eelem "rdf:Description" - += sattr "rdf:about" (uriToString id (mkUserURI baseURI Nothing) "") - += ( eelem "users" - += ( eelem "rdf:Bag" - += ( constL users - >>> - ( eelem "rdf:li" - += attr "rdf:resource" ( arr ( \ name -> - uriToString - id - (mkUserURI baseURI $ Just name) - "" - ) - >>> - mkText - ) - ) - ) - ) - ) + += ( eelem "users" + += ( constL users + >>> + ( eelem "user" + += attr "id" mkText + ) ) ) ) -< () returnA -< outputXml tree - mkUserURI :: URI -> Maybe String -> URI - mkUserURI baseURI Nothing = baseURI { uriPath = uriPath baseURI "users" } - mkUserURI baseURI (Just x) = baseURI { uriPath = uriPath baseURI "users" x } - returnUser :: String -> Resource () returnUser name = do users <- liftIO $ getUserList $ envAuthDB env diff --git a/js/Makefile b/js/Makefile index e1e6b0c..891e9eb 100644 --- a/js/Makefile +++ b/js/Makefile @@ -36,7 +36,7 @@ clean: rm -f ../Rakka/Resource/JavaScript.hs packed.js $(JQUERY_PACKED) -yuicompressor.jar: - @echo "Error: yuicompressor.jar has to be placed on this directory." +$(COMPRESSOR): + @echo "Error: $(COMPRESSOR) has to be placed on this directory." @echo " See http://www.julienlecomte.net/yuicompressor/" @exit 1 diff --git a/js/jquery-dom.js b/js/jquery-dom.js index 0127017..70b07e8 100644 --- a/js/jquery-dom.js +++ b/js/jquery-dom.js @@ -26,7 +26,7 @@ $.NBSP = '\u00a0'; $._createNode = function( tag, args ) { var fix = { 'class':'className', 'Class':'className' }; var e; - try { + //try { var attrs = args[0] || {}; e = document.createElement( tag ); for( var attr in attrs ) { @@ -40,13 +40,13 @@ $._createNode = function( tag, args ) { else for( var j = 0; j < arg.length; j++ ) append( arg[j] ); } - } - catch( ex ) { - alert( 'Cannot create <' + tag + '> element:\n' + - args.toSource() + '\n' + args ); - e = null; - } - + //} + //catch( ex ) { + //alert( 'Cannot create <' + tag + '> element:\n' + + // args.toSource() + '\n' + args ); + //e = null; + //} + function append( arg ) { if( arg == null ) return; var c = arg.constructor; @@ -56,6 +56,6 @@ $._createNode = function( tag, args ) { } e.appendChild( arg ); } - + return e; }; diff --git a/js/systemConfig.js b/js/systemConfig.js index 5fc8303..16002bb 100644 --- a/js/systemConfig.js +++ b/js/systemConfig.js @@ -1,79 +1,102 @@ (function () { - var identityDecoder = function (src) { - return src; - }; + var identityDecoder = function (src) { + return src; + }; - var identityEncoder = function (src) { - return src; - }; + var identityEncoder = function (src) { + return src; + }; - var mapDecoder = function (src) { - var map = {}; - var lines = src.split(/\n/); + var mapDecoder = function (src) { + var map = {}; + var lines = src.split(/\n/); - $.each(lines, function () { - var m = this.match(/^(\S+)\s+(\S+)$/); + $.each(lines, function () { + var m = this.match(/^(\S+)\s+(\S+)$/); - map[ m[1] ] = m[2]; - }); + map[ m[1] ] = m[2]; + }); - return map; - }; + return map; + }; - var mapEncoder = function (map) { - var lines = []; + var mapEncoder = function (map) { + var lines = []; - $.each(map, function (key) { - lines.push(key + " " + this); - }); + $.each(map, function (key) { + lines.push(key + " " + this); + }); - return lines.join("\n"); - }; + return lines.join("\n"); + }; - var boolDecoder = function (src) { - return src == "*"; - }; + var boolDecoder = function (src) { + return src == "*"; + }; - var boolEncoder = function (bool) { - return bool ? "*" : ""; - }; + var boolEncoder = function (bool) { + return bool ? "*" : ""; + }; - var decoder_of = { - siteName : identityDecoder, - baseURI : identityDecoder, - defaultPage: identityDecoder, - styleSheet : identityDecoder, - languages : mapDecoder, - globalLock : boolDecoder - }; + var decoder_of = { + siteName : identityDecoder, + baseURI : identityDecoder, + defaultPage: identityDecoder, + styleSheet : identityDecoder, + languages : mapDecoder, + globalLock : boolDecoder + }; - var encoder_of = { - siteName : identityEncoder, - baseURI : identityEncoder, - defaultPage: identityEncoder, - styleSheet : identityEncoder, - languages : mapEncoder, - globalLock : boolEncoder - }; + var encoder_of = { + siteName : identityEncoder, + baseURI : identityEncoder, + defaultPage: identityEncoder, + styleSheet : identityEncoder, + languages : mapEncoder, + globalLock : boolEncoder + }; - var cachedConf = null; + var cachedConf = null; - var isValidBaseURI = function (str) { - parseUri.options.strictMode = true; - var uri = parseUri(str); + var isValidBaseURI = function (str) { + parseUri.options.strictMode = true; + var uri = parseUri(str); - return (uri.protocol != "" && - uri.authority != "" && - uri.path != "" && - uri.path.match(/\/$/) && - uri.query == "" && - uri.anchor == ""); - }; + return (uri.protocol != "" && + uri.authority != "" && + uri.path != "" && + uri.path.match(/\/$/) && + uri.query == "" && + uri.anchor == ""); + }; - var isValidMap = function (src) { - return src.match(/^\S+\s+\S+(?:\n\S+\s+\S+)*\n?$/) != null; - }; + var isValidMap = function (src) { + return src.match(/^\S+\s+\S+(?:\n\S+\s+\S+)*\n?$/) != null; + }; + + Rakka.getUserList = function () { + var users = []; + + $.ajax({ + type: "GET", + url: Rakka.baseURI + "users", + async: false, + beforeSend: function (req) { + Rakka.setAuthorization(req); + }, + success: function (xml) { + $(xml).find("user").each(function () { + users.push(this.getAttribute("id")); + }); + }, + error: function (req) { + throw new Error(req.status + " " + req.statusText); + } + }); + + return users; + }; Rakka.getSystemConfig = function () { if (cachedConf != null) { @@ -108,11 +131,9 @@ return conf; }; - Rakka.showConfigPanel = function () { - var conf = Rakka.getSystemConfig(); - var $area = Rakka.switchScreen(); - - $area.append($.H1({}, "Configuration")); + var appendConfigPanel = function ($area) { + var conf = Rakka.getSystemConfig(); + $area.append($.H1({}, "Configuration")); var fldSiteName = $.INPUT({type: "text", value: conf.siteName}); @@ -271,11 +292,55 @@ $area.append(configPanel); }; - $(document).ready(function () { - $("input.configButton") - .click(function () { - Rakka.showConfigPanel(); - }); - }); + var appendUsersPanel = function ($area) { + $area.append($.H2({}, "Users")); + $area.append($.H3({}, "Existing Users")); + + var tbody = $.TBODY(); + + var usersPanel + = $.TABLE({className: "pageEditor"}, + $.THEAD({}, + $.TR({}, + $.TH({}, "User ID"), + $.TH({}, "Change Password"), + $.TH({}, "Delete User") + ) + ), + tbody + ); + + var updateUserList = function () { + var users = Rakka.getUserList(); + + $(tbody).empty(); + + $.each(users, function () { + var id = this; + var tr = $.TR({}, + $.TD({}, id), + $.TD({}, ""), + $.TD({}, "") + ); + tbody.appendChild(tr); + }); + }; + updateUserList(); + + $area.append(usersPanel); + }; + + Rakka.showConfigPanel = function () { + var $area = Rakka.switchScreen(); + + appendConfigPanel($area); + appendUsersPanel($area); + }; + $(document).ready(function () { + $("input.configButton") + .click(function () { + Rakka.showConfigPanel(); + }); + }); })(); \ No newline at end of file -- 2.40.0