jsgui3-server 0.0.75 → 0.0.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/examples/client-side-popup-menu-button.html +93 -93
  2. package/examples/controls/_html-server-color-palette.js +114 -114
  3. package/examples/controls/html-server-combo-box.js +104 -104
  4. package/examples/controls/html-server-list.js +98 -98
  5. package/examples/controls/html-server-popup-menu-button.js +114 -114
  6. package/examples/controls/html-server-start-stop-toggle-button.js +146 -146
  7. package/examples/controls/scs-arrow-button.js +36 -36
  8. package/examples/controls/scs-date-picker.js +157 -157
  9. package/examples/controls/scs-file-browser.js +82 -82
  10. package/examples/controls/scs-item.js +159 -159
  11. package/examples/controls/scs-month-arrow-selector.js +126 -126
  12. package/examples/controls/scs-month-view.js +95 -95
  13. package/examples/controls/scs-start-stop-toggle-button.js +40 -40
  14. package/examples/controls/scs-tree.js +49 -49
  15. package/examples/controls/scs-year-arrow-selector.js +127 -127
  16. package/examples/demos/date-picker.js +119 -119
  17. package/examples/demos/explain-encapsulation.js +9 -9
  18. package/examples/demos/resizing.js +35 -35
  19. package/examples/demos/server_time.js +6 -6
  20. package/examples/demos/square_box.js +324 -324
  21. package/examples/html-rendering.js +20 -20
  22. package/examples/html-server.js +102 -100
  23. package/fs2.js +1836 -1836
  24. package/module.js +21 -21
  25. package/old/single-control-server.js +418 -418
  26. package/package.json +44 -42
  27. package/publishing/function-publisher.js +202 -202
  28. package/publishing/notes.md +5 -5
  29. package/publishing/observable-publisher.js +118 -118
  30. package/publishing/resource-publisher.js +306 -306
  31. package/resources/data-resource.js +104 -104
  32. package/resources/fs-resource.js +148 -148
  33. package/resources/jsbuilder/Abstract_Single_Declaration.js +105 -0
  34. package/resources/jsbuilder/Abstract_Single_Declaration_Sequence.js +43 -0
  35. package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node.js +62 -0
  36. package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node_Group.js +42 -0
  37. package/resources/jsbuilder/JS_AST/JS_AST_Group_Shared.js +62 -0
  38. package/resources/jsbuilder/JS_AST/JS_AST_Node.js +94 -0
  39. package/resources/jsbuilder/JS_AST/JS_AST_Node_0-Core.js +228 -0
  40. package/resources/jsbuilder/JS_AST/JS_AST_Node_1-Babel.js +338 -0
  41. package/resources/jsbuilder/JS_AST/JS_AST_Node_10-Changing.js +40 -0
  42. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.1-Child.js +97 -0
  43. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.2-Parent.js +38 -0
  44. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.3-Ancestor.js +62 -0
  45. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.2-Inner.js +44 -0
  46. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.3-All.js +73 -0
  47. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.4-Sibling.js +93 -0
  48. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.5-Available_In_Scope.js +29 -0
  49. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.9-Signature.js +116 -0
  50. package/resources/jsbuilder/JS_AST/JS_AST_Node_3-Basics.js +160 -0
  51. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.0-Basics_First.js +179 -0
  52. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.1-Basics_Second.js +88 -0
  53. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.99-Basics_Last.js +92 -0
  54. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1-Basics_Each.js +137 -0
  55. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1.5-Basics_Count.js +74 -0
  56. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.2-Basics_Filter.js +40 -0
  57. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.3-Basics_Collect.js +86 -0
  58. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.4-Basics_Select.js +43 -0
  59. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.5-Basics_Find.js +41 -0
  60. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.6-Basics_Callmap.js +55 -0
  61. package/resources/jsbuilder/JS_AST/JS_AST_Node_4.0-Index_Indexes.js +46 -0
  62. package/resources/jsbuilder/JS_AST/JS_AST_Node_4.1-Index.js +344 -0
  63. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.0-Category.js +39 -0
  64. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.1-Category_Identifier.js +31 -0
  65. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.2-Category_Literal.js +29 -0
  66. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.3-Category_Expression.js +27 -0
  67. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.4-Category_Pattern.js +9 -0
  68. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.5-Category_Declaration.js +44 -0
  69. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.6-Category_Statement.js +22 -0
  70. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.0-Type.js +87 -0
  71. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.1-Type_Class_Declaration.js +9 -0
  72. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.2-Type_Variable_Declaration.js +28 -0
  73. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.3-Type_Variable_Declarator.js +29 -0
  74. package/resources/jsbuilder/JS_AST/JS_AST_Node_7-Query.js +737 -0
  75. package/resources/jsbuilder/JS_AST/JS_AST_Node_8-Features.js +65 -0
  76. package/resources/jsbuilder/JS_AST/JS_AST_Node_9-Planning.js +32 -0
  77. package/resources/jsbuilder/JS_AST/JS_AST_Node_Arrangement.js +15 -0
  78. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Declared_Object.js +306 -0
  79. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature.js +78 -0
  80. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declaration.js +249 -0
  81. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declarator.js +139 -0
  82. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature.js +10 -0
  83. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exported.js +101 -0
  84. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exports.js +61 -0
  85. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Interpreted.js +180 -0
  86. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/_JSGUI_Root_Node_Interpreted.js +43 -0
  87. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/special_case_objectassign_to_object.js +12 -0
  88. package/resources/jsbuilder/JS_AST/JS_AST_Node_Group.js +35 -0
  89. package/resources/jsbuilder/JS_AST/JS_AST_Operation.js +11 -0
  90. package/resources/jsbuilder/JS_AST/JS_AST_Operation_On_Relationship.js +32 -0
  91. package/resources/jsbuilder/JS_AST/JS_AST_Ordered_Relationship_Node_To_Group.js +38 -0
  92. package/resources/jsbuilder/JS_AST/JS_AST_Ordinal.js +40 -0
  93. package/resources/jsbuilder/JS_AST/JS_AST_Ordinal_Relationship.js +25 -0
  94. package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_To_Group.js +201 -0
  95. package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_Within_Group_To_Node.js +44 -0
  96. package/resources/jsbuilder/JS_AST/_JS_AST_Node_3.8-Query_Features.js +77 -0
  97. package/resources/jsbuilder/JS_AST/query/all.js +0 -0
  98. package/resources/jsbuilder/JS_AST/query/enable_array_as_queryable.js +228 -0
  99. package/resources/jsbuilder/JS_AST/query/find_object_keys.js +405 -0
  100. package/resources/jsbuilder/JS_AST/query/node_queries.js +9 -0
  101. package/resources/jsbuilder/JS_AST/query/root_queries.js +0 -0
  102. package/resources/jsbuilder/JS_AST/query/root_query_identidy.js +12 -0
  103. package/resources/jsbuilder/JS_AST_Node_Extended/JSGUI_Singular_Declaration.js +86 -0
  104. package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Declaration.js +124 -0
  105. package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended.js +88 -0
  106. package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended_0-Core.js +11 -0
  107. package/resources/jsbuilder/JS_Builder.js +10 -36
  108. package/resources/jsbuilder/JS_File/Feature/JS_File_Declared_Object.js +32 -0
  109. package/resources/jsbuilder/JS_File/Feature/JS_File_Exported_Object_Info.js +26 -0
  110. package/resources/jsbuilder/JS_File/Feature/JS_File_Exports.js +79 -0
  111. package/resources/jsbuilder/JS_File/Feature/JS_File_Feature.js +18 -0
  112. package/resources/jsbuilder/JS_File/Feature/JS_File_Imported_Object_Info.js +26 -0
  113. package/resources/jsbuilder/JS_File/Feature/JS_File_Imports.js +9 -0
  114. package/resources/jsbuilder/JS_File/JS_File.js +12 -0
  115. package/resources/jsbuilder/JS_File/JS_File_0-Core.js +202 -0
  116. package/resources/jsbuilder/JS_File/JS_File_1-Early_Parse.js +175 -0
  117. package/resources/jsbuilder/JS_File/JS_File_2-Babel.js +81 -0
  118. package/resources/jsbuilder/JS_File/JS_File_3-JS_AST_Node.js +86 -0
  119. package/resources/jsbuilder/JS_File/JS_File_4-Query.js +414 -0
  120. package/resources/jsbuilder/JS_File/JS_File_4.1-Query_Features.js +415 -0
  121. package/resources/jsbuilder/JS_File/JS_File_5-Planning.js +59 -0
  122. package/resources/jsbuilder/JS_File/JS_File_6-Changing.js +24 -0
  123. package/resources/jsbuilder/JS_File/JS_File_Export_Reference.js +12 -0
  124. package/resources/jsbuilder/JS_File/JS_File_Import_Reference.js +24 -0
  125. package/resources/jsbuilder/JS_File/JS_File_Import_References.js +32 -0
  126. package/resources/jsbuilder/JS_File/JS_File_Processor.js +16 -0
  127. package/resources/jsbuilder/JS_File/JS_Files.js +16 -0
  128. package/resources/jsbuilder/Module.js +14 -0
  129. package/resources/jsbuilder/Platform.js +13 -53
  130. package/resources/jsbuilder/Platforms.js +69 -15
  131. package/resources/jsbuilder/Project.js +109 -0
  132. package/resources/jsbuilder/Reference.js +1 -1
  133. package/resources/jsbuilder/Reference_Sequence.js +16 -7
  134. package/resources/jsbuilder/Scope.js +30 -0
  135. package/resources/jsbuilder/Variable_Name_Provider.js +43 -0
  136. package/resources/jsbuilder/_JS_File.js +226 -0
  137. package/resources/jsbuilder/ast_query.js +21 -0
  138. package/resources/jsbuilder/babel/babel_consts.js +150 -0
  139. package/resources/jsbuilder/babel/babel_node_tools.js +542 -0
  140. package/resources/jsbuilder/babel/deep_iterate/deep_iterate_babel.js +604 -0
  141. package/resources/jsbuilder/build.js +16 -0
  142. package/resources/jsbuilder/platform_notes.md +66 -0
  143. package/resources/jsbuilder/test/test_ast_node.js +451 -0
  144. package/resources/jsbuilder/test/test_js_file.js +303 -11
  145. package/resources/jsbuilder/test/test_project.js +157 -0
  146. package/resources/local-server-info-resource.js +78 -78
  147. package/resources/process-js.js +537 -537
  148. package/resources/server-resource-pool.js +84 -84
  149. package/resources/website-css-resource.js +411 -411
  150. package/resources/website-javascript-resource.js +761 -751
  151. package/resources/website-resource.js +390 -390
  152. package/resources/website-static-html-resource.js +196 -196
  153. package/server.js +170 -170
  154. package/single-control-server.js +398 -398
  155. package/single-page-app.js +129 -129
  156. package/resources/jsbuilder/Declaration.js +0 -15
  157. package/resources/jsbuilder/Declaration_Sequence.js +0 -15
  158. package/resources/jsbuilder/JS_File.js +0 -77
@@ -1,399 +1,399 @@
1
- /**
2
- * Created by james on 04/12/2016.
3
- */
4
-
5
- /**
6
- * Created by James on 02/10/2016.
7
- */
8
-
9
- // This one will need to activate on the client.
10
- // Really want the whole thing to be in one file.
11
- // Possible to have a standard activation?
12
- //
13
- // Or we need to have a client-side control?
14
- //
15
- // Some of the wiring could be done automatically.
16
- //
17
-
18
- //console.log('pre require jsgui');
19
- var jsgui = require('jsgui3-html');
20
- const each = jsgui.each;
21
- //console.log('post require jsgui');
22
- //var Start_Stop_Toggle_Button = require('../controls/start-stop-toggle-button');
23
- const is_array = jsgui.is_array;
24
- var Server = require('./server');
25
- var Website_Resource = require('./resources/website-resource');
26
- var port = 80;
27
- //console.log('!!Server', !!Server);
28
- //console.log('Object.keys(Server)', Object.keys(Server));
29
- var Server_Page_Context = require('./page-context');
30
-
31
- // js_mode option
32
- // compress
33
- // debug
34
- // (standard)
35
-
36
- // Want to get the library compressed sizes down. Particulatly client. Can do much more with oext.
37
-
38
- /*
39
- var server = new Server({
40
- '*': {
41
- 'name': 'html-server'
42
- }
43
- });
44
-
45
- */
46
- /*
47
- var resource_pool = root_server.resource_pool;
48
- // link these getters with the resource pool resource getters?
49
- let app_server = resource_pool['HTML Server'];
50
- //console.log('app_server', app_server);
51
- //
52
-
53
- //console.log('app_server.resource_names', app_server.resource_names);
54
- //console.log('!!app_server.resource_pool', !!app_server.resource_pool);
55
- let js = app_server.resource_pool['Site JavaScript'];
56
- */
57
-
58
- //console.log('Server', Server);
59
-
60
- // And choose the CSS file / files to send it.
61
- // Could send basic jsgui css by default
62
- // Then there would be app css on top of that.
63
-
64
- // Authenticated_Server?
65
- // Has got authentication mechanisms as a wrapper for the controls inside.
66
-
67
-
68
- // Want to be able to set up icons as well.
69
-
70
-
71
- class Single_Control_Server extends Server {
72
- constructor(spec) {
73
- //spec['*'] = {
74
- // 'name': 'html-server'
75
- //};
76
-
77
- // If the spec is a control contructor...
78
- if (typeof spec === 'function') {
79
- super({}, 'single-control-server');
80
- this.Ctrl = spec;
81
- this.port = 80;
82
- } else {
83
- super(spec);
84
- let Ctrl = spec.Ctrl || spec.ctrl; // not .ctrl? makes it ambiguous / inconsistent.
85
- if (is_array(Ctrl)) {
86
- this.Ctrl = Ctrl[0];
87
- this.params = Ctrl[1];
88
- } else {
89
- if (Ctrl) {
90
- this.Ctrl = Ctrl;
91
- } else {
92
- throw 'Single_Control_Server needs a Ctrl property'
93
- }
94
- }
95
-
96
-
97
- if (spec.js_mode) this.js_mode = spec.js_mode;
98
- if (spec.js_client) this.js_client = spec.js_client;
99
- // js client could be this file itself...?
100
- // creating a js client file in the same location probably makes most sense.
101
- // maybe a way of skipping that later...? Deleting it?
102
-
103
-
104
-
105
- // Context data
106
- // will get loaded into the context, and usable on the server too.
107
-
108
-
109
- if (spec.context_data) this.context_data = spec.context_data;
110
- // deliver app specific css
111
- // an obj
112
- if (spec.css) this.css = spec.css;
113
-
114
- // Not handling icons in the spec(yet). Now using load_icon_set.
115
- //if (spec.icons) this.icons = spec.icons;
116
-
117
- if (spec.include_server_ref_in_page_context) {
118
- this.include_server_ref_in_page_context = spec.include_server_ref_in_page_context;
119
- }
120
- // Ctrl.activate_app
121
- //spec.activate_app;
122
- if (spec.activate_app && !this.activate_app) {
123
- this.activate_app = spec.activate_app;
124
- }
125
- //console.log('this.activate_app', this.activate_app);
126
- //throw 'stop';
127
- if (spec.client_package) this.client_package = spec.client_package;
128
- this.port = spec.port || 80;
129
- }
130
- //this.__type_name = 'single-control-server';
131
- var app = new Website_Resource({
132
- 'name': 'html-server'
133
- });
134
- // will need to keep access to the server?
135
- // server_page_context keeping access to the server?
136
-
137
- // some place to keep variables on the server.
138
- // Especially when we are not coding any / much server-side logic.
139
- // server.shared
140
- // want an object that is shared between all server instances.
141
-
142
- // A server-side Data_Resource could be the way.
143
-
144
- // Maybe make something like Resource_Pool but simpler?
145
- // Less prescriptive, but allowing a more complex api...?
146
- // page_context.shared
147
- // shared with the server
148
- // shared with all page contexts.
149
-
150
- this.publish = (...args) => app.publish(...args);
151
- //console.log('app', app);
152
- //throw 'stop';
153
- this.resource_pool.add(app);
154
- this.server_router.set_route('*', app, app.process);
155
- this.app_server = app;
156
- }
157
-
158
- // Could start it up with a client_js reference
159
-
160
- 'start' (callback) {
161
-
162
- const {context_data} = this;
163
-
164
- //throw 'stop';
165
- //var resource_pool = this.resource_pool;
166
- var resource_pool = this.app_server.resource_pool;
167
- var server_router = this.resource_pool.get_resource('Server Router');
168
- // Build the client js and include that.
169
- // Could have been given a different client js file too.
170
- // By default want to provide the html client from jsgui.
171
- // /client/client
172
-
173
- // build the html client code.
174
- let js = this.app_server.resource_pool['Site JavaScript'];
175
- let css = this.app_server.resource_pool['Site CSS'];
176
- let imgs = this.app_server.resource_pool['Site Images'];
177
- let o_serve_package = {
178
- //'babel': 'mini'
179
- }
180
-
181
- // Other way(s) of doing this now.
182
- if (this.activate_app) {
183
- o_serve_package.replace = {
184
- '/* -- ACTIVATE-APP -- */': this.activate_app.toString()
185
- }
186
- //
187
- }
188
- o_serve_package.js_mode = 'mini';
189
- if (this.js_mode) {
190
- o_serve_package.js_mode = this.js_mode;
191
- } else {
192
- //o_serve_package.babel = 'mini';
193
- }
194
- if (this.css) {
195
- each(this.css, (path, serve_as) => {
196
- css.serve(serve_as, path);
197
- })
198
- }
199
-
200
-
201
- // css.serve_package_css
202
- // will get the css from that package?
203
- // or extract the css from the classes in the package directly?
204
-
205
-
206
- let js_client = this.client_package || this.js_client || 'jsgui3-client';
207
-
208
- // The removal of server code / recompilation shouldnt make a difference in cases where we give it client-side js to start with.
209
- // Have the case of the actual client-side js being given with no transformation needed.
210
- // Can detect whether there is any server-side code and transformation(s) needed...?
211
-
212
-
213
-
214
-
215
-
216
- console.log('js_client', js_client);
217
- //throw 'stop';
218
-
219
- js.serve_package('/js/app.js', js_client, o_serve_package, (err, served) => {
220
- //var resource_pool = this.resource_pool;
221
- //console.log('server_router', server_router);
222
- //console.log('js_client', js_client);
223
- if (!server_router) {
224
- throw 'no server_router';
225
- }
226
- var routing_tree = server_router.routing_tree;
227
- routing_tree.set('/', (req, res) => {
228
- //console.log('root path / request');
229
- const o_spc = {
230
- 'req': req,
231
- 'res': res,
232
- 'resource_pool': resource_pool
233
- }
234
-
235
- if (this.include_server_ref_in_page_context) o_spc.server = this;
236
- var server_page_context = new Server_Page_Context(o_spc);
237
- // then merge the context data :)
238
- if (this.context_data) {
239
- Object.assign(server_page_context, this.context_data);
240
- }
241
- // and .server property?
242
- // a different way to get the server info to the components is needed.
243
-
244
- // Page_Bounds_Specifier
245
- var hd = new jsgui.Client_HTML_Document({
246
- 'context': server_page_context
247
- });
248
- hd.include_client_css();
249
- hd.include_css('/css/basic.css');
250
-
251
- // include compiled css too.
252
- // not much of it yet.
253
-
254
- // Will be a separate CSS file, generated upon app start.
255
- if (this.css) {
256
- each(this.css, (path, serve_as) => {
257
- //css.serve(serve_as, path);
258
- hd.include_css('/css/' + serve_as);
259
- });
260
- }
261
- hd.include_css('/css/controls.css');
262
- var body = hd.body;
263
- let o_params = this.params || {};
264
- Object.assign(o_params, {
265
- 'context': server_page_context
266
- });
267
- //console.log('o_params', o_params);
268
- //console.log('this.Ctrl', this.Ctrl);
269
- var ctrl = this.ctrl = new this.Ctrl(o_params);
270
- ctrl.active();
271
- //var ctrl2 = new jsgui.Control({});
272
- body.add(ctrl);
273
-
274
- // it will be a client-side function.
275
-
276
- // Should not use 'add' here.
277
- // it's the script content.
278
-
279
- // want to get around that escaping.
280
- // options escaping / escape : false
281
-
282
- hd.include_js('/js/app.js');
283
-
284
- // Would this be a place to register icons?
285
- // and register client data.
286
-
287
- // If we have the client data, we merge these items into the context.
288
- // register_context_data
289
- // because the page_context js object won't have been created yet...
290
-
291
- // create the different statements.
292
- // only put that resources_script in if there is something worth doing.
293
-
294
- // Or even do the CSS compilation and property removal from the JS file, all at the same time?
295
- // Maybe could do it from reference to the client controls too.
296
-
297
- // Will work out a fairly simple way to compile together tha CSS.
298
- // May have a few methods available, make use of them in different ways / at different levels.
299
-
300
- let statement_rsr;
301
- let statement_context_data;
302
- let statements = [];
303
-
304
- // Some data will be sent to the client each time.
305
- // Could possibly deliver some kind of token as well to represent the user.
306
-
307
- // Number of entries in this.app_server.def_resource_publishers
308
-
309
- if (this.app_server.def_resource_publishers) {
310
- const c = Object.keys(this.app_server.def_resource_publishers).length;
311
- if (c > 0) {
312
- statement_rsr = `jsgui.register_server_resources(${JSON.stringify(this.app_server.def_resource_publishers)});`;
313
- statements.push(statement_rsr);
314
- }
315
- }
316
-
317
- if (context_data) {
318
- const c = Object.keys(context_data).length;
319
- if (c > 0) {
320
- statement_context_data = `jsgui.register_context_data(${JSON.stringify(context_data)});`;
321
- statements.push(statement_context_data);
322
- }
323
- }
324
-
325
- if (statements.length > 0) {
326
- let resources_script = new jsgui.script({
327
- context: server_page_context
328
- });
329
- const strc = new jsgui.String_Control({
330
- context: server_page_context,
331
- text: statements.join('')
332
- });
333
- resources_script.add(strc);
334
- body.add(resources_script);
335
- }
336
-
337
- hd.all_html_render(function (err, deferred_html) {
338
- if (err) {
339
- throw err;
340
- } else {
341
- //console.log('deferred_html', deferred_html);
342
- var mime_type = 'text/html';
343
- //console.log('mime_type ' + mime_type);
344
- res.writeHead(200, {
345
- 'Content-Type': mime_type
346
- });
347
- res.end('<!DOCTYPE html>' + deferred_html, 'utf-8');
348
- }
349
- });
350
- });
351
- //console.log('pre super start');
352
-
353
- super.start(this.port, (err, res_super_start) => {
354
- if (err) {
355
- callback(err);
356
- } else {
357
- //console.log('res_super_start', res_super_start);
358
- this.raise('scs_ready');
359
- callback(null, res_super_start);
360
- }
361
- });
362
- });
363
- // console.log('this.port', this.port);
364
- }
365
-
366
- load_icon_set(path, map_icons) {
367
- // will load each icon into the image resource.
368
- // sequential way of doing this?
369
- // need to register an image / icon by name within the image resource.
370
- // different version support too?
371
- // track original versions with name.
372
- let site_images = this.app_server.resource_pool['Site Images'];
373
- //console.log('load_icon_set');
374
- //console.log('site_images', site_images);
375
- // site_images.load_icon_set?
376
- // read each of them from disk individually?
377
- site_images.load_icon_set(path, map_icons);
378
- }
379
- }
380
-
381
- module.exports = Single_Control_Server;
382
-
383
- // Rendering single page controls makes a lot of sense.
384
- // It means the activation code can be contained better there.
385
-
386
- //console.log('resource_pool', resource_pool);
387
- //console.log('resource_pool.resources', resource_pool.resources);
388
-
389
- // The start stop toggle button would need to be registered on the client side.
390
- // May be worth it to have the standard controls registered to start with.
391
- // Or to have the app know which controls are used, so it can register them.
392
-
393
- // Get the website resource
394
-
395
- // Caching items / resources by type?
396
- // Need to give the resources a name.
397
- //var website = resource_pool.get_resource('Server Router');
398
-
1
+ /**
2
+ * Created by james on 04/12/2016.
3
+ */
4
+
5
+ /**
6
+ * Created by James on 02/10/2016.
7
+ */
8
+
9
+ // This one will need to activate on the client.
10
+ // Really want the whole thing to be in one file.
11
+ // Possible to have a standard activation?
12
+ //
13
+ // Or we need to have a client-side control?
14
+ //
15
+ // Some of the wiring could be done automatically.
16
+ //
17
+
18
+ //console.log('pre require jsgui');
19
+ var jsgui = require('jsgui3-html');
20
+ const each = jsgui.each;
21
+ //console.log('post require jsgui');
22
+ //var Start_Stop_Toggle_Button = require('../controls/start-stop-toggle-button');
23
+ const is_array = jsgui.is_array;
24
+ var Server = require('./server');
25
+ var Website_Resource = require('./resources/website-resource');
26
+ var port = 80;
27
+ //console.log('!!Server', !!Server);
28
+ //console.log('Object.keys(Server)', Object.keys(Server));
29
+ var Server_Page_Context = require('./page-context');
30
+
31
+ // js_mode option
32
+ // compress
33
+ // debug
34
+ // (standard)
35
+
36
+ // Want to get the library compressed sizes down. Particulatly client. Can do much more with oext.
37
+
38
+ /*
39
+ var server = new Server({
40
+ '*': {
41
+ 'name': 'html-server'
42
+ }
43
+ });
44
+
45
+ */
46
+ /*
47
+ var resource_pool = root_server.resource_pool;
48
+ // link these getters with the resource pool resource getters?
49
+ let app_server = resource_pool['HTML Server'];
50
+ //console.log('app_server', app_server);
51
+ //
52
+
53
+ //console.log('app_server.resource_names', app_server.resource_names);
54
+ //console.log('!!app_server.resource_pool', !!app_server.resource_pool);
55
+ let js = app_server.resource_pool['Site JavaScript'];
56
+ */
57
+
58
+ //console.log('Server', Server);
59
+
60
+ // And choose the CSS file / files to send it.
61
+ // Could send basic jsgui css by default
62
+ // Then there would be app css on top of that.
63
+
64
+ // Authenticated_Server?
65
+ // Has got authentication mechanisms as a wrapper for the controls inside.
66
+
67
+
68
+ // Want to be able to set up icons as well.
69
+
70
+
71
+ class Single_Control_Server extends Server {
72
+ constructor(spec) {
73
+ //spec['*'] = {
74
+ // 'name': 'html-server'
75
+ //};
76
+
77
+ // If the spec is a control contructor...
78
+ if (typeof spec === 'function') {
79
+ super({}, 'single-control-server');
80
+ this.Ctrl = spec;
81
+ this.port = 80;
82
+ } else {
83
+ super(spec);
84
+ let Ctrl = spec.Ctrl || spec.ctrl; // not .ctrl? makes it ambiguous / inconsistent.
85
+ if (is_array(Ctrl)) {
86
+ this.Ctrl = Ctrl[0];
87
+ this.params = Ctrl[1];
88
+ } else {
89
+ if (Ctrl) {
90
+ this.Ctrl = Ctrl;
91
+ } else {
92
+ throw 'Single_Control_Server needs a Ctrl property'
93
+ }
94
+ }
95
+
96
+
97
+ if (spec.js_mode) this.js_mode = spec.js_mode;
98
+ if (spec.js_client) this.js_client = spec.js_client;
99
+ // js client could be this file itself...?
100
+ // creating a js client file in the same location probably makes most sense.
101
+ // maybe a way of skipping that later...? Deleting it?
102
+
103
+
104
+
105
+ // Context data
106
+ // will get loaded into the context, and usable on the server too.
107
+
108
+
109
+ if (spec.context_data) this.context_data = spec.context_data;
110
+ // deliver app specific css
111
+ // an obj
112
+ if (spec.css) this.css = spec.css;
113
+
114
+ // Not handling icons in the spec(yet). Now using load_icon_set.
115
+ //if (spec.icons) this.icons = spec.icons;
116
+
117
+ if (spec.include_server_ref_in_page_context) {
118
+ this.include_server_ref_in_page_context = spec.include_server_ref_in_page_context;
119
+ }
120
+ // Ctrl.activate_app
121
+ //spec.activate_app;
122
+ if (spec.activate_app && !this.activate_app) {
123
+ this.activate_app = spec.activate_app;
124
+ }
125
+ //console.log('this.activate_app', this.activate_app);
126
+ //throw 'stop';
127
+ if (spec.client_package) this.client_package = spec.client_package;
128
+ this.port = spec.port || 80;
129
+ }
130
+ //this.__type_name = 'single-control-server';
131
+ var app = new Website_Resource({
132
+ 'name': 'html-server'
133
+ });
134
+ // will need to keep access to the server?
135
+ // server_page_context keeping access to the server?
136
+
137
+ // some place to keep variables on the server.
138
+ // Especially when we are not coding any / much server-side logic.
139
+ // server.shared
140
+ // want an object that is shared between all server instances.
141
+
142
+ // A server-side Data_Resource could be the way.
143
+
144
+ // Maybe make something like Resource_Pool but simpler?
145
+ // Less prescriptive, but allowing a more complex api...?
146
+ // page_context.shared
147
+ // shared with the server
148
+ // shared with all page contexts.
149
+
150
+ this.publish = (...args) => app.publish(...args);
151
+ //console.log('app', app);
152
+ //throw 'stop';
153
+ this.resource_pool.add(app);
154
+ this.server_router.set_route('*', app, app.process);
155
+ this.app_server = app;
156
+ }
157
+
158
+ // Could start it up with a client_js reference
159
+
160
+ 'start' (callback) {
161
+
162
+ const {context_data} = this;
163
+
164
+ //throw 'stop';
165
+ //var resource_pool = this.resource_pool;
166
+ var resource_pool = this.app_server.resource_pool;
167
+ var server_router = this.resource_pool.get_resource('Server Router');
168
+ // Build the client js and include that.
169
+ // Could have been given a different client js file too.
170
+ // By default want to provide the html client from jsgui.
171
+ // /client/client
172
+
173
+ // build the html client code.
174
+ let js = this.app_server.resource_pool['Site JavaScript'];
175
+ let css = this.app_server.resource_pool['Site CSS'];
176
+ let imgs = this.app_server.resource_pool['Site Images'];
177
+ let o_serve_package = {
178
+ //'babel': 'mini'
179
+ }
180
+
181
+ // Other way(s) of doing this now.
182
+ if (this.activate_app) {
183
+ o_serve_package.replace = {
184
+ '/* -- ACTIVATE-APP -- */': this.activate_app.toString()
185
+ }
186
+ //
187
+ }
188
+ o_serve_package.js_mode = 'mini';
189
+ if (this.js_mode) {
190
+ o_serve_package.js_mode = this.js_mode;
191
+ } else {
192
+ //o_serve_package.babel = 'mini';
193
+ }
194
+ if (this.css) {
195
+ each(this.css, (path, serve_as) => {
196
+ css.serve(serve_as, path);
197
+ })
198
+ }
199
+
200
+
201
+ // css.serve_package_css
202
+ // will get the css from that package?
203
+ // or extract the css from the classes in the package directly?
204
+
205
+
206
+ let js_client = this.client_package || this.js_client || 'jsgui3-client';
207
+
208
+ // The removal of server code / recompilation shouldnt make a difference in cases where we give it client-side js to start with.
209
+ // Have the case of the actual client-side js being given with no transformation needed.
210
+ // Can detect whether there is any server-side code and transformation(s) needed...?
211
+
212
+
213
+
214
+
215
+
216
+ console.log('js_client', js_client);
217
+ //throw 'stop';
218
+
219
+ js.serve_package('/js/app.js', js_client, o_serve_package, (err, served) => {
220
+ //var resource_pool = this.resource_pool;
221
+ //console.log('server_router', server_router);
222
+ //console.log('js_client', js_client);
223
+ if (!server_router) {
224
+ throw 'no server_router';
225
+ }
226
+ var routing_tree = server_router.routing_tree;
227
+ routing_tree.set('/', (req, res) => {
228
+ //console.log('root path / request');
229
+ const o_spc = {
230
+ 'req': req,
231
+ 'res': res,
232
+ 'resource_pool': resource_pool
233
+ }
234
+
235
+ if (this.include_server_ref_in_page_context) o_spc.server = this;
236
+ var server_page_context = new Server_Page_Context(o_spc);
237
+ // then merge the context data :)
238
+ if (this.context_data) {
239
+ Object.assign(server_page_context, this.context_data);
240
+ }
241
+ // and .server property?
242
+ // a different way to get the server info to the components is needed.
243
+
244
+ // Page_Bounds_Specifier
245
+ var hd = new jsgui.Client_HTML_Document({
246
+ 'context': server_page_context
247
+ });
248
+ hd.include_client_css();
249
+ hd.include_css('/css/basic.css');
250
+
251
+ // include compiled css too.
252
+ // not much of it yet.
253
+
254
+ // Will be a separate CSS file, generated upon app start.
255
+ if (this.css) {
256
+ each(this.css, (path, serve_as) => {
257
+ //css.serve(serve_as, path);
258
+ hd.include_css('/css/' + serve_as);
259
+ });
260
+ }
261
+ hd.include_css('/css/controls.css');
262
+ var body = hd.body;
263
+ let o_params = this.params || {};
264
+ Object.assign(o_params, {
265
+ 'context': server_page_context
266
+ });
267
+ //console.log('o_params', o_params);
268
+ //console.log('this.Ctrl', this.Ctrl);
269
+ var ctrl = this.ctrl = new this.Ctrl(o_params);
270
+ ctrl.active();
271
+ //var ctrl2 = new jsgui.Control({});
272
+ body.add(ctrl);
273
+
274
+ // it will be a client-side function.
275
+
276
+ // Should not use 'add' here.
277
+ // it's the script content.
278
+
279
+ // want to get around that escaping.
280
+ // options escaping / escape : false
281
+
282
+ hd.include_js('/js/app.js');
283
+
284
+ // Would this be a place to register icons?
285
+ // and register client data.
286
+
287
+ // If we have the client data, we merge these items into the context.
288
+ // register_context_data
289
+ // because the page_context js object won't have been created yet...
290
+
291
+ // create the different statements.
292
+ // only put that resources_script in if there is something worth doing.
293
+
294
+ // Or even do the CSS compilation and property removal from the JS file, all at the same time?
295
+ // Maybe could do it from reference to the client controls too.
296
+
297
+ // Will work out a fairly simple way to compile together tha CSS.
298
+ // May have a few methods available, make use of them in different ways / at different levels.
299
+
300
+ let statement_rsr;
301
+ let statement_context_data;
302
+ let statements = [];
303
+
304
+ // Some data will be sent to the client each time.
305
+ // Could possibly deliver some kind of token as well to represent the user.
306
+
307
+ // Number of entries in this.app_server.def_resource_publishers
308
+
309
+ if (this.app_server.def_resource_publishers) {
310
+ const c = Object.keys(this.app_server.def_resource_publishers).length;
311
+ if (c > 0) {
312
+ statement_rsr = `jsgui.register_server_resources(${JSON.stringify(this.app_server.def_resource_publishers)});`;
313
+ statements.push(statement_rsr);
314
+ }
315
+ }
316
+
317
+ if (context_data) {
318
+ const c = Object.keys(context_data).length;
319
+ if (c > 0) {
320
+ statement_context_data = `jsgui.register_context_data(${JSON.stringify(context_data)});`;
321
+ statements.push(statement_context_data);
322
+ }
323
+ }
324
+
325
+ if (statements.length > 0) {
326
+ let resources_script = new jsgui.script({
327
+ context: server_page_context
328
+ });
329
+ const strc = new jsgui.String_Control({
330
+ context: server_page_context,
331
+ text: statements.join('')
332
+ });
333
+ resources_script.add(strc);
334
+ body.add(resources_script);
335
+ }
336
+
337
+ hd.all_html_render(function (err, deferred_html) {
338
+ if (err) {
339
+ throw err;
340
+ } else {
341
+ //console.log('deferred_html', deferred_html);
342
+ var mime_type = 'text/html';
343
+ //console.log('mime_type ' + mime_type);
344
+ res.writeHead(200, {
345
+ 'Content-Type': mime_type
346
+ });
347
+ res.end('<!DOCTYPE html>' + deferred_html, 'utf-8');
348
+ }
349
+ });
350
+ });
351
+ //console.log('pre super start');
352
+
353
+ super.start(this.port, (err, res_super_start) => {
354
+ if (err) {
355
+ callback(err);
356
+ } else {
357
+ //console.log('res_super_start', res_super_start);
358
+ this.raise('scs_ready');
359
+ callback(null, res_super_start);
360
+ }
361
+ });
362
+ });
363
+ // console.log('this.port', this.port);
364
+ }
365
+
366
+ load_icon_set(path, map_icons) {
367
+ // will load each icon into the image resource.
368
+ // sequential way of doing this?
369
+ // need to register an image / icon by name within the image resource.
370
+ // different version support too?
371
+ // track original versions with name.
372
+ let site_images = this.app_server.resource_pool['Site Images'];
373
+ //console.log('load_icon_set');
374
+ //console.log('site_images', site_images);
375
+ // site_images.load_icon_set?
376
+ // read each of them from disk individually?
377
+ site_images.load_icon_set(path, map_icons);
378
+ }
379
+ }
380
+
381
+ module.exports = Single_Control_Server;
382
+
383
+ // Rendering single page controls makes a lot of sense.
384
+ // It means the activation code can be contained better there.
385
+
386
+ //console.log('resource_pool', resource_pool);
387
+ //console.log('resource_pool.resources', resource_pool.resources);
388
+
389
+ // The start stop toggle button would need to be registered on the client side.
390
+ // May be worth it to have the standard controls registered to start with.
391
+ // Or to have the app know which controls are used, so it can register them.
392
+
393
+ // Get the website resource
394
+
395
+ // Caching items / resources by type?
396
+ // Need to give the resources a name.
397
+ //var website = resource_pool.get_resource('Server Router');
398
+
399
399
  //console.log('\n\n');