11<template >
22 <div v-bind:class =" [isActive? 'canvas-mode' : '', 'jdl-editor']" >
3+ <nav class =" isFixed" >
4+ <el-form :inline =" true" >
5+ <el-form-item label =" ApplicationName" >
6+ <el-input
7+ size =" mini"
8+ v-model =" settings.baseName"
9+ placeholder =" please input Application Name"
10+ ></el-input >
11+ </el-form-item >
12+ <el-form-item label >
13+ <a href =" javascript:void(0);" @click =" settingdialogVisiable=true" >
14+ <i class =" el-icon-setting" >setting</i >
15+ </a >
16+ </el-form-item >
17+ </el-form >
18+ </nav >
19+
20+ <textarea id =" textarea" ref =" jdlcode" v-model =" code" ></textarea >
321 <canvas
422 id =" canvas"
523 v-bind:style =" {top: canvasStyle.t + 'px',left:canvasStyle.l+'px',width: canvasStyle.w+'px',height:canvasStyle.h+'px'}"
624 ></canvas >
7- <textarea id =" textarea" ref =" jdlcode" v-model =" code" ></textarea >
825 <div
926 id =" canvas-panner"
1027 @mouseenter =" isActive = true"
1330 @mouseleave =" mouseUp"
1431 v-bind:style =" {width:pannerStyle.w}"
1532 ></div >
33+
34+ <div class =" tools" >
35+ <el-col :span =" 6" >
36+ <el-upload
37+ ref =" upload"
38+ action =" #"
39+ :file-list =" fileList"
40+ :on-change =" importHandle"
41+ :auto-upload =" false"
42+ >
43+ <a href =" #" >
44+ <i class =" el-icon-upload" ></i >
45+ </a >
46+ </el-upload >
47+ </el-col >
48+ <el-col :span =" 18" >
49+ <a href =" javascript:void(0);" @click =" addHandle" >
50+ <i class =" el-icon-plus" ></i >
51+ </a >
52+ <a href =" javascript:void(0);" @click =" downHandle" >
53+ <i class =" el-icon-download" ></i >
54+ </a >
55+ <a href =" javascript:void(0);" @click =" delHandle" >
56+ <i class =" el-icon-delete" ></i >
57+ </a >
58+ </el-col >
59+ </div >
60+ <el-dialog title :visible.sync =" settingdialogVisiable" width =" 30%" :before-close =" handleClose" >
61+ <el-tabs type =" border-card" >
62+ <el-tab-pane label =" Application" name =" first" >
63+ <!-- Application form -->
64+ </el-tab-pane >
65+ <el-tab-pane label =" entities" name =" second" >
66+ <!-- entities form -->
67+ </el-tab-pane >
68+ <el-tab-pane label =" otherSettings" name =" third" >
69+ <!-- otherSettings form -->
70+ </el-tab-pane >
71+ </el-tabs >
72+ <span slot =" footer" class =" dialog-footer" >
73+ <el-button @click =" settingdialogVisiable = false" >cancel</el-button >
74+ <el-button type =" primary" @click =" settingdialogVisiable = false" >save</el-button >
75+ </span >
76+ </el-dialog >
1677 </div >
1778</template >
1879<script >
80+ import Vue from " vue" ;
1981import " codemirror/theme/base16-dark.css" ;
2082import " codemirror/lib/codemirror.css" ;
2183import " codemirror/addon/hint/show-hint.css" ;
84+ import " codemirror/addon/scroll/simplescrollbars.css" ;
85+
2286import " ./css/show-hint-jdl.css" ;
2387import " ./css/solarized.jdl.css" ;
2488
2589import _ from " lodash" ;
90+ import saveAs from " file-saver" ;
91+
2692import CodeMirror from " ./js/codemirror/codemirror.custom" ;
2793import nomnoml from " ./js/nomnoml/nomnoml.custom" ;
2894import skanaar from " ./js/nomnoml/shannar.custom" ;
95+ import parser from " jhipster-core/lib/dsl/api" ;
96+ import {
97+ DatabaseTypes ,
98+ ApplicationTypes ,
99+ convertToJHipsterJSON
100+ } from " jhipster-core" ;
101+
102+ import JDLCore from " jhipster-core" ;
29103
30104import " codemirror/addon/selection/active-line" ;
31105import " codemirror/addon/edit/matchbrackets" ;
32106import " codemirror/addon/hint/show-hint" ;
107+ import " codemirror/addon/scroll/simplescrollbars" ;
33108
34109export default {
35110 name: " jdlstudio" ,
@@ -44,10 +119,13 @@ export default {
44119 line: true ,
45120 matchBrackets: true ,
46121 smartIndent: true ,
122+ fullScreen: true ,
47123 extraKeys: {
48124 Ctrl: " autocomplete"
49- }
125+ },
126+ scrollbarStyle: " simple"
50127 },
128+
51129 code: `
52130entity Region {
53131 regionName String
@@ -73,13 +151,24 @@ relationship OneToOne {
73151 pannerwidth: " 45%" ,
74152 canvasPanner: {},
75153 vm: {},
76- zoomLevel: 0 ,
154+ zoomLevel: 1 ,
77155 offset: {
78156 x: 0 ,
79157 y: 0
80158 },
81159 mouseDownPoint: false ,
82- editor: {}
160+ settings: {
161+ baseName: " test" ,
162+ applicationType: " microservice" ,
163+ packageName: " com.test" ,
164+ prodDatabaseType: " mysql" ,
165+ devDatabaseType: " mysql" ,
166+ buildTool: " maven" ,
167+ cacheProvider: " hazelcast"
168+ },
169+ settingdialogVisiable: false ,
170+ editor: {},
171+ fileList: []
83172 };
84173 },
85174 computed: {},
@@ -123,9 +212,8 @@ relationship OneToOne {
123212 },
124213 positionCanvas (rect , superSampling , offset ) {
125214 var w = rect .width / superSampling;
126- var h = rect .height / superSampling - 60 ;
127- var t =
128- 300 * (1 - h / document .documentElement .clientHeight ) + offset .y + 50 ;
215+ var h = rect .height / superSampling;
216+ var t = 300 * (1 - h / document .documentElement .clientHeight ) + offset .y ;
129217 var l = 150 + (document .documentElement .clientWidth - w) / 2 + offset .x ;
130218 this .canvasStyle = {
131219 t: t,
@@ -144,6 +232,9 @@ relationship OneToOne {
144232 scale
145233 );
146234 this .positionCanvas (this .canvasElement , superSampling, this .offset );
235+ // save context
236+ Vue .localStorage .set (this .settings .baseName , this .editor .getValue ());
237+ // save file
147238 } catch (e) {
148239 console .error (e);
149240 }
@@ -174,36 +265,85 @@ relationship OneToOne {
174265 this .isActive = false ;
175266 this .mouseDownPoint = false ;
176267 this .pannerStyle .w = " 45%" ;
268+ },
269+ importHandle (file , fileList ) {
270+ var reader = new FileReader ();
271+ reader .readAsText (file .raw , " UTF-8" );
272+ reader .onload = e => {
273+ let data = e .currentTarget .result ;
274+ if (_ .endsWith (file .name , " .json" )) {
275+ console .log (data);
276+ }
277+ if (_ .endsWith (file .name , " .jdl" )) {
278+ this .editor .setValue (data);
279+ // data->jdlobject
280+ data = data .replace (/ \/\/ [^ \n\r ] * / gm , " " );
281+ let jdlObject = parser .parse (data);
282+ console .log (jdlObject);
283+ // TODO convert jdlObject to JSON
284+ // let jdlconfig = {
285+ // jdlObject: jdlObject,
286+ // databaseType: JDLCore.JHipsterDatabaseTypes.MYSQL,
287+ // applicationType: JDLCore.JHipsterApplicationTypes.MICROSERVICE
288+ // };
289+ // convertToJHipsterJSON(jdlconfig);
290+ }
291+ this .fileList = [];
292+ };
293+ },
294+ addHandle () {},
295+ downHandle () {
296+ let text = this .editor .getValue ();
297+ let blob = new Blob ([text], { type: " text/plain;charset=utf-8" });
298+ saveAs (blob, this .settings .baseName + " .jdl" );
299+ },
300+ delHandle () {
301+ this .editor .setValue (" " );
302+ },
303+ handleClose () {
304+ this .settingdialogVisiable = false ;
177305 }
178306 }
179307};
180308 </script >
181309
182310<style lang="css">
311+ .isFixed {
312+ position : fixed ;
313+ height : 25px ;
314+ left : 33% ;
315+ top : 5px ;
316+ transform : translate (-50% , -50% );
317+ z-index : 999 ;
318+ background : rgba (0 , 0 , 0 , 0 );
319+ transition : all 1s ;
320+ color : #657b83 ;
321+ }
183322#textarea {
184323 outline : none ;
185324 position : absolute ;
186325 z-index : 1 ;
187326 width : 100% ;
188- height : auto ;
327+ height : 100 % ;
189328 background : rgba (0 , 0 , 0 , 0 );
190329 box-sizing : border-box ;
191330 border : 0 ;
192331 font-family : Consolas, Menlo, monospace ;
193332 color : #657b83 ;
194- padding : 30px 0 0 40px ;
195333 resize : none ;
196334 opacity : 1 ;
335+ margin : 60px 0 20px 0 ;
197336 transition : opacity 0.3s ;
198337}
199338.CodeMirror {
200- height : auto ;
339+ height : 100 % ;
201340 border : 0 ;
202341 width : 100% ;
203342 margin : 60px 0 20px 0 ;
204343 line-height : 25px ;
205344 font-size : 16px ;
206345 font-family : Consolas, Monaco, monospace ;
346+ font-weight : 500 ;
207347 opacity : 1 ;
208348 transition : opacity 0.3s ;
209349}
@@ -220,6 +360,9 @@ relationship OneToOne {
220360 color : #fdf6e3 ;
221361 font-size : 1.2em ;
222362}
363+ .tools .tool-btn {
364+ padding-left : 2px ;
365+ }
223366.canvas-tools i {
224367 font-size : 1.5em ;
225368}
@@ -284,9 +427,7 @@ relationship OneToOne {
284427 height : 24px ;
285428 margin-bottom : 5px ;
286429}
287- .tools > a {
288- margin-left : 5px ;
289- }
430+
290431.tools > .logo {
291432 color : #fdf6e3 ;
292433 font-size : 150% ;
@@ -325,4 +466,28 @@ relationship OneToOne {
325466 font-size : 25px ;
326467 margin : 0 10px ;
327468}
469+ .el-upload-list {
470+ display : none ;
471+ }
472+ .el-form-item__label {
473+ color : #fdf6e3 ;
474+ font-weight : 600 ;
475+ }
476+ .el-form-item a {
477+ color : #fdf6e3 ;
478+ }
479+ .el-input--mini .el-input__inner {
480+ background : rgb (0 , 0 , 0 , 0 );
481+ border : 1px solid rgb (40 , 44 , 52 );
482+ color : aliceblue ;
483+ }
484+ .el-dialog__body {
485+ padding : 10px 20px ;
486+ }
487+ .el-dialog__headerbtn {
488+ position : absolute ;
489+ top : 10px ;
490+ right : 10px ;
491+ font-size : 20px ;
492+ }
328493 </style >
0 commit comments