Commit 69cfdd07ccec299efc3944377f4d62e2ef472458

Authored by Georg Hopp
1 parent 1af8b32f

moved several static content to various files

  1 +<?xml version="1.0" encoding="iso-8859-1"?>
  2 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3 +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4 +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5 + <head>
  6 + <title>My own little Web-App</title>
  7 + <link rel="stylesheet" type="text/css" href="/assets/style/common">
  8 + <script type="text/javascript" src="/assets/js/jquery"></script>
  9 + <script type="text/javascript" src="/assets/js/serverval"></script>
  10 + <script>
  11 + //<![CDATA[
  12 + $(document).ready(function() {
  13 + var sval = new ServerVal("#randval");
  14 +
  15 + $("ul#menu li:eq(0)").click(function() {
  16 + sval.start();
  17 + });
  18 +
  19 + $("#randval").click(function() {
  20 + sval.stop();
  21 + });
  22 + });
  23 + //]]>
  24 + </script>
  25 + </head>
  26 + <body>
  27 + <ul id="menu">
  28 + <li>random Value</li>
  29 + </ul>
  30 + <div id="randval" class="hide">
  31 + <span class=\"small">
  32 + Value created at: <br />
  33 + <span></span><br>
  34 + Next value in: <span></span><br />
  35 + </span>
  36 + Value: <span></span>
  37 + </div>
  38 + <div id="main">
  39 + <h1>Testpage</h1>
  40 + Welcome You!!!<br />
  41 + <img src="/image/me" />
  42 + </div>
  43 + <hr />
  44 + <div id="msg"></div>
  45 + </body>
  46 +</html>
  47 +
  48 +<!-- vim: set ts=4 sw=4: -->
... ...
  1 +function ServerVal(eId)
  2 +{
  3 + this.eId = eId;
  4 + this.eCtime = eId + " span:eq(1)";
  5 + this.eVnext = eId + " span:eq(2)";
  6 + this.eValue = eId + " span:eq(3)";
  7 +
  8 + this.interval = null;
  9 + this.ctime = null;
  10 + this.vnext = 0;
  11 + this.value = null;
  12 +}
  13 +
  14 +ServerVal.prototype.loadJSON = function(data)
  15 +{
  16 + this.ctime = new Date(data.ctime * 1000);
  17 + this.vnext = data.vnext;
  18 + this.value = data.value;
  19 +
  20 + this.show();
  21 +}
  22 +
  23 +ServerVal.prototype.show = function()
  24 +{
  25 + $(this.eCtime).empty().append(this.ctime.toString());
  26 + $(this.eVnext).empty().append(this.vnext);
  27 + $(this.eValue).empty().append(this.value);
  28 +
  29 + if ($(this.eId).hasClass("hide")) {
  30 + $(this.eId).removeClass("hide");
  31 + }
  32 +}
  33 +
  34 +ServerVal.prototype.start = function()
  35 +{
  36 + this.interval = setInterval($.proxy(this.process, this), 1000);
  37 +}
  38 +
  39 +ServerVal.prototype.process = function()
  40 +{
  41 + if (0 >= this.vnext) {
  42 + $.getJSON("/randval/", $.proxy(this.loadJSON, this));
  43 + }
  44 +
  45 + else {
  46 + this.vnext--;
  47 + $(this.eVnext).empty().append(this.vnext);
  48 + }
  49 +}
  50 +
  51 +ServerVal.prototype.stop = function()
  52 +{
  53 + $(this.eId).addClass("hide");
  54 +
  55 + clearInterval(this.interval);
  56 + this.interval = null;
  57 + this.vnext = 0;
  58 +}
  59 +
  60 +// vim: set ts=4 sw=4:
... ...
  1 +div#randval {
  2 + left: 200px;
  3 + top: 100px;
  4 + padding: 10px;
  5 + position: fixed;
  6 + background-color: white;
  7 + border: 1px solid black;
  8 + border-radius: 10px;
  9 +}
  10 +
  11 +div.hide#randval {
  12 + top: -500px;
  13 +}
  14 +
  15 +.small {
  16 + font-size: small;
  17 +}
  18 +
  19 +ul#menu {
  20 + list-style: none inside;
  21 + margin: 0px;
  22 + padding: 1px 0px 0px;
  23 + border-bottom: 1px solid #7b0b2b;
  24 + display: inline-block;
  25 + width: 100%;
  26 +}
  27 +
  28 +ul#menu li {
  29 + padding: 2px;
  30 + border-top-left-radius: 10px;
  31 + border-top-right-radius: 10px;
  32 + border-top: 1px solid #7b0b2b;
  33 + border-left: 1px solid #7b0b2b;
  34 + border-right: 1px solid #7b0b2b;
  35 + text-align: center;
  36 + cursor: pointer;
  37 +
  38 + float: left;
  39 + margin-right: 1px;
  40 +}
  41 +/* vim: set st=4 sw=4: */
... ...
... ... @@ -30,7 +30,6 @@ RESP = http/response.c \
30 30 http/response/403.c \
31 31 http/response/login_form.c \
32 32 http/response/asset.c \
33   - http/response/me.c \
34 33 http/response/randval.c
35 34 PARSER = http/parser.c \
36 35 http/parser/parse.c \
... ...
... ... @@ -57,67 +57,32 @@
57 57 "font-size: small;" \
58 58 "}" \
59 59 "</style>" \
60   - "<script type=\"text/javascript\" src=\"/jquery/\"></script>" \
  60 + "<script type=\"text/javascript\" src=\"/assets/js/jquery\"></script>" \
  61 + "<script type=\"text/javascript\" src=\"/assets/js/serverval\"></script>" \
61 62 "<script>" \
62 63 "$(document).ready(function() {" \
63   - "var intervalId;" \
64   - "var vnext = 0;" \
65   - "var clickclose = function() {" \
66   - "clearInterval(intervalId);" \
67   - "vnext = 0;" \
68   - "$(\"#randval\").addClass(\"hide\");" \
69   - "};" \
70   - "var counter = function() {" \
71   - "if (0 >= vnext) {" \
72   - "$.getJSON(\"/randval/\", function(data, xhr) {" \
73   - "var date = new Date(data.ctime * 1000);" \
74   - "$(\"#ctime\").empty().append(date.toString());" \
75   - "vnext = data.vnext;" \
76   - "$(\"#value\").empty().append(data.value);" \
77   - "$(\"#vnext\").empty().append(vnext);" \
78   - "$(\"#randval\").on(\"click\", clickclose);" \
79   - "}).error(function(event, request, settings) {" \
80   - "clearInterval(intervalId);" \
81   - "$.get(\"/login/\", function(data) {" \
82   - "$(\"#randval\")" \
83   - ".off(\"click\", clickclose)" \
84   - ".empty().append(data);" \
85   - "});" \
86   - "});" \
87   - "if ($(\"#randval\").hasClass(\"hide\")) {" \
88   - "$(\"#randval\").removeClass(\"hide\");" \
89   - "}" \
90   - "} else {" \
91   - "vnext--;" \
92   - "$(\"#vnext\").empty().append(vnext);" \
93   - "}" \
94   - "};" \
95   - "$(\"#msg\").ajaxError(function(event, request, settings) {" \
96   - "$(this).append(" \
97   - "\"<li>Error requesting page \" + " \
98   - "settings.url + " \
99   - "\"</li>\");" \
100   - "vnext = 0;" \
101   - "});" \
  64 + "var sval = new ServerVal(\"#randval\");" \
102 65 "$(\"a\").click(function() {" \
103   - "intervalId = setInterval(counter, 1000);" \
  66 + "sval.start();" \
104 67 "});" \
105 68 "});" \
106 69 "</script>" \
107 70 "</head>" \
108   - "<body>" \
  71 + "<body>"
  72 + "<ul id=\"menu\">" \
  73 + "<li>serverval</li>" \
  74 + "</ul>" \
109 75 "<div id=\"randval\" class=\"hide\">" \
110 76 "<span class=\"small\">" \
111   - "Value created at: <br /><span id=\"ctime\"></span><br>" \
112   - "Next value in: <span id=\"vnext\"></span><br />" \
  77 + "Value created at: <br /><span></span><br>" \
  78 + "Next value in: <span></span><br />" \
