Skip to content

Instantly share code, notes, and snippets.

Created August 1, 2019 03:26
Show Gist options
  • Save supanadit/c69e0413de13df824d3300d8fb2eac1e to your computer and use it in GitHub Desktop.
Save supanadit/c69e0413de13df824d3300d8fb2eac1e to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Belajar Socket.IO</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.7 -->
<link rel="stylesheet" href="<?= base_url() ?>/assets/bootstrap/dist/css/bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="<?= base_url() ?>/assets/font-awesome/css/font-awesome.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="<?= base_url() ?>/assets/Ionicons/css/ionicons.min.css">
<!-- DataTables -->
<link rel="stylesheet" href="<?= base_url() ?>/assets/">
<!-- Toastr -->
<link rel="stylesheet" href="<?= base_url() ?>/assets/toastr/build/toastr.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="<?= base_url() ?>/assets/adminlte/css/AdminLTE.min.css">
<!-- AdminLTE Skins. Choose a skin from the css/skins
folder instead of downloading all of them to reduce the load. -->
<link rel="stylesheet" href="<?= base_url() ?>/assets/adminlte/css/skins/_all-skins.min.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src=""></script>
<script src=""></script>
<!-- Google Font -->
<link rel="stylesheet"
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
<header class="main-header">
<!-- Logo -->
<a href="<?= base_url('admin') ?>" class="logo">
<!-- mini logo for sidebar mini 50x50 pixels -->
<span class="logo-mini"><b>S</b>IO</span>
<!-- logo for regular state and mobile devices -->
<span class="logo-lg"><b>Socket</b>IO</span>
<!-- Header Navbar: style can be found in header.less -->
<nav class="navbar navbar-static-top">
<!-- Sidebar toggle button-->
<a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<div class="navbar-custom-menu">
<ul class="nav navbar-nav">
<!-- User Account: style can be found in dropdown.less -->
<li class="dropdown user user-menu">
<a href="<?= base_url('admin') ?>">
<img src="<?= base_url() ?>/assets/adminlte/img/user2-160x160.jpg" class="user-image"
alt="User Image">
<span class="hidden-xs">Alexander Pierce</span>
<!-- Left side column. contains the logo and sidebar -->
<aside class="main-sidebar">
<!-- sidebar: style can be found in sidebar.less -->
<section class="sidebar">
<!-- Sidebar user panel -->
<div class="user-panel">
<div class="pull-left image">
<img src="<?= base_url() ?>/assets/adminlte/img/user2-160x160.jpg" class="img-circle"
alt="User Image">
<div class="pull-left info">
<p>Alexander Pierce</p>
<a href="#"><i class="fa fa-circle text-success"></i> Online</a>
<!-- /.search form -->
<!-- sidebar menu: : style can be found in sidebar.less -->
<ul class="sidebar-menu" data-widget="tree">
<li class="header">MAIN NAVIGATION</li>
<li class="active">
<a href="<?= base_url('admin') ?>">
<i class="fa fa-th"></i> <span>Employee</span>
<!-- /.sidebar -->
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-header">
<h3 class="box-title">List Employee</h3>
<div class="pull-right box-tools">
<button type="button" class="btn btn-info btn-sm" data-toggle="modal"
data-target="#modal-default" title="Add New Employee">
<i class="fa fa-plus"></i></button>
<!-- /.box-header -->
<div class="box-body">
<table id="employee" class="table table-bordered table-striped">
<th>Employee Name</th>
<!-- /.box-body -->
<!-- /.box -->
<!-- /.col -->
<!-- /.row -->
<!-- /.content -->
<!-- /.content-wrapper -->
<footer class="main-footer">
<div class="pull-right hidden-xs">
<b>Version</b> 2.4.13
<strong>Copyright &copy; 2019 <a href="<?= base_url('admin') ?>">Supan Adit Pratama</a>.</strong> All rights
<div class="modal fade" id="modal-default">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Add Employee</h4>
<div class="modal-body">
<input type="text" class="form-control" placeholder="Employee Name" id="employee_name"/>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" data-dismiss="modal" id="add_employee">Add</button>
<!-- /.modal-content -->
<!-- /.modal-dialog -->
<!-- /.modal -->
<!-- ./wrapper -->
<!-- jQuery 3 -->
<script src="<?= base_url() ?>/assets/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="<?= base_url() ?>/assets/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="<?= base_url() ?>/assets/"></script>
<script src="<?= base_url() ?>/assets/"></script>
<!-- SlimScroll -->
<script src="<?= base_url() ?>/assets/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="<?= base_url() ?>/assets/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="<?= base_url() ?>/assets/adminlte/js/adminlte.min.js"></script>
<!-- Toastr -->
<script src="<?= base_url() ?>/assets/toastr/build/toastr.min.js"></script>
<!-- Socket.IO -->
<script src="<?= base_url() ?>/assets/"></script>
<!-- page script -->
$(function () {
let ipAddress = "<?= $ip ?>";
if (ipAddress == "::1") {
ipAddress = "localhost"
const port = "3000";
const socketIoAddress = `http://${ipAddress}:${port}`;
const socket = io(socketIoAddress);
const employeeTable = $('#employee').DataTable();
const reloadTable = function () {
url: "<?= base_url('api/list_employee') ?>",
method: "GET",
dataType: "json",
async: false,
success: function (data) {
const employee =;
if (employee.length != 0) {
for (let x of employee) {
$("#add_employee").click(function () {
const employeeName = $("#employee_name");
if (employeeName != null && employeeName != "") {
url: "<?= base_url('api/add_employee') ?>",
method: "POST",
async: false,
data: JSON.stringify({
employee_name: employeeName.val(),
type: "application/json",
success: function (data) {
toastr.success(data.message, 'Adding New Employee');
socket.on('reload', () => {'Other User Adding New Employee', 'Reload');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment