view framework.vistxt @ 138:1411de6050e1

First stab at transaction data structures, needs work
author Mike Pavone <pavone@retrodev.com>
date Tue, 16 Nov 2010 21:53:18 -0500
parents 76568becd6d6
children
line wrap: on
line source

Import webserver.vistxt

Framework Handler(8,0)
|:
	page <- New@Page[title(6), path(1), use session(7), queryvars(3), headers(4)]
	out list <- [handler(5)]Do[ [[New@List[]]Append[page]]Append[path(1)] ]
	handler page <- [out list]Index[0]
	If[[request type(2)] = ["POST"]]
	|:
		final page <- Process POST[handler page, con(0), headers(4)]
	:||:
		final page <- Val[handler page]
	:|
	string,headers <- [final page]Render
	
	[HTTP OK[client(0), Get Content Type[".html"], [string]Length, headers]
	]Put String[string]
:|

Handler Fixer(1,1)
|:
	If[[Type Of[handler(0)]] = ["List"]]
	|:
		out(0) <- [[["Framework Handler"]Set Input[5, [handler(0)]Index[0]]]Set Input[6, [handler(0)]Index[1]]]Set Input[7, [handler(0)]Index[2]]
	:||:
		out(0) <- handler(0)
	:|
:|

Start Web(1,0)
|:
	Print["Starting Rhope Web Server"]
	Listen on Port[80,["Connection Start"]Set Input[1, Map[handlers(0),"Handler Fixer"]]]
	Wait Forever[]
:|

Get Class(1,1)
|:
	If[[[[container(0)]Class >>]Length] > [0]]
	|:
		class(0) <- [[" class=\""]Append[[container(0)]Class >>]]Append["\""]
	:||:
		class(0) <- ""
	:|
:|

Company Web Event
|:
	Event Name
	Origin
	Data
:|

New@Web Event(3,1)
|:
	out(0) <- [[[Build["Web Event"]]Event Name <<[name(0)]]Origin <<[origin(1)]]Data <<[data(2)]	
:|

Company Web Container
|:
	Tag Name
	Class
	Propagate Events
	Children
	Handlers
	Named Children
	Session
	Use Session
:|

New@Web Container(1,1)
|:
	out(0) <- [[[[[[[Build["Web Container"]
	]Tag Name <<["div"]
	]Class <<[class(0)]
	]Propagate Events <<[No]
	]Children <<[New@List[]]
	]Named Children <<[New@Dictionary[]]
	]Handlers <<[New@Dictionary[]]
	]Use Session <<[No]
:|

Name@Web Container(1,2)
|:
	none(1) <- cont(0)
:|
	
Render Child(2,1)
|:
	out(0) <- [start(0)]Append[[container(1)]Render]
:|

Set Session@Web Container(2,1)
|:
	out(0) <- [
				[
					[container(0)]Use Session <<[Yes]
				]Session <<[session(1)]
			]Children <<[ Map[ [container(0)]Children >>, ["Set Session"]Set Input[1, session(1)] ] ]
:|

Set Handler@Web Container(3,1)
|:
	out(0) <- [container(0)]Handlers <<[ [[container(0)]Handlers >>	]Set[event name(1), handler(2)] ]
:|

Render@Web Container(1,2)
|:
	out(0) <- [[[[[[["<"]Append[ [container(0)]Tag Name >> ]
		]Append[Get Class[container(0)]]
		]Append[">\n\t"]
		]Append[Fold[["Render Child"]<String@Worker, "", [container(0)]Children >>]]
		]Append["\n</"]
		]Append[ [container(0)]Tag Name >> ]
		]Append[">\n"]
:|

Container Event Handler(2,2)
|:
	event <- [events(1)]Index[index(2)]
	[[container(0)]Handlers >>]Index[ [event]Event Name >>]
	|:
		result list <- [~]Do[
				[[New@List[]]Append[container(0)]]Append[event]
		]
		new container <- [result list]Index[0]
		[result list]Index[1]
		|:
			events(1) <- [result events]Append[~]
		:||:
			events(1) <- Val[result events]
		:|
	:||:
		new container <- container(0)
		events(1) <- Val[result events]
	:|
	
	[events(1)]Next[index(2)]
	|:
		cont(0), result events <- Container Event Handler[new container, events(1), ~]
	:||:
		cont(0) <- Val[new container]
		result events <- New@List[]
	:|
:|

Container Postback Helper(4,2)
|:
	,current events <- [[[container(0)]Children >>]Index[index(2)]]Postback[post data(1)]
	|:
		new container <- [container(0)]Children <<[[[container(0)]Children >>]Set[index(2), ~]]
	:|
	events <- Concatenate[events(3), current events]
	[[new container]Children >>]Next[index(2)]
	|:
		out(0), events(1) <- Container Postback Helper[new container, post data(1), ~, events]
	:||:
		[events]First
		|:
			out(0), newevents <- Container Event Handler[new container, events, ~]
			events(1) <- Concatenate[events, newevents]
		:||:
			out(0) <- Val[new container]
			events(1) <- Val[events]
		:|
	:|
:|

Postback@Web Container(2,2)
|:
	[[container(0)]Children >>]First
	|:
		out(0), events <- Container Postback Helper[container(0), post data(1), ~, New@List[]]
		If[[container(0)]Propagate Events >>]
		|:
			events(1) <- Val[events]
		:||:
			events(1) <- New@List[]
		:|
	:||:
		out(0) <- container(0)
		events(1) <- New@List[]
	:|
:|
	
Add Child(2,1)
|:
	If[[cont(0)]Use Session >>]
	|:
		child <- [child(1)]Set Session[[cont(0)]Session >>]
	:||:
		child <- Val[child(1)]
	:|
	with child <- [cont(0)]Children <<[ [[cont(0)]Children >>]Append[child] ]
	
	[child]Name
	|:
		out(0) <- [with child]Named Children <<[ [[with child]Named Children >>]Set[~, [[[with child]Children >>]Length] - [1]] ]
	:||:
		out(0) <- Val[with child]
	:|
:|

Get Child By Name(2,2)
|:
	,not found(1) <- [[container(0)]Named Children >>]Index[name(1)]
	|:
		out(0) <- [[container(0)]Children >>]Index[~]
	:|
:|
	
Company Page
|:
	Title
	URL
	CSS
	Children
	Named Children
	Handlers
	Use Session
	Session
	Session ID
:|

Set Handler@Page(3,1)
|:
	out(0) <- [container(0)]Handlers <<[ [[container(0)]Handlers >>	]Set[event name(1), handler(2)] ]
:|
	
New@Page(5,1)
|:
	page <- [[[[[[[Build["Page"]
	]Title <<[title(0)]
	]URL <<[url(1)]
	]CSS <<[[New@List[]]Append["/default.css"]]
	]Children <<[New@List[]]
	]Named Children <<[New@Dictionary[]]
	]Handlers <<[New@Dictionary[]]
	]Use Session <<[use session(2)]
	If[use session(2)]
	|:
		Load@Session[queryvars(3), headers(4)]
		|:
			out(0) <- [[page]Session <<[~]]Session ID <<[ [~]Session ID>>]
		:|
	:||:
		out(0) <- Val[page]
	:|
:|

Get Action@Page(1,1)
|:
	If[[page(0)]Use Session>>]
	|:	
		[[page(0)]Session >>]Get Link Params
		|:
			out(0) <- [[[page(0)]URL >>]Append["?"]]Append[~]
		:||:
			out(0) <- [page(0)]URL >>
		:|
	:||:
		out(0) <- [page(0)]URL >>
	:|
:|
	
Render@Page(1,2)
|:
	out(0) <- [[[[[[["<html>\n\t<head>\n\t\t<title>"]Append[[page(0)]Title >>]
		]Append["</title>\n\t\t<link rel=\"stylesheet\" href=\""]
		]Append[[[page(0)]CSS >>]Join["\">\n\t\t<link rel=\"stylesheet\" href=\""]]
		]Append["\">\n\t</head>\n\t<body>\n\t<form method=\"POST\" action=\""]
		]Append[[[page(0)]Get Action]Append["\">\n"]]
		]Append[Fold[["Render Child"]<String@Worker, "", [page(0)]Children >>]]
		]Append["\t</form>\n\t</body>\n</html>"]
	If[[page(0)]Use Session>>]
	|:
		headers(1) <- [[page(0)]Session >>]Finalize[New@Dictionary[]]
	:||:
		headers(1) <- New@Dictionary[]
	:|
:|

Clear Children(1,1)
|:
	out(0) <- [[page(0)]Children <<[New@List[]]]Named Children <<[New@Dictionary[]]
