Commit f075c266 authored by NGPixel's avatar NGPixel

refactor: vuex re-org + modal-create-page

parent 12132ad4
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
/* eslint-disable no-new */ /* eslint-disable no-new */
import $ from 'jquery' import $ from 'jquery'
import _ from 'lodash'
import Vue from 'vue' import Vue from 'vue'
import VueResource from 'vue-resource' import VueResource from 'vue-resource'
import VueClipboards from 'vue-clipboards' import VueClipboards from 'vue-clipboards'
import VueLodash from 'vue-lodash'
import store from './store' import store from './store'
import io from 'socket-io-client' import io from 'socket-io-client'
import i18next from 'i18next' import i18next from 'i18next'
...@@ -16,6 +18,12 @@ import 'jquery-smooth-scroll' ...@@ -16,6 +18,12 @@ import 'jquery-smooth-scroll'
import 'jquery-sticky' import 'jquery-sticky'
// ==================================== // ====================================
// Load Helpers
// ====================================
import helpers from './helpers'
// ====================================
// Load Vue Components // Load Vue Components
// ==================================== // ====================================
...@@ -40,6 +48,7 @@ import sourceViewComponent from './pages/source-view.component.js' ...@@ -40,6 +48,7 @@ import sourceViewComponent from './pages/source-view.component.js'
Vue.use(VueResource) Vue.use(VueResource)
Vue.use(VueClipboards) Vue.use(VueClipboards)
Vue.use(VueI18Next) Vue.use(VueI18Next)
Vue.use(VueLodash, _)
i18next i18next
.use(i18nextXHR) .use(i18nextXHR)
...@@ -78,6 +87,7 @@ $(() => { ...@@ -78,6 +87,7 @@ $(() => {
const i18n = new VueI18Next(i18next) const i18n = new VueI18Next(i18next)
new Vue({ new Vue({
mixins: [helpers],
components: { components: {
alert: alertComponent, alert: alertComponent,
adminProfile: adminProfileComponent, adminProfile: adminProfileComponent,
......
<template lang="pug"> <template lang="pug">
.modal(v-if='isShown') .modal(v-bind:class='{ "is-active": isShown }')
.modal-background .modal-background
.modal-container .modal-container
.modal-content .modal-content
header.is-light-blue Create New Document header.is-light-blue Create New Document
section section
label.label Enter the new document path: label.label Enter the new document path:
p.control.is-fullwidth(v-class='{ "is-loading": isLoading }') p.control.is-fullwidth(v-bind:class='{ "is-loading": isLoading }')
input.input(type='text', placeholder='page-name', v-model='entrypath', autofocus) input.input(type='text', placeholder='page-name', v-model='entrypath', autofocus)
span.help.is-danger(v-show='isInvalid') This document path is invalid! span.help.is-danger(v-show='isInvalid') This document path is invalid!
footer footer
...@@ -15,30 +15,29 @@ ...@@ -15,30 +15,29 @@
</template> </template>
<script> <script>
import { isEmpty } from 'lodash'
// import { makeSafePath } from '../helpers/pages'
import { mapState } from 'vuex' import { mapState } from 'vuex'
export default { export default {
name: 'modal-create', name: 'modal-create-page',
props: ['basepath'],
data () { data () {
return { return {
isLoading: false isLoading: false
} }
}, },
computed: mapState('createPage', { computed: {
entrypath: '', entrypath () { return this.$store.state.modalCreatePage.entrypath }
isShown: 'shown', isShown () { return this.$store.state.modalCreatePage.shown }
isInvalid: 'invalid' isInvalid () { return this.$store.state.modalCreatePage.invalid }
}), },
methods: { methods: {
cancel: function () { cancel: function () {
this.$store.dispatch('createPageClose') this.$store.dispatch('modalCreatePage/close')
}, },
create: function () { create: function () {
this.isInvalid = false this.isInvalid = false
let newDocPath = makeSafePath(this.entrypath) let newDocPath = this.helpers.pages.makeSafePath(this.entrypath)
if (isEmpty(newDocPath)) { if (this._.isEmpty(newDocPath)) {
this.$store.createPage.commit('') this.$store.createPage.commit('')
} else { } else {
this.isLoading = true this.isLoading = true
...@@ -47,7 +46,7 @@ ...@@ -47,7 +46,7 @@
} }
}, },
mounted () { mounted () {
// this.entrypath = currentBasePath + '/new-page' this.$store.commit('modalCreatePage/pathChange', this.basepath + '/new-page')
} }
} }
</script> </script>
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
<script> <script>
export default { export default {
name: 'admin-users-create', name: 'modal-create-user',
data () { data () {
return { return {
email: '', email: '',
...@@ -48,12 +48,12 @@ ...@@ -48,12 +48,12 @@
}, },
computed: { computed: {
isShown () { isShown () {
return this.$store.state.adminUsersCreate.shown return this.$store.state.modalCreateUser.shown
} }
}, },
methods: { methods: {
cancel () { cancel () {
this.$store.dispatch('adminUsersCreateClose') this.$store.dispatch('modalCreateUser/close')
this.email = '' this.email = ''
this.provider = 'local' this.provider = 'local'
}, },
......
'use strict' 'use strict'
import $ from 'jquery' import $ from 'jquery'
import delay from 'lodash/delay' import _ from 'lodash'
module.exports = { module.exports = {
complete () { complete() {
$('#page-loader').addClass('is-loaded') $('#page-loader').addClass('is-loaded')
delay(() => { _.delay(() => {
$('#page-loader').addClass('is-hidden') $('#page-loader').addClass('is-hidden')
}, 1100) }, 1100)
} }
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
</template> </template>
<script> <script>
import * as _ from 'lodash'
import * as $ from 'jquery' import * as $ from 'jquery'
export default { export default {
...@@ -44,7 +43,7 @@ ...@@ -44,7 +43,7 @@
socket.emit('search', { terms: val }, (data) => { socket.emit('search', { terms: val }, (data) => {
self.searchres = data.match self.searchres = data.match
self.searchsuggest = data.suggest self.searchsuggest = data.suggest
self.searchmovearr = _.concat([], self.searchres, self.searchsuggest) self.searchmovearr = self._.concat([], self.searchres, self.searchsuggest)
if (self.searchload > 0) { self.searchload-- } if (self.searchload > 0) { self.searchload-- }
}) })
} else { } else {
......
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
</template> </template>
<script> <script>
import * as _ from 'lodash'
export default { export default {
name: '', name: '',
data () { data () {
...@@ -31,9 +29,9 @@ ...@@ -31,9 +29,9 @@
self.$nextTick(() => { self.$nextTick(() => {
socket.emit('treeFetch', { basePath }, (data) => { socket.emit('treeFetch', { basePath }, (data) => {
if (self.tree.length > 0) { if (self.tree.length > 0) {
let branch = _.last(self.tree) let branch = self._.last(self.tree)
branch.hasChildren = true branch.hasChildren = true
_.find(branch.pages, { _id: basePath }).isActive = true self._.find(branch.pages, { _id: basePath }).isActive = true
} }
self.tree.push({ self.tree.push({
hasChildren: false, hasChildren: false,
...@@ -49,14 +47,14 @@ ...@@ -49,14 +47,14 @@
unfold (entryPath) { unfold (entryPath) {
let self = this let self = this
let lastIndex = 0 let lastIndex = 0
_.forEach(self.tree, branch => { self._.forEach(self.tree, branch => {
lastIndex++ lastIndex++
if (_.find(branch.pages, { _id: entryPath }) !== undefined) { if (self._.find(branch.pages, { _id: entryPath }) !== undefined) {
return false return false
} }
}) })
self.tree = _.slice(self.tree, 0, lastIndex) self.tree = self._.slice(self.tree, 0, lastIndex)
let branch = _.last(self.tree) let branch = self._.last(self.tree)
branch.hasChildren = false branch.hasChildren = false
branch.pages.forEach(page => { branch.pages.forEach(page => {
page.isActive = false page.isActive = false
......
'use strict'
export default {
helpers: {
form: require('./form'),
pages: require('./pages')
}
}
'use strict' 'use strict'
export default { export default {
namespaced: true,
state: { state: {
shown: false entrypath: '',
shown: false,
invalid: false
}, },
getters: {}, getters: {},
mutations: { mutations: {
shownChange: (state, shownState) => { state.shown = shownState } shownChange: (state, shownState) => { state.shown = shownState },
pathChange: (state, newpath) => { state.entrypath = newpath }
}, },
actions: { actions: {
adminUsersCreateOpen({ commit }) { commit('shownChange', true) }, open({ commit }) { commit('shownChange', true) },
adminUsersCreateClose({ commit }) { commit('shownChange', false) } close({ commit }) { commit('shownChange', false) }
} }
} }
'use strict' 'use strict'
export default { export default {
namespaced: true,
state: { state: {
shown: false shown: false
}, },
...@@ -9,7 +10,7 @@ export default { ...@@ -9,7 +10,7 @@ export default {
shownChange: (state, shownState) => { state.shown = shownState } shownChange: (state, shownState) => { state.shown = shownState }
}, },
actions: { actions: {
adminUsersCreateOpen({ commit }) { commit('shownChange', true) }, open({ commit }) { commit('shownChange', true) },
adminUsersCreateClose({ commit }) { commit('shownChange', false) } close({ commit }) { commit('shownChange', false) }
} }
} }
...@@ -47,6 +47,32 @@ if (args.d) { ...@@ -47,6 +47,32 @@ if (args.d) {
} }
// ====================================================== // ======================================================
// BUILD VARS
// ======================================================
const ALIASES = {
'brace-ext-modelist': 'brace/ext/modelist.js',
'simplemde': 'simplemde/dist/simplemde.min.js',
'socket-io-client': 'socket.io-client/dist/socket.io.js',
'vue': (dev) ? 'vue/dist/vue.js' : 'vue/dist/vue.min.js',
'vue-lodash': 'vue-lodash/dist/vue-lodash.min.js'
}
const SHIMS = {
_preinit: {
source: '.build/_preinit.js',
exports: '_preinit'
},
jquery: {
source: 'node_modules/jquery/dist/jquery.js',
exports: '$'
},
mathjax: {
source: 'node_modules/mathjax/MathJax.js',
exports: 'MathJax'
}
}
// ======================================================
// Global Tasks // Global Tasks
// ====================================================== // ======================================================
...@@ -191,27 +217,6 @@ let globalTasks = Promise.mapSeries([ ...@@ -191,27 +217,6 @@ let globalTasks = Promise.mapSeries([
// Fuse Tasks // Fuse Tasks
// ====================================================== // ======================================================
const ALIASES = {
'brace-ext-modelist': 'brace/ext/modelist.js',
'simplemde': 'simplemde/dist/simplemde.min.js',
'socket-io-client': 'socket.io-client/dist/socket.io.js',
'vue': (dev) ? 'vue/dist/vue.js' : 'vue/dist/vue.min.js'
}
const SHIMS = {
_preinit: {
source: '.build/_preinit.js',
exports: '_preinit'
},
jquery: {
source: 'node_modules/jquery/dist/jquery.js',
exports: '$'
},
mathjax: {
source: 'node_modules/mathjax/MathJax.js',
exports: 'MathJax'
}
}
globalTasks.then(() => { globalTasks.then(() => {
let fuse = fsbx.FuseBox.init({ let fuse = fsbx.FuseBox.init({
homeDir: './client', homeDir: './client',
...@@ -222,7 +227,7 @@ globalTasks.then(() => { ...@@ -222,7 +227,7 @@ globalTasks.then(() => {
fsbx.EnvPlugin({ NODE_ENV: (dev) ? 'development' : 'production' }), fsbx.EnvPlugin({ NODE_ENV: (dev) ? 'development' : 'production' }),
fsbx.VuePlugin(), fsbx.VuePlugin(),
['.scss', fsbx.SassPlugin({ outputStyle: (dev) ? 'nested' : 'compressed' }), fsbx.CSSPlugin()], ['.scss', fsbx.SassPlugin({ outputStyle: (dev) ? 'nested' : 'compressed' }), fsbx.CSSPlugin()],
fsbx.BabelPlugin({ comments: false, presets: ['es2015'] }), dev && fsbx.BabelPlugin({ comments: false, presets: ['es2015'] }),
fsbx.JSONPlugin(), fsbx.JSONPlugin(),
!dev && fsbx.UglifyESPlugin({ !dev && fsbx.UglifyESPlugin({
compress: { unused: false }, compress: { unused: false },
...@@ -240,13 +245,14 @@ globalTasks.then(() => { ...@@ -240,13 +245,14 @@ globalTasks.then(() => {
}) })
} }
const bundleLibs = fuse.bundle('libs').instructions('~ index.js - brace') // const bundleLibs = fuse.bundle('libs').instructions('~ index.js - brace')
const bundleApp = fuse.bundle('app').instructions('!> [index.js]') // const bundleApp = fuse.bundle('app').instructions('!> [index.js]')
const bundleApp = fuse.bundle('app').instructions('> index.js')
const bundleSetup = fuse.bundle('configure').instructions('> configure.js') const bundleSetup = fuse.bundle('configure').instructions('> configure.js')
switch (mode) { switch (mode) {
case 'dev': case 'dev':
bundleLibs.watch() // bundleLibs.watch()
bundleApp.watch() bundleApp.watch()
break break
case 'dev-configure': case 'dev-configure':
......
...@@ -139,7 +139,7 @@ ...@@ -139,7 +139,7 @@
"eslint-plugin-node": "latest", "eslint-plugin-node": "latest",
"eslint-plugin-promise": "latest", "eslint-plugin-promise": "latest",
"eslint-plugin-standard": "latest", "eslint-plugin-standard": "latest",
"fuse-box": "^2.0.0", "fuse-box": "2.1.0-beta.10",
"i18next-xhr-backend": "^1.4.1", "i18next-xhr-backend": "^1.4.1",
"jest": "latest", "jest": "latest",
"jquery": "^3.2.1", "jquery": "^3.2.1",
...@@ -147,6 +147,7 @@ ...@@ -147,6 +147,7 @@
"jquery-simple-upload": "^1.0.0", "jquery-simple-upload": "^1.0.0",
"jquery-smooth-scroll": "^2.2.0", "jquery-smooth-scroll": "^2.2.0",
"jquery-sticky": "^1.0.4", "jquery-sticky": "^1.0.4",
"lodash-cli": "^4.17.4",
"lodash-es": "^4.17.4", "lodash-es": "^4.17.4",
"mathjax": "^2.7.1", "mathjax": "^2.7.1",
"node-sass": "latest", "node-sass": "latest",
...@@ -159,6 +160,7 @@ ...@@ -159,6 +160,7 @@
"vee-validate": "^2.0.0-rc.3", "vee-validate": "^2.0.0-rc.3",
"vue": "^2.3.3", "vue": "^2.3.3",
"vue-clipboards": "^1.0.0", "vue-clipboards": "^1.0.0",
"vue-lodash": "^1.0.3",
"vue-resource": "^1.3.3", "vue-resource": "^1.3.3",
"vue-template-compiler": "^2.3.3", "vue-template-compiler": "^2.3.3",
"vue-template-es2015-compiler": "^1.5.2", "vue-template-es2015-compiler": "^1.5.2",
......
...@@ -18,7 +18,7 @@ html(data-logic='login') ...@@ -18,7 +18,7 @@ html(data-logic='login')
link(rel='manifest', href='/manifest.json') link(rel='manifest', href='/manifest.json')
// JS / CSS // JS / CSS
script(type='text/javascript', src='/js/libs.min.js') //- script(type='text/javascript', src='/js/libs.min.js')
script(type='text/javascript', src='/js/app.min.js') script(type='text/javascript', src='/js/app.min.js')
body body
......
...@@ -18,7 +18,7 @@ html(data-logic='error') ...@@ -18,7 +18,7 @@ html(data-logic='error')
link(rel='manifest', href='/manifest.json') link(rel='manifest', href='/manifest.json')
// JS / CSS // JS / CSS
script(type='text/javascript', src='/js/libs.min.js') //- script(type='text/javascript', src='/js/libs.min.js')
script(type='text/javascript', src='/js/app.min.js') script(type='text/javascript', src='/js/app.min.js')
body(class='is-forbidden') body(class='is-forbidden')
......
...@@ -18,7 +18,7 @@ html(data-logic='error') ...@@ -18,7 +18,7 @@ html(data-logic='error')
link(rel='manifest', href='/manifest.json') link(rel='manifest', href='/manifest.json')
// JS / CSS // JS / CSS
script(type='text/javascript', src='/js/libs.min.js') //- script(type='text/javascript', src='/js/libs.min.js')
script(type='text/javascript', src='/js/app.min.js') script(type='text/javascript', src='/js/app.min.js')
body(class='is-notexist') body(class='is-notexist')
......
...@@ -18,7 +18,7 @@ html(data-logic='error') ...@@ -18,7 +18,7 @@ html(data-logic='error')
link(rel='manifest', href='/manifest.json') link(rel='manifest', href='/manifest.json')
// JS / CSS // JS / CSS
script(type='text/javascript', src='/js/libs.min.js') //- script(type='text/javascript', src='/js/libs.min.js')
script(type='text/javascript', src='/js/app.min.js') script(type='text/javascript', src='/js/app.min.js')
body(class='is-error') body(class='is-error')
......
...@@ -23,7 +23,7 @@ html ...@@ -23,7 +23,7 @@ html
var siteRoot = '!{appconfig.host}'; var siteRoot = '!{appconfig.host}';
//- JS / CSS //- JS / CSS
script(type='text/javascript', src='/js/libs.min.js') //- script(type='text/javascript', src='/js/libs.min.js')
script(type='text/javascript', src='/js/app.min.js') script(type='text/javascript', src='/js/app.min.js')
block head block head
......
...@@ -3,7 +3,7 @@ extends ./_layout.pug ...@@ -3,7 +3,7 @@ extends ./_layout.pug
block rootNavRight block rootNavRight
loading-spinner loading-spinner
.nav-item .nav-item
a.button(v-on:click='$store.dispatch("adminUsersCreateOpen")') a.button(v-on:click='$store.dispatch("modalCreateUser/open")')
i.icon-plus i.icon-plus
span= t('admin:users.createauthorize') span= t('admin:users.createauthorize')
...@@ -43,4 +43,4 @@ block adminContent ...@@ -43,4 +43,4 @@ block adminContent
td.is-centered= moment(usr.createdAt).format('lll') td.is-centered= moment(usr.createdAt).format('lll')
td.is-centered= moment(usr.updatedAt).format('lll') td.is-centered= moment(usr.updatedAt).format('lll')
admin-users-create modal-create-user
...@@ -25,13 +25,12 @@ block rootNavRight ...@@ -25,13 +25,12 @@ block rootNavRight
a.button(href='/edit/' + pageData.meta.path) a.button(href='/edit/' + pageData.meta.path)
i.icon-document-text i.icon-document-text
span= t('nav.edit') span= t('nav.edit')
a.button.btn-create-prompt a.button(v-on:click='$store.dispatch("modalCreatePage/open")')
i.icon-plus i.icon-plus
span= t('nav.create') span= t('nav.create')
block content block content
//- #page-type-view.page-type-container(data-entrypath=pageData.meta.path)
content-view(inline-template) content-view(inline-template)
.container.is-fluid.has-mkcontent .container.is-fluid.has-mkcontent
.columns.is-gapless .columns.is-gapless
...@@ -82,6 +81,5 @@ block content ...@@ -82,6 +81,5 @@ block content
.content.mkcontent .content.mkcontent
!= pageData.html != pageData.html
include ../modals/create.pug modal-create-page(basepath=pageData.meta.path)
include ../modals/move.pug
anchor anchor
This diff was suppressed by a .gitattributes entry.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment