Redmind commited on
Commit
ee5e190
·
verified ·
1 Parent(s): b65eeaf

Update templates/dashboard.html

Browse files
Files changed (1) hide show
  1. templates/dashboard.html +140 -44
templates/dashboard.html CHANGED
@@ -1,39 +1,26 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Dashboard</title>
6
- <!-- AdminLTE CSS -->
7
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/admin-lte/3.1.0/css/adminlte.min.css">
8
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
9
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
10
- <style>
11
- html, body {
12
- height: 100%;
13
- margin: 0;
14
- display: flex;
15
- flex-direction: column;
16
- }
17
- .wrapper {
18
- flex: 1; /* This allows the content to grow and push the footer down */
19
- padding: 10px;
20
- margin-left: -35px;
21
- }
22
-
23
- </style>
24
- </head>
25
  <body>
 
26
  {% include 'sidepane.html' %}
27
 
28
-
29
  <div class="wrapper">
30
  <section class="main-header" style="border-bottom: none;border-top: none;">
31
  <div class="container-fluid">
 
 
 
 
 
 
 
 
 
 
32
  <div class="row">
33
  <div class="col-lg-4 col-6">
34
  <div class="small-box bg-info">
35
  <div class="inner margin-left:10px;">
36
- <h3>{{table_count_of_each_table.knowledge_base}}</h3>
37
  <h4>KnowledgeBase</h4>
38
  </div>
39
  <div class="icon">
@@ -45,7 +32,7 @@
45
  <div class="col-lg-4 col-6">
46
  <div class="small-box bg-success">
47
  <div class="inner">
48
- <h3>{{table_count_of_each_table.data_connectors}}</h3>
49
  <h4>Data connectors</h4>
50
  </div>
51
  <div class="icon">
@@ -57,7 +44,7 @@
57
  <div class="col-lg-4 col-6">
58
  <div class="small-box bg-warning">
59
  <div class="inner">
60
- <h3>{{table_count_of_each_table.api_connectors}}</h3>
61
  <h4>API Connectors</h4>
62
  </div>
63
  <div class="icon">
@@ -69,7 +56,7 @@
69
  <div class="col-lg-4 col-6">
70
  <div class="small-box bg-warning">
71
  <div class="inner">
72
- <h3>{{table_count_of_each_table.prompt_templates}}</h3>
73
  <h4>Prompt_Templates</h4>
74
  </div>
75
  <div class="icon">
@@ -77,13 +64,16 @@
77
  </div>
78
  </div>
79
  </div>
 
80
  </div>
81
  </div>
82
  </section>
83
  </div>
84
-
85
- <input type="hidden" id="userRole" name="userRole" value={{ role }}>
86
-
 
 
87
  <footer>
88
  {% include 'footer.html' %}
89
  </footer>
@@ -91,16 +81,25 @@
91
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/adminlte.min.js"></script>
92
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
93
  <script>
94
- window.addEventListener('pageshow', function(event) {
95
- if (event.persisted || (window.performance && window.performance.navigation.type === 2)) {
96
- window.location.reload();
97
- }
98
- });
99
-
100
 
101
 
102
- document.addEventListener('DOMContentLoaded', function() {
103
  var role1 = document.getElementById("userRole").value;
 
 
 
 
 
 
 
 
 
 
104
  if (!role1) {
105
  var roleFromInput = sessionStorage.getItem('userRole');
106
  sessionStorage.setItem('userRole', roleFromInput);
@@ -109,10 +108,107 @@
109
  sessionStorage.setItem('userRole', role1);
110
  console.log("Retrieved user role from input:", role1); // Debugging
111
  }
 
 
 
 
112
 
113
- });
114
- </script>
115
- </body>
116
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  </body>
118
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <body>
2
+
3
  {% include 'sidepane.html' %}
4
 
5
+
6
  <div class="wrapper">
7
  <section class="main-header" style="border-bottom: none;border-top: none;">
