browser_app_base 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32eb1959381928c1c8be5a8760701706f771df4207232dd7a9047940a6f359a8
4
- data.tar.gz: 38edd65c1cd9cbf4efa10a714bf1a0675fc9043642379b4c5b731e211ce3e0ad
3
+ metadata.gz: a22a122d81077a56ab0c76ef5faa6bcff0df41828eb333087735243890835f1a
4
+ data.tar.gz: 8360c3f68edf2eb31783ed4dcef383b3bba6c53ebc2924fb4023cb265bc1775a
5
5
  SHA512:
6
- metadata.gz: e4aca516b044caa09f15225fb1dc0f3b61c256bb1b36351a1575fc0e6bc4e242e0d9c4f682fbb276250a4d6848e6c30d78490e73b2f78e9df4f82c056d266d37
7
- data.tar.gz: 7b5ff83d5c26485836a54d41fbb8e71188147fc65663f4a3bfbd87407d45cf0dd701104c7826cff6116bd0f8f31574c45b412b69555dadcbecc5da3ad19a7977
6
+ metadata.gz: 7ee58439f8cec945ab9577fe7f2d27770a69ea070ef1ee00ce49d4a106bd114d0a3d0a1eae971b89532c64a3a3c435989cc92a39b03bf3c9f7697106b46d7856
7
+ data.tar.gz: a477e7007e72552b287078b76e19760896a19360ea31229ee34841d7171397b87b1b80a871a7e55d0e8cf2f07f06171aebad88a0cdf32801179fe941b0349184
data/.gitignore CHANGED
@@ -10,3 +10,5 @@ Gemfile.lock
10
10
 
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+ /lib/template/logs
14
+ /history/history.json
data/.vscode/launch.json CHANGED
@@ -15,6 +15,7 @@
15
15
  "type": "Ruby",
16
16
  "request": "launch",
17
17
  "cwd": "${workspaceRoot}/lib/template",
18
+ "args": [ "test" ],
18
19
  "program": "${workspaceRoot}/lib/template/start.rb"
19
20
  }
20
21
  ]
data/README.md CHANGED
@@ -62,6 +62,8 @@ ui application sample
62
62
  $ /tmp/test/bin/start_my_app.rb
63
63
  ```
64
64
 
65
+ ![app](img/app.png)
66
+
65
67
  ## browser setting
66
68
 
67
69
  ${home}/${app_nane}/config/browser.json
@@ -103,6 +105,85 @@ class MyApp < AppMainBase
103
105
  end
104
106
  ```
105
107
 
108
+ ## Application Setting
109
+
110
+ ${home}/${app_nane}/config/setting.json
111
+
112
+
113
+ ```json
114
+ [
115
+ {
116
+ "name": "name1",
117
+ "value": "value1 2 3 4",
118
+ "type": "input",
119
+ "select": "",
120
+ "description": "設定項目1"
121
+ },
122
+ {
123
+ "name": "name2",
124
+ "value": true,
125
+ "type": "checkbox",
126
+ "select": "",
127
+ "description": "有効にする場合はチェック"
128
+ },
129
+ {
130
+ "name": "name3",
131
+ "value": "2",
132
+ "type": "select",
133
+ "select": [
134
+ "1",
135
+ "2",
136
+ "3",
137
+ "4",
138
+ "5"
139
+ ],
140
+ "description": "選択項目"
141
+ },
142
+ {
143
+ "name": "name4",
144
+ "value": "value4",
145
+ "type": "input",
146
+ "select": "",
147
+ "description": "設定項目4"
148
+ },
149
+ {
150
+ "name": "name5",
151
+ "value": "value5",
152
+ "type": "input",
153
+ "select": "",
154
+ "description": "設定項目5"
155
+ },
156
+ {
157
+ "name": "name6",
158
+ "value": "value6",
159
+ "type": "input",
160
+ "select": "",
161
+ "description": "設定項目6"
162
+ }
163
+ ]
164
+ ```
165
+ ```ruby
166
+ class MyApp < AppMainBase
167
+ def start(argv)
168
+ # popup message
169
+ app_send("popup:message string")
170
+
171
+ # log message
172
+ yield "log message"
173
+ end
174
+
175
+ # read setting
176
+ puts @config["name1"]
177
+ end
178
+ ```
179
+
180
+ Setting menu
181
+ ![app](img/setting_menu.png)
182
+
183
+
184
+ Setting screen
185
+ ![app](img/setting.png)
186
+
106
187
  ## Development