:|

Set@Page(3,1)
|:
	out(0) <- [page(0)]Session <<[ [[page(0)]Session >>]Set[key(1), val(2)] ]
:|

Index@Page(2,2)
|:
	out(0),not found(1) <- [[page(0)]Session >>]Index[key(1)]
:|

First@Page(1,2)
|:
	first(0),not found(1) <- [[page(0)]Session >>]First
:|

Next@Page(2,2)
|:
	next(0),not found(1) <- [[page(0)]Session >>]Next[last(1)]	
:|

Add CSS@Page(1,1)
|:
	out(0) <- [page(0)]CSS <<[ [[page(0)]CSS >>]Append[css(1)] ]
:|

Clear CSS@Page(1,1)
|:
	out(0) <- [page(0)]CSS <<[New@List[]]	
:|

Decode Helper Decode(3,1)
|:
	code,rest <- [[list(0)]Index[index(2)]]Slice[2]
	newlist <- [destlist(1)]Set[index(2), [[""]Put Byte[From Hex@Whole Number[code]]]Append[rest]]
	[list(0)]Next[index(2)]
	|:
		out(0) <- Decode Helper Decode[list(0), newlist, ~]
	:||:
		out(0) <- Val[newlist]
	:|
:|

Decode Helper Straight(3,1)
|:
	newlist <- [destlist(1)]Set[index(2), [list(0)]Index[index(2)]]
	[list(0)]Next[index(2)]
	|:
		out(0) <- Decode Helper Decode[list(0), newlist, ~]
	:||:
		out(0) <- Val[newlist]
	:|
:|

URL Decode(1,1)
|:
	parts <- [val(0)]Split["%"]
	[parts]First
	|:
		val(0) <- [Decode Helper Straight[parts, New@List[], ~]]Join[""]
	:||:
		val(0) <- val(0)
	:|
:|

URL Encode Path(1,1)
|:
	out(0) <- [[[[string(0)]Replace["%","%25"]]Replace[" ","%20"]]Replace["/","%2F"]]Replace["?","%3F"]
:|

Decode Pair(2,2)
|:
	val(0) <- URL Decode[val(0)]
	key(1) <- URL Decode[key(1)]
:|

Process POST(3,1)
|:
	[con(1)]Get FString[[headers(2)]Index["Content-Length"]] |::|
	|:
		post string <- [~]Replace["+"," "]
	:|
	post data <- Key Value Map[Dict Split[post string, "=", "&"], ["Decode Pair"]<String@Worker]
	out(0) <- [page(0)]Postback[post data]
:|

Postback@Page(2,2)
|:
	[[container(0)]Children >>]First
	|:
		out(0), events(1) <- Container Postback Helper[container(0), post data(1), ~, New@List[]]
	:||:
		page(0) <- page(0)
	:|
	events(1) <- New@List[]
:|
	
Company Web Text
|:
	Text
	Enclosing Tag
:|
	
New@Web Text(2,1)
|:
	out(0) <- [[Build["Web Text"]]Text <<[text(0)]]Enclosing Tag <<[tag(1)]
:|

Name@Web Text(1,2)
|:
	none(1) <- text(0)
:|

Escape HTML Text(1,1)
|:
	out(0) <- [[[string(0)]Replace["&","&amp;"]]Replace["<", "&lt;"]]Replace[">", "&gt;"]
:|
	
Render@Web Text(1,2)
|:
	processed text <- [Escape HTML Text[[text(0)]Text >>]]Replace["\n","<br>\n\t"]
	If[[[[text(0)]Enclosing Tag >>]Length] = [0]]
	|:
		out(0) <- Val[processed text]
	:||:
		out(0) <- [[[["<"]Append[[text(0)]Enclosing Tag >>]]Append[">"]]Append[processed text]]Append[[["</"]Append[[text(0)]Enclosing Tag >>]]Append[">"]]
	:|
:|

Postback@Web Text(2,2)
|:
	out(0) <- in(0) 
	events(1) <- New@List[]
:|

Set Session@Web Text(2,1)
|:
	(0) <- (0)
:|

Render@String(1,2)
|:
	out(0) <- [New@Web Text[string(0),""]]Render	
:|

Name@String(1,2)
|:
	none(1) <- string(0)
:|

Postback@String(2,2)
|:
 	out(0) <- in(0)
 	events(1) <- New@List[]
