active_designer 0.0.0
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.
- checksums.yaml +7 -0
- data/bin/active_designer +8 -0
- data/lib/active_designer/file_converter.rb +27 -0
- data/lib/active_designer/public/css/bootstrap.min.css +7 -0
- data/lib/active_designer/public/css/cards.css +107 -0
- data/lib/active_designer/public/css/font-awesome-4.7.0/css/font-awesome.min.css +4 -0
- data/lib/active_designer/public/css/font-awesome-4.7.0/fonts/FontAwesome.otf +0 -0
- data/lib/active_designer/public/css/font-awesome-4.7.0/fonts/fontawesome-webfont.eot +0 -0
- data/lib/active_designer/public/css/font-awesome-4.7.0/fonts/fontawesome-webfont.svg +2671 -0
- data/lib/active_designer/public/css/font-awesome-4.7.0/fonts/fontawesome-webfont.ttf +0 -0
- data/lib/active_designer/public/css/font-awesome-4.7.0/fonts/fontawesome-webfont.woff +0 -0
- data/lib/active_designer/public/css/font-awesome-4.7.0/fonts/fontawesome-webfont.woff2 +0 -0
- data/lib/active_designer/public/css/main.css +199 -0
- data/lib/active_designer/public/js/bootstrap.min.js +7 -0
- data/lib/active_designer/public/js/jquery-3.1.1.js +10220 -0
- data/lib/active_designer/public/js/jsPlumb-2.2.8.js +13836 -0
- data/lib/active_designer/public/js/schema/add-column.js +82 -0
- data/lib/active_designer/public/js/schema/edit-checker.js +14 -0
- data/lib/active_designer/public/js/schema/edit-table-name.js +77 -0
- data/lib/active_designer/public/js/schema/jsPlumb.js +70 -0
- data/lib/active_designer/public/js/schema/listeners.js +265 -0
- data/lib/active_designer/public/js/schema/main.js +72 -0
- data/lib/active_designer/public/js/schema/mouse-controls.js +15 -0
- data/lib/active_designer/public/js/schema/table-html.js +24 -0
- data/lib/active_designer/public/js/tether.min.js +1 -0
- data/lib/active_designer/schema_creator.rb +86 -0
- data/lib/active_designer/template.html.erb +121 -0
- data/lib/active_designer.rb +69 -0
- metadata +76 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
function editColumnName(){
|
2
|
+
$('body').unbind('click')
|
3
|
+
$('.column-title').click(function() {
|
4
|
+
if (openEditChecker()) { return }
|
5
|
+
$(this).popover('hide');
|
6
|
+
this.outerHTML = "<form><input class='column-form' type='text' name='tableName' value='" + this.innerText + "'></form>";
|
7
|
+
enterKeypressColumn()
|
8
|
+
clickOutsideColumnKeypress()
|
9
|
+
});
|
10
|
+
}
|
11
|
+
|
12
|
+
function enterKeypressColumn() {
|
13
|
+
$('.column-form').keypress(function (e) {
|
14
|
+
var key = e.which;
|
15
|
+
if(key == 13) {
|
16
|
+
updateColumnName()
|
17
|
+
return false;
|
18
|
+
}
|
19
|
+
});
|
20
|
+
}
|
21
|
+
|
22
|
+
function updateColumnName() {
|
23
|
+
let columnName = $('.column-form')[0].value;
|
24
|
+
$('.column-form')[0].parentElement.outerHTML =
|
25
|
+
"<span class='column-title' data-toggle='popover' data-trigger='hover' data-content='Edit column name'>" + columnName.toLowerCase() + "</span>"
|
26
|
+
$('[data-toggle="popover"]').popover()
|
27
|
+
editColumnName()
|
28
|
+
}
|
29
|
+
|
30
|
+
function clickOutsideColumnKeypress() {
|
31
|
+
$('body').click(function() {
|
32
|
+
if($(event.target).is('span.column-title')) { return }
|
33
|
+
if(!$(event.target).is('.column-form')) {
|
34
|
+
updateColumnName()
|
35
|
+
}
|
36
|
+
});
|
37
|
+
}
|
38
|
+
|
39
|
+
function editTypeName(columnType){
|
40
|
+
$('.tag-pill').click(function() {
|
41
|
+
if ($('input').length === 0) {
|
42
|
+
$(this).popover('hide');
|
43
|
+
$('body').append(
|
44
|
+
"<form><input class='type-form' type='hidden' value='placeholder'></form>"
|
45
|
+
)
|
46
|
+
this.outerHTML =
|
47
|
+
"<div class='dropdown open float-xs-left'>" +
|
48
|
+
"<div class='btn btn-default btn-xs dropdown-toggle' id='dropdownMenuButton' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>" +
|
49
|
+
columnType +
|
50
|
+
"</div>" +
|
51
|
+
"<div class='dropdown-menu' aria-labelledby='dropdownMenuButton'>" +
|
52
|
+
"<div class='dropdown-item'>integer</div>" +
|
53
|
+
"<div class='dropdown-item'>decimal</div>" +
|
54
|
+
"<div class='dropdown-item'>text</div>" +
|
55
|
+
"<div class='dropdown-item'>ref</div>" +
|
56
|
+
"</div>" +
|
57
|
+
"</div>"
|
58
|
+
setTimeout(cont,10)
|
59
|
+
function cont() {
|
60
|
+
$("#dropdownMenuButton").dropdown("toggle")
|
61
|
+
}
|
62
|
+
$('.dropdown-item').click(function() {
|
63
|
+
let typeName = this.innerText;
|
64
|
+
this.parentElement.parentElement.outerHTML =
|
65
|
+
"<span class='tag tag-default tag-pill float-xs-left' data-toggle='popover' data-trigger='hover' data-content='Edit type'>" + typeName + "</span>"
|
66
|
+
$('[data-toggle="popover"]').popover()
|
67
|
+
$('input')[0].outerHTML = ""
|
68
|
+
editTypeName(columnType)
|
69
|
+
});
|
70
|
+
}
|
71
|
+
});
|
72
|
+
}
|
73
|
+
|
74
|
+
function columnHTML(columnObj,deleteClass) {
|
75
|
+
return `<li class='list-group-item' id='${columnObj.id}'>` +
|
76
|
+
`<span class='tag tag-default float-xs-left type-span' >${columnObj.type}</span>` +
|
77
|
+
"<div class='column-title-outer' >" +
|
78
|
+
`<span class='column-title'>${columnObj.name}</span>` +
|
79
|
+
"</div>" +
|
80
|
+
`<i class='fa fa-trash ${deleteClass}' data-toggle='popover' data-trigger='hover' data-content='Destroy column'></i>` +
|
81
|
+
"</li>"
|
82
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
function getSchema() {
|
2
|
+
return JSON.parse(localStorage.getItem('schema'));
|
3
|
+
}
|
4
|
+
|
5
|
+
function setSchema(schema) {
|
6
|
+
localStorage.setItem("schema",JSON.stringify(schema));
|
7
|
+
}
|
8
|
+
|
9
|
+
let newTableID = 301;
|
10
|
+
|
11
|
+
function openEditChecker() {
|
12
|
+
if ($('input').length > 0) { return true };
|
13
|
+
return false;
|
14
|
+
}
|
@@ -0,0 +1,77 @@
|
|
1
|
+
function editTableName(){
|
2
|
+
$('body').unbind('click');
|
3
|
+
$('.table-title').on('dblclick',null,null,setupTableNameForm);
|
4
|
+
}
|
5
|
+
|
6
|
+
function setupTableNameForm(event) {
|
7
|
+
if (openEditChecker()) { return };
|
8
|
+
let originalTitle = this.innerText;
|
9
|
+
$(this).popover('hide');
|
10
|
+
let cardID = $(this).parents('.card')[0].id;
|
11
|
+
this.outerHTML = tableTitleFormHTML(this.innerText);
|
12
|
+
addEditTableNameListeners(originalTitle, cardID);
|
13
|
+
}
|
14
|
+
|
15
|
+
function addEditTableNameListeners(originalTitle, cardID) {
|
16
|
+
$('.table-form').on('keypress', null, { originalTitle: originalTitle,
|
17
|
+
cardID: cardID
|
18
|
+
}, titleKeypressListener);
|
19
|
+
$('body').on('click', null, { originalTitle: originalTitle,
|
20
|
+
cardID: cardID,
|
21
|
+
count: 0
|
22
|
+
}, titleBodyClickListener);
|
23
|
+
}
|
24
|
+
|
25
|
+
function titleKeypressListener(e) {
|
26
|
+
var key = e.which;
|
27
|
+
if(key == 13) {
|
28
|
+
titleUpdate(e)
|
29
|
+
return false;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
function titleBodyClickListener(e) {
|
34
|
+
if(!$(event.target).is('.table-form') && e.data.count >= 1 ) {
|
35
|
+
titleUpdate(e);
|
36
|
+
}
|
37
|
+
e.data.count++;
|
38
|
+
}
|
39
|
+
|
40
|
+
function titleUpdate(e) {
|
41
|
+
let schema = getSchema();
|
42
|
+
let tableName = $('.table-form')[0].value;
|
43
|
+
$('.table-form')[0].parentElement.outerHTML = tableTitleHTML(tableName);
|
44
|
+
$('[data-toggle="popover"]').popover();
|
45
|
+
if (e.data.originalTitle !== tableName) {
|
46
|
+
let cardID = e.data.cardID;
|
47
|
+
schema[cardID].name = tableName;
|
48
|
+
checkTitleStatus(cardID,schema);
|
49
|
+
}
|
50
|
+
editTableName();
|
51
|
+
setSchema(schema);
|
52
|
+
}
|
53
|
+
|
54
|
+
function tableTitleHTML(tableName) {
|
55
|
+
return "<h4 class='card-title table-title' data-toggle='popover' data-trigger='hover' data-content='Edit table name'>" +
|
56
|
+
tableName +
|
57
|
+
"</h4>";
|
58
|
+
}
|
59
|
+
|
60
|
+
function tableTitleFormHTML(priorText) {
|
61
|
+
return `<form><input class='table-form' type='text' name='tableName' value='${priorText}'></form>`;
|
62
|
+
}
|
63
|
+
|
64
|
+
function checkTitleStatus(cardID,schema) {
|
65
|
+
|
66
|
+
if (schema[cardID].status.new === false) {
|
67
|
+
updateTitleStatus(cardID,schema);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
function updateTitleStatus(cardID,schema) {
|
72
|
+
if (schema[cardID].name === schema[cardID].original_name) {
|
73
|
+
schema[cardID].status.modified = false;
|
74
|
+
} else {
|
75
|
+
schema[cardID].status.modified = true;
|
76
|
+
}
|
77
|
+
}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
let zoom = .7;
|
2
|
+
|
3
|
+
let connections = {}
|
4
|
+
|
5
|
+
let j = jsPlumb.getInstance({
|
6
|
+
Container:"foo"
|
7
|
+
});
|
8
|
+
|
9
|
+
jsPlumb.ready(function() {
|
10
|
+
let canvasLeft = 0
|
11
|
+
let canvasTop = 0
|
12
|
+
|
13
|
+
window.setZoom = function(zoom, instance, transformOrigin, el) {
|
14
|
+
transformOrigin = transformOrigin || [ 0.5, 0.5 ];
|
15
|
+
instance = instance || jsPlumb;
|
16
|
+
el = el || instance.getContainer();
|
17
|
+
var p = [ "webkit", "moz", "ms", "o" ],
|
18
|
+
s = "scale(" + zoom + ")",
|
19
|
+
oString = (transformOrigin[0] * 100) + "% " + (transformOrigin[1] * 100) + "%";
|
20
|
+
|
21
|
+
for (var i = 0; i < p.length; i++) {
|
22
|
+
el.style[p[i] + "Transform"] = s;
|
23
|
+
el.style[p[i] + "TransformOrigin"] = oString;
|
24
|
+
}
|
25
|
+
|
26
|
+
el.style["transform"] = s;
|
27
|
+
el.style["transformOrigin"] = oString;
|
28
|
+
|
29
|
+
instance.setZoom(zoom);
|
30
|
+
};
|
31
|
+
|
32
|
+
$('#zoom-in').click(function() {
|
33
|
+
if (zoom > .4) {
|
34
|
+
let position = $('.slider').position().left + 10
|
35
|
+
$('.slider').css({left: position})
|
36
|
+
zoom = zoom - .05
|
37
|
+
window.setZoom(zoom,null,null,$('#foo')[0])
|
38
|
+
}
|
39
|
+
})
|
40
|
+
|
41
|
+
$('#zoom-out').click(function() {
|
42
|
+
if (zoom < 1) {
|
43
|
+
let position = $('.slider').position().left - 10;
|
44
|
+
$('.slider').css({left: position});
|
45
|
+
zoom = zoom + .05;
|
46
|
+
window.setZoom(zoom,null,null,$('#foo')[0]);
|
47
|
+
}
|
48
|
+
})
|
49
|
+
});
|
50
|
+
|
51
|
+
function setCardDraggable(card) {
|
52
|
+
jsPlumb.draggable(card, {filter:':not(.fa-arrows)'});
|
53
|
+
}
|
54
|
+
|
55
|
+
function createConnector(source,target,tableID) {
|
56
|
+
let conn = jsPlumb.connect({
|
57
|
+
source:source,
|
58
|
+
target:target,
|
59
|
+
anchors:[["Continuous", { faces: ["left", "right"] }],["Continuous", { faces: ["left", "right"] }]],
|
60
|
+
endpoint:["Dot", { radius: 2}],
|
61
|
+
paintStyle: { strokeWidth:5, stroke:'#D9D9DA' },
|
62
|
+
detachable: false,
|
63
|
+
maxConnections:-1
|
64
|
+
});
|
65
|
+
if (connections[tableID]) {
|
66
|
+
connections[tableID].push(conn)
|
67
|
+
} else {
|
68
|
+
connections[tableID] = [conn]
|
69
|
+
}
|
70
|
+
}
|
@@ -0,0 +1,265 @@
|
|
1
|
+
|
2
|
+
function destroyTable(){
|
3
|
+
if (openEditChecker()) { return };
|
4
|
+
$('.delete-table').unbind('click');
|
5
|
+
$('.delete-table').click(function() {
|
6
|
+
$(this).popover('dispose');
|
7
|
+
let card = $(this).parents('.card');
|
8
|
+
let listItems = card.find('.list-group-item');
|
9
|
+
for(let i = 0; i < listItems.length; i++) {
|
10
|
+
jsPlumb.remove(listItems[i]);
|
11
|
+
};
|
12
|
+
card[0].outerHTML = "";
|
13
|
+
});
|
14
|
+
}
|
15
|
+
|
16
|
+
function destroyColumn() {
|
17
|
+
let schema = getSchema();
|
18
|
+
if (openEditChecker()) { return }
|
19
|
+
$('.delete-column').unbind('click')
|
20
|
+
$('.delete-column').click(function() {
|
21
|
+
$(this).popover('dispose');
|
22
|
+
let column = $(this).parents('.list-group-item')[0];
|
23
|
+
let columnID = column.id;
|
24
|
+
column.outerHTML = "";
|
25
|
+
let tableID = `tbl-${columnID.split('-')[1]}`;
|
26
|
+
let conns = connections[tableID];
|
27
|
+
if (typeof(conns) !== "undefined") {
|
28
|
+
for(let i = 0; i < conns.length; i++) {
|
29
|
+
jsPlumb.repaintEverything()
|
30
|
+
jsPlumb.repaint(conns[i].source)
|
31
|
+
}
|
32
|
+
}
|
33
|
+
let columns = schema[tableID].columns
|
34
|
+
let status = columns[columnID].status;
|
35
|
+
if (status.new) {
|
36
|
+
columns[columnID] = undefined;
|
37
|
+
} else {
|
38
|
+
status.deleted = true
|
39
|
+
}
|
40
|
+
});
|
41
|
+
setSchema(schema);
|
42
|
+
}
|
43
|
+
|
44
|
+
function destroyReference() {
|
45
|
+
if (openEditChecker()) { return };
|
46
|
+
let schema = getSchema();
|
47
|
+
$('.delete-ref').unbind('click')
|
48
|
+
$('.delete-ref').click(function() {
|
49
|
+
$(this).popover('dispose');
|
50
|
+
let reference = $(this).parents('.list-group-item')[0];
|
51
|
+
let referenceID = reference.id;
|
52
|
+
let tableID = `tbl-${referenceID.split('-')[1]}`;
|
53
|
+
jsPlumb.remove(reference);
|
54
|
+
let conns = connections[tableID];
|
55
|
+
for(let i = 0; i < conns.length; i++) {
|
56
|
+
if (conns[i].source) {
|
57
|
+
jsPlumb.repaintEverything()
|
58
|
+
jsPlumb.repaint(conns[i].source)
|
59
|
+
}
|
60
|
+
}
|
61
|
+
let references = schema[tableID].references
|
62
|
+
let status = references[referenceID].status;
|
63
|
+
if (status.new) {
|
64
|
+
references[referenceID] = undefined;
|
65
|
+
} else {
|
66
|
+
status.deleted = true
|
67
|
+
}
|
68
|
+
});
|
69
|
+
setSchema(schema);
|
70
|
+
}
|
71
|
+
|
72
|
+
function newColumnObj(tableID, columnName, columnType, schema) {
|
73
|
+
let tableNum = tableID.split('-')[1];
|
74
|
+
let prevID = 100;
|
75
|
+
let columnIDs = Object.keys(schema[`tbl-${tableNum}`].columns);
|
76
|
+
if (columnIDs.length !== 0) {
|
77
|
+
prevID = parseInt(columnIDs[columnIDs.length -1].split('-')[2]);
|
78
|
+
}
|
79
|
+
let columnID = `col-${tableNum}-${prevID + 1}`;
|
80
|
+
return schema[tableID].columns[columnID] = {
|
81
|
+
name: columnName,
|
82
|
+
original_name: null,
|
83
|
+
type: columnType,
|
84
|
+
original_type: null,
|
85
|
+
id: columnID,
|
86
|
+
status: { original: false, modified: false, new: true }
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
function newRefObj(tableID,foreignTableName,foreignTableID, schema) {
|
91
|
+
let tableNum = tableID.split('-')[1];
|
92
|
+
let prevID = 100;
|
93
|
+
let columnIDs = Object.keys(schema[`tbl-${tableNum}`].references);
|
94
|
+
if (columnIDs.length !== 0) {
|
95
|
+
prevID = parseInt(columnIDs[columnIDs.length -1].split('-')[2]);
|
96
|
+
}
|
97
|
+
let columnID = `col-${tableNum}-${prevID + 1}`;
|
98
|
+
return schema[tableID].references[columnID] = {
|
99
|
+
id: columnID,
|
100
|
+
table_id: tableID,
|
101
|
+
foreign_table_name: foreignTableName,
|
102
|
+
foreign_table_id: foreignTableID,
|
103
|
+
status: { original: false, new: true, deleted: false}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
function addColumn() {
|
108
|
+
if (openEditChecker()) { return };
|
109
|
+
$('.fa-plus-square').unbind('click');
|
110
|
+
$('.fa-plus-square').on('click', null, {}, displayColumnJumbo);
|
111
|
+
}
|
112
|
+
|
113
|
+
function displayColumnJumbo() {
|
114
|
+
$('body').append(addColumnCardHTML());
|
115
|
+
let card = $(this).parents('.card');
|
116
|
+
$('#column-reference').change(function(){
|
117
|
+
if (this.checked) {
|
118
|
+
$('.add-column-card').find('.column-html').addClass('hidden')
|
119
|
+
$('.add-column-card').find('.reference-html').removeClass('hidden')
|
120
|
+
} else if (!this.checked) {
|
121
|
+
$('.add-column-card').find('.reference-html').addClass('hidden')
|
122
|
+
$('.add-column-card').find('.column-html').removeClass('hidden')
|
123
|
+
}
|
124
|
+
});
|
125
|
+
|
126
|
+
$('.add-column-card .fa-times').click(function() {
|
127
|
+
$('.add-column-card')[0].outerHTML = ""
|
128
|
+
});
|
129
|
+
|
130
|
+
$('form button').click(function() {
|
131
|
+
let schema = getSchema();
|
132
|
+
let referenceChecked = $('form input#column-reference')[0].checked
|
133
|
+
if (referenceChecked) {
|
134
|
+
let foreignTableName = $('form input#foreign-table-name').val()
|
135
|
+
let cardIDs = Object.keys(schema)
|
136
|
+
for(let i = 0; i < cardIDs.length; i++) {
|
137
|
+
if (schema[cardIDs[i]].name === foreignTableName) {
|
138
|
+
let referenceRelationship = $('input[name="ref-rel"]:checked').val()
|
139
|
+
let foreignTableHTML = $(`#${cardIDs[i]}`);
|
140
|
+
|
141
|
+
let prevRefs = schema[card[0].id].references
|
142
|
+
let prevRefKeys = Object.keys(prevRefs)
|
143
|
+
let prevStatus = false
|
144
|
+
for(let i = 0; i < prevRefKeys.length; i++) {
|
145
|
+
if (prevRefs[prevRefKeys[i]].foreign_table_name === foreignTableName) {
|
146
|
+
prevStatus = true
|
147
|
+
}
|
148
|
+
}
|
149
|
+
if (!prevStatus) {
|
150
|
+
let foreignKeyHTML = foreignTableHTML.find(`#${foreignTableHTML[0].id}-id-column`);
|
151
|
+
let listGroup = card.find('.list-group');
|
152
|
+
let refObj = newRefObj(card[0].id, foreignTableName, foreignTableHTML[0].id, schema);
|
153
|
+
listGroup.append(columnHTML({id: refObj.id, type: "integer", name: `${foreignTableName}_id`},"delete-ref"));
|
154
|
+
let newColumnHTML = $(`#${refObj.id}`)[0]
|
155
|
+
createConnector(newColumnHTML,foreignKeyHTML);
|
156
|
+
}
|
157
|
+
else {
|
158
|
+
console.log("already happend")
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}
|
162
|
+
} else {
|
163
|
+
let columnName = $('form input#column-name').val()
|
164
|
+
let columnType = $('form select#column-type-select').val()
|
165
|
+
let listGroup = card.find('.list-group');
|
166
|
+
let columnObj = newColumnObj(card[0].id, columnName, columnType, schema)
|
167
|
+
listGroup.append(columnHTML(columnObj, "delete-column"));
|
168
|
+
}
|
169
|
+
setSchema(schema);
|
170
|
+
$('.add-column-card')[0].outerHTML = ""
|
171
|
+
destroyColumn()
|
172
|
+
destroyReference()
|
173
|
+
return false
|
174
|
+
})
|
175
|
+
|
176
|
+
$('[data-toggle="popover"]').popover();
|
177
|
+
}
|
178
|
+
|
179
|
+
function addColumnCardHTML() {
|
180
|
+
return "<div class='card add-column-card'>" +
|
181
|
+
"<div class='card-header'>" +
|
182
|
+
"<h4 class='card-title'>Enter Column Information</h4>" +
|
183
|
+
"<i class='fa fa-times' aria-hidden='true'></i>" +
|
184
|
+
"</div>" +
|
185
|
+
"<div class='card-block'>" +
|
186
|
+
"<form>" +
|
187
|
+
"<div class='ref-check'>" +
|
188
|
+
"<label class='ref-check-label'>" +
|
189
|
+
"<input class='ref-check-input' type='checkbox' id='column-reference' value='reference' > reference" +
|
190
|
+
"</label>" +
|
191
|
+
"</div>" +
|
192
|
+
datatypeSelectoHTML() +
|
193
|
+
foreignTableRadioButtonHTML() +
|
194
|
+
"<div class='form-group'>" +
|
195
|
+
"<button type='submit' class='btn btn-primary'>Submit</button>" +
|
196
|
+
"</div>" +
|
197
|
+
"</form>" +
|
198
|
+
"</div>" +
|
199
|
+
"</div>"
|
200
|
+
}
|
201
|
+
|
202
|
+
|
203
|
+
function foreignTableRadioButtonHTML() {
|
204
|
+
return "<div class='reference-html hidden'>" +
|
205
|
+
"<div class='form-group'>" +
|
206
|
+
"<input type='text' class='form-control' id='foreign-table-name' placeholder='foreign table name'>" +
|
207
|
+
"</div>" +
|
208
|
+
"<div class='form-check'>" +
|
209
|
+
"<label class='form-check-label'>" +
|
210
|
+
"<input class='form-check-input' type='radio' name='ref-rel' id='ref-rel-mto' value='mto'>" +
|
211
|
+
" Many to one reference" +
|
212
|
+
"</label>" +
|
213
|
+
"</div>" +
|
214
|
+
"<div class='form-check'>" +
|
215
|
+
"<label class='form-check-label'>" +
|
216
|
+
"<input class='form-check-input' type='radio' name='ref-rel' id='ref-rel-mto' value='mtm'>" +
|
217
|
+
" Many to many reference" +
|
218
|
+
"</label>" +
|
219
|
+
"</div>" +
|
220
|
+
"</div>"
|
221
|
+
}
|
222
|
+
|
223
|
+
function datatypeSelectoHTML() {
|
224
|
+
return "<div class='column-html'>" +
|
225
|
+
"<div class='form-group'>" +
|
226
|
+
"<input type='text' class='form-control' id='column-name' placeholder='column name'>" +
|
227
|
+
"</div>" +
|
228
|
+
"<div class='form-group'>" +
|
229
|
+
"<label for='column-type-select'>Column Type</label>" +
|
230
|
+
"<select id='column-type-select'>" +
|
231
|
+
"<option selected>select</option>" +
|
232
|
+
"<option value='character'>CHARACTER(n)</option>" +
|
233
|
+
"<option value='varchar'>VARCHAR(n)</option>" +
|
234
|
+
"<option value='binary'>BINARY(n)</option>" +
|
235
|
+
"<option value='boolean'>BOOLEAN</option>" +
|
236
|
+
"<option value='varbinary'>VARBINARY(n)</option>" +
|
237
|
+
"<option value='integer-precision'>INTEGER(p)</option>" +
|
238
|
+
"<option value='smallint'>SMALLINT</option>" +
|
239
|
+
"<option value='integer'>INTEGER</option>" +
|
240
|
+
"<option value='bigint'>BIGINT</option>" +
|
241
|
+
"<option value='decimal'>DECIMAL(p,s)</option>" +
|
242
|
+
"<option value='numeric'>NUMERIC(p,s)</option>" +
|
243
|
+
"<option value='float'>FLOAT(p)</option>" +
|
244
|
+
"<option value='real'>REAL</option>" +
|
245
|
+
"<option value='float'>FLOAT</option>" +
|
246
|
+
"<option value='date'>DATE</option>" +
|
247
|
+
"<option value='time'>TIME</option>" +
|
248
|
+
"<option value='timestamp'>TIMESTAMP</option>" +
|
249
|
+
"<option value='interval'>INTERVAL</option>" +
|
250
|
+
"<option value='array'>ARRAY</option>" +
|
251
|
+
"<option value='multiset'>MULTISET</option>" +
|
252
|
+
"<option value='xml'>XML</option>" +
|
253
|
+
"</select>" +
|
254
|
+
"</div>" +
|
255
|
+
"</div>"
|
256
|
+
}
|
257
|
+
|
258
|
+
function addListeners(){
|
259
|
+
destroyTable()
|
260
|
+
editTableName()
|
261
|
+
addColumn()
|
262
|
+
destroyColumn()
|
263
|
+
destroyReference()
|
264
|
+
$('[data-toggle="popover"]').popover()
|
265
|
+
}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
$(document).ready(function() {
|
2
|
+
|
3
|
+
function createSchemaFromParams() {
|
4
|
+
setCardDraggable($('.card'));
|
5
|
+
window.setZoom(zoom,null,null,$('#foo')[0]);
|
6
|
+
addReferences();
|
7
|
+
addListeners();
|
8
|
+
}
|
9
|
+
|
10
|
+
function addReferences() {
|
11
|
+
let schema = getSchema();
|
12
|
+
let refs = $("li[id^='ref-']");
|
13
|
+
for(let i = 0; i < refs.length; i++) {
|
14
|
+
let referenceID = refs[i].id;
|
15
|
+
let tableIDNum = referenceID.split('-')[1];
|
16
|
+
let tableID = `tbl-${tableIDNum}`;
|
17
|
+
let tableObj = schema[tableID];
|
18
|
+
let refObj = tableObj.references[referenceID];
|
19
|
+
let foreignTableID = refObj.foreign_table_id;
|
20
|
+
let foreignTableIDEl = $(`#${foreignTableID}-id-column`)[0];
|
21
|
+
let refEl = refs[i];
|
22
|
+
createConnector(refEl,foreignTableIDEl,tableID);
|
23
|
+
}
|
24
|
+
setSchema(schema);
|
25
|
+
}
|
26
|
+
|
27
|
+
function addTableByClick(tableName) {
|
28
|
+
zoom = 1;
|
29
|
+
window.setZoom(zoom,null,null,$('#foo')[0]);
|
30
|
+
$('.slider').css({left: 5});
|
31
|
+
$('.canvasBorder').click(function(event) {
|
32
|
+
$('.canvasBorder').unbind('click');
|
33
|
+
let coords = findTargetCoord();
|
34
|
+
$('.jsPlumbBoundary').append(tableHTML(tableName,coords.x,coords.y));
|
35
|
+
setCursorAfterBoundaryClick();
|
36
|
+
setCardDraggable($(`#tbl-${newTableID}`));
|
37
|
+
addListeners();
|
38
|
+
addEmptyTableToSchema();
|
39
|
+
newTableID += 1;
|
40
|
+
});
|
41
|
+
}
|
42
|
+
|
43
|
+
function findTargetCoord() {
|
44
|
+
let target = $(event.target)
|
45
|
+
let offset = target.position()
|
46
|
+
return { x: event.clientX - offset.left,
|
47
|
+
y: event.clientY - offset.top}
|
48
|
+
}
|
49
|
+
|
50
|
+
$('.fa-plus-square-o').click(function(){
|
51
|
+
if (openEditChecker()) { return }
|
52
|
+
setCursorBeforeBoundaryClick()
|
53
|
+
addTableByClick("table_name")
|
54
|
+
})
|
55
|
+
|
56
|
+
function addEmptyTableToSchema() {
|
57
|
+
tableID = `tbl-${newTableID}`;
|
58
|
+
let schema = getSchema();
|
59
|
+
schema[tableID] = {
|
60
|
+
name: "table_name",
|
61
|
+
original_name: null,
|
62
|
+
columns: {},
|
63
|
+
references: {},
|
64
|
+
status: { original: false, modified: false, new: true, deleted: false },
|
65
|
+
id: tableID
|
66
|
+
};
|
67
|
+
setSchema(schema);
|
68
|
+
}
|
69
|
+
|
70
|
+
createSchemaFromParams()
|
71
|
+
|
72
|
+
});
|
@@ -0,0 +1,15 @@
|
|
1
|
+
function setCursorBeforeBoundaryClick() {
|
2
|
+
$('.navbar').css({cursor: 'not-allowed'})
|
3
|
+
$('body').css({cursor: 'not-allowed'})
|
4
|
+
$('.btn').css({cursor: 'not-allowed'})
|
5
|
+
$('.fa').css({cursor: 'not-allowed'})
|
6
|
+
$('.jsPlumbBoundary').css({cursor: 'crosshair'})
|
7
|
+
}
|
8
|
+
|
9
|
+
function setCursorAfterBoundaryClick() {
|
10
|
+
$('.navbar').css({cursor: 'auto'})
|
11
|
+
$('body').css({cursor: 'auto'})
|
12
|
+
$('.btn').css({cursor: 'auto'})
|
13
|
+
$('.fa').css({cursor: 'auto'})
|
14
|
+
$('.jsPlumbBoundary').css({cursor: 'auto'})
|
15
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
function tableHTML(tableName,tableX,tableY) {
|
2
|
+
return `<div class='card' id='tbl-${newTableID}' style='top:${tableY}px;left:${tableX}px;'>` +
|
3
|
+
"<div class='card-header'>" +
|
4
|
+
'<i class="fa fa-arrows" aria-hidden="true"></i>' +
|
5
|
+
"<h4 class='card-title table-title' data-toggle='popover' data-trigger='hover' data-content='Edit table name'>" +
|
6
|
+
`${tableName}` +
|
7
|
+
"</h4>" +
|
8
|
+
"<div class='table-nav-buttons'>" +
|
9
|
+
"<i class='fa fa-plus-square' data-toggle='popover' data-trigger='hover' data-content='Add column'></i>" +
|
10
|
+
"<i class='fa fa-trash' data-toggle='popover' data-trigger='hover' data-content='Destroy table'></i>" +
|
11
|
+
"</div>" +
|
12
|
+
"</div>" +
|
13
|
+
"<div class='card-block'>" +
|
14
|
+
"<ul class='list-group'>" +
|
15
|
+
"<li class='list-group-item' >" +
|
16
|
+
"<span class='tag tag-default float-xs-left type-span'>integer</span>" +
|
17
|
+
"<div class='column-title-outer' >" +
|
18
|
+
"<span class='column-title' >id</span>" +
|
19
|
+
"</div>" +
|
20
|
+
"</li>" +
|
21
|
+
"</ul>" +
|
22
|
+
"</div>" +
|
23
|
+
"</div>"
|
24
|
+
};
|