8
  <div class="container-fluid">
9
+ <div id="company-block" class="form-group left-align" style="display: none;">
10
+ <label for="company" class="ml-3" style="display: inline-block; margin-right: 10px;">Select the Company Name
11
+ to view the details <span class="text-danger">*</span>
12
+ </label>
13
+ <select type="text" id="company" name="company" class="ml-3 form-control"
14
+ style="display: inline-block; width: 20%;" required>
15
+ <option value="" selected>Select</option>
16
+ </select>
17
+ </div>
18
+
19
  <div class="row">
20
  <div class="col-lg-4 col-6">
21
  <div class="small-box bg-info">
22
  <div class="inner margin-left:10px;">
23
+ <h3 id="knowledgeBaseCount">{{table_count_of_each_table.knowledge_base}}</h3>
24
  <h4>KnowledgeBase</h4>
25
  </div>
26
  <div class="icon">
 
32
  <div class="col-lg-4 col-6">
33
  <div class="small-box bg-success">
34
  <div class="inner">
35
+ <h3 id="dataConnectorsCount">{{table_count_of_each_table.data_connectors}}</h3>
36
  <h4>Data connectors</h4>
37
  </div>
38
  <div class="icon">
 
44
  <div class="col-lg-4 col-6">
45
  <div class="small-box bg-warning">
46
  <div class="inner">
47
+ <h3 id="apiConnectorsCount">{{table_count_of_each_table.api_connectors}}</h3>
48
  <h4>API Connectors</h4>
49
  </div>
50
  <div class="icon">
 
56
  <div class="col-lg-4 col-6">
57
  <div class="small-box bg-warning">
58
  <div class="inner">
59
+ <h3 id="promptTemplatesCount">{{table_count_of_each_table.prompt_templates}}</h3>
60
  <h4>Prompt_Templates</h4>
61
  </div>
62
  <div class="icon">
 
64
  </div>
65
  </div>
66
  </div>
67
+
68
  </div>
69
  </div>
70
  </section>
71
  </div>
72
+
73
+ <input type="hidden" id="userRole" name="userRole" value={{role}}>
74
+ <input type="hidden" id="company_id" name="company_id" value={{company_id}}>
75
+ <input type="hidden" id="username" name="username" value={{username}}>
76
+ <input type="hidden" id="company_name" name="company_name" value={{company_name}}>
77
  <footer>
78
  {% include 'footer.html' %}
79
  </footer>
 
81
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/adminlte.min.js"></script>
82
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
83
  <script>
84
+ window.addEventListener('pageshow', function (event) {
85
+ if (event.persisted || (window.performance && window.performance.navigation.type === 2)) {
86
+ window.location.reload();
87
+ }
88
+ });
 
89
 
90
 
91
+ document.addEventListener('DOMContentLoaded', function () {
92
  var role1 = document.getElementById("userRole").value;
93
+ var company_id1 = document.getElementById("company_id").value;
94
+ var company_name1=document.getElementById("company_name").value;
95
+ var username1=document.getElementById("username").value;
96
+ console.log("companyid in dasshboard",username1);
97
+ sessionStorage.setItem('userRole', role1);
98
+ // sessionStorage.setItem('siderole',role1);
99
+ // sessionStorage.setItem('sidecompanyId',company_id1);
100
+ sessionStorage.setItem('company_id', company_id1);
101
+ sessionStorage.setItem('company_name',company_name1);
102
+ sessionStorage.setItem('username',username1);
103
  if (!role1) {
104
  var roleFromInput = sessionStorage.getItem('userRole');
105
  sessionStorage.setItem('userRole', roleFromInput);
 
108
  sessionStorage.setItem('userRole', role1);
109
  console.log("Retrieved user role from input:", role1); // Debugging
110
  }
111
+ if (role1 === "superadmin") {
112
+ document.getElementById('company-block').style.display = 'block';
113
+ fetchCompanies();
114
+ }
115
 
116
+ });
117
+ document.getElementById('company').addEventListener('change', async function () {
118
+ const selectedCompany = this.value;
119
+ sessionStorage.setItem("company_name",selectedCompany);
120
+ if (selectedCompany!== "Select") {
121
+ try {
122
+ const response = await fetch(`/api/company_id?company_name=${encodeURIComponent(selectedCompany)}`);
123
+ if (!response.ok) {
124
+ contentSection.style.display = 'none';
125
+ displayErrorMessage("Document details do not exist for this company. Please fill in the details.");
126
+ throw new Error('Network response was not ok');
127
+ }
128
+ const data = await response.json();
129
+ console.log('data returned', data);
130
+ const companyId = data.company_id;
131
+ sessionStorage.setItem("company_id",companyId);
132
+ console.log("company id for superadmin", company_id);
133
+ //document.getElementById('company_id').value = companyId;
134
+
135
+
136
+ if (companyId) {
137
+ try {
138
+ const countResponse = await fetch(`/api/company_record_count/${companyId}`);
139
+ if (!countResponse.ok) {
140
+ throw new Error('Network response was not ok');
141
+ }
142
+ const countData = await countResponse.json();
143
+ console.log('Count data:', countData); // Log the response data
144
+ updateRecordCounts(countData.table_counts);
145
+ } catch (error) {
146
+ console.error('Error fetching record counts:', error);
147
+ }
148
+ } else {
149
+ clearRecordCounts();
150
+ }
151
+ } catch (error) {
152
+ console.error('No details for this company ID or data documents:', error);
153
+ // displayEmptyTable();
154
+
155
+ displayErrorMessage("company details do not exist for this company.");
156
+
157
+ }
158
+ }
159
+ });
160
+
161
+
162
+ function updateRecordCounts(counts) {
163
+ // Update the counts displayed in the dashboard
164
+ document.getElementById('knowledgeBaseCount').textContent = counts.knowledge_base || 0;
165
+ document.getElementById('dataConnectorsCount').textContent = counts.data_connectors || 0;
166
+ document.getElementById('apiConnectorsCount').textContent = counts.api_connectors || 0;
167
+ document.getElementById('promptTemplatesCount').textContent = counts.prompt_templates || 0;
168
+ }
169
+
170
+ function clearRecordCounts() {
171
+ document.getElementById('knowledgeBaseCount').textContent = 0;
172
+ document.getElementById('dataConnectorsCount').textContent = 0;
173
+ document.getElementById('apiConnectorsCount').textContent = 0;
174
+ document.getElementById('promptTemplatesCount').textContent = 0;
175
+ }
176
+
177
+
178
+ async function fetchCompanies() {
179
+ try {
180
+ const response = await fetch('/api/companies');
181
+ if (!response.ok) {
182
+ throw new Error('Network response was not ok');
183
+ }
184
+ const data = await response.json();
185
+ displayCompanies(data.companies);
186
+ } catch (error) {
187
+ console.error('Error fetching companies:', error);
188
+ }
189
+ }
190
+
191
+ function displayCompanies(companies) {
192
+ const companySelect = document.getElementById('company');
193
+ companySelect.innerHTML = '<option value="" selected>Select</option>'; // Reset the dropdown
194
+ companies.forEach(company => {
195
+ const option = document.createElement('option');
196
+ option.value = company.name;
197
+ option.textContent = company.name;
198
+ companySelect.appendChild(option);
199
+ });
200
+ }
201
+ function clearFormFields() {
202
+ document.getElementById('APIName').value = "";
203
+ document.getElementById('APIEndpoint').value = "";
204
+ document.getElementById('Auth_Bearer').value = "";
205
+ document.getElementById('Inputjson').value = "";
206
+ document.getElementById('OutputJson').value = "";
207
+ document.getElementById('Description').value = "";
208
+ }
209
+
210
+
211
+ </script>
212
  </body>
213
+
214
+ </html>