refactor: Source view Vue component

pull/112/head
NGPixel 8 years ago
parent bf6eae1428
commit 45d94e7e94

@ -29,6 +29,7 @@ import adminUsersCreateComponent from './modals/admin-users-create.vue'
import adminProfileComponent from './pages/admin-profile.component.js' import adminProfileComponent from './pages/admin-profile.component.js'
import adminSettingsComponent from './pages/admin-settings.component.js' import adminSettingsComponent from './pages/admin-settings.component.js'
import sourceComponent from './pages/source.component.js'
// ==================================== // ====================================
// Initialize Vue Modules // Initialize Vue Modules
@ -83,6 +84,7 @@ $(() => {
colorPicker: colorPickerComponent, colorPicker: colorPickerComponent,
loadingSpinner: loadingSpinnerComponent, loadingSpinner: loadingSpinnerComponent,
search: searchComponent, search: searchComponent,
sourceView: sourceComponent,
tree: treeComponent tree: treeComponent
}, },
store, store,

@ -1,112 +0,0 @@
'use strict'
import Vue from 'vue'
import _ from 'lodash'
/**
* Alerts
*/
class Alerts {
/**
* Constructor
*
* @class
*/
constructor () {
let self = this
self.mdl = new Vue({
el: '#alerts',
data: {
children: []
},
methods: {
acknowledge: (uid) => {
self.close(uid)
}
}
})
self.uidNext = 1
}
/**
* Show a new Alert
*
* @param {Object} options Alert properties
* @return {null} Void
*/
push (options) {
let self = this
let nAlert = _.defaults(options, {
_uid: self.uidNext,
class: 'info',
message: '---',
sticky: false,
title: '---'
})
self.mdl.children.push(nAlert)
if (!nAlert.sticky) {
_.delay(() => {
self.close(nAlert._uid)
}, 5000)
}
self.uidNext++
}
/**
* Shorthand method for pushing errors
*
* @param {String} title The title
* @param {String} message The message
*/
pushError (title, message) {
this.push({
class: 'error',
message,
sticky: false,
title
})
}
/**
* Shorthand method for pushing success messages
*
* @param {String} title The title
* @param {String} message The message
*/
pushSuccess (title, message) {
this.push({
class: 'success',
message,
sticky: false,
title
})
}
/**
* Close an alert
*
* @param {Integer} uid The unique ID of the alert
*/
close (uid) {
let self = this
let nAlertIdx = _.findIndex(self.mdl.children, ['_uid', uid])
let nAlert = _.nth(self.mdl.children, nAlertIdx)
if (nAlertIdx >= 0 && nAlert) {
nAlert.class += ' exit'
Vue.set(self.mdl.children, nAlertIdx, nAlert)
_.delay(() => {
self.mdl.children.splice(nAlertIdx, 1)
}, 500)
}
}
}
export default Alerts

@ -1,14 +1,17 @@
'use strict' 'use strict'
import $ from 'jquery'
import * as ace from 'brace' import * as ace from 'brace'
import 'brace/theme/tomorrow_night' import 'brace/theme/tomorrow_night'
import 'brace/mode/markdown' import 'brace/mode/markdown'
import pageLoader from '../components/page-loader' import pageLoader from '../components/page-loader'
module.exports = (alerts) => { export default {
if ($('#page-type-source').length) { name: 'source-view',
var scEditor = ace.edit('source-display') data() {
return {}
},
mounted() {
let scEditor = ace.edit('source-display')
scEditor.setTheme('ace/theme/tomorrow_night') scEditor.setTheme('ace/theme/tomorrow_night')
scEditor.getSession().setMode('ace/mode/markdown') scEditor.getSession().setMode('ace/mode/markdown')
scEditor.setOption('fontSize', '14px') scEditor.setOption('fontSize', '14px')
@ -16,12 +19,6 @@ module.exports = (alerts) => {
scEditor.setOption('wrap', true) scEditor.setOption('wrap', true)
scEditor.setReadOnly(true) scEditor.setReadOnly(true)
scEditor.renderer.updateFull() scEditor.renderer.updateFull()
let currentBasePath = ($('#page-type-source').data('entrypath') !== 'home') ? $('#page-type-source').data('entrypath') : ''
require('../modals/create.js')(currentBasePath)
require('../modals/move.js')(currentBasePath, alerts)
scEditor.renderer.on('afterRender', () => { scEditor.renderer.on('afterRender', () => {
pageLoader.complete() pageLoader.complete()
}) })

@ -347,7 +347,7 @@
height: 100%; height: 100%;
}*/ }*/
#page-type-source .ace-container { main > .ace-container {
min-height: 95vh; min-height: 95vh;
} }

@ -4,7 +4,7 @@ block rootNavCenter
h2.nav-item= pageData.meta.title h2.nav-item= pageData.meta.title
block rootNavRight block rootNavRight
i.nav-item#notifload loading-spinner
span.nav-item span.nav-item
if rights.write if rights.write
a.button.is-outlined.btn-move-prompt.is-hidden a.button.is-outlined.btn-move-prompt.is-hidden
@ -23,7 +23,7 @@ block rootNavRight
block content block content
#page-type-source(data-entrypath=pageData.meta.path) source-view(inline-template, data-entrypath=pageData.meta.path)
.ace-container .ace-container
#source-display= pageData.markdown #source-display= pageData.markdown

Loading…
Cancel
Save