107
188
 
108
189
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
data/img/app.png ADDED
Binary file
data/img/setting.png ADDED
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BrowserAppBase
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
@@ -102,6 +102,6 @@ configure do
102
102
 
103
103
  end
104
104
 
105
- #\ --port 58656
105
+ #\ --port 40173
106
106
 
107
107
  run Sinatra::Application
@@ -121,4 +121,58 @@ input[type="search"] {
121
121
 
122
122
  input[type="search"]::-webkit-search-cancel-button {
123
123
  -webkit-appearance: searchfield-cancel-button;
124
+ }
125
+
126
+ /* menu */
127
+ .menu {
128
+ display: flex;
129
+ justify-content: flex-start;
130
+ list-style-type: none;
131
+ color: #393737;
132
+ padding: 0;
133
+ font-size: 16px;
134
+ font-weight: bold;
135
+ }
136
+
137
+ .menu li {
138
+ position: relative;
139
+ width: 100px;
140
+ margin-left: 1px;
141
+ padding: 5px;
142
+ background: #d8dada;
143
+ list-style-type: none;
144
+ }
145
+
146
+ .menu li a {
147
+ color: rgb(20, 114, 192);
148
+ }
149
+
150
+ .menu li a:hover {
151
+ background: #eba399;
152
+ }
153
+
154
+ .menuSub {
155
+ position: absolute;
156
+ margin-left: -6px;
157
+ padding: 0;
158
+ display: none;
159
+ }
160
+
161
+ /*.openが付与された時、表示の設定*/
162
+ .menuSub.open {
163
+ display: block;
164
+ }
165
+
166
+ .menuSub li a {
167
+ padding: 5px;
168
+ margin-left: -5px;
169
+ margin-right: -5px;
170
+ margin-bottom: -5px;
171
+ display: block;
172
+ color: rgb(20, 114, 192);
173
+ text-decoration: none;
174
+ }
175
+
176
+ .menuSub li a:hover {
177
+ background: #eba399;
124
178
  }
@@ -11,8 +11,8 @@
11
11
  <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
12
12
  <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
13
13
 
14
- <script src="http://localhost:58656/js/main.js"></script>
15
- <link rel="stylesheet" href="http://localhost:58656/css/index.css" type="text/css">
14
+ <script src="js/main.js"></script>
15
+ <link rel="stylesheet" href="css/index.css" type="text/css">
16
16
  </head>
17
17
 
18
18
  <body>
@@ -21,22 +21,33 @@
21
21
  </div>
22
22
  <h4>RubyAppBase</h4>
23
23
  <hr>
24
- <table>
25
- <tr>
26
- <td>
27
- <input type="button" id="exec" name="exec" value="実行">
28
- </td>
29
- <td>
30
- <input type="button" id="stop" name="stop" value="停止">
31
- </td>
32
- <td>
33
- <div id="setting_dialog" style="display:none;">
34
- <dl id="wrap"></dl>
35
- </div>
36
- <input type="button" id="setting" value="設定" />
37
- </td>
38
- </tr>
39
- </table>
24
+ <!-- menu -->
25
+ <div id="setting_dialog" style="display:none;">
26
+ <dl id="wrap"></dl>
27
+ </div>
28
+ <div>
29
+ <ul class="menu">
30
+ <Li><a href="#" id="exec" name="exec">実行</a></li>
31
+ <li><a href="#" id="stop" name="stop">停止</a></li>
32
+ <li>
33
+ 設定
34
+ <ul class="menuSub">
35
+ <li><a href="#" id="setting">設定</a></li>
36
+ <li><a href="#" id="save_setting">設定保存</a></li>
37
+ <li><a href="#" id="load_setting">設定読み込み</a></li>
38
+ </ul>
39
+ </li>
40
+ <!--
41
+ <li>
42
+ menu3
43
+ <ul class="menuSub">
44
+ <li><a href="#">menu3-1</a></li>
45
+ <li><a href="#">menu3-2</a></li>
46
+ </ul>
47
+ </li>
48
+ -->
49
+ </ul>
50
+ </div>
40
51
 
41
52
  <div id="dialog1" style="display:none;">
42
53
  <input class="inarea" type="search" name="search_str" id="search_str">
@@ -115,7 +115,7 @@ function autocomp(id, file_kind) {
115
115
  },
116
116
  source: function (req, resp) {
117
117
  $.ajax({
118
- url: "http://localhost:58656/search?path=" + $("#" + id).val() + "&kind=" + file_kind,
118
+ url: "search?path=" + $("#" + id).val() + "&kind=" + file_kind,
119
119
  type: "GET",
120
120
  cache: false,
121
121
  dataType: "json",
@@ -148,7 +148,7 @@ function autocomp_history(id, file_name) {
148
148
  },
149
149
  source: function (req, resp) {
150
150
  $.ajax({
151
- url: "http://localhost:58656/history/" + file_name,
151
+ url: "history/" + file_name,
152
152
  type: "POST",
153
153
  cache: false,
154
154
  dataType: "json",
@@ -291,6 +291,7 @@ function setting_dialog(open_id, dialog_id, json_file) {
291
291
  //console.log("type=" + s[i].type);
292
292
  }
293
293
  }
294
+ // Jsonデータをサーバに送信
294
295
  $ws.send("setting:" + JSON.stringify(json_data));
295
296
  });
296
297
  $(this).dialog("close");
@@ -303,6 +304,57 @@ function setting_dialog(open_id, dialog_id, json_file) {
303
304
  });
304
305
  }
305
306
 
307
+ // 設定読み込み
308
+ function load_setting(open_id) {
309
+ document.getElementById(open_id).onclick = async () => {
310
+ [fileHandle] = await window.showOpenFilePicker();
311
+ const file = await fileHandle.getFile();
312
+ const json_data = await file.text();
313
+ console.log(json_data);
314
+ // Jsonデータをサーバに送信
315
+ $ws.send("setting:" + json_data);
316
+ };
317
+ }
318
+
319
+ // 設定保存
320
+ function save_setting(open_id, json_file) {
321
+ document.getElementById(open_id).onclick = async () => {
322
+ var json_data = ""
323
+ $.ajax({
324
+ // jsonの読み込み
325
+ type: "GET",
326
+ url: json_file, // ファイルパス(相対パス)
327
+ dataType: "json", // ファイル形式
328
+ async: false // 非同期通信フラグ
329
+ }).then(
330
+ function (json) {
331
+ // 読み込み成功時の処理
332
+ json_data = JSON.stringify(json, null, 2);
333
+ console.log("json=" + json_data);
334
+ },
335
+ function () {
336
+ // 読み込み失敗時の処理
337
+ console.log("読み込みに失敗しました");
338
+ }
339
+ );
340
+ // Jsonを保存
341
+ const opts = {
342
+ suggestedName: 'setting.json',
343
+ types: [{
344
+ description: 'Text file',
345
+ accept: { 'text/plain': ['.json'] },
346
+ }],
347
+ };
348
+ // ファイルをどこにどんな名前で保存するか訊くダイアログを表示
349
+ const saveHandle = await window.showSaveFilePicker(opts)
350
+ // 保存先ファイルに書き込み準備
351
+ const writable = await saveHandle.createWritable();
352
+ // 先程同様に書き込んで終了
353
+ await writable.write(json_data);
354
+ await writable.close();
355
+ };
356
+ }
357
+
306
358
  function get_dirname(path) {
307
359
  var result = path.replace(/\\/g, '/').replace(/\/[^\/]*$/, '');
308
360
  if (result.match(/^[^\/]*\.[^\/\.]*$/)) {
@@ -324,12 +376,26 @@ function openFile(file) {
324
376
  $(document).ready(function () {
325
377
 
326
378
  // サーバに接続
327
- server_connect("ws://localhost:58656/wsserver")
379
+ server_connect("ws://localhost:40173/wsserver")
328
380
  window.onload = function (e) {
329
381
  // サーバに接続
330
- //server_connect("ws://localhost:58656/wsserver")
382
+ //server_connect("ws://localhost:40173/wsserver")
331
383
  }
332
384
 
385
+ // menu
386
+ $(function () {
387
+ $(".menu li").hover(
388
+ function () {
389
+ //クラス名「open」を付与する
390
+ $(this).children(".menuSub").addClass("open");
391
+ //hoverが外れた場合
392
+ }, function () {
393
+ //クラス名「open」を取り除く
394
+ $(this).children(".menuSub").removeClass("open");
395
+ }
396
+ );
397
+ });
398
+
333
399
  // ウインドウサイズ
334
400
  var width = 800;
335
401
  var height = 600;
@@ -358,6 +424,15 @@ $(document).ready(function () {
358
424
  //console.log("auto_scroll=" + $auto_scroll);
359
425
  });
360
426
 
427
+ // 設定ダイアログ
428
+ setting_dialog("setting", "setting_dialog", "config/setting.json");
429
+
430
+ // 設定保存
431
+ save_setting("save_setting", "config/setting.json");
432
+
433
+ // 設定読み込み
434
+ load_setting("load_setting");
435
+
361
436
  // ハンドラ登録
362
437
  $("#stop").click(function () {
363
438
  send_message("stop");
@@ -368,12 +443,11 @@ $(document).ready(function () {
368
443
  send_message("exec:" + $("#upFile").val());
369
444
  });
370
445
 
446
+
371
447
  select_file_dialog("search_str", "file", "dialog1", "select_file", "upFile");
372
448
 
373
449
  select_file_dialog("search_str2", "dir", "dialog2", "select_dir", "upDir");
374
450
 
375
- setting_dialog("setting", "setting_dialog", "config/setting.json");
376
-
377
451
  autocomp_history("upFile", "history.json")
378
452
 
379
453
  });
@@ -51,7 +51,13 @@ dir = File.dirname(File.expand_path(__FILE__))
51
51
  FileUtils.cd dir
52
52
 
53
53
  # ディレクトリ作成
54
- $home_dir = ENV["HOME"] + "/" + dir.split("/")[-1] + "/"
54
+ pp ARGV
55
+ if ARGV[0] == "test"
56
+ $home_dir = "./"
57
+ ARGV = []
58
+ else
59
+ $home_dir = ENV["HOME"] + "/" + dir.split("/")[-1] + "/"
60
+ end
55
61
  puts "home_dir=#{$home_dir}"
56
62
  FileUtils.mkdir_p("#{$home_dir}/logs")
57
63
  FileUtils.mkdir_p("#{$home_dir}/history")
@@ -97,12 +97,17 @@ class WsServer < Sinatra::Base
97
97
  end
98
98
  if msg =~ /^setting:/
99
99
  json_string = msg.gsub(/^setting:/, "")
100
- json = JSON.parse(json_string)
101
- File.open("#{$home_dir}/config/setting.json", "w") do |w|
102
- w.puts JSON.pretty_generate(json)
100
+ begin
101
+ json = JSON.parse(json_string)
102
+ File.open("#{$home_dir}/config/setting.json", "w") do |w|
103
+ w.puts JSON.pretty_generate(json)
104
+ end
105
+ json_config = config_json_hash(json)
106
+ $app.set_config(json_config)
107
+ rescue
108
+ # jsonファイルではない
109
+ ws_send("app_end:error")
103
110
  end
104
- json_config = config_json_hash(json)
105
- $app.set_config(json_config)
106
111
  end
107
112
  if msg =~ /^openfile:/
108
113
  file = msg.gsub(/^openfile:/, "")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browser_app_base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - masataka kuwayama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-26 00:00:00.000000000 Z
11
+ date: 2022-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -113,6 +113,9 @@ files:
113
113
  - bin/create_browser_app.rb
114
114
  - bin/start_sample.rb
115
115
  - browser_app_base.gemspec
116
+ - img/app.png
117
+ - img/setting.png
118
+ - img/setting_menu.png
116
119
  - lib/browser_app_base.rb
117
120
  - lib/browser_app_base/version.rb
118
121
  - lib/template/app_load.rb