Added custom notification

This commit is contained in:
Gregorio Chiko Putra 2017-10-26 14:59:49 +07:00
parent bc21934274
commit a106344dc8
15 changed files with 238 additions and 103 deletions

View File

@ -43,7 +43,9 @@ class Api
}
}
if ($table == 'kategori') {
$get['count'] = count($get['data']);
if ($table == 'kategori' && $get['count'] != 0) {
if (isset($get['data'][0])) {
for ($i=0; $i < count($get['data']); $i++) {
$get['data'][$i]['posts'] = count(\App\Models\Pengumuman::showAll('pengumuman', [
@ -58,8 +60,7 @@ class Api
]));
}
}
$get['count'] = count($get['data']);
header('Content-Type: application/json');
echo json_encode($get);
@ -82,6 +83,7 @@ class Api
$put['status'] = true;
$put['data'] = $update;
$put['count'] = count($put['data']);
$put['message'] = ucfirst($table) . ' berhasil diubah';
}
header('Content-Type: application/json');
@ -105,6 +107,7 @@ class Api
$post['status'] = true;
$post['data'] = $entry;
$post['count'] = count($post['data']);
$post['message'] = ucfirst($table) . ' berhasil ditambahkan';
}
header('Content-Type: application/json');

View File

@ -39,14 +39,19 @@ class Home
$password = $args['password'];
$user = Access::showAll([
['username', '=', $username],
['flag', '=', 0]
['username', '=', $username]
]);
if ($user == false) {
$info = "Username/password salah";
$logged_in['status'] = $info;
$logged_in['status'] = false;
$logged_in['message'] = $info;
} else {
if ($user['flag'] != 0) {
$info = "User telah login";
$logged_in['status'] = false;
$logged_in['message'] = $info;
}
$hash = Hash::compare($password, $user['salt'], $user['password']);
if ($hash == true) {
@ -66,11 +71,12 @@ class Home
$info = "Berhasil masuk";
$logged_in['status'] = true;
$logged_in['redirect_to'] = '/?s='.$session['id']."&u=".$session['uid'];
$logged_in['message'] = 'Berhasil login';
}
}
} else {
$info = "Username/password salah";
$logged_in['status'] = $info;
$logged_in['message'] = $info;
}
}
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
@ -101,16 +107,18 @@ class Home
$info = "Berhasil keluar";
$logged_out['status'] = true;
$logged_out['redirect_to'] = '/';
$logged_out['redirect_to'] = '';
$logged_out['message'] = 'Berhasil logout';
} catch (\Exception $e) {
$logged_out['status'] = $e->getMessage();
$logged_out['status'] = false;
$logged_out['message'] = $e->getMessage();
}
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode($logged_out);die();
}
// Session::flash('info', $info);
// Redirect::to('/');
Session::flash('info', $info);
Redirect::to('/');
}
public function register()
@ -131,7 +139,7 @@ class Home
foreach ($args as $value) {
if ($value == '') {
$info = 'Semua data harus diisi';
$registered['status'] = 'false';
$registered['status'] = false;
$registered['message'] = $info;
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode($registered);die();
@ -183,7 +191,8 @@ class Home
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode([
'status' => true,
'route_to' => ''
'route_to' => '',
'message' => 'User berhasil ditambahkan'
]);die();
}
Session::flash('info', 'Registrasi berhasil');

View File

@ -338,6 +338,7 @@ class Posts
}
$post['status'] = true;
$post['route_to'] = '';
$post['message'] = 'Pengumuman berhasil ditambahkan';
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode($post);
die();
@ -350,6 +351,7 @@ class Posts
public function put($args)
{
// echo json_encode($args); die();
$update = [];
if (isset($args['_addon'])) {
@ -413,6 +415,7 @@ class Posts
if ($this->model->update($args, $id)) {
$update['status'] = true;
$update['route_to'] = '';
$update['message'] = 'Pengumuman berhasil diubah';
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode($update);
die();

View File

@ -12,21 +12,6 @@
<body>
<script src="/js/landing.js"></script>
<script>
function fadeOutEffect() {
var fadeTarget = document.getElementById("info");
var fadeEffect = setInterval(function () {
if (!fadeTarget.style.opacity) {
fadeTarget.style.opacity = 1;
}
if (fadeTarget.style.opacity < 0.1) {
clearInterval(fadeEffect);
fadeTarget.remove();
} else {
fadeTarget.style.opacity -= 0.1;
}
}, 50);
}
</script>
<script></script>
</body>
</html>

View File

@ -0,0 +1,23 @@
let m = require('mithril')
let fadeOutEffect = require('../others/fadeOutEffect')
module.exports = {
view: function() {
return m('.label.top', {
style: {
position: 'fixed',
top: '15px',
fontSize: 'small',
margin: '0 35%',
left: '0',
right: '0',
overflowY: 'auto',
maxWidth: '100%',
maxHeight: '100%'
},
onclick: function() {
fadeOutEffect.fade(this)
}
}, window.message)
}
}

View File

@ -27,7 +27,7 @@ var listAdmin = {
m('em', [
pengumuman.creatorName,
' - ',
fecha.format(fecha.parse(pengumuman.valid_at, 'YYYY-MM-DD H:i:s'), 'DD/MM/YYYY')
fecha.format(fecha.parse(pengumuman.created_at, 'YYYY-MM-DD H:i:s'), 'DD/MM/YYYY')
])
]),
m('span.stack', {style:'color:' + pengumuman.foreground + '; overflow-y: auto;'}, m.trust(marked(pengumuman.content))),

View File

@ -1,5 +1,7 @@
let m = require('mithril')
let _ = require('lodash')
let user = require('../models/user')
let fadeOutEffect = require('../others/fadeOutEffect')
var login = {
view: function() {
@ -18,7 +20,8 @@ var login = {
maxlength: '25',
autocomplete: 'off',
oninput: m.withAttr('value', function(value) {user.current.username = value}),
value: user.current.username
value: user.current.username,
required: 'required'
})),
m('.fourth-600.full', m('input', {
type: 'password',
@ -27,18 +30,32 @@ var login = {
oninput: m.withAttr('value', function(value) {
user.current.password = value
}),
value: user.current.password
value: user.current.password,
required: 'required'
})),
m('.fourth-600.none'),
m('.fourth-600.none'),
m('div', m('button.half-600.full.pseudo', {
m('.half-600.full', m('button.full.pseudo', {
type: 'submit'
}, [
m('i.fa.fa-check.fa-fw'),
m('span', {
style: 'font-size:smaller;'
}, 'Masuk')
]))
])),
m('.fourth-600.none'),
m('.fourth-600.none'),
_.isNil(window.message) == false ? [
m('.half-600.full.label.error', {
style: 'margin: 0; font-size: smaller;',
onclick: function() {
window.message = null
}
}, window.message),
m('.fourth-600.none'),
m('.fourth-600.none')
]
: null
])
]))
}

View File

@ -18,7 +18,8 @@ var registerUser = {
autocomplete: 'off',
oninput: m.withAttr('value', function(value) {
user.current.full_name = value
})
}),
required: 'required'
})),
m('.fourth-600.full', m('input', {
type: 'text',
@ -28,7 +29,8 @@ var registerUser = {
autocomplete: 'off',
oninput: m.withAttr('value', function(value) {
user.current.username = value
})
}),
required: 'required'
})),
m('.fourth-600.full', m('input', {
type: 'password',
@ -36,7 +38,8 @@ var registerUser = {
placeholder: 'Password',
oninput: m.withAttr('value', function(value) {
user.current.password = value
})
}),
required: 'required'
})),
m('.fourth-600.none'),
m('div', m('button.pseudo.three-fourth-600.full', {

View File

@ -10,6 +10,7 @@ let createPost = require('./components/createPost')
let editPost = require('./components/editPost')
let cookie = require('./others/cookie')
let idleTimeout = require('./others/idleTimeout')
let label = require('./components/label')
require('../css/index.css')
@ -24,13 +25,19 @@ if (page == '') {
})
} else {
m.route(root, '', {
'': { view: function() { return m('span', [
'': { view: function() { return m('span',
window.message || window.message != null ?
m(label) : null,
[
m(nav),
m(showPost, { 'status': 3 })
]) } },
'/kategori': {
view: function() {
return m('span', [
return m('span',
window.message || window.message != null ?
m(label) : null,
[
m(nav),
m(createCategory, { 'id': 0 })
])
@ -38,44 +45,86 @@ if (page == '') {
},
'/kategori/:id': {
view: function(vnode) {
return m('span', [
return m('span',
window.message || window.message != null ?
m(label) : null,
[
m(nav),
m(editCategory, { 'id': vnode.attrs.id })
])
}
},
'/register': { view: function() { return m('span'), [
m(nav),
cookie.get('signal') == 1 ? m(registerUser) : null
] }},
'/posts': { view: function() { return m('span', [
m(nav),
m(showPost, { 'status': 3 })
]) } },
'/register': { view: function() {
return m('span',
window.message || window.message != null ?
m(label) : null,
[
m(nav),
cookie.get('signal') == 1 ? m(registerUser) : null
])
}
},
'/posts': { view: function() {
return m('span',
window.message || window.message != null ?
m(label) : null,
[
m(nav),
m(showPost, { 'status': 3 })
])
}
},
'/posts/edit/:id': {
view: function(vnode) {
return m('span', [
return m('span',
window.message || window.message != null ?
m(label) : null,
[
m(nav),
m(editPost, { 'id': vnode.attrs.id })
])
}
},
'/posts/active': { view: function() { return m('span', [
m(nav),
m(showPost, { 'status': 1 })
]) } },
'/posts/soon': { view: function() { return m('span', [
m(nav),
m(showPost, { 'status': 2 })
]) } },
'/posts/inactive': { view: function() { return m('span', [
m(nav),
m(showPost, { 'status': 0 })
]) } },
'/posts/entry': { view: function() { return m('span', [
m(nav),
m(createPost)
])} }
'/posts/active': { view: function() {
return m('span',
window.message || window.message != null ?
m(label) : null,
[
m(nav),
m(showPost, { 'status': 1 })
])
}
},
'/posts/soon': { view: function() {
return m('span',
window.message || window.message != null ?
m(label) : null,
[
m(nav),
m(showPost, { 'status': 2 })
])
}
},
'/posts/inactive': { view: function() {
return m('span',
window.message || window.message != null ?
m(label) : null,
[
m(nav),
m(showPost, { 'status': 0 })
])
}
},
'/posts/entry': { view: function() {
return m('span',
window.message || window.message != null ?
m(label) : null,
[
m(nav),
m(createPost)
])
}
}
})
idleTimeout.setup();

View File

@ -41,13 +41,13 @@ var category = {
headers: {'x-query': window.location.search}
})
.then(function(result) {
console.log(result)
category.current = {}
if (result.status == true) {
m.route.set('/kategori')
} else if (result.status == 401) {
user.logout();
}
window.message = result.message
})
},
entry: function() {
@ -59,20 +59,24 @@ var category = {
headers: {'x-query': window.location.search}
})
.then(function(result) {
console.log(result);
if (result.status == true) {
category.loadList()
} else if (result.status == 401) {
user.logout()
}
window.message = result.message
})
},
toggleStatus: function(id){
category.current = _.find(category.list, function(o) { return o.id == id })
if (category.current.posts == 0) {
category.current.status == 1 ? category.current.status = 0 : category.current.status = 1
category.save()
} else {
category.current = {}
m.redraw()
window.message = 'Kategori memiliki pengumuman aktif'
}
category.save()
}
}

View File

@ -47,11 +47,10 @@ var post = {
.then(function(response) {
if (response.status) {
m.route.set(response.route_to)
} else {
console.log(response);
}
post.current = {}
post.loading = false
window.message = response.message
})
},
save: function() {
@ -61,16 +60,15 @@ var post = {
url: '/posts/put/' + window.location.search,
data: post.current,
withCredentials: true,
headers: {client: 'api'}
headers: {client: 'api', 'x-query': window.location.search}
})
.then(function(response) {
post.current = {}
if (response.status) {
m.route.set(response.route_to)
} else {
console.log(response);
}
post.loading = false;
window.message = response.message
})
},
toggleStatus: function(id) {
@ -88,21 +86,23 @@ var post = {
post.current = _.find(post.list, function(o) { return o.id == id })
// console.log(new Date(post.current.valid_at) > new Date());
if (new Date(post.current.valid_at) > new Date()) {
status = 2
// console.log(post.current.id, 'soon');
} else if (new Date(post.current.valid_at) <= new Date()) {
if (new Date(post.current.expired_at) < new Date()) {
status = 0
// console.log(post.current.id, 'expired');
} else {
status = 1
// console.log(post.current.id, 'active');
if (post.current.status != 0) {
if (new Date(post.current.valid_at) > new Date()) {
status = 2
// console.log(post.current.id, 'soon');
} else if (new Date(post.current.valid_at) <= new Date()) {
if (new Date(post.current.expired_at) < new Date()) {
status = 0
// console.log(post.current.id, 'expired');
} else {
status = 1
// console.log(post.current.id, 'active');
}
}
if (post.current.status != status) {
post.current.status = status
post.save()
}
}
if (post.current.status != status) {
post.current.status = status
post.save()
}
// console.log(post.current);
}

View File

@ -13,9 +13,8 @@ var user = {
.then(function(response) {
if (response.status == true) {
window.location = response.redirect_to
} else {
console.log(response.status);
}
window.message = response.message
})
},
logout: function() {
@ -26,26 +25,26 @@ var user = {
headers: {client: 'api', 'x-query': window.location.search}
})
.then(function(response) {
console.log(response);
if (response.status) {
window.location = response.redirect_to
}
window.message = response.message
})
},
register: function() {
return m.request({
method: 'POST',
url: '/post',
url: '/post/' + window.location.search,
data: user.current,
withCredentials: true,
headers: {client: 'api', 'x-query': window.location.search}
})
.then(function(response) {
console.log(response);
if (response.status == true) {
m.route.set(response.route_to)
} else {
console.log(response);
}
window.message = response.message
})
}
}

View File

@ -0,0 +1,18 @@
module.exports = {
fade: function(target) {
// var fadeTarget = document.getElementById(target);
var fadeTarget = target
var fadeEffect = setInterval(function () {
if (!fadeTarget.style.opacity) {
fadeTarget.style.opacity = 1;
}
if (fadeTarget.style.opacity < 0.1) {
clearInterval(fadeEffect);
fadeTarget.remove();
window.message = null;
} else {
fadeTarget.style.opacity -= 0.1;
}
}, 50);
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long