Mithril as main method

This commit is contained in:
2017-10-25 12:08:41 +07:00
parent 6040809710
commit d1d5ee1b0c
157 changed files with 19593 additions and 716 deletions

View File

@@ -0,0 +1,14 @@
let m = require('mithril')
var Loading = {
view: function() {
return m('.loading', [
m('.loading-bar'),
m('.loading-bar'),
m('.loading-bar'),
m('.loading-bar')
])
}
}
module.exports = Loading

View File

@@ -0,0 +1,107 @@
let m = require('mithril')
let _ = require('lodash')
let category = require('../models/category')
let nav = require('./nav')
let Loading = require('./Loading')
var createCategory = {
oninit: function() {
category.loadList()
},
current: [],
view: function() {
return m('main.documentation', m('section', [
m('h1', 'Kategori'),
category.loading ? m(Loading) :
m('.flex.two-600.full.grow', [
m('div', m('form', {
onsubmit: function(e) {
e.preventDefault()
category.entry()
}
}, [
m('h2', 'Tambah Kategori'),
m('.flex.three-600.two.grow', [
m('.third-600.full', m('label', {for: 'category'}, 'Nama')),
m('.two-third-600.full', m('input', {
type: 'text',
name: 'category',
autocomplete: 'off',
oninput: m.withAttr('value', function(value) {
category.current.category = value
}),
value: _.isString(category.current.category) ? category.current.category : ''
})),
m('.third-600.full', m('label', {for: 'background'}, 'Background')),
m('.two-third-600.full', m('input', {
type: 'color',
name: 'background',
oninput: m.withAttr('value', function(value) {
category.current.background = value
}),
value: _.isString(category.current.background) ? category.current.background : ''
})),
m('.third-600.full', m('label', {for: 'foreground'}, 'Teks')),
m('.two-third-600.full', m('input', {
type: 'color',
name: 'foreground',
oninput: m.withAttr('value', function(value) {
category.current.foreground = value
}),
value: _.isString(category.current.foreground) ? category.current.foreground : ''
})),
m('button.pseudo.full', {
type: 'submit'
}, [
m('i.fa.fa-plus.fa-fw', {
'aria-hidden': 'true'
}),
m('span', 'Tambah')
])
])
])),
m('div', [
m('h2', 'List'),
m('ul', {
style: 'margin-top:0;'
}, category.list.map(function(cat) {
return m('li', [
m('div', {
style: 'height: initial; text-align: center; border-radius: 5px; background-color: ' + cat.background + '; color: ' + cat.foreground + ';'
}, m('span', cat.category)),
m('.flex.two-600.full.grow', {
style: 'margin: 0;'
}, [
m('div', m('a.pseudo.button.full', {
href: '/kategori/' + cat.id,
oncreate: m.route.link
}, [
m('i.fa.fa-edit.fa-fw'),
m('span', {
style: 'font-size: smaller'
}, 'Ubah')
])),
m('div', m('button.pseudo.full', {
style: 'height: inherit',
onclick: function() {
category.toggleStatus(cat.id)
}
}, [
m('i.fa.fa-fw', {
class: (cat.status == 1) ? 'fa-times-circle-o' : 'fa-check'
}),
m('span', {
style: 'font-size: smaller;'
}, (cat.status == 1) ? 'Matikan' : 'Aktifkan')
]))
]),
m('.fourth-600.none')
])
}))
])
])
]))
}
}
module.exports = createCategory

View File

