├── .gitignore
├── README.md
├── _config.yml
├── app.js
├── bin
└── www
├── controller
└── profile.js
├── package.json
├── public
├── javascripts
│ └── all.js
└── stylesheets
│ └── style.css
├── routes
├── index.js
├── profile.js
└── users.js
├── schema.js
└── views
├── error.pug
├── index.pug
├── layout.pug
├── profile-add.pug
├── profile-edit.pug
├── profile-lists.pug
└── profile-view.pug
/.gitignore:
--------------------------------------------------------------------------------
1 | pids
2 | logs
3 | results
4 |
5 | npm-debug.log
6 |
7 | .DS_Store
8 | node_modules/
9 |
10 |
11 | run.sh
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Simple CRUD Node.js & MySQL
2 | This is a very basic example of CRUD in Node.js n mySQL.
3 | ## Installation
4 | *for newbies : Clone or download zip to your machine then hit this :
5 |
6 | npm install
7 |
8 | ## Configuration (database)
9 | app.js
10 |
11 | host: 'localhost',
12 | user: 'root', // mysql username
13 | password : 'root', // mysql password
14 | port : 3306, //port mysql
15 | database:'nodejs' // mysql database name
16 |
17 |
18 |
19 | You're gonna need to create a DB named 'nodejs'
20 |
21 | ## NOTES
22 | This repo use Express 4.x.
23 |
24 | ## Open your Browser
25 | And type: localhost:5000
26 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-cayman
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | var express = require('express');
2 | var path = require('path');
3 | var favicon = require('serve-favicon');
4 | var logger = require('morgan');
5 | var cookieParser = require('cookie-parser');
6 | var session = require('express-session');
7 | var bodyParser = require('body-parser');
8 | var flash = require('express-flash-messages')
9 | var moment = require('moment');
10 | var schema = require('./schema');
11 |
12 | var mysql = require('mysql'),
13 | connection = require('express-myconnection'),
14 | config = {
15 | host: 'localhost',
16 | user: 'root',
17 | password: '',
18 | port: 3306,
19 | database: 'nodejs'
20 | };
21 | var index = require('./routes/index');
22 | var users = require('./routes/users');
23 | /*Profile Routes*/
24 | var profile = require('./routes/profile');
25 |
26 | var app = express();
27 | app.use(flash());
28 | app.locals.moment = require('moment');
29 | app.set('views', path.join(__dirname, 'views'));
30 | app.set('view engine', 'pug');
31 |
32 | // uncomment after placing your favicon in /public
33 | //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
34 | app.use(logger('dev'));
35 | app.use(bodyParser.json());
36 | app.use(bodyParser.urlencoded({
37 | extended: false
38 | }));
39 | app.use(cookieParser());
40 | app.use(express.static(path.join(__dirname, 'public')));
41 | app.use(session({
42 | secret: 'OzhclfxGp956SMjtq',
43 | resave: true,
44 | saveUninitialized: false,
45 | cookie: { maxAge: 60000 }
46 | }));
47 |
48 |
49 | // DB connection
50 | app.use(connection(mysql, config, 'request'));
51 |
52 | app.use('/', index);
53 | app.use('/users', users);
54 | app.use('/profiles', profile);
55 |
56 | // catch 404 and forward to error handler
57 | app.use(function(req, res, next) {
58 | var err = new Error('Not Found');
59 | err.status = 404;
60 | next(err);
61 | });
62 |
63 | // error handler
64 | app.use(function(err, req, res, next) {
65 | // set locals, only providing error in development
66 | res.locals.message = err.message;
67 | res.locals.error = req.app.get('env') === 'development' ? err : {};
68 |
69 | // render the error page
70 | res.status(err.status || 500);
71 | res.render('error');
72 | });
73 |
74 | module.exports = app;
75 |
--------------------------------------------------------------------------------
/bin/www:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | /**
4 | * Module dependencies.
5 | */
6 |
7 | var app = require('../app');
8 | var debug = require('debug')('myapp:server');
9 | var http = require('http');
10 |
11 | /**
12 | * Get port from environment and store in Express.
13 | */
14 |
15 | var port = normalizePort(process.env.PORT || '5000');
16 | app.set('port', port);
17 |
18 | /**
19 | * Create HTTP server.
20 | */
21 |
22 | var server = http.createServer(app);
23 |
24 | /**
25 | * Listen on provided port, on all network interfaces.
26 | */
27 |
28 | server.listen(port);
29 | server.on('error', onError);
30 | server.on('listening', onListening);
31 |
32 | /**
33 | * Normalize a port into a number, string, or false.
34 | */
35 |
36 | function normalizePort(val) {
37 | var port = parseInt(val, 10);
38 |
39 | if (isNaN(port)) {
40 | // named pipe
41 | return val;
42 | }
43 |
44 | if (port >= 0) {
45 | // port number
46 | return port;
47 | }
48 |
49 | return false;
50 | }
51 |
52 | /**
53 | * Event listener for HTTP server "error" event.
54 | */
55 |
56 | function onError(error) {
57 | if (error.syscall !== 'listen') {
58 | throw error;
59 | }
60 |
61 | var bind = typeof port === 'string'
62 | ? 'Pipe ' + port
63 | : 'Port ' + port;
64 |
65 | // handle specific listen errors with friendly messages
66 | switch (error.code) {
67 | case 'EACCES':
68 | console.error(bind + ' requires elevated privileges');
69 | process.exit(1);
70 | break;
71 | case 'EADDRINUSE':
72 | console.error(bind + ' is already in use');
73 | process.exit(1);
74 | break;
75 | default:
76 | throw error;
77 | }
78 | }
79 |
80 | /**
81 | * Event listener for HTTP server "listening" event.
82 | */
83 |
84 | function onListening() {
85 | var addr = server.address();
86 | var bind = typeof addr === 'string'
87 | ? 'pipe ' + addr
88 | : 'port ' + addr.port;
89 | debug('Listening on ' + bind);
90 | }
91 |
--------------------------------------------------------------------------------
/controller/profile.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Controller for Add / Update / Delete of Profile table
3 | */
4 | var flash = require('express-flash-messages')
5 | // Single Profile View
6 | exports.view = function(req, res){
7 | var id = req.params.id;
8 | req.getConnection(function(err, connection){
9 | var query = connection.query("SELECT * FROM profile WHERE id = ?", [id], function(err, rows){
10 | if(err) console.log("Error Selecting list : %s", err);
11 | res.render('profile-view',{
12 | title : "Nodejs CRUD: Profile of "+rows[0].first_name,
13 | secondaryTitle: rows[0].first_name + ' ' + rows[0].last_name,
14 | profiles: rows
15 | });
16 | });
17 | });
18 | };
19 |
20 | // Profile list Export
21 | exports.list = function(req, res){
22 | req.getConnection(function(err, connection){
23 | var query = connection.query("SELECT * FROM profile", function(err, rows){
24 | if(err) console.log("Error Selecting list : %s", err);
25 | res.render('profile-lists',{
26 | title : "Nodejs CRUD: Profile List",
27 | secondaryTitle: "There are " + rows.length + " Users Profile created",
28 | profiles: rows
29 | });
30 | });
31 | });
32 | };
33 |
34 | // Profile Add
35 | exports.add = function(req, res){
36 | res.render("profile-add",{
37 | title : "Nodejs CRUD: Profile Add",
38 | secondaryTitle: "Add Profile",
39 | })
40 | }
41 |
42 | // Profile Edit
43 | exports.edit = function(req, res){
44 | var id = req.params.id;
45 | req.getConnection(function(err, connection){
46 | var query = connection.query("SELECT * FROM profile WHERE id = ?", [id], function(err, rows){
47 | if(err) console.log("Error Editing list : %s", err);
48 | res.render('profile-edit', {
49 | title : "Nodejs CRUD: Profile Edit",
50 | profiles: rows
51 | })
52 | });
53 | });
54 | };
55 |
56 | //Profile save
57 | exports.save = function(req, res){
58 | var input = JSON.parse(JSON.stringify(req.body));
59 | req.getConnection(function(err, connection){
60 | var data = {
61 | first_name: input.first_name,
62 | last_name: input.last_name,
63 | email: input.email,
64 | phone: input.phone,
65 | street_address: input.street_address,
66 | street_address_2: input.street_address_2,
67 | city: input.city,
68 | state: input.state,
69 | country: input.country
70 | };
71 | var query = connection.query("INSERT INTO profile set ?", data, function(err, rows, fields){
72 | if(err)
73 | console.log("Error in Inserting Data : %s", err);
74 | else{
75 | var query = connection.query("SELECT * FROM profile WHERE id = ?", rows.insertId, function(err, rows){
76 | if(err) console.log("Error Editing list : %s", err);
77 | req.flash('success', '' + rows[0].first_name + ' Your Profile Created');
78 | res.redirect('/profiles');
79 | });
80 |
81 | }
82 | });
83 | });
84 | };
85 |
86 | //Profile Save Edit
87 | exports.save_edit = function(req, res){
88 | var input = JSON.parse(JSON.stringify(req.body));
89 | var id = req.params.id;
90 | req.getConnection(function(err, connection){
91 | var data = {
92 | first_name: input.first_name,
93 | last_name: input.last_name,
94 | email: input.email,
95 | phone: input.phone,
96 | street_address: input.street_address,
97 | street_address_2: input.street_address_2,
98 | city: input.city,
99 | state: input.state,
100 | country: input.country
101 | };
102 | connection.query("UPDATE profile set ? WHERE id = ?", [data, id], function(err, rows){
103 | if(err)
104 | console.log("Error in Updating : %s", err);
105 | else{
106 | var query = connection.query("INSERT INTO profile set ?", data, function(err, rows, fields){
107 | if(err)
108 | console.log("Error in Inserting Data : %s", err);
109 | else{
110 | var query = connection.query("SELECT * FROM profile WHERE id = ?", rows.insertId, function(err, rows){
111 | if(err) console.log("Error Editing list : %s", err);
112 | req.flash('success', '' + rows[0].first_name + ' Your Profile Updated.');
113 | res.redirect('/profiles');
114 | });
115 |
116 | }
117 | });
118 | }
119 | });
120 | });
121 | };
122 |
123 | //Profile DELETE
124 | exports.delete = function(req, res){
125 | var id = req.params.id;
126 | req.getConnection(function(err, connection){
127 | connection.query("DELETE FROM profile WHERE id = ? ", [id], function(err, rows){
128 | if(err)
129 | console.log("Error in Deleting : %s", err);
130 | else{
131 | console.log("Profile Deleted: %s", rows);
132 | req.flash('warning', 'Your Profile Deleted.');
133 | res.redirect("/profiles")
134 | }
135 | });
136 | });
137 | };
138 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "myapp",
3 | "version": "0.0.0",
4 | "private": true,
5 | "scripts": {
6 | "start": "node ./bin/www"
7 | },
8 | "dependencies": {
9 | "body-parser": "~1.17.1",
10 | "cookie-parser": "~1.4.3",
11 | "debug": "~2.6.3",
12 | "express": "~4.15.2",
13 | "express-myconnection": "^1.0.4",
14 | "express-session": "^1.15.2",
15 | "moment": "^2.18.1",
16 | "morgan": ">=1.9.1",
17 | "mysql": "^2.13.0",
18 | "pug": "~2.0.0-beta11",
19 | "serve-favicon": "~2.4.2"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/public/javascripts/all.js:
--------------------------------------------------------------------------------
1 | function confimrDelete(id) {
2 | var r = confirm("Are you sure what to delete?");
3 | if (r == true) {
4 | window.location.href='/profiles/delete/'+id;
5 | return;
6 | } else {
7 | return false;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/public/stylesheets/style.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding: 50px;
3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4 | }
5 |
6 | a {
7 | color: #00B7FF;
8 | }
9 |
--------------------------------------------------------------------------------
/routes/index.js:
--------------------------------------------------------------------------------
1 | var express = require('express');
2 | var router = express.Router();
3 |
4 | /* GET home page. */
5 | router.get('/', function(req, res, next) {
6 | res.render('index', { title: 'Express' });
7 | });
8 |
9 | module.exports = router;
10 |
--------------------------------------------------------------------------------
/routes/profile.js:
--------------------------------------------------------------------------------
1 | var express = require('express'),
2 | router = express.Router(),
3 | profile = require('../controller/profile');
4 |
5 | // Profile Routing List
6 | router.get('/', profile.list);
7 | router.get('/add', profile.add);
8 | router.post('/add', profile.save);
9 | router.get('/delete/:id', profile.delete);
10 | router.get('/edit/:id', profile.edit);
11 | router.post('/edit/:id', profile.save_edit);
12 | router.get('/view/:id', profile.view);
13 | module.exports = router;
14 |
--------------------------------------------------------------------------------
/routes/users.js:
--------------------------------------------------------------------------------
1 | var express = require('express');
2 | var router = express.Router();
3 |
4 | /* GET users listing. */
5 | router.get('/', function(req, res, next) {
6 | res.send('respond with a resource');
7 | });
8 |
9 | module.exports = router;
10 |
--------------------------------------------------------------------------------
/schema.js:
--------------------------------------------------------------------------------
1 | var mysql = require('mysql'),
2 | connection = mysql.createConnection({
3 | host: 'localhost',
4 | user: 'root',
5 | password: '',
6 | port: 3306,
7 | database: 'nodejs'
8 | });
9 | connection.query('CREATE TABLE IF NOT EXISTS `profile` (`id` int(11) NOT NULL AUTO_INCREMENT, `first_name` varchar(255) NOT NULL,`last_name` varchar(255) NOT NULL, `email` varchar(255) NOT NULL, `phone` varchar(255) NOT NULL, `street_address` varchar(255) NOT NULL, `street_address_2` varchar(255) NOT NULL, `city` varchar(255) NOT NULL, `state` varchar(255) NOT NULL, `country` varchar(255) NOT NULL, `profile_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1', function(err, result){
10 | // Case there is an error during the creation
11 | if(err) {
12 | console.log(err);
13 | }
14 | else{
15 | console.log("Table profile Created");
16 | }
17 | });
18 |
--------------------------------------------------------------------------------
/views/error.pug:
--------------------------------------------------------------------------------
1 | extends layout
2 |
3 | block content
4 | .container.mt-5
5 | h1= message
6 | h2.mb-3= error.status
7 | pre #{error.stack}
8 |
--------------------------------------------------------------------------------
/views/index.pug:
--------------------------------------------------------------------------------
1 | extends layout
2 |
3 | block content
4 | .container.mt-5.d-flex.flex-column.align-content-center.flex-wrap
5 | h1= title
6 | p Welcome to #{title}
7 |
--------------------------------------------------------------------------------
/views/layout.pug:
--------------------------------------------------------------------------------
1 | doctype html(lang='en')
2 | html
3 | head
4 | meta(charset='utf-8')
5 | meta(name='viewport', content='width=device-width, initial-scale=1.0')
6 | title= title
7 | link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css')
8 | body
9 | nav.navbar.navbar-toggleable-md.navbar-light.bg-faded.bg-primary.navbar-inverse
10 | button.navbar-toggler.navbar-toggler-right(type='button', data-toggle='collapse' data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation")
11 | span.navbar-toggler-icon
12 | a.navbar-brand(href='/') Node CRUD
13 | #navbarNav.collapse.navbar-collapse
14 | ul.navbar-nav
15 | li.nav-item
16 | a.nav-link(href='/') Home
17 | li.nav-item
18 | a.nav-link(href='/profiles') Profile List
19 | li.nav-item
20 | a.nav-link(href='/profiles/add') Add Profile
21 | block content
22 | script(src="https://code.jquery.com/jquery-3.1.1.slim.min.js")
23 | script(src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js")
24 | script(src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js")
25 | script(src="/javascripts/all.js")
26 |
--------------------------------------------------------------------------------
/views/profile-add.pug:
--------------------------------------------------------------------------------
1 | extends layout
2 |
3 | block content
4 | h1.text-center.mt-3= title
5 | p.text-center.mt-3 #{secondaryTitle}
6 | .container
7 | form(method='post', action='/profiles/add').pt-3
8 | .row
9 | .col-sm-6
10 | .form-group
11 | label.col-form-label.mb-2(for='first_name') First Name
12 | input.form-control(type='text', placeholder='First Name', id='first_name', name='first_name')
13 | .col-sm-6
14 | .form-group
15 | label.col-form-label.mb-2(for='last_name') Last Name
16 | input.form-control(type='text', placeholder='Last Name', id='last_name', name='last_name')
17 | .col-sm-6
18 | .form-group
19 | label.col-form-label.mb-2(for='email') Email Address
20 | input.form-control(type='text', placeholder='Email Address', id='email', name='email')
21 | .col-sm-6
22 | .form-group
23 | label.col-form-label.mb-2(for='phone') Phone Number
24 | input.form-control(type='text', placeholder='Phone Number', id='phone', name='phone')
25 | .col-sm-6
26 | .form-group
27 | label.col-form-label.mb-2(for='street_address') Street Address
28 | input.form-control(type='text', placeholder='Street Address', id='street_address', name='street_address')
29 | .col-sm-6
30 | .form-group
31 | label.col-form-label.mb-2(for='street_address_2') Street Address 2
32 | input.form-control(type='text', placeholder='Street Address 2', id='street_address_2', name='street_address_2')
33 | .col-sm-6
34 | .form-group
35 | label.col-form-label.mb-2(for='city') City
36 | input.form-control(type='text', placeholder='City', id='city', name='city')
37 | .col-sm-6
38 | .form-group
39 | label.col-form-label.mb-2(for='state') State
40 | input.form-control(type='text', placeholder='State', id='state', name='state')
41 | .col-sm-6
42 | .form-group
43 | label.col-form-label.mb-2(for='country') Country
44 | input.form-control(type='text', placeholder='Country', id='country', name='country')
45 | .col-sm-6
46 | .form-group
47 | input.form-control(type='hidden', placeholder='Profile Create', id='profile_create', name='profile_create', value=moment().format("YYYY-MM-DD k:mm:ss"))
48 | .col-sm-6
49 | button.btn.btn-primary.col-sm-2(type='submit') Submit
50 |
--------------------------------------------------------------------------------
/views/profile-edit.pug:
--------------------------------------------------------------------------------
1 | extends layout
2 |
3 | block content
4 | h1.text-center.mt-3= title
5 | p.text-center.mt-3 Welcome to #{secondaryTitle}
6 | .container
7 | form(method='post', action='/profiles/edit/'+profiles[0].id).pt-3
8 | .row
9 | .col-sm-6
10 | .form-group
11 | label.col-form-label.mb-2(for='first_name') First Name
12 | input.form-control(type='text', value=profiles[0].first_name, placeholder='First Name', id='first_name', name='first_name')
13 | .col-sm-6
14 | .form-group
15 | label.col-form-label.mb-2(for='last_name') Last Name
16 | input.form-control(type='text', value=profiles[0].last_name, placeholder='Last Name', id='last_name', name='last_name')
17 | .col-sm-6
18 | .form-group
19 | label.col-form-label.mb-2(for='email') Email Address
20 | input.form-control(type='text',value=profiles[0].email, placeholder='Email Address', id='email', name='email')
21 | .col-sm-6
22 | .form-group
23 | label.col-form-label.mb-2(for='phone') Phone Number
24 | input.form-control(type='text',value=profiles[0].phone, placeholder='Phone Number', id='phone', name='phone')
25 | .col-sm-6
26 | .form-group
27 | label.col-form-label.mb-2(for='street_address') Street Address
28 | input.form-control(type='text',value=profiles[0].street_address, placeholder='Street Address', id='street_address', name='street_address')
29 | .col-sm-6
30 | .form-group
31 | label.col-form-label.mb-2(for='street_address_2') Street Address 2
32 | input.form-control(type='text',value=profiles[0].street_address_2, placeholder='Street Address 2', id='street_address_2', name='street_address_2')
33 | .col-sm-6
34 | .form-group
35 | label.col-form-label.mb-2(for='city') City
36 | input.form-control(type='text',value=profiles[0].city, placeholder='City', id='city', name='city')
37 | .col-sm-6
38 | .form-group
39 | label.col-form-label.mb-2(for='state') State
40 | input.form-control(type='text',value=profiles[0].state, placeholder='State', id='state', name='state')
41 | .col-sm-6
42 | .form-group
43 | label.col-form-label.mb-2(for='country') Country
44 | input.form-control(type='text',value=profiles[0].country, placeholder='Country', id='country', name='country')
45 | .col-sm-6
46 | button.btn.btn-primary.col-sm-2(type='submit') Submit
47 |
--------------------------------------------------------------------------------
/views/profile-lists.pug:
--------------------------------------------------------------------------------
1 | extends layout
2 |
3 | block content
4 | h1.text-center.mt-3= title
5 | p.text-center.mt-3 #{secondaryTitle}
6 | .container
7 | - var messages = getMessages()
8 | if messages.success
9 | .alert.alert-success(role='alert') #[strong Well done!] !{messages.success}
10 | if messages.warning
11 | .alert.alert-danger(role='alert') #[strong Oh snap!] !{messages.warning}
12 | .row
13 | if (profiles.length)
14 | each profile, i in profiles
15 | .col-sm-4.mt-3
16 | .card
17 | h3.card-header #{profile.first_name}
18 | if (profile.last_name.length)
19 | = ', '
20 | = profile.last_name
21 | .card-block
22 | if (profile.email.length)
23 | p.card-text.font-weight-bold.font-italic
24 | span.d-sm-block.text-gray-dark.font-weight-normal Email ID
25 | = profile.email
26 | if (profile.phone.length)
27 | p.card-text.font-weight-bold.font-italic
28 | span.d-sm-block.text-gray-dark.font-weight-normal Phone Number
29 | = profile.phone
30 | if (profile.street_address.length)
31 | p.card-text.font-weight-bold.font-italic
32 | span.d-sm-block.text-gray-dark.font-weight-normal Street Address
33 | = profile.street_address
34 | if (profile.street_address_2.length)
35 | p.card-text.font-weight-bold.font-italic
36 | span.d-sm-block.text-gray-dark.font-weight-normal Street Address 2
37 | = profile.street_address_2
38 | if (profile.city.length)
39 | p.card-text.font-weight-bold.font-italic
40 | span.d-sm-block.text-gray-dark.font-weight-normal City
41 | = profile.city
42 | if (profile.state.length)
43 | p.card-text.font-weight-bold.font-italic
44 | span.d-sm-block.text-gray-dark.font-weight-normal State
45 | = profile.state
46 | if (profile.country.length)
47 | p.card-text.font-weight-bold.font-italic
48 | span.d-sm-block.text-gray-dark.font-weight-normal Country
49 | = profile.country
50 | if (profile.country.length == 0 && profile.state.length == 0 && profile.city.length == 0 && profile.street_address.length == 0 && profile.street_address_2.length == 0 && profile.phone.length == 0 && profile.email.length == 0 )
51 | p.card-text.font-weight-bold.text-center
52 | .alert.alert-success(role='alert') #[strong No Data Available]
53 | a.card-link(href='../profiles/edit/'+profile.id) Edit Profile
54 | a.card-link(href='javascript:void(0);', onclick="confimrDelete(" + profile.id + ")") Delete Profile
55 | a.card-link(href='../profiles/view/'+profile.id) View Profile
56 | .card-footer.text-muted= profile.profile_create
57 | else
58 | h3 No Profile Created
59 |
--------------------------------------------------------------------------------
/views/profile-view.pug:
--------------------------------------------------------------------------------
1 | extends layout
2 |
3 | block content
4 | h1.text-center.mt-3= title
5 | p.text-center.mt-3.text-muted Welcome #{secondaryTitle}
6 | .container
7 | if (profiles.length)
8 | .card.mt-5
9 | h3.card-header #{profiles[0].first_name}
10 | if (profiles[0].last_name.length)
11 | = ', '
12 | = profiles[0].last_name
13 | .card-block
14 | if (profiles[0].email.length)
15 | .row.mt-3
16 | .col-sm-2
17 | p.card-text.font-weight-bold
18 | span.d-sm-block.text-gray-dark.font-weight-normal Email ID:
19 | .col-sm-10
20 | p.card-text.font-weight-bold.font-italic
21 | = profiles[0].email
22 | if (profiles[0].phone.length)
23 | .row.mt-3
24 | .col-sm-2
25 | p.card-text.font-weight-bold
26 | span.d-sm-block.text-gray-dark.font-weight-normal Phone Number
27 | .col-sm-10
28 | p.card-text.font-weight-bold.font-italic
29 | = profiles[0].phone
30 | if (profiles[0].street_address.length)
31 | .row.mt-3
32 | .col-sm-2
33 | p.card-text.font-weight-bold
34 | span.d-sm-block.text-gray-dark.font-weight-normal Street Address
35 | .col-sm-10
36 | p.card-text.font-weight-bold.font-italic
37 | = profiles[0].street_address
38 | if (profiles[0].street_address_2.length)
39 | .row.mt-3
40 | .col-sm-2
41 | p.card-text.font-weight-bold
42 | span.d-sm-block.text-gray-dark.font-weight-normal Street Address 2
43 | .col-sm-10
44 | p.card-text.font-weight-bold.font-italic
45 | = profiles[0].street_address_2
46 | if (profiles[0].city.length)
47 | .row.mt-3
48 | .col-sm-2
49 | p.card-text.font-weight-bold
50 | span.d-sm-block.text-gray-dark.font-weight-normal City
51 | .col-sm-10
52 | p.card-text.font-weight-bold.font-italic
53 | = profiles[0].city
54 | if (profiles[0].state.length)
55 | .row.mt-3
56 | .col-sm-2
57 | p.card-text.font-weight-bold
58 | span.d-sm-block.text-gray-dark.font-weight-normal State
59 | .col-sm-10
60 | p.card-text.font-weight-bold.font-italic
61 | = profiles[0].state
62 | if (profiles[0].country.length)
63 | .row.mt-3
64 | .col-sm-2
65 | p.card-text.font-weight-bold
66 | span.d-sm-block.text-gray-dark.font-weight-normal Country
67 | .col-sm-10
68 | p.card-text.font-weight-bold.font-italic
69 | = profiles[0].country
70 | if (profiles[0].country.length == 0 && profiles[0].state.length == 0 && profiles[0].city.length == 0 && profiles[0].street_address.length == 0 && profiles[0].street_address_2.length == 0 && profiles[0].phone.length == 0 && profiles[0].email.length == 0 )
71 | p.card-text.font-weight-bold.text-center
72 | .alert.alert-success(role='alert') #[strong No Data Available]
73 | .mt-5
74 | a.card-link(href='/profiles/edit/'+profiles[0].id) Edit Profile
75 | a.card-link(href='javascript:void(0);', onclick="confimrDelete("+ profiles[0].id +")") Delete Profile
76 | .card-footer.text-muted= profiles[0].profile_create
77 | else
78 | h3 No Profile Created
79 |
--------------------------------------------------------------------------------