active_designer 0.0.0 → 0.0.3
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 +4 -4
- data/lib/active_designer.rb +4 -1
- data/lib/active_designer/public/js/schema/edit-table-name.js +39 -7
- data/lib/active_designer/public/js/schema/listeners.js +137 -58
- data/lib/active_designer/public/js/schema/main.js +0 -14
- data/lib/active_designer/public/js/schema/table-html.js +2 -2
- data/lib/active_designer/template.html.erb +4 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9473ab18b3540a1e51362d8d9ac74a763d318508
|
4
|
+
data.tar.gz: 7c2cb8cfb28757ab14a26dba1c229d49025a5cef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae61e1234a802e9c3eba1f55d838bdeec3772706e129d9a39a2181f50281495bca196616b450711f2ed13c9221cb720ac8dd4fc5ba1870ee9520ad0542152dab
|
7
|
+
data.tar.gz: 824d6f4a9a6f63012c96179f115883deb6bc78cca7bbe37291255c767e61b9fa72d1bb6e3a1ffca2b4af0b393449569b2ba8b7c75e0df65e5222dc5d166debb8
|
data/lib/active_designer.rb
CHANGED
@@ -12,7 +12,7 @@ module ActiveDesigner
|
|
12
12
|
end
|
13
13
|
|
14
14
|
if command == "--help" || command == "-h"
|
15
|
-
stdout.puts "To create a schema run '$ active-designer create filepath'"
|
15
|
+
stdout.puts "To create a schema run '$ active-designer --create filepath'"
|
16
16
|
stdout.puts "If youre in the root of a Sinatra or Ruby on Rails project the filepath should be './db/schema.rb'"
|
17
17
|
return 0
|
18
18
|
end
|
@@ -24,11 +24,13 @@ module ActiveDesigner
|
|
24
24
|
|
25
25
|
if !input_path
|
26
26
|
stderr.puts "No path was provided, use -h or --help for more information"
|
27
|
+
|
27
28
|
return 1
|
28
29
|
end
|
29
30
|
|
30
31
|
if !File.exist?(input_path)
|
31
32
|
stderr.puts "#{input_path.inspect} does not exist, use -h or --help for more information"
|
33
|
+
|
32
34
|
return 1
|
33
35
|
end
|
34
36
|
|
@@ -36,6 +38,7 @@ module ActiveDesigner
|
|
36
38
|
|
37
39
|
if File.exist?(output_path) && !overwrite?(stdin, stdout, output_path)
|
38
40
|
stderr.puts "Aborted"
|
41
|
+
|
39
42
|
return 1
|
40
43
|
end
|
41
44
|
|
@@ -39,18 +39,51 @@ function titleBodyClickListener(e) {
|
|
39
39
|
|
40
40
|
function titleUpdate(e) {
|
41
41
|
let schema = getSchema();
|
42
|
-
let
|
43
|
-
$('.
|
42
|
+
let newTableName = $('.table-form')[0].value;
|
43
|
+
let cards = $('.card');
|
44
|
+
for (var i = 0; i < cards.length; i++) {
|
45
|
+
if ($(cards[i]).find('form').length === 0) {
|
46
|
+
let tableName = $(cards[i]).find('h4.table-title').text().trim()
|
47
|
+
if (tableName === newTableName) {
|
48
|
+
$('.table-form')[0].parentElement.outerHTML = tableTitleHTML(e.data.originalTitle);
|
49
|
+
editTableName();
|
50
|
+
setSchema(schema);
|
51
|
+
return
|
52
|
+
// Should produce an error here
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
$('.table-form')[0].parentElement.outerHTML = tableTitleHTML(newTableName);
|
44
57
|
$('[data-toggle="popover"]').popover();
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
58
|
+
let tableID = e.data.cardID;
|
59
|
+
updateRefs(schema[tableID],schema,newTableName)
|
60
|
+
if (e.data.originalTitle !== newTableName) {
|
61
|
+
schema[tableID].name = newTableName;
|
62
|
+
checkTitleStatus(tableID,schema);
|
49
63
|
}
|
50
64
|
editTableName();
|
51
65
|
setSchema(schema);
|
52
66
|
}
|
53
67
|
|
68
|
+
function updateRefs(table,schema,newTableName) {
|
69
|
+
let refs = $("li[id^='ref-']");
|
70
|
+
for (var i = 0; i < refs.length; i++) {
|
71
|
+
let refName = $(refs[i]).find('span.column-title').text().split('_');
|
72
|
+
refName.pop();
|
73
|
+
refName = refName.join('_');
|
74
|
+
if (refName === table.name) {
|
75
|
+
$(refs[i]).find('span.column-title').text(`${newTableName}_id`);
|
76
|
+
let refID = refs[i].id;
|
77
|
+
let tableID = `tbl-${refID.split('-')[1]}`;
|
78
|
+
let refObj = schema[tableID].references[refID];
|
79
|
+
refObj.foreign_table_name = newTableName;
|
80
|
+
if (!refObj.status.new) {
|
81
|
+
refObj.status.modified = true;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
54
87
|
function tableTitleHTML(tableName) {
|
55
88
|
return "<h4 class='card-title table-title' data-toggle='popover' data-trigger='hover' data-content='Edit table name'>" +
|
56
89
|
tableName +
|
@@ -62,7 +95,6 @@ function tableTitleFormHTML(priorText) {
|
|
62
95
|
}
|
63
96
|
|
64
97
|
function checkTitleStatus(cardID,schema) {
|
65
|
-
|
66
98
|
if (schema[cardID].status.new === false) {
|
67
99
|
updateTitleStatus(cardID,schema);
|
68
100
|
}
|
@@ -1,15 +1,38 @@
|
|
1
|
-
|
2
1
|
function destroyTable(){
|
3
2
|
if (openEditChecker()) { return };
|
4
3
|
$('.delete-table').unbind('click');
|
5
4
|
$('.delete-table').click(function() {
|
6
5
|
$(this).popover('dispose');
|
7
6
|
let card = $(this).parents('.card');
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
jsPlumb.remove(card);
|
8
|
+
let schema = getSchema();
|
9
|
+
let table = schema[card[0].id];
|
10
|
+
let status = table.status;
|
11
|
+
if (status.new) {
|
12
|
+
schema[card[0].id] = null;
|
13
|
+
} else {
|
14
|
+
status.deleted = true;
|
15
|
+
}
|
16
|
+
|
17
|
+
refs = $("li[id^='ref-']");
|
18
|
+
for (let i = 0; i < refs.length; i++) {
|
19
|
+
let refEl = $(refs[i]);
|
20
|
+
let refID = $(refs[i])[0].id;
|
21
|
+
let foreignCard = refEl.parents('.card');
|
22
|
+
let foreignCardID = foreignCard[0].id;
|
23
|
+
let refObj = schema[foreignCardID].references[refID];
|
24
|
+
|
25
|
+
if (refObj.foreign_table_name === table.name) {
|
26
|
+
if (refObj.status.new) {
|
27
|
+
refObj = null;
|
28
|
+
} else {
|
29
|
+
refObj.status.deleted = true;
|
30
|
+
}
|
31
|
+
jsPlumb.remove(refs[i]);
|
32
|
+
jsPlumb.recalculateOffsets(foreignCard);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
setSchema(schema);
|
13
36
|
});
|
14
37
|
}
|
15
38
|
|
@@ -19,17 +42,12 @@ function destroyColumn() {
|
|
19
42
|
$('.delete-column').unbind('click')
|
20
43
|
$('.delete-column').click(function() {
|
21
44
|
$(this).popover('dispose');
|
22
|
-
let column = $(this).parents('
|
45
|
+
let column = $(this).parents("li[id^='col-']")[0];
|
23
46
|
let columnID = column.id;
|
24
|
-
|
47
|
+
let card = $(this).parents(".card")[0];
|
48
|
+
jsPlumb.remove(column)
|
49
|
+
jsPlumb.recalculateOffsets(card)
|
25
50
|
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
51
|
let columns = schema[tableID].columns
|
34
52
|
let status = columns[columnID].status;
|
35
53
|
if (status.new) {
|
@@ -47,17 +65,12 @@ function destroyReference() {
|
|
47
65
|
$('.delete-ref').unbind('click')
|
48
66
|
$('.delete-ref').click(function() {
|
49
67
|
$(this).popover('dispose');
|
50
|
-
let reference = $(this).parents('
|
68
|
+
let reference = $(this).parents("li[id^='ref-']")[0];
|
51
69
|
let referenceID = reference.id;
|
52
70
|
let tableID = `tbl-${referenceID.split('-')[1]}`;
|
71
|
+
let card = $(this).parents(".card")[0];
|
53
72
|
jsPlumb.remove(reference);
|
54
|
-
|
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
|
-
}
|
73
|
+
jsPlumb.recalculateOffsets(card)
|
61
74
|
let references = schema[tableID].references
|
62
75
|
let status = references[referenceID].status;
|
63
76
|
if (status.new) {
|
@@ -90,11 +103,14 @@ function newColumnObj(tableID, columnName, columnType, schema) {
|
|
90
103
|
function newRefObj(tableID,foreignTableName,foreignTableID, schema) {
|
91
104
|
let tableNum = tableID.split('-')[1];
|
92
105
|
let prevID = 100;
|
106
|
+
|
107
|
+
|
108
|
+
|
93
109
|
let columnIDs = Object.keys(schema[`tbl-${tableNum}`].references);
|
94
110
|
if (columnIDs.length !== 0) {
|
95
111
|
prevID = parseInt(columnIDs[columnIDs.length -1].split('-')[2]);
|
96
112
|
}
|
97
|
-
let columnID = `
|
113
|
+
let columnID = `ref-${tableNum}-${prevID + 1}`;
|
98
114
|
return schema[tableID].references[columnID] = {
|
99
115
|
id: columnID,
|
100
116
|
table_id: tableID,
|
@@ -104,15 +120,13 @@ function newRefObj(tableID,foreignTableName,foreignTableID, schema) {
|
|
104
120
|
}
|
105
121
|
}
|
106
122
|
|
107
|
-
function
|
123
|
+
function addColumnDisplay() {
|
108
124
|
if (openEditChecker()) { return };
|
109
125
|
$('.fa-plus-square').unbind('click');
|
110
126
|
$('.fa-plus-square').on('click', null, {}, displayColumnJumbo);
|
111
127
|
}
|
112
128
|
|
113
|
-
function
|
114
|
-
$('body').append(addColumnCardHTML());
|
115
|
-
let card = $(this).parents('.card');
|
129
|
+
function refColToggle() {
|
116
130
|
$('#column-reference').change(function(){
|
117
131
|
if (this.checked) {
|
118
132
|
$('.add-column-card').find('.column-html').addClass('hidden')
|
@@ -122,43 +136,109 @@ function displayColumnJumbo() {
|
|
122
136
|
$('.add-column-card').find('.column-html').removeClass('hidden')
|
123
137
|
}
|
124
138
|
});
|
139
|
+
}
|
125
140
|
|
141
|
+
function displayColumnJumboExit() {
|
126
142
|
$('.add-column-card .fa-times').click(function() {
|
127
143
|
$('.add-column-card')[0].outerHTML = ""
|
128
144
|
});
|
145
|
+
}
|
129
146
|
|
130
|
-
|
131
|
-
|
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]}`);
|
147
|
+
function addEmptyTableToSchema(tableName = "table_name") {
|
148
|
+
tableID = `tbl-${newTableID}`;
|
140
149
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
150
|
+
let schema = getSchema();
|
151
|
+
schema[tableID] = {
|
152
|
+
name: tableName,
|
153
|
+
original_name: null,
|
154
|
+
columns: {},
|
155
|
+
references: {},
|
156
|
+
status: { original: false, modified: false, new: true, deleted: false },
|
157
|
+
id: tableID
|
158
|
+
};
|
159
|
+
setSchema(schema);
|
160
|
+
return schema[tableID]
|
161
|
+
}
|
162
|
+
|
163
|
+
function createNewRef(schema,currentTableHTML) {
|
164
|
+
let foreignTableName = $('form input#foreign-table-name').val()
|
165
|
+
let cardIDs = Object.keys(schema)
|
166
|
+
for(let i = 0; i < cardIDs.length; i++) {
|
167
|
+
if (schema[cardIDs[i]].name === foreignTableName) {
|
168
|
+
let referenceRelationship = $('input[name="ref-rel"]:checked').val();
|
169
|
+
let foreignTableHTML = $(`#${cardIDs[i]}`);
|
170
|
+
|
171
|
+
if (referenceRelationship === "mtm" ) {
|
172
|
+
let currentTableName = currentTableHTML.find('h4.table-title').text().trim();
|
173
|
+
let joinTableName = createJoinTableName(currentTableName, foreignTableName);
|
174
|
+
for(let i = 0; i < cardIDs.length; i++) {
|
175
|
+
if (schema[cardIDs[i]] && schema[cardIDs[i]].name === joinTableName) {
|
158
176
|
console.log("already happend")
|
177
|
+
return
|
159
178
|
}
|
160
179
|
}
|
180
|
+
let joinTableObj = addEmptyTableToSchema(joinTableName);
|
181
|
+
$('.jsPlumbBoundary').append(tableHTML(joinTableName,500,500));
|
182
|
+
let joinTableHTML = $(`#${joinTableObj.id}`);
|
183
|
+
setCardDraggable(joinTableHTML)
|
184
|
+
let foreignTableIDColumnHTML = foreignTableHTML.find(`#${foreignTableHTML[0].id}-id-column`);
|
185
|
+
let currentTableIDColumnHTML = currentTableHTML.find(`#${currentTableHTML[0].id}-id-column`);
|
186
|
+
let currentRefObj = newRefObj(currentTableHTML[0].id, joinTableName, joinTableObj.id, schema);
|
187
|
+
let foreignRefObj = newRefObj(foreignTableHTML[0].id, joinTableName, joinTableObj.id, schema);
|
188
|
+
let joinTableListGroup = joinTableHTML.find('.list-group');
|
189
|
+
joinTableListGroup.append(columnHTML({id: currentRefObj.id, type: "integer", name: `${currentTableName}_id`},"delete-ref"));
|
190
|
+
joinTableListGroup.append(columnHTML({id: foreignRefObj.id, type: "integer", name: `${foreignTableName}_id`},"delete-ref"));
|
191
|
+
let joinTableCurrentKeyHTML = $(`#${currentRefObj.id}`)[0];
|
192
|
+
let joinTableForeignKeyHTML = $(`#${foreignRefObj.id}`)[0];
|
193
|
+
createConnector(joinTableCurrentKeyHTML,currentTableIDColumnHTML);
|
194
|
+
createConnector(joinTableForeignKeyHTML,foreignTableIDColumnHTML);
|
195
|
+
newTableID += 1;
|
196
|
+
} else {
|
197
|
+
|
198
|
+
let prevRefs = schema[currentTableHTML[0].id].references
|
199
|
+
let prevRefKeys = Object.keys(prevRefs)
|
200
|
+
let prevStatus = false
|
201
|
+
for(let i = 0; i < prevRefKeys.length; i++) {
|
202
|
+
if (prevRefs[prevRefKeys[i]].foreign_table_name === foreignTableName) {
|
203
|
+
prevStatus = true
|
204
|
+
}
|
205
|
+
}
|
206
|
+
if (!prevStatus) {
|
207
|
+
let foreignKeyHTML = foreignTableHTML.find(`#${foreignTableHTML[0].id}-id-column`);
|
208
|
+
let listGroup = currentTableHTML.find('.list-group');
|
209
|
+
let refObj = newRefObj(currentTableHTML[0].id, foreignTableName, foreignTableHTML[0].id, schema);
|
210
|
+
listGroup.append(columnHTML({id: refObj.id, type: "integer", name: `${foreignTableName}_id`},"delete-ref"));
|
211
|
+
let newColumnHTML = $(`#${refObj.id}`)[0]
|
212
|
+
createConnector(newColumnHTML,foreignKeyHTML);
|
213
|
+
}
|
214
|
+
else {
|
215
|
+
console.log("already happend")
|
216
|
+
}
|
161
217
|
}
|
218
|
+
}
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
function createJoinTableName(firstName, secondName) {
|
223
|
+
if (firstName < secondName) {
|
224
|
+
return `${firstName}_${secondName}`;
|
225
|
+
} else {
|
226
|
+
return `${firstName}_${secondName}`;
|
227
|
+
}
|
228
|
+
}
|
229
|
+
|
230
|
+
function displayColumnJumbo() {
|
231
|
+
$('body').append(addColumnCardHTML());
|
232
|
+
let card = $(this).parents('.card');
|
233
|
+
|
234
|
+
refColToggle()
|
235
|
+
displayColumnJumboExit()
|
236
|
+
$('form button').click(function() {
|
237
|
+
let schema = getSchema();
|
238
|
+
let referenceChecked = $('form input#column-reference')[0].checked
|
239
|
+
if (referenceChecked) {
|
240
|
+
createNewRef(schema,card)
|
241
|
+
schema = getSchema()
|
162
242
|
} else {
|
163
243
|
let columnName = $('form input#column-name').val()
|
164
244
|
let columnType = $('form select#column-type-select').val()
|
@@ -199,7 +279,6 @@ function addColumnCardHTML() {
|
|
199
279
|
"</div>"
|
200
280
|
}
|
201
281
|
|
202
|
-
|
203
282
|
function foreignTableRadioButtonHTML() {
|
204
283
|
return "<div class='reference-html hidden'>" +
|
205
284
|
"<div class='form-group'>" +
|
@@ -207,7 +286,7 @@ function foreignTableRadioButtonHTML() {
|
|
207
286
|
"</div>" +
|
208
287
|
"<div class='form-check'>" +
|
209
288
|
"<label class='form-check-label'>" +
|
210
|
-
"<input class='form-check-input' type='radio' name='ref-rel' id='ref-rel-mto' value='mto'>" +
|
289
|
+
"<input class='form-check-input' type='radio' name='ref-rel' id='ref-rel-mto' value='mto' checked >" +
|
211
290
|
" Many to one reference" +
|
212
291
|
"</label>" +
|
213
292
|
"</div>" +
|
@@ -258,7 +337,7 @@ function datatypeSelectoHTML() {
|
|
258
337
|
function addListeners(){
|
259
338
|
destroyTable()
|
260
339
|
editTableName()
|
261
|
-
|
340
|
+
addColumnDisplay()
|
262
341
|
destroyColumn()
|
263
342
|
destroyReference()
|
264
343
|
$('[data-toggle="popover"]').popover()
|
@@ -53,20 +53,6 @@ $(document).ready(function() {
|
|
53
53
|
addTableByClick("table_name")
|
54
54
|
})
|
55
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
56
|
createSchemaFromParams()
|
71
57
|
|
72
58
|
});
|
@@ -7,12 +7,12 @@ function tableHTML(tableName,tableX,tableY) {
|
|
7
7
|
"</h4>" +
|
8
8
|
"<div class='table-nav-buttons'>" +
|
9
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>" +
|
10
|
+
"<i class='fa fa-trash delete-table' data-toggle='popover' data-trigger='hover' data-content='Destroy table'></i>" +
|
11
11
|
"</div>" +
|
12
12
|
"</div>" +
|
13
13
|
"<div class='card-block'>" +
|
14
14
|
"<ul class='list-group'>" +
|
15
|
-
|
15
|
+
`<li class='list-group-item' id='tbl-${newTableID}-id-column' >` +
|
16
16
|
"<span class='tag tag-default float-xs-left type-span'>integer</span>" +
|
17
17
|
"<div class='column-title-outer' >" +
|
18
18
|
"<span class='column-title' >id</span>" +
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<html>
|
3
3
|
|
4
4
|
<head>
|
5
|
-
<title>
|
5
|
+
<title>Active Designer</title>
|
6
6
|
<link rel="stylesheet" href="<%= @path %>/public/css/bootstrap.min.css">
|
7
7
|
<script src="<%= @path %>/public/js/tether.min.js"></script>
|
8
8
|
<script src="<%= @path %>/public/js/jquery-3.1.1.js"></script>
|
@@ -111,8 +111,9 @@
|
|
111
111
|
<% end %>
|
112
112
|
</div>
|
113
113
|
</div>
|
114
|
-
<script>
|
115
|
-
|
114
|
+
<script>
|
115
|
+
localStorage.setItem("schema",JSON.stringify(<%= @schema %>))
|
116
|
+
</script>
|
116
117
|
|
117
118
|
</body>
|
118
119
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_designer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thom Schlereth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Active Designer is a gem that allows a user to easily create a visual
|
14
14
|
format of their Active Record schema.rb file for an SQL database. With just one
|