@@ -0,0 +1,86 @@
let m = require('mithril')
let fecha = require('fecha')
let category = require('../models/category')
let rome = require('../vendor/rome')
let SimpleMDE = require('../vendor/simplemde.min')
let post = require('../models/post')
var createPost = {
oninit: function() {
category.loadList()
},
oncreate: function() {
var valid_at = rome(left, {
dateValidator: rome.val.beforeEq(right),
time: false,
inputFormat: 'YYYY/MM/DD',
required: true
})
var expired_at = rome(right, {
dateValidator: rome.val.afterEq(left),
time: false,
inputFormat: 'YYYY/MM/DD',
required: true
})
var simplemde = new SimpleMDE({ element: document.getElementById("smde") });
simplemde.codemirror.on('change', function() {
post.current.content = simplemde.value();
});
},
view: function() {
return m('main.documentation', m('section', [
m('h2', 'Tambah Pengumuman'),
m('form', {
onsubmit: function(e) {
e.preventDefault()
// do things
// console.log(post.current);
post.upload()
}
}, m('.flex.three.grow', [
m('.full.third-600', [
m('label', {for: 'category'}, 'Kategori:'),
m('select', {
name: 'category',
oninput: m.withAttr('value', function(value) {
post.current.category = value
})
}, [
m('option'),
category.list.map(function(cat) {
return m('option', {value: cat.id}, cat.category)
})
]),
m('br'),
m('label', {for: 'valid_at'}, 'Berlaku dari: '),
m('input#left', {
name: 'valid_at',
onfocusout: m.withAttr('value', function(value) {
post.current.valid_at = value
})
}),
m('br'),
m('label', {for: 'expired_at'}, 'Berlaku sampai: '),
m('input#right', {
name: 'expired_at',
onfocusout: m.withAttr('value', function(value) {
post.current.expired_at = value
})
})
]),
m('.full.two-third-600', [
m('label', {for: 'content'}, 'Konten: '),
m('textarea#smde', {name: 'content'})
]),
m('br'),
m('button.pseudo', {type: 'submit'}, [
m('i.fa.fa-check.fa-fw'),
m('span', {style: 'font-size: smaller'}, 'Unggah')
])
]))
]))
}
}
module.exports = createPost

View File

@@ -0,0 +1,67 @@
let m = require('mithril')
let category = require('../models/category')
let nav = require('./nav')
let _ = require('lodash')
let Loading = require('./Loading')
var editCategory = {
oninit: function(vnode) {
category.loadCurrent(vnode.attrs.id)
},
view: function() {
return m('main.documentation', m('section', [
m('h1', 'Kategori'),
category.loading ? m(Loading) :
m('.flex.two-600.full.grow', [
m('div', m('form', {
onsubmit: function(e) {
e.preventDefault()
category.save()
}
}, [
m('h2', 'Ubah Kategori'),
m('.flex.three-600.two.grow', [
m('.third-600.full', m('label', {for: 'category'}, 'Nama')),
m('.two-third-600.full', m('input', {
type: 'text',
name: 'category',
autocomplete: 'off',
oninput: m.withAttr('value', function(value) {
category.current.category = value
}),
value: category.current.category
})),
m('.third-600.full', m('label', {for: 'background'}, 'Background')),
m('.two-third-600.full', m('input', {
type: 'color',
name: 'background',
oninput: m.withAttr('value', function(value) {
category.current.background = value
}),
value: category.current.background
})),
m('.third-600.full', m('label', {for: 'foreground'}, 'Teks')),
m('.two-third-600.full', m('input', {
type: 'color',
name: 'foreground',
oninput: m.withAttr('value', function(value) {
category.current.foreground = value
}),
value: category.current.foreground
})),
m('button.pseudo.full', {
type: 'submit'
}, [
m('i.fa.fa-edit.fa-fw', {
'aria-hidden': 'true'
}),
m('span', 'Ubah')
])
])
]))
])
]))
}
}
module.exports = editCategory

View File

@@ -0,0 +1,102 @@
let m = require('mithril')
let fecha = require('fecha')
let category = require('../models/category')
let rome = require('../vendor/rome')
let SimpleMDE = require('../vendor/simplemde.min')
let post = require('../models/post')
var createPost = {
oninit: function(vnode) {
post.loadCurrent(vnode.attrs.id)
category.loadList(1)
},
oncreate: function() {
var valid_at = rome(left, {
dateValidator: rome.val.beforeEq(right),
time: false,
inputFormat: 'YYYY/MM/DD',
required: true
})
var expired_at = rome(right, {
dateValidator: rome.val.afterEq(left),
time: false,
inputFormat: 'YYYY/MM/DD',
required: true
})
var simplemde = new SimpleMDE({ element: document.getElementById("smde") });
setTimeout(function() {
simplemde.value(post.current.content)
simplemde.codemirror.on('change', function() {
post.current.content = simplemde.value();
});
}, 1000)
},
view: function() {
return m('main.documentation', m('section', [
m('h2', 'Tambah Pengumuman'),
m('form', {
onsubmit: function(e) {
e.preventDefault()
// do things
// console.log(post.current);
post.save()
}
}, m('.flex.three.grow', [
m('.full.third-600', [
m('label', {for: 'category'}, 'Kategori:'),
m('select', {
name: 'category',
oninput: m.withAttr('value', function(value) {
post.current.category = value
})
}, [
// m('option'),
category.list.map(function(cat) {
return cat.id == post.current.category ? [
m('option', {
value: cat.id,
selected: 'selected'
}, cat.category)
] : [
m('option', {
value: cat.id
}, cat.category)
]
})
]),
m('br'),
m('label', {for: 'valid_at'}, 'Berlaku dari: '),
m('input#left', {
name: 'valid_at',
onfocusout: m.withAttr('value', function(value) {
post.current.valid_at = value
}),
value: post.current.valid_at
}),
m('br'),
m('label', {for: 'expired_at'}, 'Berlaku sampai: '),
m('input#right', {
name: 'expired_at',
onfocusout: m.withAttr('value', function(value) {
post.current.expired_at = value
}),
value: post.current.expired_at
})
]),
m('.full.two-third-600', [
m('label', {for: 'content'}, 'Konten: '),
m('textarea#smde', {name: 'content'})
]),
m('br'),
m('button.pseudo', {type: 'submit'}, [
m('i.fa.fa-check.fa-fw'),
m('span', {style: 'font-size: smaller'}, 'Unggah')
])
]))
]))
}
}
module.exports = createPost

View File

@@ -0,0 +1,37 @@
let m = require('mithril')
let images = require('./images')
var header = {
oncreate: function() {
var rootSwiper = document.getElementById('nouser')
images.root = rootSwiper
m.mount(rootSwiper, images)
},
view: function() {
return m('span', [
m('nav', [
m('span.brand', m('a.title', {
href: '',
oncreate: m.route.link
}, 'Live Info')),
// m('input#bmenug.show', {type: 'checkbox'}),
// m('label.burger.pseudo.button', {for: 'bmenug'}, m('i.fa.fa-bars', {'aria-hidden': 'true'})),
m('.menu', m('a.navy.hidden-hover.button', {
href: '/login',
'data-tooltip': 'Masuk',
oncreate: m.route.link
}, [
m('i.fa.fa-sign-in', {
'aria-hidden': 'true'
}),
' Masuk'
]))
]),
m('main.documentation#doc-main', [
m('#nouser', {style: 'text-align:left;width:100%'})
])
])
}
}
module.exports = header

View File

@@ -0,0 +1,48 @@
let m = require('mithril')
let landingPost = require('../models/landingPost')
let swiper = require('swiper')
let marked = require('../vendor/marked')
let fitText = require('../others/fitText')
require('../../../node_modules/swiper/dist/css/swiper.css')
var images = {
root: null,
oncreate: function() {
setTimeout(function() {
landingPost(images.root)
var imgSwiper = new swiper('.swiper-container', {
speed: 500,
autoplay: 5000,
autoplayDisableOnInteraction: false,
loop: true,
onTransitionEnd: function(imgSwiper) {
landingPost(images.root)
}
})
fitText.fitAll('fitThis')
}, 500)
window.onresize = function() {
setTimeout(function() {
fitText.fitAll('fitThis')
}, 100)
}
},
list: [],
view: function() {
return m('.swiper-container', [
m('.swiper-wrapper', images.list != [] ? [
images.list.map(function(item) {
return m('.swiper-slide.fitThis', {
"data-swiper-autoplay": item.delay,
style: "text-align: center; word-wrap: break-word;background-color:" + item.background + "; color:" + item.foreground + ";"
}, m.trust(marked(item.content)))
})
] : m('.swiper-slide.fitty', {
style: "background-color: #F0F0F0;color: #FFF;padding: 15vh 0;"
}, m.trust(marked("*Tidak ada pengumuman*"))))
])
}
}
module.exports = images

