Skip to content

Commit e113e92

Browse files
Add Success-Error Info Division
1 parent 60d8f16 commit e113e92

7 files changed

Lines changed: 79 additions & 26 deletions

File tree

debug-db/src/main/assets/debugDbHome/css/custom.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,41 @@
1818
background: #dff0d8 !important;
1919
color: #3c763d !important;
2020
font-weight: bold;
21+
}
22+
23+
#snackbar {
24+
visibility: hidden;
25+
min-width: 250px;
26+
margin-left: -125px;
27+
background-color: #5cb85c;
28+
color: #fff;
29+
text-align: center;
30+
border-radius: 2px;
31+
padding: 16px;
32+
position: fixed;
33+
z-index: 1;
34+
left: 50%;
35+
bottom: 30px;
36+
font-size: 17px;
37+
}
38+
39+
#snackbar.show {
40+
visibility: visible;
41+
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
42+
animation: fadein 0.5s, fadeout 0.5s 2.5s;
43+
}
44+
45+
@-webkit-keyframes fadein {
46+
from {bottom: 0; opacity: 0;}
47+
to {bottom: 30px; opacity: 1;}
48+
}
49+
50+
@keyframes fadein {
51+
from {bottom: 0; opacity: 0;}
52+
to {bottom: 30px; opacity: 1;}
53+
}
54+
55+
@-webkit-keyframes fadeout {
56+
from {bottom: 30px; opacity: 1;}
57+
to {bottom: 0; opacity: 0;}
2158
}

debug-db/src/main/assets/debugDbHome/index.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@
118118
<label for="query">Query</label>
119119
<input class="form-control" id="query">
120120
</div>
121-
<button id="selected-db-info" type="button" onclick="downloadDb()" class="btn btn-info">Welcome</button>
122-
<button id="success-info" type="button" class="btn btn-success display-none">Query Executed</button>
123-
<button id="error-info" type="button" class="btn btn-danger display-none">Query Not Executed</button>
124-
<button id="run-query" type="submit" onclick="queryFunction()" class="btn btn-primary pull-right disabled">Run
121+
<button id="selected-db-info" type="button" onclick="downloadDb()" class="btn btn-info">
122+
Welcome
123+
</button>
124+
<button id="run-query" type="submit" onclick="queryFunction()"
125+
class="btn btn-primary pull-right disabled">Run
125126
Query
126127
</button>
127128
</div>
@@ -153,6 +154,8 @@
153154
</div>
154155
</div>
155156

157+
<div id="snackbar">Data Updated Successfully</div>
158+
156159
</div>
157160

158161
<script src="debugDbHome/js/app.js"></script>