:|

Set Session@String(2,1)
|:
	(0) <- (0)
:|

Company Web Field
|:
	Name
	Value
	Type
	Class
:|

Name@Web Field(1,2)
|:
	name(0) <- [field(0)]Name >>	
:|

New@Web Field(3,1)
|:
	out(0) <- [[[[Build["Web Field"]]Name <<[name(0)]]Value <<[value(1)]]Type <<[type(2)]]Class <<[""]
:|

Set Session@Web Field(2,1)
|:
	(0) <- (0)
:|

Render@Web Field(1,2)
|:
	If[[[field(0)]Type >>] = ["multiline"]]
	|:
		out(0) <- [[[[[["<textarea name=\""]Append[[field(0)]Name >>]]Append["\""]]Append[Get Class[field(0)]]]Append[">"]]Append[[field(0)]Value >>]]Append["</textarea>"]
	:||:
		out(0) <- [[[[[[[["<input type=\""]Append[[field(0)]Type >>]]Append["\" name=\""]]Append[[field(0)]Name >>]]Append["\""]]Append[Get Class[field(0)]]]Append[" value=\""]]Append[[field(0)]Value >>]]Append["\">"]
	:|
	
:|

Postback@Web Field(2,2)
|:
	[post data(1)]Index[[field(0)]Name >>]
	|:
		out(0) <- [field(0)]Value <<[~]

		If[[[field(0)]Value >>] = [~]] 
		|:
			event(1) <- New@List[]
		:||:
			event(1) <- [New@List[]]Append[ New@Web Event["change", [field(0)]Name >>, [field(0)]Value >>] ]
		:|
	:||:
		out(0) <- field(0)
		event(1) <- New@List[]
	:|
:|

Company Web Button
|:
	Name
	Label
	Class
:|

New@Web Button(2,1)
|:
	out(0) <- [[[Build["Web Button"]]Name <<[name(0)]]Label <<[label(1)]]Class <<[""]	
:|

Name@Web Button(1,2)
|:
	name(0) <- [button(0)]Name >>
:|

Set Session@Web Button(2,1)
|:
	(0) <- (0)
:|

Postback@Web Button(2,2)
|:
	out(0) <- button(0)
	[post data(1)]Index[[button(0)]Name >>]
	|:
		events(1) <- [New@List[]]Append[ New@Web Event["click", [button(0)]Name >>, 0] ]
	:||:
		events(1) <- New@List[]
	:|
:|

Render@Web Button(1,2)
|:
	out(0) <- [[[[[["<input type=\"submit\" name=\""]Append[[field(0)]Name >>]]Append["\""]]Append[Get Class[button(0)]]]Append[" value=\""]]Append[[button(0)]Label >>]]Append["\">"]
:|

Company Session
|:
	Session ID
	IP Address
	Use Cookies
	Data
:|

Get Unique ID(0,1) uses Session
|:
	out(0) <- [[[::ID]<Whole Number@String]Append["_"]]Append[Random[]]
	::ID <- [::ID]+[1]
:|

New@Session(0,1)
|:
	out(0) <- [[[Build["Session"]]Session ID <<[Get Unique ID[]]]Use Cookies <<[No]]Data <<[New@Dictionary[]]
:|

Load@Session(2,1) uses Session
|:
	,checkquery <- [headers(1)]Index["Cookie"]
	|:
		parts <- Dict Split[~, "=", "; "]
		,checkquery <- [parts]Index["session_id"]
		|:
			,checkquery <- [::Sessions]Index[~]
			|:
				out(0) <- [~]Use Cookies <<[Yes]
			:|
		:|
	:|
	
	
	checkquery
	|:
		,makenew <- [queryvars(0)]Index["session_id"]
		|:
			out(0), makenew <- [::Sessions]Index[~]
		:|
	:|
	
	makenew
	|:
		out(0) <- New@Session[]
	:|
:|

Get Link Params@Session(1,2)
|:
	If[[session(0)]Use Cookies >>]
	|:
		no params(1) <- No
	:||:
		out(0) <- ["session_id="]Append[[session(0)]Session ID >>]
	:|
:|

Set@Session(3,1)
|:
	out(0) <- [session(0)]Data <<[ [[session(0)]Data >>]Set[key(1), val(2)] ]
:|

