5uck1t commited on
Commit
58b80d0
·
verified ·
1 Parent(s): 53c2ef3

Promote version a92e9af to main

Browse files

Promoted commit a92e9af4a93dd3f61beade5a8b10706fc492f4af to main branch

Files changed (3) hide show
  1. index.html +4 -15
  2. script.js +18 -82
  3. style.css +1 -30
index.html CHANGED
@@ -68,31 +68,20 @@
68
  <div class="lg:w-2/3 h-full">
69
  <div class="bg-gray-800 rounded-lg shadow-xl h-full flex flex-col">
70
  <div class="p-4 border-b border-gray-700 flex justify-between items-center">
71
- <custom-tab-group>
72
- <button slot="tabs" class="tab-btn">Entity</button>
73
- <button slot="tabs" class="tab-btn">Repository</button>
74
- <div slot="contents" class="tab-content">
75
- <textarea id="output-entity" class="w-full h-full bg-gray-800 text-gray-100 p-4 rounded-lg border border-gray-700 focus:border-primary-500 focus:ring-1 focus:ring-primary-500 resize-none" readonly></textarea>
76
- </div>
77
- <div slot="contents" class="tab-content">
78
- <textarea id="output-repository" class="w-full h-full bg-gray-800 text-gray-100 p-4 rounded-lg border border-gray-700 focus:border-primary-500 focus:ring-1 focus:ring-primary-500 resize-none" readonly></textarea>
79
- </div>
80
- </custom-tab-group>
81
  <button id="download-btn" class="bg-primary-500 hover:bg-primary-600 text-white px-4 py-2 rounded-lg flex items-center">
82
  <i data-feather="download" class="w-4 h-4 mr-2"></i> Download
83
  </button>
84
  </div>
85
 
86
  <div class="p-4 flex-1">
87
- <div id="output-tabs" class="h-full">
88
- <!-- Tab content will be inserted here by script -->
89
- </div>
90
  </div>
91
- </div>
92
  </div>
 
93
  </div>
94
  </div>
95
- <script src="components/tab-component.js"></script>
96
  <script src="script.js"></script>
97
  <script>
98
  feather.replace();
 
68
  <div class="lg:w-2/3 h-full">
69
  <div class="bg-gray-800 rounded-lg shadow-xl h-full flex flex-col">
70
  <div class="p-4 border-b border-gray-700 flex justify-between items-center">
71
+ <h2 class="text-xl font-semibold text-primary-500">Generated Output</h2>
 
 
 
 
 
 
 
 
 
72
  <button id="download-btn" class="bg-primary-500 hover:bg-primary-600 text-white px-4 py-2 rounded-lg flex items-center">
73
  <i data-feather="download" class="w-4 h-4 mr-2"></i> Download
74
  </button>
75
  </div>
76
 
77
  <div class="p-4 flex-1">
78
+ <textarea id="output-text" class="w-full h-full bg-gray-800 text-gray-100 p-4 rounded-lg border border-gray-700 focus:border-primary-500 focus:ring-1 focus:ring-primary-500 resize-none" readonly></textarea>
 
 
79
  </div>
 
80
  </div>
81
+ </div>
82
  </div>
83
  </div>
84
+
85
  <script src="script.js"></script>
86
  <script>
87
  feather.replace();
script.js CHANGED
@@ -3,11 +3,11 @@ document.addEventListener('DOMContentLoaded', function() {
3
  // Initialize highlight.js
4
  hljs.highlightAll();
5
 
6
- // Add input field
7
  const addInputBtn = document.getElementById('add-input');
8
  const inputContainer = document.getElementById('input-container');
9
 
10
- function addInputField() {
11
  const inputGroup = document.createElement('div');
12
  inputGroup.className = 'input-group';
13
  inputGroup.innerHTML = `
@@ -18,7 +18,7 @@ document.addEventListener('DOMContentLoaded', function() {
18
  <button class="remove-input mt-1 text-red-400 hover:text-red-300 text-sm flex items-center">
19
  <i data-feather="trash-2" class="w-3 h-3 mr-1"></i> Remove
20
  </button>
21
- `;
22
  inputContainer.appendChild(inputGroup);
23
  feather.replace();
24
 
@@ -27,40 +27,9 @@ document.addEventListener('DOMContentLoaded', function() {
27
  removeBtn.addEventListener('click', () => {
28
  inputGroup.remove();
29
  });
30
- }
31
-
32
- addInputBtn.addEventListener('click', addInputField);
33
-
34
- // Initialize tabs if they exist
35
- // Initialize tabs
36
- const tabGroup = document.querySelector('custom-tab-group');
37
- if (tabGroup) {
38
- setTimeout(() => {
39
- const tabs = tabGroup.shadowRoot.querySelectorAll('slot[name="tabs"]').item(0).assignedElements();
40
- const contents = tabGroup.shadowRoot.querySelectorAll('slot[name="contents"]').item(0).assignedElements();
41
-
42
- tabs.forEach((tab, index) => {
43
- tab.addEventListener('click', () => {
44
- tabs.forEach(t => t.classList.remove('active'));
45
- contents.forEach(c => c.classList.remove('active'));
46
-
47
- tab.classList.add('active');
48
- if (contents[index]) {
49
- contents[index].classList.add('active');
50
- }
51
- });
52
-
53
- if (index === 0) {
54
- tab.classList.add('active');
55
- if (contents[0]) {
56
- contents[0].classList.add('active');
57
- }
58
- }
59
- });
60
- });
61
- }
62
- });
63
- // Remove input field
64
  document.addEventListener('click', function(e) {
65
  if (e.target.classList.contains('remove-input') || e.target.closest('.remove-input')) {
66
  const btn = e.target.classList.contains('remove-input') ? e.target : e.target.closest('.remove-input');
@@ -81,9 +50,10 @@ generateBtn.addEventListener('click', () => {
81
  type: inputs[1].value || 'String'
82
  };
83
  });
 
84
  // Generate JPA Entity
85
- let jpaCode = `package com.example.entity;\n\n`;
86
- jpaCode += `import jakarta.persistence.Entity;\n`;
87
  jpaCode += `import jakarta.persistence.GeneratedValue;\n`;
88
  jpaCode += `import jakarta.persistence.GenerationType;\n`;
89
  jpaCode += `import jakarta.persistence.Id;\n\n`;
@@ -139,54 +109,20 @@ jpaCode += `import jakarta.persistence.Entity;\n`;
139
  });
140
 
141
  jpaCode += `}\n`;
142
- // Generate Repository
143
- let repositoryCode = `package com.example.repository;\n\n`;
144
- repositoryCode += `import com.example.entity.${className};\n`;
145
- repositoryCode += `import org.springframework.data.jpa.repository.JpaRepository;\n`;
146
- repositoryCode += `import org.springframework.stereotype.Repository;\n\n`;
147
- repositoryCode += `@Repository\n`;
148
-
149
- // Find ID field type (default to Long if not found)
150
- let idFieldType = 'Long';
151
- const idField = fields.find(f => f.name.toLowerCase() === 'id');
152
- if (idField) {
153
- idFieldType = idField.type;
154
- }
155
-
156
- repositoryCode += `public interface ${className}Repository extends JpaRepository<${className}, ${idFieldType}> {\n\n`;
157
- repositoryCode += `}\n`;
158
-
159
- // Update outputs
160
- const outputEntity = document.getElementById('output-entity');
161
- const outputRepository = document.getElementById('output-repository');
162
-
163
- outputEntity.value = jpaCode;
164
- outputRepository.value = repositoryCode;
165
-
166
- hljs.highlightElement(outputEntity);
167
- hljs.highlightElement(outputRepository);
168
 
169
  // Set up download functionality
170
- const downloadBtn = document.getElementById('download-btn');
171
- downloadBtn.onclick = function() {
172
- // Determine which tab is active
173
- const activeTab = document.querySelector('.tab-btn.active');
174
- let content, filename;
175
-
176
- if (activeTab.textContent === 'Entity') {
177
- content = jpaCode;
178
- filename = `${className}.java`;
179
- } else {
180
- content = repositoryCode;
181
- filename = `${className}Repository.java`;
182
- }
183
-
184
- const blob = new Blob([content], { type: 'text/plain' });
185
  const url = URL.createObjectURL(blob);
186
  const a = document.createElement('a');
187
  a.href = url;
188
- a.download = filename;
189
- document.body.appendChild(a);
190
  a.click();
191
  document.body.removeChild(a);
192
  URL.revokeObjectURL(url);
 
3
  // Initialize highlight.js
4
  hljs.highlightAll();
5
 
6
+ // Add input field
7
  const addInputBtn = document.getElementById('add-input');
8
  const inputContainer = document.getElementById('input-container');
9
 
10
+ addInputBtn.addEventListener('click', () => {
11
  const inputGroup = document.createElement('div');
12
  inputGroup.className = 'input-group';
13
  inputGroup.innerHTML = `
 
18
  <button class="remove-input mt-1 text-red-400 hover:text-red-300 text-sm flex items-center">
19
  <i data-feather="trash-2" class="w-3 h-3 mr-1"></i> Remove
20
  </button>
21
+ `;
22
  inputContainer.appendChild(inputGroup);
23
  feather.replace();
24
 
 
27
  removeBtn.addEventListener('click', () => {
28
  inputGroup.remove();
29
  });
30
+ });
31
+
32
+ // Remove input field
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  document.addEventListener('click', function(e) {
34
  if (e.target.classList.contains('remove-input') || e.target.closest('.remove-input')) {
35
  const btn = e.target.classList.contains('remove-input') ? e.target : e.target.closest('.remove-input');
 
50
  type: inputs[1].value || 'String'
51
  };
52
  });
53
+
54
  // Generate JPA Entity
55
+ let jpaCode = `package com.example.accessingdatajpa;\n\n`;
56
+ jpaCode += `import jakarta.persistence.Entity;\n`;
57
  jpaCode += `import jakarta.persistence.GeneratedValue;\n`;
58
  jpaCode += `import jakarta.persistence.GenerationType;\n`;
59
  jpaCode += `import jakarta.persistence.Id;\n\n`;
 
109
  });
110
 
111
  jpaCode += `}\n`;
112
+ // Update output
113
+ // Update output
114
+ outputTextarea.value = jpaCode;
115
+ hljs.highlightElement(outputTextarea);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
  // Set up download functionality
118
+ const downloadBtn = document.getElementById('download-btn');
119
+ downloadBtn.onclick = function() {
120
+ const blob = new Blob([jpaCode], { type: 'text/plain' });
 
 
 
 
 
 
 
 
 
 
 
 
121
  const url = URL.createObjectURL(blob);
122
  const a = document.createElement('a');
123
  a.href = url;
124
+ a.download = `${className}.java`;
125
+ document.body.appendChild(a);
126
  a.click();
127
  document.body.removeChild(a);
128
  URL.revokeObjectURL(url);
style.css CHANGED
@@ -27,37 +27,8 @@ body {
27
  flex: 1;
28
  min-height: 0;
29
  }
30
- .tab-btn {
31
- padding: 0.5rem 1rem;
32
- background: transparent;
33
- border: none;
34
- color: #9ca3af;
35
- cursor: pointer;
36
- font-weight: 500;
37
- border-bottom: 2px solid transparent;
38
- transition: all 0.2s ease;
39
- }
40
-
41
- .tab-btn:hover {
42
- color: #6366f1;
43
- }
44
-
45
- .tab-btn.active {
46
- color: #6366f1;
47
- border-bottom-color: #6366f1;
48
- }
49
-
50
- .tab-content {
51
- display: none;
52
- height: 100%;
53
- }
54
-
55
- .tab-content.active {
56
- display: block;
57
- }
58
-
59
  textarea {
60
- height: 100% !important;
61
  min-height: 0;
62
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
63
  font-size: 0.875rem;
 
27
  flex: 1;
28
  min-height: 0;
29
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  textarea {
31
+ height: 100% !important;
32
  min-height: 0;
33
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
34
  font-size: 0.875rem;