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

okay now generate output button will generate another output that will be on the second tab called Repository, the original tab is called Entity, the repository output will also be generated from the inputs and it will look like this:

Browse files

"package com.example.repository;

import com.example.entity.Customer;
import org.springframework.data.jpa.repository.CrudRepository;
import org.springframework.stereotype.Repository;

// The @Repository annotation is optional if extending JpaRepository, but good practice
public interface CustomerRepository extends CrudRepository<Customer, Long> {

}"

Files changed (2) hide show
  1. index.html +19 -7
  2. script.js +28 -8
index.html CHANGED
@@ -67,21 +67,33 @@
67
  <!-- Right Column - Output -->
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();
 
67
  <!-- Right Column - Output -->
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
+ <custom-tab-group class="border-b border-gray-700">
71
+ <button slot="tabs" class="tab-btn">Entity</button>
72
+ <button slot="tabs" class="tab-btn">Repository</button>
73
+
74
+ <div slot="contents" class="tab-content h-full">
75
+ <div class="p-4 flex-1 h-full">
76
+ <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>
77
+ </div>
78
+ </div>
79
+
80
+ <div slot="contents" class="tab-content h-full">
81
+ <div class="p-4 flex-1 h-full">
82
+ <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>
83
+ </div>
84
+ </div>
85
+ </custom-tab-group>
86
+
87
+ <div class="p-4 border-t border-gray-700 flex justify-end">
88
  <button id="download-btn" class="bg-primary-500 hover:bg-primary-600 text-white px-4 py-2 rounded-lg flex items-center">
89
  <i data-feather="download" class="w-4 h-4 mr-2"></i> Download
90
  </button>
91
  </div>
 
 
 
 
92
  </div>
93
  </div>
94
  </div>
95
  </div>
96
+ <script src="components/tab-component.js"></script>
97
  <script src="script.js"></script>
98
  <script>
99
  feather.replace();
script.js CHANGED
@@ -109,20 +109,40 @@ generateBtn.addEventListener('click', () => {
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);
 
109
  });
110
 
111
  jpaCode += `}\n`;
112
+ // Generate Repository output
113
+ let repositoryCode = `package com.example.repository;\n\n`;
114
+ repositoryCode += `import com.example.entity.${className};\n`;
115
+ repositoryCode += `import org.springframework.data.jpa.repository.JpaRepository;\n`;
116
+ repositoryCode += `import org.springframework.stereotype.Repository;\n\n`;
117
+ repositoryCode += `@Repository\n`;
118
+ repositoryCode += `public interface ${className}Repository extends JpaRepository<${className}, Long> {\n\n`;
119
+ repositoryCode += `}\n`;
120
+
121
+ // Update outputs
122
+ document.getElementById('output-entity').value = jpaCode;
123
+ document.getElementById('output-repository').value = repositoryCode;
124
+ hljs.highlightAll();
125
 
126
  // Set up download functionality
127
+ const downloadBtn = document.getElementById('download-btn');
128
+ downloadBtn.onclick = function() {
129
  const blob = new Blob([jpaCode], { type: 'text/plain' });
130
  const url = URL.createObjectURL(blob);
131
  const a = document.createElement('a');
132
  a.href = url;
133
+ // Get active tab content
134
+ const activeTab = document.querySelector('custom-tab-group').shadowRoot.querySelector('.tab-btn.active');
135
+ const tabIndex = Array.from(document.querySelector('custom-tab-group').shadowRoot.querySelectorAll('.tab-btn')).indexOf(activeTab);
136
+
137
+ const contentToDownload = tabIndex === 0 ? jpaCode : repositoryCode;
138
+ const fileName = tabIndex === 0 ? `${className}.java` : `${className}Repository.java`;
139
+
140
+ const blob = new Blob([contentToDownload], { type: 'text/plain' });
141
+ const url = URL.createObjectURL(blob);
142
+ const a = document.createElement('a');
143
+ a.href = url;
144
+ a.download = fileName;
145
+ document.body.appendChild(a);
146
  a.click();
147
  document.body.removeChild(a);
148
  URL.revokeObjectURL(url);