View File

@@ -1,40 +1,47 @@
let m = require('mithril')
let post = require('../models/post')
let marked = require('../vendor/marked')
let fecha = require('fecha')
let Loading = require('./Loading')
var listAdmin = {
view: function() {
return m('.flex.four-900.full.card-wrapper', [
m('a.fourth-900.half-600.card.box.new', {href:'/posts/entry'}, m('i.fa.fa-plus.fa-3x', '')),
post.list.map(function(post) {
return m('.fourth-900.half-600.card.box', {style:'background-color:' + post.background}, [
m('span.stack', {style:'font-size:smaller;color:rgba(17,17,17,.4);margin-bottom:.6em;'}, post.valid_at + ' - ' + post.expired_at),
m('span.stack', {style:'color:' + post.foreground}, m.trust(marked(post.content))),
m('form', {method:'post',action:'/'}, m('footer.flex.full.grow', (post.status != 0) ? [
m('.half-900', m('a.button.full', {href: '/posts/edit/' + post.id}, [
post.loading ? m(Loading) :
m('a.fourth-900.half-600.card.box.new', {href:'/posts/entry', oncreate: m.route.link}, m('i.fa.fa-plus.fa-3x', '')),
post.list.map(function(pengumuman) {
return m('.fourth-900.half-600.card.box', {style:'background-color:' + pengumuman.background}, [
m('span.stack', {
style:'font-size: smaller; color:rgba(17,17,17,.4);',
'data-tooltip': 'Active: '
+ fecha.format(new Date(pengumuman.valid_at), 'DD/MM/YYYY')
+ ' - '
+ fecha.format(new Date(pengumuman.expired_at), 'DD/MM/YYYY')
+ "\n"
+ 'Edited: '
+ fecha.format(fecha.parse(pengumuman.edited_at, 'YYYY-MM-DD H:i:s'), 'DD/MM/YYYY')
}, [
m('em', [
pengumuman.creatorName,
' - ',
fecha.format(fecha.parse(pengumuman.valid_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))),
m('span', m('footer.flex.full.grow', (pengumuman.status != 0 && pengumuman.creator == window.location.search.split('&')[1].slice('2')) ? [
m('.half-900', m('a.button.full', {href: '/posts/edit/' + pengumuman.id, oncreate: m.route.link}, [
m('i.fa.fa-edit.fa-fw', ''),
m('span', {style: 'font-size:smaller'}, 'Ubah')
])),
m('.half-900', (post.status == 1) ? [
m('input', {type: 'hidden', name: 'id'}, post.id),
m('input', {type: 'hidden', name: 'status'}, '0'),
m('input', {type: 'hidden', name: '_method'}, 'delete'),
m('input', {type: 'hidden', name: '_token'}, 'abc123'),
m('button.error.full', {type: 'submit'}, [
m('i.fa.fa-times-circle-o.fa-fw', ''),
m('span', {style: 'font-size:smaller'}, 'Matikan')
])
] : [
m('input', {type: 'hidden', name: 'id'}, post.id),
m('input', {type: 'hidden', name: 'valid_at'}, '##date##'),
m('input', {type: 'hidden', name: 'status'}, '1'),
m('input', {type: 'hidden', name: '_method'}, 'put'),
m('input', {type: 'hidden', name: '_token'}, 'abc123'),
m('button.success.full', {type: 'submit'}, [
m('i.fa.fa-check.fa-fw', ''),
m('span', {style: 'font-size:smaller;'}, 'Aktifkan')
])
])
m('.half-900', m('button.full', {
class: pengumuman.status == 1 ? 'error' : 'success',
onclick: function() { post.toggleStatus(pengumuman.id) }
}, [
m('i.fa.fa-fw', {
class: pengumuman.status == 1 ? 'fa-times-circle-o' : 'fa-check'
}),
m('span', {style: 'font-size:smaller'}, pengumuman.status == 1 ? 'Matikan' : 'Aktifkan')
]))
] : m('.half-900', m('span.button.pseudo.full', {style: 'color:rgba(17,17,17,.3);'}, 'Nonaktif'))))
])
})

View File

@@ -0,0 +1,47 @@
let m = require('mithril')
let user = require('../models/user')
var login = {
view: function() {
return m('section', m('form', {
onsubmit: function(e) {
e.preventDefault()
user.login()
}
}, [
m('h1', 'Masuk'),
m('.flex.four.grow', [
m('.fourth-600.full', m('input', {
type: 'text',
name: 'username',
placeholder: 'Username',
maxlength: '25',
autocomplete: 'off',
oninput: m.withAttr('value', function(value) {user.current.username = value}),
value: user.current.username
})),
m('.fourth-600.full', m('input', {
type: 'password',
name: 'password',
placeholder: 'Password',
oninput: m.withAttr('value', function(value) {
user.current.password = value
}),
value: user.current.password
})),
m('.fourth-600.none'),
m('.fourth-600.none'),
m('div', m('button.half-600.full.pseudo', {
type: 'submit'
}, [
m('i.fa.fa-check.fa-fw'),
m('span', {
style: 'font-size:smaller;'
}, 'Masuk')
]))
])
]))
}
}
module.exports = login

View File

@@ -0,0 +1,53 @@
let m = require('mithril')
let user = require('../models/user')
var nav = {
view: function() {
return m('nav', [
m('span.brand', m('a.title', {href: '', oncreate: m.route.link}, 'Live Info')),
m('input#bmenug.show', {type: 'checkbox'}),
m('label.burger.pseudo.button', {for: 'bmenug'}, m('i.fa.fa-bars', {'aria-hidden': 'true'})),
m('.menu#menu', [
m('a.navy.button', {
href: 'https://backup.lepisi.ac.id/gregorio/lepisi-pengumuman/blob/master/README.md#dokumentasi',
target: '_blank',
'data-tooltip': 'Dokumentasi'
}, m('i.fa.fa-dot-circle-o', {
'aria-hidden': 'true'
})
),
m('a.navy.button', {
href: '/kategori',
'data-tooltip': 'Kategori',
oncreate: m.route.link
}, [
m('i.fa.fa-list-ul', {
'aria-hidden': 'true'
}),
' Kategori'
]),
m('a.navy.button', {
href: '/register',
'data-tooltip': 'User Baru',
oncreate: m.route.link
}, [
m('i.fa.fa-user-plus', {
'aria-hidden': 'true'
}),
' User'
]),
m('a.navy.button', {
'data-tooltip': 'Keluar',
onclick: function() {user.logout()}
}, [
m('i.fa.fa-sign-out', {
'aria-hidden': 'true'
}),
' Keluar'
])
])
])
}
}
module.exports = nav

View File

@@ -0,0 +1,57 @@
let m = require('mithril')
let user = require('../models/user')
var registerUser = {
view: function() {
return m('main.documentation', m('section', [
m('h1', 'Registrasi'),
m('form', {
onsubmit: function(e) {
e.preventDefault()
user.register()
}
}, m('.flex.four.grow', [
m('.fourth-600.full', m('input', {
type: 'text',
name: 'full_name',
placeholder: 'Nama Lengkap',
autocomplete: 'off',
oninput: m.withAttr('value', function(value) {
user.current.full_name = value
})
})),
m('.fourth-600.full', m('input', {
type: 'text',
name: 'username',
placeholder: 'Username',
maxlength: '25',
autocomplete: 'off',
oninput: m.withAttr('value', function(value) {
user.current.username = value
})
})),
m('.fourth-600.full', m('input', {
type: 'password',
name: 'password',
placeholder: 'Password',
oninput: m.withAttr('value', function(value) {
user.current.password = value
})
})),
m('.fourth-600.none'),
m('div', m('button.pseudo.three-fourth-600.full', {
type: 'submit'
}, [
m('i.fa.fa-plus-circle.fa-fw', {
'aria-hidden': 'true'
}),
m('span', {
style: 'font-size: smaller;'
}, 'Register')
]))
]))
]))
}
}
module.exports = registerUser

View File

@@ -4,19 +4,19 @@ var secondaryNav = {
view: function() {
return m('.filter.flex.six-600.four.grow', [
m('.sixth-600.none', ''),
m('div', m('a[href=/].navy', {
m('div', m('a[href=/posts].navy', {
oncreate: m.route.link,
style: 'font-size:smaller;'
}, 'Semua')),
m('div', m('a[href=/active].navy', {
m('div', m('a[href=/posts/active].navy', {
oncreate: m.route.link,
style: 'font-size:smaller;'
}, 'Aktif')),
m('div', m('a[href=/soon].navy', {
m('div', m('a[href=/posts/soon].navy', {
oncreate: m.route.link,
style: 'font-size:smaller;'
}, 'Belum Aktif')),
m('div', m('a[href=/inactive].navy', {
m('div', m('a[href=/posts/inactive].navy', {
oncreate: m.route.link,
style: 'font-size:smaller;'
}, 'Nonaktif')),

View File

@@ -1,17 +1,26 @@
let m = require('mithril')
let post = require('../models/post')
let listAdmin = require('./listAdmin')
let secondaryNav = require('./secondaryNav')
var showPost = {
interval: 10000,
oninit: function(vnode) {
post.curStatus = vnode.attrs.status
post.loadList()
setInterval(function() {
post.loadList()
}, post.interval)
}, showPost.interval)
},
view: function() {
return m(listAdmin)
return m('main.documentation', m('#nouser', {
style: 'text-align:left;width:100%'
}, m('div', {
style: 'background:#FFF;text-align:left;width:100%;padding:10vh 0 0;'
}, [
m('#secondaryNav', m(secondaryNav)),
m('#mit', m(listAdmin))
])))
}
}

View File

@@ -0,0 +1,22 @@
let m = require('mithril')
let doc = require('./doc')
let user = require('../models/user')
let editCategory = require('../components/editCategory')
var title = {
view: function() {
return m('span', [
m('span#doc')
])
},
oncreate: function() {
var rootDoc = document.getElementById('doc')
// m.route(document.getElementById('menu'), '/kategori', {
// // '': doc,
// '/kategori': editCategory
// })
// m.mount(rootDoc, doc)
}
}
module.exports = title

View File

@@ -1,56 +1,82 @@
let m = require('mithril')
let swiper = require('swiper')
let _ = require('lodash')
require('../../node_modules/swiper/dist/css/swiper.css')
let header = require('./components/header')
let login = require('./components/login')
let nav = require('./components/nav')
let showPost = require('./components/showPost')
let createCategory = require('./components/createCategory')
let editCategory = require('./components/editCategory')
let registerUser = require('./components/registerUser')
let createPost = require('./components/createPost')
let editPost = require('./components/editPost')
let cookie = require('./others/cookie')
let idleTimeout = require('./others/idleTimeout')
let marked = require('./vendor/marked')
require('../css/index.css')
var root = document.getElementById('nouser')
var root = document.body
var page = cookie.get('signal')
const getPageData = function() {
m.request({
method: 'GET',
url: '/api/posts',
background: false
if (page == '') {
m.mount(root, header)
m.route(document.getElementById('doc-main'), '', {
'': header,
'/login': login
})
.then(function(res) {
if (!_.isEqual(res['data'], images.list)) {
images.list = res['data']
m.mount(root, null)
m.mount(root, images)
}
} else {
m.route(root, '', {
'': { view: function() { return m('span', [
m(nav),
m(showPost, { 'status': 3 })
]) } },
'/kategori': {
view: function() {
return m('span', [
m(nav),
m(createCategory, { 'id': 0 })
])
}
},
'/kategori/:id': {
view: function(vnode) {
return m('span', [
m(nav),
m(editCategory, { 'id': vnode.attrs.id })
])
}
},
'/register': { view: function() { return m('span'), [
m(nav),
m(registerUser)
] }},
'/posts': { view: function() { return m('span', [
m(nav),
m(showPost, { 'status': 3 })
]) } },
'/posts/edit/:id': {
view: function(vnode) {
return m('span', [
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)
])} }
})
}
var images = {
oninit: getPageData,
oncreate: function() {
setTimeout(function() {
var imgSwiper = new swiper('.swiper-container', {
speed: 500,
autoplay: 5000,
autoplayDisableOnInteraction: false,
loop: true,
onTransitionEnd: function(imgSwiper) {
getPageData()
}
})
}, 500)
},
list: [],
view: function() {
return m('.swiper-container', {
}, [
m('.swiper-wrapper', [
images.list.map(function(item) {
return m('.swiper-slide.fitty', {
"data-swiper-autoplay": item.delay,
style: "background-color:" + item.background + "; color:" + item.foreground + "; padding: 15vh 0;"
}, m.trust(marked(item.content)))
})
])
])
}
idleTimeout.setup();
}
m.mount(root, images)

View File

@@ -0,0 +1,74 @@
let m = require('mithril')
let _ = require('lodash')
let post = require('./post')
var category = {
loading: false,
list: [],
current: {},
loadList: function() {
category.loading = true
category.current = {}
return m.request({
method: 'GET',
url: '/api/kategori',
withCredentials: true
})
.then(function(results) {
category.list = results.data
category.loading = false
})
},
loadCurrent: function(id) {
category.loading = true
return m.request({
method: 'GET',
url: '/api/kategori/' + id,
withCredentials: true
})
.then(function(result) {
category.current = result.data
category.loading = false
})
},
save: function() {
return m.request({
method: 'PUT',
url: '/api/kategori',
data: category.current,
withCredentials: true
})
.then(function(result) {
category.current = {}
if (result.status) {
m.route.set('/kategori')
} else {
console.log(result)
}
})
},
entry: function() {
return m.request({
method: 'POST',
url: '/api/kategori',
data: category.current,
withCredentials: true
})
.then(function(result) {
if (result.status) {
category.loadList()
} else {
console.log(result.status)
}
})
},
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()
}
}
module.exports = category

View File

@@ -0,0 +1,20 @@
let m = require('mithril')
let _ = require('lodash')
const landingPost = function(root) {
m.request({
method: 'GET',
url: '/api/pengumuman/?status=1',
background: false
})
.then(function(res) {
let images = require('../components/images')
if (!_.isEqual(res['data'], images.list)) {
images.list = res['data']
m.mount(root, null)
m.mount(root, images)
}
})
}
module.exports = landingPost

View File

@@ -1,18 +1,110 @@
let m = require('mithril')
let fecha = require('fecha')
let user = require('./user')
let cookie = require('../others/cookie')
var post = {
loading: false,
list: [],
current: {},
curStatus: 3,
interval: 10000,
loadList: function() {
post.loading = true
return m.request({
method: 'GET',
url: '/api/posts/' + post.curStatus,
url: '/api/pengumuman/?status=' + post.curStatus,
withCredentials: true
})
.then(function(result) {
post.list = result.data
post.list.map(function(p) {
post.validateStatus(p.id)
})
post.loading = false
})
},
loadCurrent: function(id) {
post.loading = true
return m.request({
method: 'GET',
url: '/api/pengumuman/' + id,
withCredentials: true
})
.then(function(result) {
post.current = result.data
post.loading = false
})
},
upload: function() {
post.loading = true
return m.request({
method: 'POST',
url: '/posts/post/' + window.location.search,
data: post.current,
withCredentials: true,
headers: {client: 'api', 'x-query': window.location.search}
})
.then(function(response) {
if (response.status) {
m.route.set(response.route_to)
} else {
console.log(response);
}
post.current = {}
post.loading = false
})
},
save: function() {
post.loading = true
return m.request({
method: 'POST',
url: '/posts/put/' + window.location.search,
data: post.current,
withCredentials: true,
headers: {client: 'api'}
})
.then(function(response) {
post.current = {}
if (response.status) {
m.route.set(response.route_to)
} else {
console.log(response);
}
post.loading = false;
})
},
toggleStatus: function(id) {
post.current = _.find(post.list, function(o) { return o.id == id })
if (post.current.status == 2) {
post.current.status = 1
post.current.valid_at = fecha.format(new Date(), 'YYYY/MM/DD')
} else if (post.current.status == 1) {
post.current.status = 0
}
post.save()
// console.log(post.current);
},
validateStatus: function(id) {
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 != status) {
post.current.status = status
post.save()
}
// console.log(post.current);
}
}

53
assets/js/models/user.js Normal file
View File

@@ -0,0 +1,53 @@
let m = require('mithril')
var user = {
current: {},
login: function() {
return m.request({
method: 'POST',
url: '/login',
data: user.current,
withCredentials: true,
headers: {client: 'api'}
})
.then(function(response) {
if (response.status == true) {
window.location = response.redirect_to
} else {
console.log(response.status);
}
})
},
logout: function() {
return m.request({
method: 'GET',
url: '/logout',
withCredentials: true,
headers: {client: 'api', 'x-query': window.location.search}
})
.then(function(response) {
console.log(response);
if (response.status) {
window.location = response.redirect_to
}
})
},
register: function() {
return m.request({
method: 'POST',
url: '/post',
data: user.current,
withCredentials: true,
headers: {client: 'api'}
})
.then(function(response) {
if (response.status == true) {
m.route.set(response.route_to)
} else {
console.log(response);
}
})
}
}
module.exports = user

View File

@@ -0,0 +1,17 @@
module.exports = {
get: function(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
}

View File

@@ -0,0 +1,32 @@
var fitText = {
fitAll: function(cl) {
var elFS, elH
cl = document.getElementsByClassName(cl)
var h = window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight
// console.log(h, window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight);
for (var i = 0; i < cl.length; i++) {
elFS = parseInt(window.getComputedStyle(cl[i].children[0]).fontSize)
cl[i].children[0].style.fontSize = elFS + 'px'
elH = parseInt(window.getComputedStyle(cl[i].children[0]).height)
while (elH < h - (h*.15)) {
elFS++
cl[i].children[0].style.fontSize = elFS + 'px'
elH = parseInt(window.getComputedStyle(cl[i].children[0]).height)
}
while (elH > h - (h*.15)) {
elFS--
cl[i].children[0].style.fontSize = elFS + 'px'
elH = parseInt(window.getComputedStyle(cl[i].children[0]).height)
}
}
return true
}
}
module.exports = fitText

View File

@@ -0,0 +1,25 @@
let user = require('../models/user')
var idleTimeout = {
timeoutId: 0,
setup: function() {
window.addEventListener("mousemove", idleTimeout.resetTimer, false);
window.addEventListener("mousedown", idleTimeout.resetTimer, false);
window.addEventListener("keypress", idleTimeout.resetTimer, false);
window.addEventListener("DOMMouseScroll", idleTimeout.resetTimer, false);
window.addEventListener("mousewheel", idleTimeout.resetTimer, false);
window.addEventListener("touchmove", idleTimeout.resetTimer, false);
window.addEventListener("MSPointerMove", idleTimeout.resetTimer, false);
idleTimeout.startTimer();
},
startTimer: function() {
idleTimeout.timeoutId = window.setTimeout(user.logout, 60000*5);
},
resetTimer: function() {
window.clearTimeout(idleTimeout.timeoutId);
idleTimeout.startTimer();
}
}
module.exports = idleTimeout