Fix a bunch of IE errors

This commit is contained in:
Jonatan Nilsson 2019-10-01 11:35:00 +00:00
parent 298910198e
commit bc3aecb5d4
22 changed files with 3327 additions and 135 deletions

View file

@ -1,5 +1,5 @@
const { getAllArticlesPagination, removeArticle } = require('../api/article')
const { fetchPage } = require('../api/pagination')
const Article = require('../api/article')
const pagination = require('../api/pagination')
const Dialogue = require('../widgets/dialogue')
const Pages = require('../widgets/pages')
@ -24,7 +24,7 @@ const AdminArticles = {
this.links = null
this.lastpage = m.route.param('page') || '1'
return fetchPage(getAllArticlesPagination({
return pagination.fetchPage(Article.getAllArticlesPagination({
per_page: 10,
page: this.lastpage,
includes: ['parent'],
@ -46,7 +46,7 @@ const AdminArticles = {
let removingArticle = this.removeArticle
this.removeArticle = null
this.loading = true
removeArticle(removingArticle, removingArticle.id)
Article.removeArticle(removingArticle, removingArticle.id)
.then(this.oninit.bind(this, vnode))
.catch(function(err) {
vnode.state.error = err.message

View file

@ -1,10 +1,10 @@
const Authentication = require('../authentication')
const FileUpload = require('../widgets/fileupload')
const Froala = require('./froala')
const { Tree } = require('../api/page')
const { uploadFile } = require('../api/file')
const Page = require('../api/page')
const File = require('../api/file')
const Fileinfo = require('../widgets/fileinfo')
const { createArticle, updateArticle, getArticle } = require('../api/article')
const Article = require('../api/article')
const EditArticle = {
getFroalaOptions: function() {
@ -67,7 +67,7 @@ const EditArticle = {
this.loadedFroala = Froala.loadedFroala
if (this.lastid !== 'add') {
getArticle(this.lastid)
Article.getArticle(this.lastid)
.then(function(result) {
vnode.state.editedPath = true
vnode.state.article = result
@ -127,7 +127,7 @@ const EditArticle = {
let promise
if (this.article.id) {
promise = updateArticle(this.article.id, {
promise = Article.updateArticle(this.article.id, {
name: this.article.name,
path: this.article.path,
parent_id: this.article.parent_id,
@ -136,7 +136,7 @@ const EditArticle = {
media_id: this.article.media && this.article.media.id,
})
} else {
promise = createArticle({
promise = Article.createArticle({
name: this.article.name,
path: this.article.path,
parent_id: this.article.parent_id,
@ -165,12 +165,12 @@ const EditArticle = {
})
},
uploadFile(vnode, event) {
uploadFile: function(vnode, event) {
if (!event.target.files[0]) return
vnode.state.error = ''
vnode.state.loadingFile = true
uploadFile(this.article.id, event.target.files[0])
File.uploadFile(this.article.id, event.target.files[0])
.then(function(res) {
vnode.state.article.files.push(res)
})
@ -186,7 +186,7 @@ const EditArticle = {
getFlatTree: function() {
let out = [{id: null, name: '-- Frontpage --'}]
Tree.forEach(function(page) {
Page.Tree.forEach(function(page) {
out.push({ id: page.id, name: page.name })
if (page.children.length) {
page.children.forEach(function(sub) {

View file

@ -1,7 +1,7 @@
const Authentication = require('../authentication')
const FileUpload = require('../widgets/fileupload')
const Froala = require('./froala')
const { createPage, updatePage, getPage, Tree } = require('../api/page')
const Page = require('../api/page')
const EditPage = {
getFroalaOptions: function() {
@ -39,7 +39,7 @@ const EditPage = {
this.loadedFroala = Froala.loadedFroala
if (m.route.param('key') !== 'add') {
getPage(m.route.param('key'))
Page.getPage(m.route.param('key'))
.then(function(result) {
vnode.state.editedPath = true
vnode.state.page = result
@ -105,7 +105,7 @@ const EditPage = {
let promise
if (this.page.id) {
promise = updatePage(this.page.id, {
promise = Page.updatePage(this.page.id, {
name: this.page.name,
path: this.page.path,
parent_id: this.page.parent_id,
@ -114,7 +114,7 @@ const EditPage = {
media_id: this.page.media && this.page.media.id || null,
})
} else {
promise = createPage({
promise = Page.createPage({
name: this.page.name,
path: this.page.path,
parent_id: this.page.parent_id,
@ -145,7 +145,7 @@ const EditPage = {
},
view: function(vnode) {
const parents = [{id: null, name: '-- Frontpage --'}].concat(Tree).filter(function (page) { return !vnode.state.page || page.id !== vnode.state.page.id})
const parents = [{id: null, name: '-- Frontpage --'}].concat(Page.Tree).filter(function (page) { return !vnode.state.page || page.id !== vnode.state.page.id})
return (
this.loading ?
m('div.loading-spinner')

View file

@ -1,4 +1,4 @@
const { createStaff, updateStaff, getStaff } = require('../api/staff')
const Staff = require('../api/staff')
const EditStaff = {
oninit: function(vnode) {
@ -24,7 +24,7 @@ const EditStaff = {
}
if (this.lastid !== 'add') {
getStaff(this.lastid)
Staff.getStaff(this.lastid)
.then(function(result) {
vnode.state.editedPath = true
vnode.state.staff = result
@ -61,14 +61,14 @@ const EditStaff = {
let promise
if (this.staff.id) {
promise = updateStaff(this.staff.id, {
promise = Staff.updateStaff(this.staff.id, {
fullname: this.staff.fullname,
email: this.staff.email,
level: this.staff.level,
password: this.staff.password,
})
} else {
promise = createStaff({
promise = Staff.createStaff({
fullname: this.staff.fullname,
email: this.staff.email,
level: this.staff.level,

View file

@ -1,4 +1,4 @@
const { getAllPages, removePage } = require('../api/page')
const Page = require('../api/page')
const Dialogue = require('../widgets/dialogue')
const AdminPages = {
@ -24,7 +24,7 @@ const AdminPages = {
this.pages = []
this.removePage = null
getAllPages()
Page.getAllPages()
.then(function(result) {
vnode.state.pages = AdminPages.parseTree(result)
})
@ -41,7 +41,7 @@ const AdminPages = {
let removingPage = this.removePage
this.removePage = null
this.loading = true
removePage(removingPage, removingPage.id)
Page.removePage(removingPage, removingPage.id)
.then(this.oninit.bind(this, vnode))
.catch(function(err) {
vnode.state.error = err.message

View file

@ -1,4 +1,4 @@
const { getAllStaff, removeStaff } = require('../api/staff')
const Staff = require('../api/staff')
const Dialogue = require('../widgets/dialogue')
const Pages = require('../widgets/pages')
@ -15,7 +15,7 @@ const AdminStaffList = {
fetchStaffs: function(vnode) {
this.loading = true
return getAllStaff()
return Staff.getAllStaff()
.then(function(result) {
vnode.state.staff = result
})
@ -32,7 +32,7 @@ const AdminStaffList = {
let removingStaff = this.removeStaff
this.removeStaff = null
this.loading = true
removeStaff(removingStaff.id)
Staff.removeStaff(removingStaff.id)
.then(this.oninit.bind(this, vnode))
.catch(function(err) {
vnode.state.error = err.message

View file

@ -1,7 +1,7 @@
const { sendRequest } = require('./common')
const common = require('./common')
exports.createArticle = function(body) {
return sendRequest({
return common.sendRequest({
method: 'POST',
url: '/api/articles',
body: body,
@ -9,7 +9,7 @@ exports.createArticle = function(body) {
}
exports.updateArticle = function(id, body) {
return sendRequest({
return common.sendRequest({
method: 'PUT',
url: '/api/articles/' + id,
body: body,
@ -17,7 +17,7 @@ exports.updateArticle = function(id, body) {
}
exports.getAllArticles = function() {
return sendRequest({
return common.sendRequest({
method: 'GET',
url: '/api/articles?includes=parent',
})
@ -43,7 +43,7 @@ exports.getAllArticlesPagination = function(options) {
}
exports.getAllPageArticles = function(pageId, includes) {
return sendRequest({
return common.sendRequest({
method: 'GET',
url: '/api/pages/' + pageId + '/articles?includes=' + includes.join(','),
})
@ -69,14 +69,14 @@ exports.getAllPageArticlesPagination = function(pageId, options) {
}
exports.getArticle = function(id) {
return sendRequest({
return common.sendRequest({
method: 'GET',
url: '/api/articles/' + id + '?includes=media,parent,banner,files',
})
}
exports.removeArticle = function(article, id) {
return sendRequest({
return common.sendRequest({
method: 'DELETE',
url: '/api/articles/' + id,
})

View file

@ -1,10 +1,10 @@
const { sendRequest } = require('./common')
const common = require('./common')
exports.uploadFile = function(articleId, file) {
let formData = new FormData()
formData.append('file', file)
return sendRequest({
return common.sendRequest({
method: 'POST',
url: '/api/articles/' + articleId + '/file',
body: formData,

View file

@ -1,10 +1,10 @@
const { sendRequest } = require('./common')
const common = require('./common')
exports.uploadMedia = function(file) {
let formData = new FormData()
formData.append('file', file)
return sendRequest({
return common.sendRequest({
method: 'POST',
url: '/api/media',
body: formData,

View file

@ -1,11 +1,11 @@
const { sendRequest } = require('./common')
const common = require('./common')
const Tree = window.__nfptree || []
exports.Tree = Tree
exports.createPage = function(body) {
return sendRequest({
return common.sendRequest({
method: 'POST',
url: '/api/pages',
body: body,
@ -26,14 +26,14 @@ exports.createPage = function(body) {
}
exports.getTree = function() {
return sendRequest({
return common.sendRequest({
method: 'GET',
url: '/api/pages?tree=true&includes=children&fields=id,name,path,children(id,name,path)',
})
}
exports.updatePage = function(id, body) {
return sendRequest({
return common.sendRequest({
method: 'PUT',
url: '/api/pages/' + id,
body: body,
@ -62,21 +62,21 @@ exports.updatePage = function(id, body) {
}
exports.getAllPages = function() {
return sendRequest({
return common.sendRequest({
method: 'GET',
url: '/api/pages',
})
}
exports.getPage = function(id) {
return sendRequest({
return common.sendRequest({
method: 'GET',
url: '/api/pages/' + id + '?includes=media,banner,children,news,news.media',
})
}
exports.removePage = function(page, id) {
return sendRequest({
return common.sendRequest({
method: 'DELETE',
url: '/api/pages/' + id,
}).then(function() {

View file

@ -1,12 +1,12 @@
const parse = require('parse-link-header')
const { sendRequest } = require('./common')
const common = require('./common')
exports.fetchPage = function(url) {
return sendRequest({
return common.sendRequest({
method: 'GET',
url: url,
}, true)
.then(result => {
.then(function(result) {
return {
data: result.data,
links: parse(result.headers.link || ''),

View file

@ -1,7 +1,7 @@
const { sendRequest } = require('./common')
const common = require('./common')
exports.createStaff = function(body) {
return sendRequest({
return common.sendRequest({
method: 'POST',
url: '/api/staff',
body: body,
@ -9,7 +9,7 @@ exports.createStaff = function(body) {
}
exports.updateStaff = function(id, body) {
return sendRequest({
return common.sendRequest({
method: 'PUT',
url: '/api/staff/' + id,
body: body,
@ -17,21 +17,21 @@ exports.updateStaff = function(id, body) {
}
exports.getAllStaff = function() {
return sendRequest({
return common.sendRequest({
method: 'GET',
url: '/api/staff',
})
}
exports.getStaff = function(id) {
return sendRequest({
return common.sendRequest({
method: 'GET',
url: '/api/staff/' + id,
})
}
exports.removeStaff = function(id) {
return sendRequest({
return common.sendRequest({
method: 'DELETE',
url: '/api/staff/' + id,
})

View file

@ -1,5 +1,5 @@
const m = require('mithril')
const { getArticle } = require('../api/article')
const ApiArticle = require('../api/article')
const Authentication = require('../authentication')
const Fileinfo = require('../widgets/fileinfo')
@ -26,7 +26,7 @@ const Article = {
}
this.loading = true
getArticle(this.path)
ApiArticle.getArticle(this.path)
.then(function(result) {
vnode.state.article = result
})

View file

@ -1,5 +1,5 @@
const m = require('mithril')
const { Tree } = require('../api/page')
const Page = require('../api/page')
const Authentication = require('../authentication')
const Footer = {
@ -12,7 +12,7 @@ const Footer = {
m('div.sitemap', [
m('div', 'Sitemap'),
m(m.route.Link, { class: 'root', href: '/' }, 'Home'),
Tree.map(function(page) {
Page.Tree.map(function(page) {
return [
m(m.route.Link, { class: 'root', href: '/page/' + page.path }, page.name),
(page.children.length

View file

@ -1,8 +1,8 @@
const m = require('mithril')
const { Tree } = require('../api/page')
const { getAllArticlesPagination } = require('../api/article')
const { fetchPage } = require('../api/pagination')
const Page = require('../api/page')
const Article = require('../api/article')
const Pagination = require('../api/pagination')
const Pages = require('../widgets/pages')
const Newsitem = require('../widgets/newsitem')
@ -32,14 +32,14 @@ const Frontpage = {
}
},
fetchArticles(vnode) {
fetchArticles: function(vnode) {
this.error = ''
this.loading = true
this.links = null
this.articles = []
this.lastpage = m.route.param('page') || '1'
return fetchPage(getAllArticlesPagination({
return Pagination.fetchPage(Article.getAllArticlesPagination({
per_page: 10,
page: this.lastpage,
includes: ['parent', 'files', 'media', 'banner'],
@ -96,7 +96,7 @@ const Frontpage = {
m('aside.sidebar', [
m('div.categories', [
m('h4', 'Categories'),
Tree.map(function(page) {
Page.Tree.map(function(page) {
return [
m(m.route.Link, { class: 'root', href: '/page/' + page.path }, page.name),
(page.children.length

View file

@ -1,6 +1,6 @@
const m = require('mithril')
const Authentication = require('../authentication')
const { sendRequest } = require('../api/common')
const Api = require('../api/common')
const Login = {
loadedGoogle: false,
@ -81,7 +81,7 @@ const Login = {
Login.loading = true
sendRequest({
Api.sendRequest({
method: 'POST',
url: '/api/login/user',
body: {

View file

@ -1,7 +1,7 @@
const m = require('mithril')
const Authentication = require('../authentication')
const Darkmode = require('../darkmode')
const { Tree, getTree } = require('../api/page')
const Page = require('../api/page')
const Menu = {
currentActive: 'home',
@ -18,14 +18,14 @@ const Menu = {
oninit: function(vnode) {
Menu.onbeforeupdate()
if (Tree.length) return
if (Page.Tree.length) return
Menu.loading = true
getTree()
Page.getTree()
.then(function(results) {
Tree.splice(0, Tree.length)
Tree.push.apply(Tree, results)
Page.Tree.splice(0, Page.Tree.length)
Page.Tree.push.apply(Page.Tree, results)
})
.catch(function(err) {
Menu.error = err.message
@ -72,7 +72,7 @@ const Menu = {
href: '/',
class: Menu.currentActive === 'home' ? 'active' : '',
}, 'Home'),
Menu.loading ? m('div.loading-spinner') : Tree.map(function(page) {
Menu.loading ? m('div.loading-spinner') : Page.Tree.map(function(page) {
if (page.children.length) {
return m('div.hassubmenu', [
m(m.route.Link, {

View file

@ -1,7 +1,7 @@
const m = require('mithril')
const { getPage } = require('../api/page')
const { getAllPageArticlesPagination } = require('../api/article')
const { fetchPage } = require('../api/pagination')
const ApiPage = require('../api/page')
const Article = require('../api/article')
const pagination = require('../api/pagination')
const Authentication = require('../authentication')
const Newsentry = require('../widgets/newsentry')
const Pages = require('../widgets/pages')
@ -27,7 +27,7 @@ const Page = {
}
this.loading = true
getPage(this.path)
ApiPage.getPage(this.path)
.then(function(result) {
vnode.state.page = result
})
@ -52,7 +52,7 @@ const Page = {
this.newslinks = null
this.lastpage = m.route.param('page') || '1'
return fetchPage(getAllPageArticlesPagination(this.page.id, {
return pagination.fetchPage(Article.getAllPageArticlesPagination(this.page.id, {
per_page: 10,
page: this.lastpage,
includes: ['files', 'media'],

View file

@ -1,5 +1,5 @@
const Fileinfo = {
getPrefix(vnode) {
getPrefix: function(vnode) {
if (!vnode.attrs.file.filename.endsWith('.torrent')) {
return vnode.attrs.file.filename.split('.').slice(-1)
}
@ -15,21 +15,21 @@ const Fileinfo = {
return 'Other'
},
getTitle(vnode) {
getTitle: function(vnode) {
if (vnode.attrs.file.meta.torrent) {
return vnode.attrs.file.meta.torrent.name
}
return vnode.attrs.file.filename
},
getDownloadName(vnode) {
getDownloadName: function(vnode) {
if (vnode.attrs.file.meta.torrent) {
return 'Torrent'
}
return 'Download'
},
getSize(orgSize) {
getSize: function(orgSize) {
var size = orgSize
var i = -1
var byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB']

View file

@ -1,12 +1,12 @@
const { uploadMedia } = require('../api/media')
const Media = require('../api/media')
const FileUpload = {
uploadFile(vnode, event) {
uploadFile: function(vnode, event) {
if (!event.target.files[0]) return
vnode.state.updateError(vnode, '')
vnode.state.loading = true
uploadMedia(event.target.files[0])
Media.uploadMedia(event.target.files[0])
.then(function(res) {
if (vnode.attrs.onupload) {
vnode.attrs.onupload(res)

View file

@ -1,49 +0,0 @@
{
"NODE_ENV": "development",
"server": {
"port": 4030,
"host": "0.0.0.0"
},
"CIRCLECI_VERSION": "circleci_version_number",
"knex": {
"client": "pg",
"connection": {
"host" : "127.0.0.1",
"user" : "postgres",
"password" : "postgres",
"database" : "nfpmoe"
},
"connectionslave": null,
"migrations": {
},
"acquireConnectionTimeout": 10000
},
"bunyan": {
"name": "nfpmoe",
"streams": [{
"stream": "process.stdout",
"level": "debug"
}
]
},
"frontend": {
"url": "http://localhost:8080"
},
"jwt": {
"secret": "this-is-my-secret",
"options": {
"expiresIn": 604800
}
},
"googleid": "1076074914074-3no1difo1jq3dfug3glfb25pn1t8idud.apps.googleusercontent.com",
"sessionsecret": "this-is-session-secret-lol",
"bcrypt": 5,
"fileSize": 524288000,
"upload": {
"baseurl": "http://192.168.42.14",
"port": "2111",
"host": "storage01.nfp.is",
"name": "nfpmoe-dev",
"secret": "nfpmoe-dev"
}
}

File diff suppressed because one or more lines are too long