diff options
| author | jmreddy2106 <[email protected]> | 2022-05-03 12:39:38 -0400 |
|---|---|---|
| committer | jmreddy2106 <[email protected]> | 2022-05-03 12:39:38 -0400 |
| commit | 40eac9bcc99f0dc0139a9356464df66e9cf5c7dc (patch) | |
| tree | 61f3f6e00cd1d171b77c3cf526559939d8e2ac3a | |
| parent | b0b1938f0e2ae2d159f0a616f8043d0b7f24f2eb (diff) | |
| download | Welfare-Schemes-DMQL-40eac9bcc99f0dc0139a9356464df66e9cf5c7dc.tar.xz Welfare-Schemes-DMQL-40eac9bcc99f0dc0139a9356464df66e9cf5c7dc.zip | |
added edit functionality to citizens
| -rw-r--r-- | interface/config/db.config.js | 2 | ||||
| -rw-r--r-- | interface/controllers/citizens.controller.js | 30 | ||||
| -rw-r--r-- | interface/models/citizens.model.js | 2 | ||||
| -rw-r--r-- | interface/views/citizens.ejs | 137 | ||||
| -rw-r--r-- | interface/views/partials/scripts.ejs | 8 |
5 files changed, 160 insertions, 19 deletions
diff --git a/interface/config/db.config.js b/interface/config/db.config.js index ea90d0c..622d5f5 100644 --- a/interface/config/db.config.js +++ b/interface/config/db.config.js @@ -3,7 +3,7 @@ module.exports = { // The name of the database database: process.env.DATABASE, // The username used to connect to the database - username: process.env.USERNAME, + username: process.env.USER, // The password used to connect to the database password: process.env.PASSWORD, // The dialect of the database you are connecting to diff --git a/interface/controllers/citizens.controller.js b/interface/controllers/citizens.controller.js index b50ee74..9eaf153 100644 --- a/interface/controllers/citizens.controller.js +++ b/interface/controllers/citizens.controller.js @@ -1,21 +1,43 @@ +const req = require("express/lib/request"); const db = require("../models"); const citizens = db.citizens; +const village_master = db.village_master; +const {QueryTypes} = require('sequelize'); +const { sequelize } = require("../models"); + // Retrieve all citizens from the database. Limit the number of citizens returned to 10. exports.findXCitizens = () => { + /** + * select c.first_name, c.last_name, c.address, c.mobile_num, c.dob, c.gender, c.marital_status, v.village_name + from citizens c + join village_master v + on c.village_id = v.village_id + limit 10 + */ const limit = 10; - return citizens.findAll({ - limit: limit, - }); + // Raw query in Sequelize + + query = `select c.citizen_id, c.first_name, c.last_name, c.address, c.mobile_num, c.dob, c.gender, c.marital_status, c.village_id, v.village_name + from citizens c + join village_master v + on c.village_id = v.village_id + limit 10` + + return sequelize.query(query, { type: QueryTypes.SELECT }) }; + + + + // Get total number of male and female citizens exports.findGenderDistribution = () => { // group by the 'gender' column /** * This code is equivalent to the following SQL query: - * select count(gender), gender from citizens group by gender; + * select count(gender), gender from citizens group by gender ; */ return citizens.findAll({ diff --git a/interface/models/citizens.model.js b/interface/models/citizens.model.js index f6310b0..5096417 100644 --- a/interface/models/citizens.model.js +++ b/interface/models/citizens.model.js @@ -1,3 +1,4 @@ + module.exports = (Sequelize, sequelize) => { const Citizens = sequelize.define("citizens", { citizen_id: { @@ -61,5 +62,6 @@ module.exports = (Sequelize, sequelize) => { }, }, }); + return Citizens; }; diff --git a/interface/views/citizens.ejs b/interface/views/citizens.ejs index 97c98fa..d11b4f5 100644 --- a/interface/views/citizens.ejs +++ b/interface/views/citizens.ejs @@ -1,51 +1,160 @@ <!DOCTYPE html> <html lang="en"> + + +<script> + + function editCitizensRecord(citizen) { + $(".edit.modal").modal("show"); + $("#address").val(citizen.address); + $("#mobilenumber").val(citizen.mobile_num); + $("#dob").val(citizen.dob); + $("#marital_status").val(citizen.marital_status); + $('#villagename').val(citizen.village_name); + + } + + function editCitizen(event) { + event.preventDefault(); + var data = { + address: $("#address").val(), + mobilenumber: $("#mobilenumber").val(), + dob: $("#dob").val(), + marital_status: $("#marital_status").val(), + villagename: $("#villagename").val(), + }; + $.ajax({ + url: "/citizen/edit", + type: "POST", + data: data, + success: function(response) { + console.log(response); + $(".edit.modal").modal("hide"); + location.reload(); + } + }); + } + +</script> + <head> <%- include('partials/head') %> </head> <body> + <div class="ui modal edit"> + <i class="close icon"></i> + <div class="header">Log in to continue</div> + <div + class="ui padded container segment" + style="border: none; box-shadow: none" + > + <div class="ui form"> + <div class="field"> + <label>Address</label> + <input + placeholder="Address" + name="address" + type="text" + autocomplete="off" + id="address" + /> + </div> + <div class="field"> + <label>Mobile Number</label> + <input + type="text" + name="mobile_number" + placeholder="Mobuile Number" + id="mobilenumber" + /> + </div> + <div class="field"> + <label>Date of Birth</label> + <input + type="date" + name="dob" + placeholder="DOB" + id="dob" + /> + </div> + <div class="field"> + <label>Marital Status</label> + <select class="ui dropdown" id="marital_status"> + <option value="M">Married</option> + <option value="UM">Unmarried</option> + </select> + </div> + <div class="field"> + <label>Village Name</label> + <input + type="text" + name="village" + placeholder="Village Name" + id="villagename" + /> + </div> + + <div class="ui primary button" id="submit">Submit</div> + <div class="ui error message"></div> + </div> + </div> + </div> + <%- include('partials/navbar') %> - <table class="ui selectable table"> + <table class="ui selectable table" style="padding: 2%"> <thead> <tr> - <th>Citizen ID</th> + <!-- <th>Citizen ID</th> --> <th>First Name</th> - <th>Middle Name</th> + <!-- <th>Middle Name</th> --> <th>Last Name</th> <th>Address</th> <th>Mobile Number</th> <th>Date of Birth</th> <th>Gender</th> <th>Marital Status</th> - <th>Disabled</th> - <th>Disabled Percentage</th> - <th>Caste</th> - <th>Village ID</th> + <!-- <th>Disabled</th> + <th>Disabled Percentage</th> --> + <!-- <th>Caste</th> --> + <th>Village Name</th> + <th></th> </tr> </thead> <tbody> <% for(var i=0; i < citizens.length; i++) { %> <tr> - <td><%= citizens[i].citizen_id %></td> + <!-- <td><%= citizens[i].citizen_id %></td> --> <td><%= citizens[i].first_name %></td> - <td> + <!-- <td> <%= citizens[i].middle_name ? citizens[i].middle_name : '-' %> - </td> + </td> --> <td><%= citizens[i].last_name %></td> <td><%= citizens[i].address %></td> <td><%= citizens[i].mobile_num %></td> <td><%= citizens[i].dob %></td> <td><%= citizens[i].gender %></td> <td><%= citizens[i].marital_status %></td> - <td><%= citizens[i].disabled %></td> - <td><%= citizens[i].disbaled_percentage %></td> - <td><%= citizens[i].caste %></td> - <td><%= citizens[i].village_id %></td> + <!-- <td><%= citizens[i].disabled %></td> --> + <!-- <td><%= citizens[i].disbaled_percentage %></td> --> + <!-- <td><%= citizens[i].caste %></td> --> + <td><%= citizens[i].village_name %></td> + <td> + <div class="ui teal buttons"> + <div class="ui button" onclick="editCitizensRecord(<%=JSON.stringify(citizens[i])%>)">Edit</div> + <div class="ui floating dropdown icon button"> + <i class="dropdown icon"></i> + <div class="menu"> + <div class="item" onclick="deleteCitizenRecord(<%= JSON.stringify(citizens[i])%>)"><i class="delete icon"></i> Delete</div> + </div> + </div> + </div> + </td> </tr> <% } %> </tbody> </table> </body> <%- include('partials/scripts') %> + </html> diff --git a/interface/views/partials/scripts.ejs b/interface/views/partials/scripts.ejs index a90467a..02a61ab 100644 --- a/interface/views/partials/scripts.ejs +++ b/interface/views/partials/scripts.ejs @@ -7,3 +7,11 @@ <script src="/verify.js"></script> <script src="/router.js"></script> <script src="/logout.js"></script> +<script> + $('.dropdown') + .dropdown({ + // you can use any ui transition + transition: 'drop' + }) +; +</script>
\ No newline at end of file |