113 79 "</span>" \
114   - "Value: <span id=\"value\"></span>" \
  80 + "Value: <span></span>" \
115 81 "</div>" \
116 82 "<div id=\"main\">" \
117 83 "<h1>Testpage</h1>" \
118 84 "Welcome %s<br />" \
119 85 "<img src=\"/image/\" />" \
120   - "<br /><a href=\"#\">Link</a>" \
121 86 "</div>" \
122 87 "<hr /><div id=\"msg\"></div>" \
123 88 "</body>" \
... ...
... ... @@ -108,7 +108,10 @@ httpWorkerProcess(HttpWorker this, Stream st)
108 108 new(Session, val, nval));
109 109 nbuf = sprintf(buffer, "sid=%lu;Path=/", this->session->id);
110 110
111   - response = (HttpMessage)httpResponseMe(this->session->username);
  111 + response = httpWorkerGetAsset(
  112 + request,
  113 + "./assets/html/main.html",
  114 + CSTRA("text/html"));
112 115
113 116 httpHeaderAdd(
114 117 &(response->header),
... ... @@ -122,34 +125,50 @@ httpWorkerProcess(HttpWorker this, Stream st)
122 125 response = (HttpMessage)httpResponseLoginForm();
123 126 }
124 127
125   - if (0 == strcmp("/me/", request->uri)) {
126   - char * uname = (NULL != this->session)? this->session->username : "";
127   - response = (HttpMessage)httpResponseMe(uname);
  128 + if (0 == strcmp("/", request->uri)) {
  129 + response = httpWorkerGetAsset(
  130 + request,
  131 + "./assets/html/main.html",
  132 + CSTRA("text/html"));
128 133 }
129 134
130 135 if (0 == strcmp("/randval/", request->uri)) {
131   - if (NULL != this->session) {
  136 + //if (NULL != this->session) {
132 137 response = (HttpMessage)httpResponseRandval(
133 138 this->val->timestamp,
134 139 this->val->value);
135   - } else {
136   - response = (HttpMessage)httpResponse403();
137   - }
  140 + //} else {
  141 + // response = (HttpMessage)httpResponse403();
  142 + //}
138 143 }
139 144
140   - if (0 == strcmp("/image/", request->uri)) {
  145 + if (0 == strcmp("/image/me", request->uri)) {
141 146 response = httpWorkerGetAsset(
142 147 request,
143   - "./assets/waldschrat.jpg",
  148 + "./assets/image/waldschrat.jpg",
144 149 CSTRA("image/jpeg"));
145 150 }
146 151
147   - if (0 == strcmp("/jquery/", request->uri)) {
  152 + if (0 == strcmp("/assets/js/jquery", request->uri)) {
148 153 response = httpWorkerGetAsset(
149 154 request,
150   - "./assets/jquery-1.7.1.min.js",
  155 + "./assets/js/jquery-1.7.1.min.js",
151 156 CSTRA("text/javascript"));
152 157 }
  158 +
  159 + if (0 == strcmp("/assets/js/serverval", request->uri)) {
  160 + response = httpWorkerGetAsset(
  161 + request,
  162 + "./assets/js/serverval.js",
  163 + CSTRA("text/javascript"));
  164 + }
  165 +
  166 + if (0 == strcmp("/assets/style/common", request->uri)) {
  167 + response = httpWorkerGetAsset(
  168 + request,
  169 + "./assets/style/common.css",
  170 + CSTRA("text/css"));
  171 + }
153 172 }
154 173
155 174 if (NULL == response) {
... ...
... ... @@ -135,7 +135,7 @@ main()
135 135 shm_unlink("/fooshm");
136 136 close(shm);
137 137
138   - logger = new(LoggerStderr, LOGGER_DEBUG);
  138 + logger = new(LoggerSyslog, LOGGER_ERR);
139 139 worker = new(HttpWorker, "testserver", value);
140 140 server = new(Server, logger, worker, 11212, SOMAXCONN);
141 141
... ...
Please register or login to post a comment