-
Notifications
You must be signed in to change notification settings - Fork 30
/
ui_index.html
215 lines (206 loc) · 6.18 KB
/
ui_index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link href="./css/ui_index.less" rel="stylesheet/less"/>
<script type="text/javascript" src="js/less.min.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<link href="./css/icomoon/style.css" rel="stylesheet"/>
<script type="text/javascript" src="js/i18.js"></script>
<script>
//whether run in nw.js
var is_nwjs = (typeof nw != 'undefined');
//whether run in dev mode (nw.js SDK version)
var is_nwjsdev = is_nwjs && (window.navigator.plugins.namedItem('Native Client') !== null);
if (is_nwjsdev)
nw.Window.get().showDevTools();
//the render window(native nw.js window)
var render_win = null;
//initialization after load
$(document).ready(function(){
var win = nw.Window.get();
win.on('close', function() {
if (render_win)
{
render_win.close(true);
render_win = null;
}
win.close(true);
});
//native window menu
if (is_nwjs)
{
var menu = new nw.Menu({type:'menubar'});
var submenu_file = new nw.Menu();
submenu_file.append(new nw.MenuItem({label:menu_text('file-open'), click: function(){open_file();}}));
submenu_file.append(new nw.MenuItem({label:menu_text('file-save-as'), click: function(){save_file_as();}}));
menu.append(new nw.MenuItem({ label: menu_text('file'), submenu:submenu_file }));
var submenu_img = new nw.Menu();
submenu_img.append(new nw.MenuItem({label:menu_text('img-png'), click: function(){export_img('png');}}));
submenu_img.append(new nw.MenuItem({label:menu_text('img-jpeg'), click: function(){export_img('jpeg');}}));
menu.append(new nw.MenuItem({ label: menu_text('img'), submenu:submenu_img }));
menu.append(new nw.MenuItem({ label: menu_text('zoomin'), click: function(){zoom(0.2);} }));
menu.append(new nw.MenuItem({ label: menu_text('zoomout'), click: function(){zoom(-0.2);} }));
menu.append(new nw.MenuItem({ label: menu_text('zoomrst'), click: function(){zoom(0);} }));
win.menu = menu;
}
//toolbar for non-native env or dev mode
if (!is_nwjs || is_nwjsdev)
{
document.getElementById('toolbar').style['display'] = 'block';
}
//open the render window
nw.Window.open('ui_render.html', {
new_instance:false,
id:"render",
title:'Sequence Diagram View',
min_width:200,
min_height:200
},
function(w){
render_win = w;
win.focus();
render_win.on('close', function(){
render_win.close(true);
win.close(true);
});
}
);
//editor update event handler
var editor = $('#editor');
editor.change(function(){
$(this).attr('editor_updated',1);
}).keyup(function(){
$(this).attr('editor_updated',1);
});
setInterval(function(){
var updated = parseInt(editor.attr('editor_updated'));
if (updated>0 && render_win!=null)
{
render_win.window.draw(editor.val());
editor.attr('editor_updated',0);
}
},1500);
//dragndrop local file to open
window.ondrop=function(e)
{
e.preventDefault();
if (e.dataTransfer.files.length>0)
{
var file_path = e.dataTransfer.files[0].path;
const fs = require('fs');
fs.readFile(file_path, (err,data)=>{
if(err)
{
alert(err);
return;
}
editor.val(data).attr('editor_updated',1);
});
}
return false;
}
});
//open and load local file into editor
function open_file()
{
$('#open_file').click();
}
function open_file_on_select()
{
var file = $('#open_file').val();
fs = require('fs');
fs.readFile(file, function(err, data) {
if (err)
{
alert('Open file error: '+err);
return;
}
var editor = $('#editor');
editor.val(data).change();
});
}
//save content into file as select path-name
function save_file_as()
{
$('#save_file_as').click();
}
function save_file_as_on_select()
{
var file = $('#save_file_as').val();
fs = require('fs');
fs.writeFile(file, $('#editor').val(), function(err) {
if (err)
{
alert('Save file error: '+err);
return;
}
});
}
//export diagram imange and save on local disk
function export_img(format)
{
if (!is_nwjs)
{
alert('Only supported in native version. goto https://github.com/echoma/text_sequence_diagram/wiki/Download');
return;
}
//check format, set mime
var mime = 'image/png';
if (format=='jpeg')
{
mime = 'image/jpeg';
}
else if (format!='png')
{
alert('Non-supported format: '+format);
return;
}
render_win.capturePage(
function(img_data){
var alink = document.getElementById('export_img');
alink.download = 'export.'+format;
alink.href = img_data;
//alink.dataset.downloadurl = [mime, alink.download, alink.href].join(':');
alink.click();
},{format:format, datatype:'datauri'}
);
}
//adjust zoom ratio
function zoom(inc)
{
if (inc==0)
render_win.zoomLevel = 0;
else
render_win.zoomLevel += inc;
}
</script>
</head>
<body>
<div id="toolbar" class="toolbar">
<button onClick="zoom(0.2)" title="Zoom In"><span class="icon-zoom-in"></span> Zoom In</button>
<button onClick="zoom(-0.2)" title="Zoom Out"><span class="icon-zoom-out"></span> Zoom Out</button>
<button onClick="zoom(0)" title="Zoom Reset"><span class="icon-spinner11"></span> Zoom Reset</button>
</div>
<textarea id="editor" class="editor" editor_updated="1">
Sample Diagram @ v1.0 @ 20160416 @ EchoMa
# Main Part
Conn Server -> Safe Domain GW : new order request
Safe Domain GW -> Logic Control : internal protocol
Logic Control : check param
Logic Control -> Order Manage : add new order
Order Manage -> Logic Control : order created
Logic Control --> Safe Domain GW : success response
Safe Domain GW --> Conn Server : response
# Bottom
[This is a description for this diagram]
[ how an order request is passed between sub-systems ]
# TIPS:
# 1. You can drag and drop a text file into this editor.
# 2. UTF-8 is used when opening a text file.
</textarea>
<a id="export_img" style="display:none"></a>
<input id="open_file" type="file" style="display:none" onchange="open_file_on_select()"/>
<input id="save_file_as" type="file" style="display:none" onchange="save_file_as_on_select()" nwsaveas />
</body>
</html>