debug-db/src/main/assets/debugDbHome/js/app.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ function openDatabaseAndGetTableList(db) {
121121
function inflateData(result){
122122

123123
if(result.isSuccessful){
124-
showSuccessInfo();
124+
125+
if(!result.isSelectQuery){
126+
showSuccessInfo("Query Executed Successfully");
127+
}
128+
125129
var columnHeader = result.tableInfos;
126130

127131
// set function to return cell data for different usages like set, display, filter, search etc..
@@ -183,7 +187,11 @@ function inflateData(result){
183187
$(".dataTables_scrollHeadInner").css({"width":"100%"});
184188
$(".table ").css({"width":"100%"});
185189
}else{
186-
showErrorInfo();
190+
if(!result.isSelectQuery){
191+
showSuccessInfo("Query Execution Failed");
192+
}else {
193+
showErrorInfo("Some Error Occurred");
194+
}
187195
}
188196

189197
}
@@ -217,6 +225,7 @@ function updateTableData(updatedData, callback) {
217225
if(response.isSuccessful){
218226
console.log("Data updated successfully");
219227
callback(true);
228+
showSuccessInfo("Data Updated Successfully");
220229
} else {
221230
console.log("Data updated failed");
222231
callback(false);
@@ -225,17 +234,18 @@ function updateTableData(updatedData, callback) {
225234
})
226235
}
227236

228-
function showSuccessInfo(){
229-
$("#success-info").show();
230-
$("#error-info").hide();
237+
function showSuccessInfo(message){
238+
var snackbar = document.getElementById("snackbar")
239+
snackbar.className = "show";
240+
snackbar.style.backgroundColor = "#5cb85c";
241+
snackbar.innerHTML = message;
242+
setTimeout(function(){ snackbar.className = snackbar.className.replace("show", ""); }, 2000);
231243
}
232244

233-
function showErrorInfo(){
234-
$("#success-info").hide();
235-
$("#error-info").show();
245+
function showErrorInfo(message){
246+
var snackbar = document.getElementById("snackbar")
247+
snackbar.className = "show";
248+
snackbar.style.backgroundColor = "#d9534f";
249+
snackbar.innerHTML = message;
250+
setTimeout(function(){ snackbar.className = snackbar.className.replace("show", ""); }, 2000);
236251
}
237-
238-
function hideBothInfo(){
239-
$("#success-info").hide();
240-
$("#error-info").hide();
241-
}

debug-db/src/main/java/com/amitshekhar/model/TableDataResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class TableDataResponse {
3232
public List<Object> rows;
3333
public String errorMessage;
3434
public boolean isEditable;
35+
public boolean isSelectQuery;
3536

3637
public static class TableInfo {
3738
public String title;

debug-db/src/main/java/com/amitshekhar/server/RequestHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private String executeQueryAndGetResponse(String route) {
219219
TableDataResponse response = DatabaseHelper.getTableData(mDatabase, query, null);
220220
data = mGson.toJson(response);
221221
} else {
222-
Response response = DatabaseHelper.exec(mDatabase, query);
222+
TableDataResponse response = DatabaseHelper.exec(mDatabase, query);
223223
data = mGson.toJson(response);
224224
}
225225
}

debug-db/src/main/java/com/amitshekhar/utils/DatabaseHelper.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static Response getAllTableName(SQLiteDatabase database) {
6363
public static TableDataResponse getTableData(SQLiteDatabase db, String selectQuery, String tableName) {
6464

6565
TableDataResponse tableData = new TableDataResponse();
66-
66+
tableData.isSelectQuery = true;
6767
if (tableName == null) {
6868
tableName = getTableName(selectQuery);
6969
}
@@ -239,18 +239,19 @@ public static UpdateRowResponse updateRow(SQLiteDatabase db, String tableName, L
239239
return updateRowResponse;
240240
}
241241

242-
public static Response exec(SQLiteDatabase database, String sql) {
243-
Response response = new Response();
242+
public static TableDataResponse exec(SQLiteDatabase database, String sql) {
243+
TableDataResponse tableDataResponse = new TableDataResponse();
244+
tableDataResponse.isSelectQuery = false;
244245
try {
245246
database.execSQL(sql);
246247
} catch (Exception e) {
247248
e.printStackTrace();
248-
response.isSuccessful = false;
249-
response.error = e.getMessage();
250-
return response;
249+
tableDataResponse.isSuccessful = false;
250+
tableDataResponse.errorMessage = e.getMessage();
251+
return tableDataResponse;
251252
}
252-
response.isSuccessful = true;
253-
return response;
253+
tableDataResponse.isSuccessful = true;
254+
return tableDataResponse;
254255
}
255256

256257
private static String getTableName(String selectQuery) {

debug-db/src/main/java/com/amitshekhar/utils/PrefHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public static TableDataResponse getAllPrefData(Context context, String tag) {
8888

8989
TableDataResponse response = new TableDataResponse();
9090
response.isSuccessful = true;
91+
response.isSelectQuery = true;
9192

9293
TableDataResponse.TableInfo keyInfo = new TableDataResponse.TableInfo();
9394
keyInfo.isPrimary = true;

0 commit comments

Comments
 (0)