Index@Session(2,2)
|:
	out(0),not found(1) <- [[session(0)]Data >>]Index[key(1)]
:|

First@Session(1,2)
|:
	first(0),not found(1) <- [[session(0)]Data >>]First
:|

Next@Session(2,2)
|:
	next(0),not found(1) <- [[session(0)]Data >>]Next[last(1)]	
:|

Init Session Store(0,1)
|:
	Init Store["Session"]
	out(0) <- 0
:|

Set Session Store(0,0) uses Session
|:
	::ID <- 1
	::Sessions <- New@Dictionary[]
:|

Init Sessions(0,1)
|:
	Init Session Store[] |:
	Set Session Store[] :|
	out(0) <- 0
:|

Finalize@Session(2,1) uses Session
|:
	::Sessions <- [::Sessions]Set[[session(0)]Session ID >>, session(0)]
	out headers(0) <- [headers(1)]Set["Set-Cookie", ["session_id="]Append[[session(0)]Session ID >>]]
:|

Company Web Link
|:
	Text
	Target
	Class
	Query Params
:|

New@Web Link(2,1)
|:
	out(0) <- [[[[Build["Web Link"]]Text <<[text(0)]]Target <<[target(1)]]Class <<[""]]Query Params <<[New@Dictionary[]]	
:|
	

With Session@Web Link(3,1)
|:
	New@Web Link[text(0), target(1)]
	|:
		out(0) <- [~]Query Params <<[[[~]Query Params >>]Set["session_id", [session(2)]Session ID >>]]
	:|
:|

Render@Web Link(1,2)
|:
	[[link(0)]Query Params>>]First
	|:
		queryvars <- ["?"]Append[Key Value Join[[link(0)]Query Params>>, "=","&"]]
	:||:
		queryvars <- ""
	:|
	out(0) <- [[[[[[["<a href=\""]Append[[link(0)]Target>>]]Append[queryvars]]Append["\""]
				]Append[Get Class[link(0)]]]Append[">"]]Append[Escape HTML Text[[link(0)]Text>>]]]Append["</a>"]
:|

Postback@Web Link(2,2)
|:
	out(0) <- in(0)
	events(1) <- New@List[]	
:|

Name@Web Link(1,2)
|:
	none(1) <- link(0)
:|

Set Session@Web Link(2,1)
|:
	If[[[[link(0)]Target >>]Slice[7]] = ["http://"]]
	|:
		out(0) <- link(0)
	:||:
		If[[session(1)]Use Cookies >>]
		|:
			out(0) <- link(0)
		:||:
			out(0) <- [link(0)]Query Params <<[[[link(0)]Query Params >>]Set["session_id", [session(1)]Session ID>>]]
		:|
	:|
:|

Company Web Table
|:
	Headers
	Data
:|

New@Web Table(2,1)
|:
	out(0) <- [[Build["Web Table"]]Headers <<[headers(0)]]Data <<[data(1)]
:|

Name@Web Table(1,2)
|:
	none(1) <- link(0)
:|

Set Session@Web Table(2,1)
|:
	(0) <- (0)
:|

Postback@Web Table(2,2)
|:
	(0) <- (0)
	(1) <- {}
:|

Make Header Row(2,1)
|:
	out(0) <- [[[string(0)]Append["\t\t\t<th>"]]Append[header(1)]]Append["</th>\n"]
:|

Get Header Row@Web Table(1,1)
|:
	If[[[[table(0)]Headers >>]Length] > [0]]
	|:
		out(0) <- [Fold[["Make Header Row"]<String@Worker, "\t\t<tr>\n", [table(0)]Headers >>]]Append["\t\t</tr>\n"]
	:||:
		out(0) <- ""
	:|
:|

Make Table Cell(2,1)
|:
	out(0) <- [[[string(0)]Append["\t\t\t<td>"]]Append[[cell(1)]Render]]Append["</td>\n"]
:|

Make Table Row(2,1)
|:
	out(0) <- [Fold[["Make Table Cell"]<String@Worker, [string(0)]Append["\t\t<tr>\n"], row(1)]]Append["\t\t</tr>"]
:|

Render@Web Table(1,2)
|:
	out(0) <- [
				[
					["\t<table>\n"]Append[[table(0)]Get Header Row]
				]Append[ Fold[["Make Table Row"]<String@Worker, "", [table(0)]Data >>] ]
			]Append["\t</table>\n"]
:|