feat: storage module refactor + UI fixes

This commit is contained in:
NGPixel 2018-07-08 01:12:43 -04:00
parent bc12db7295
commit 9e2f1caaf7
40 changed files with 334 additions and 329 deletions

View File

@ -51,7 +51,7 @@
v-model='cfg.value.value'
prepend-icon='settings_applications'
)
v-divider
v-divider.mt-3
v-subheader.pl-0 Registration
.pr-3
v-switch.ml-3(

View File

@ -9,14 +9,14 @@
a(href='https://requarks.io', target='_blank') requarks.io
a(href='https://github.com/Requarks/wiki/graphs/contributors', target='_blank') {{ $t('admin:contribute.openSourceContributors') }}
.body-1.pt-3.pl-3 {{ $t('admin:contribute.needYourHelp') }}
v-divider
v-divider.mt-3
v-subheader {{ $t('admin:contribute.fundOurWork') }}
.body-1.pl-3 {{ $t('admin:contribute.openCollective') }}
v-card-actions.mt-3.ml-2
v-btn(depressed, color='primary', href='https://opencollective.com/wikijs')
v-icon(left) local_atm
span {{ $t('admin:contribute.makeADonation') }}
v-divider
v-divider.mt-3
v-subheader {{ $t('admin:contribute.contribute') }}
.body-1.pl-3
ul
@ -26,7 +26,7 @@
a(href='https://github.com/Requarks/wiki/issues', target='_blank') Github
i18next(path='admin:contribute.helpTranslate', tag='li')
a(href='https://gitter.im/Requarks/wiki', target='_blank') Gitter
v-divider
v-divider.mt-3
v-subheader {{ $t('admin:contribute.spreadTheWord') }}
.body-1.pl-3
ul

View File

@ -15,7 +15,7 @@
v-subheader General
.px-3
v-text-field(label='Site Title', required, :counter='50', v-model='siteTitle', prepend-icon='public')
v-divider
v-divider.mt-3
v-subheader SEO
.px-3
v-text-field(label='Site Description', :counter='255', prepend-icon='public')
@ -51,7 +51,7 @@
persistent-hint
hint='Check this option if a round logo frame doesn\'t work with your logo.'
)
v-divider
v-divider.mt-3
v-switch(
v-model='displayMascot'
label='Display Wiki.js Mascot'

View File

@ -22,10 +22,10 @@
v-spacer
v-text-field(solo, append-icon='search', label='Search', single-line, hide-details, v-model='search')
v-data-table(
:items='groups',
:headers='headers',
:search='search',
:pagination.sync='pagination',
:items='groups'
:headers='headers'
:search='search'
:pagination.sync='pagination'
:rows-per-page-items='[15]'
hide-actions
)

View File

@ -31,7 +31,7 @@
v-list-tile-content
v-list-tile-title(v-html='data.item.name')
v-list-tile-sub-title(v-html='data.item.nativeName')
v-divider
v-divider.mt-3
v-switch(
v-model='autoUpdate'
:label='$t("admin:locale.autoUpdate.label")'
@ -65,7 +65,7 @@
)
span {{ $t('admin:locale.namespacingPrefixWarning.title', { langCode: selectedLocale }) }}
.caption.grey--text {{ $t('admin:locale.namespacingPrefixWarning.subtitle') }}
v-divider
v-divider.mt-3.mb-4
v-select(
:disabled='!namespacing'
:items='installedLocales'

View File

@ -169,7 +169,7 @@
persistent-hint
hint='Links will automatically be converted to clickable links.'
)
v-divider
v-divider.mt-3
v-switch(
v-model='linkify'
label='Automatically convert line breaks'
@ -177,7 +177,7 @@
persistent-hint
hint='Add linebreaks within paragraphs.'
)
v-divider
v-divider.mt-3
v-switch(
v-model='linkify'
label='Highlight code blocks'

View File

@ -51,7 +51,7 @@
v-model='cfg.value.value'
prepend-icon='settings_applications'
)
v-divider
v-divider.mt-3
v-subheader.pl-0 Sync Direction
.body-1.ml-3 Choose how content synchronization is handled for this storage target.
.pr-3.pt-3

View File

@ -25,7 +25,7 @@
v-list-tile-action
v-list-tile-action-text {{ $t('admin:system.published') }} {{ info.latestVersionReleaseDate | moment('from') }}
v-divider
v-divider.mt-3
v-subheader {{ $t('admin:system.hostInfo') }}
v-list-tile(avatar)
@ -76,7 +76,7 @@
v-list-tile-content
v-list-tile-title {{ info.nodeVersion }}
v-divider
v-divider.mt-3
v-subheader Redis
v-list-tile(avatar)
@ -89,7 +89,7 @@
v-list-tile-action
v-list-tile-action-text {{ $t('admin:system.ramUsage', { used: info.redisUsedRAM, total: info.redisTotalRAM }) }}
v-divider
v-divider.mt-3
v-subheader {{ info.dbType }}
v-list-tile(avatar)

View File

@ -26,7 +26,7 @@
v-list-tile-content
v-list-tile-title(v-html='data.item.text')
v-list-tile-sub-title(v-html='data.item.author')
v-divider
v-divider.mt-3
v-switch(
v-model='darkMode'
label='Dark Mode'

View File

@ -1,6 +1,5 @@
@import "global";
@import "base/reset";
@import "base/base";
@import 'base/icons';

View File

@ -2,7 +2,6 @@ const Model = require('objection').Model
const autoload = require('auto-load')
const path = require('path')
const _ = require('lodash')
const commonHelper = require('../../helpers/common')
/* global WIKI */
@ -56,7 +55,7 @@ module.exports = class Authentication extends Model {
if (_.isPlainObject(value)) {
let cfgValue = {
type: typeof value.type(),
value: !_.isNil(value.default) ? value.default : commonHelper.getTypeDefaultValue(value)
value: !_.isNil(value.default) ? value.default : new value() // eslint-disable-line new-cap
}
if (_.isArray(value.enum)) {
cfgValue.enum = value.enum
@ -65,7 +64,7 @@ module.exports = class Authentication extends Model {
} else {
_.set(result, key, {
type: typeof value(),
value: commonHelper.getTypeDefaultValue(value)
value: new value() // eslint-disable-line new-cap
})
}
return result

View File

@ -1,7 +1,8 @@
const Model = require('objection').Model
const autoload = require('auto-load')
const path = require('path')
const fs = require('fs-extra')
const _ = require('lodash')
const yaml = require('js-yaml')
const commonHelper = require('../../helpers/common')
/* global WIKI */
@ -35,9 +36,18 @@ module.exports = class Storage extends Model {
static async refreshTargetsFromDisk() {
try {
const dbTargets = await WIKI.db.storage.query()
const diskTargets = autoload(path.join(WIKI.SERVERPATH, 'modules/storage'))
// -> Fetch definitions from disk
const storageDirs = await fs.readdir(path.join(WIKI.SERVERPATH, 'modules/storage'))
let diskTargets = []
for (let dir of storageDirs) {
const def = await fs.readFile(path.join(WIKI.SERVERPATH, 'modules/storage', dir, 'definition.yml'), 'utf8')
diskTargets.push(yaml.safeLoad(def))
}
// -> Insert new targets
let newTargets = []
_.forOwn(diskTargets, (target, targetKey) => {
_.forEach(diskTargets, target => {
if (!_.some(dbTargets, ['key', target.key])) {
newTargets.push({
key: target.key,
@ -47,8 +57,8 @@ module.exports = class Storage extends Model {
config: _.transform(target.props, (result, value, key) => {
if (_.isPlainObject(value)) {
let cfgValue = {
type: typeof value.type(),
value: !_.isNil(value.default) ? value.default : commonHelper.getTypeDefaultValue(value)
type: value.type.toLowerCase(),
value: !_.isNil(value.default) ? value.default : commonHelper.getTypeDefaultValue(value.type)
}
if (_.isArray(value.enum)) {
cfgValue.enum = value.enum
@ -56,7 +66,7 @@ module.exports = class Storage extends Model {
_.set(result, key, cfgValue)
} else {
_.set(result, key, {
type: typeof value(),
type: value.toLowerCase(),
value: commonHelper.getTypeDefaultValue(value)
})
}

View File

@ -1,17 +1,18 @@
const _ = require('lodash')
module.exports = {
/**
* Get default value of type
*
* @param {any} Type Primitive Type
* @param {any} type primitive type name
* @returns Default value
*/
getTypeDefaultValue (Type) {
if (_.isArray(Type)) {
return _.head(Type)
} else {
return new Type()
getTypeDefaultValue (type) {
switch (type.toLowerCase()) {
case 'string':
return ''
case 'number':
return 0
case 'boolean':
return false
}
}
}

View File

@ -1,30 +0,0 @@
module.exports = {
key: 'azure',
title: 'Azure Blob Storage',
props: {
accountName: String,
accountKey: String,
container: String
},
activated(opts) {
},
deactivated(opts) {
},
init(opts) {
},
created(opts) {
},
updated(opts) {
},
deleted(opts) {
},
renamed(opts) {
}
}

View File

@ -0,0 +1,7 @@
key: azure
title: Azure Blob Storage
author: requarks.io
props:
accountName: String
accountKey: String
container: String

View File

@ -0,0 +1,23 @@
module.exports = {
async activated(opts) {
},
async deactivated(opts) {
},
async init(opts) {
},
async created(opts) {
},
async updated(opts) {
},
async deleted(opts) {
},
async renamed(opts) {
}
}

View File

@ -1,34 +0,0 @@
module.exports = {
key: 'digitalocean',
title: 'DigialOcean Spaces',
props: {
accessKeyId: String,
accessSecret: String,
region: {
type: String,
default: 'nyc3'
},
bucket: String
},
activated(opts) {
},
deactivated(opts) {
},
init(opts) {
},
created(opts) {
},
updated(opts) {
},
deleted(opts) {
},
renamed(opts) {
}
}

View File

@ -0,0 +1,10 @@
key: digitalocean
title: DigialOcean Spaces
author: requarks.io
props:
accessKeyId: String
accessSecret: String
region:
type: String
default: nyc3
bucket: String

View File

@ -0,0 +1,23 @@
module.exports = {
async activated(opts) {
},
async deactivated(opts) {
},
async init(opts) {
},
async created(opts) {
},
async updated(opts) {
},
async deleted(opts) {
},
async renamed(opts) {
}
}

View File

@ -1,28 +0,0 @@
module.exports = {
key: 'disk',
title: 'Local FS',
props: {
path: String
},
activated(opts) {
},
deactivated(opts) {
},
init(opts) {
},
created(opts) {
},
updated(opts) {
},
deleted(opts) {
},
renamed(opts) {
}
}

View File

@ -0,0 +1,5 @@
key: disk
title: Local FS
author: requarks.io
props:
path: String

View File

@ -0,0 +1,23 @@
module.exports = {
async activated(opts) {
},
async deactivated(opts) {
},
async init(opts) {
},
async created(opts) {
},
async updated(opts) {
},
async deleted(opts) {
},
async renamed(opts) {
}
}

View File

@ -1,29 +0,0 @@
module.exports = {
key: 'dropbox',
title: 'Dropbox',
props: {
appKey: String,
appSecret: String
},
activated(opts) {
},
deactivated(opts) {
},
init(opts) {
},
created(opts) {
},
updated(opts) {
},
deleted(opts) {
},
renamed(opts) {
}
}

View File

@ -0,0 +1,6 @@
key: dropbox
title: Dropbox
author: requarks.io
props:
appKey: String
appSecret: String

View File

@ -0,0 +1,23 @@
module.exports = {
async activated(opts) {
},
async deactivated(opts) {
},
async init(opts) {
},
async created(opts) {
},
async updated(opts) {
},
async deleted(opts) {
},
async renamed(opts) {
}
}

View File

@ -1,29 +0,0 @@
module.exports = {
key: 'gdrive',
title: 'Google Drive',
props: {
clientId: String,
clientSecret: String
},
activated(opts) {
},
deactivated(opts) {
},
init(opts) {
},
created(opts) {
},
updated(opts) {
},
deleted(opts) {
},
renamed(opts) {
}
}

View File

@ -0,0 +1,6 @@
key: gdrive
title: Google Drive
author: requarks.io
props:
clientId: String
clientSecret: String

View File

@ -0,0 +1,23 @@
module.exports = {
async activated(opts) {
},
async deactivated(opts) {
},
async init(opts) {
},
async created(opts) {
},
async updated(opts) {
},
async deleted(opts) {
},
async renamed(opts) {
}
}

View File

@ -1,44 +0,0 @@
module.exports = {
key: 'git',
title: 'Git',
props: {
authType: {
type: String,
default: 'ssh',
enum: ['basic', 'ssh']
},
repoUrl: String,
branch: {
type: String,
default: 'master'
},
verifySSL: {
type: Boolean,
default: true
},
sshPrivateKeyPath: String,
basicUsername: String,
basicPassword: String
},
activated(opts) {
},
deactivated(opts) {
},
init(opts) {
},
created(opts) {
},
updated(opts) {
},
deleted(opts) {
},
renamed(opts) {
}
}

View File

@ -0,0 +1,20 @@
key: git
title: Git
author: requarks.io
props:
authType:
type: String
default: 'ssh'
enum:
- 'basic'
- 'ssh'
repoUrl: String
branch:
type: String
default: 'master'
verifySSL:
type: Boolean
default: true
sshPrivateKeyPath: String
basicUsername: String
basicPassword: String

View File

@ -0,0 +1,23 @@
module.exports = {
async activated(opts) {
},
async deactivated(opts) {
},
async init(opts) {
},
async created(opts) {
},
async updated(opts) {
},
async deleted(opts) {
},
async renamed(opts) {
}
}

View File

@ -1,29 +0,0 @@
module.exports = {
key: 'onedrive',
title: 'OneDrive',
props: {
clientId: String,
clientSecret: String
},
activated(opts) {
},
deactivated(opts) {
},
init(opts) {
},
created(opts) {
},
updated(opts) {
},
deleted(opts) {
},
renamed(opts) {
}
}

View File

@ -0,0 +1,6 @@
key: onedrive
title: OneDrive
author: requarks.io
props:
clientId: String
clientSecret: String

View File

@ -0,0 +1,23 @@
module.exports = {
async activated(opts) {
},
async deactivated(opts) {
},
async init(opts) {
},
async created(opts) {
},
async updated(opts) {
},
async deleted(opts) {
},
async renamed(opts) {
}
}

View File

@ -1,31 +0,0 @@
module.exports = {
key: 's3',
title: 'Amazon S3',
props: {
accessKeyId: String,
accessSecret: String,
region: String,
bucket: String
},
activated(opts) {
},
deactivated(opts) {
},
init(opts) {
},
created(opts) {
},
updated(opts) {
},
deleted(opts) {
},
renamed(opts) {
}
}

View File

@ -0,0 +1,8 @@
key: s3
title: Amazon S3
author: requarks.io
props:
accessKeyId: String
accessSecret: String
region: String
bucket: String

View File

@ -0,0 +1,23 @@
module.exports = {
async activated(opts) {
},
async deactivated(opts) {
},
async init(opts) {
},
async created(opts) {
},
async updated(opts) {
},
async deleted(opts) {
},
async renamed(opts) {
}
}

View File

@ -1,38 +0,0 @@
module.exports = {
key: 'scp',
title: 'SCP (SSH)',
props: {
host: String,
port: {
type: Number,
default: 22
},
username: String,
privateKeyPath: String,
basePath: {
type: String,
default: '~'
}
},
activated(opts) {
},
deactivated(opts) {
},
init(opts) {
},
created(opts) {
},
updated(opts) {
},
deleted(opts) {
},
renamed(opts) {
}
}

View File

@ -0,0 +1,13 @@
key: scp
title: SCP (SSH)
author: requarks.io
props:
host: String
port:
type: Number
default: 22
username: String
privateKeyPath: String
basePath:
type: String
default: '~'

View File

@ -0,0 +1,23 @@
module.exports = {
async activated(opts) {
},
async deactivated(opts) {
},
async init(opts) {
},
async created(opts) {
},
async updated(opts) {
},
async deleted(opts) {
},
async renamed(opts) {
}
}