Navigation Menu

Skip to content

Commit

Permalink
feat: save page - updated + page history
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Jul 23, 2018
1 parent 076e923 commit 803d86f
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 53 deletions.
99 changes: 73 additions & 26 deletions client/components/editor.vue
Expand Up @@ -6,7 +6,9 @@
v-icon(color='green', left) check
span.white--text(v-if='mode === "create"') {{ $t('common:actions.create') }}
span.white--text(v-else) {{ $t('common:actions.save') }}
v-btn.is-icon(outline, color='red').mx-0: v-icon(color='red') close
v-btn(outline, color='red').mx-0
v-icon(color='red', left) close
span.white--text {{ $t('common:actions.discard') }}
v-btn(outline, color='blue', @click.native.stop='openModal(`properties`)', dark)
v-icon(left) sort_by_alpha
span.white--text {{ $t('editor:page') }}
Expand Down Expand Up @@ -42,6 +44,7 @@ import { get, sync } from 'vuex-pathify'
import { AtomSpinner } from 'epic-spinners'
import createPageMutation from 'gql/editor/create.gql'
import updatePageMutation from 'gql/editor/update.gql'
import editorStore from '@/store/editor'
Expand Down Expand Up @@ -90,35 +93,79 @@ export default {
},
async save() {
this.showProgressDialog('saving')
if (this.$store.get('editor/mode') === 'create') {
const resp = await this.$apollo.mutate({
mutation: createPageMutation,
variables: {
content: this.$store.get('editor/content'),
description: this.$store.get('editor/description'),
editor: 'markdown',
locale: this.$store.get('editor/locale'),
isPrivate: false,
isPublished: this.$store.get('editor/isPublished'),
path: this.$store.get('editor/path'),
publishEndDate: this.$store.get('editor/publishEndDate'),
publishStartDate: this.$store.get('editor/publishStartDate'),
tags: this.$store.get('editor/tags'),
title: this.$store.get('editor/title')
}
})
if (_.get(resp, 'data.pages.create.responseResult.succeeded')) {
this.$store.commit('showNotification', {
message: this.$t('editor:save.success'),
style: 'success',
icon: 'check'
try {
if (this.$store.get('editor/mode') === 'create') {
// --------------------------------------------
// -> CREATE PAGE
// --------------------------------------------
let resp = await this.$apollo.mutate({
mutation: createPageMutation,
variables: {
content: this.$store.get('editor/content'),
description: this.$store.get('editor/description'),
editor: 'markdown',
locale: this.$store.get('editor/locale'),
isPrivate: false,
isPublished: this.$store.get('editor/isPublished'),
path: this.$store.get('editor/path'),
publishEndDate: this.$store.get('editor/publishEndDate'),
publishStartDate: this.$store.get('editor/publishStartDate'),
tags: this.$store.get('editor/tags'),
title: this.$store.get('editor/title')
}
})
this.$store.set('editor/mode', 'update')
resp = _.get(resp, 'data.pages.create', {})
if (_.get(resp, 'responseResult.succeeded')) {
this.$store.commit('showNotification', {
message: this.$t('editor:save.success'),
style: 'success',
icon: 'check'
})
this.$store.set('editor/id', _.get(resp, 'page.id'))
this.$store.set('editor/mode', 'update')
} else {
throw new Error(_.get(resp, 'responseResult.message'))
}
} else {
// --------------------------------------------
// -> UPDATE EXISTING PAGE
// --------------------------------------------
let resp = await this.$apollo.mutate({
mutation: updatePageMutation,
variables: {
id: this.$store.get('editor/id'),
content: this.$store.get('editor/content'),
description: this.$store.get('editor/description'),
editor: 'markdown',
locale: this.$store.get('editor/locale'),
isPrivate: false,
isPublished: this.$store.get('editor/isPublished'),
path: this.$store.get('editor/path'),
publishEndDate: this.$store.get('editor/publishEndDate'),
publishStartDate: this.$store.get('editor/publishStartDate'),
tags: this.$store.get('editor/tags'),
title: this.$store.get('editor/title')
}
})
resp = _.get(resp, 'data.pages.update', {})
if (_.get(resp, 'responseResult.succeeded')) {
this.$store.commit('showNotification', {
message: this.$t('editor:save.success'),
style: 'success',
icon: 'check'
})
} else {
throw new Error(_.get(resp, 'responseResult.message'))
}
}
} else {
} catch (err) {
this.$store.commit('showNotification', {
message: err.message,
style: 'error',
icon: 'warning'
})
}
this.hideProgressDialog()
}
Expand Down
17 changes: 14 additions & 3 deletions client/components/editor/editor-modal-properties.vue
Expand Up @@ -7,13 +7,24 @@
v-icon(color='white') sort_by_alpha
.subheading.white--text.ml-2 Page Properties
v-spacer
v-btn(
v-btn.mx-0(
outline
dark
@click.native='close'
)
v-icon(left) close
span Close
v-icon(left) check
span {{ $t('common:actions.ok') }}
v-menu
v-btn.is-icon(
slot='activator'
outline
dark
)
v-icon more_horiz
v-list
v-list-tile
v-list-tile-avatar: v-icon delete
v-list-tile-title Delete Page
v-card(tile)
v-card-text
v-subheader.pl-0 Page Info
Expand Down
39 changes: 23 additions & 16 deletions client/components/setup.vue
Expand Up @@ -50,7 +50,7 @@
.body-1.pt-3
svg.icons.is-18.is-outlined.has-right-pad.is-text: use(xlink:href='#nc-cd-reader')
span You are about to install Wiki.js #[strong {{wikiVersion}}].
v-divider
v-divider.mt-3
v-form
v-checkbox(
color='primary',
Expand All @@ -67,7 +67,7 @@
hint='Check this box if you are upgrading from Wiki.js 1.x and wish to migrate your existing data.'
)
v-divider
.text-xs-center
.pt-3.text-xs-center
v-btn(color='primary', @click='proceedToSyscheck', :disabled='loading') Start

//- ==============================================
Expand All @@ -94,7 +94,7 @@
v-list-tile-title {{rs.title}}
v-list-tile-sub-title {{rs.subtitle}}
v-divider
.text-xs-center
.pt-3.text-xs-center
v-btn(@click='proceedToWelcome', :disabled='loading') Back
v-btn(color='primary', @click='proceedToSyscheck', v-if='!loading && !syscheck.ok') Check Again
v-btn(color='red', dark, @click='proceedToGeneral', v-if='!loading && !syscheck.ok') Continue Anyway
Expand All @@ -113,6 +113,8 @@
v-layout(row, wrap)
v-flex(xs12, sm6).pr-3
v-text-field(
outline
background-color='grey lighten-2'
v-model='conf.title',
label='Site Title',
:counter='255',
Expand All @@ -126,6 +128,8 @@
)
v-flex.pr-3(xs12, sm6)
v-text-field(
outline
background-color='grey lighten-2'
v-model='conf.port',
label='Server Port',
persistent-hint,
Expand All @@ -139,6 +143,8 @@
v-layout(row, wrap).mt-3
v-flex(xs12, sm6).pr-3
v-text-field(
outline
background-color='grey lighten-2'
v-model='conf.pathContent',
label='Content Data Path',
persistent-hint,
Expand All @@ -151,6 +157,8 @@
)
v-flex(xs12, sm6)
v-text-field(
outline
background-color='grey lighten-2'
v-model='conf.pathData',
label='Temporary Data Path',
persistent-hint,
Expand All @@ -170,15 +178,8 @@
persistent-hint,
hint='Should the site be accessible (read only) without login.'
)
v-checkbox.mt-2(
color='primary',
v-model='conf.selfRegister',
label='Allow Self-Registration',
persistent-hint,
hint='Can users create their own account to gain access?'
)
v-divider
.text-xs-center
.pt-3.text-xs-center
v-btn(@click='proceedToSyscheck', :disabled='loading') Back
v-btn(color='primary', @click='proceedToAdmin', :disabled='loading') Continue

Expand All @@ -196,7 +197,8 @@
v-layout(row, wrap)
v-flex(xs12)
v-text-field(
autofocus
outline
background-color='grey lighten-2'
v-model='conf.adminEmail',
label='Administrator Email',
hint='The email address of the administrator account',
Expand All @@ -208,6 +210,8 @@
)
v-flex.pr-3(xs6)
v-text-field(
outline
background-color='grey lighten-2'
ref='adminPassword',
counter='255'
v-model='conf.adminPassword',
Expand All @@ -224,6 +228,8 @@
)
v-flex(xs6)
v-text-field(
outline
background-color='grey lighten-2'
ref='adminPasswordConfirm',
counter='255'
v-model='conf.adminPasswordConfirm',
Expand All @@ -238,7 +244,7 @@
data-vv-scope='admin',
:error-messages='errors.collect(`adminPasswordConfirm`)'
)
.text-xs-center
.pt-3.text-xs-center
v-btn(@click='proceedToGeneral', :disabled='loading') Back
v-btn(color='primary', @click='proceedToUpgrade', :disabled='loading') Continue

Expand All @@ -256,6 +262,8 @@
v-layout(row)
v-flex(xs12)
v-text-field(
outline
background-color='grey lighten-2'
v-model='conf.upgMongo',
placeholder='mongodb://',
label='Connection String to Wiki.js 1.x MongoDB database',
Expand All @@ -267,7 +275,7 @@
data-vv-scope='upgrade',
:error-messages='errors.collect(`upgMongo`)'
)
.text-xs-center
.pt-3.text-xs-center
v-btn(@click='proceedToAdmin', :disabled='loading') Back
v-btn(color='primary', @click='proceedToFinal', :disabled='loading') Continue

Expand All @@ -290,7 +298,7 @@
v-alert(type='success', outline, :value='!loading && final.ok') Wiki.js was configured successfully and is now ready for use.
v-alert(type='error', outline, :value='!loading && !final.ok') {{ final.error }}
v-divider
.text-xs-center
.pt-3.text-xs-center
v-btn(@click='!conf.upgrade ? proceedToAdmin() : proceedToUpgrade()', :disabled='loading') Back
v-btn(color='primary', @click='proceedToFinal', v-if='!loading && !final.ok') Try Again
v-btn(color='success', @click='finish', v-if='loading || final.ok', :disabled='loading') Continue
Expand Down Expand Up @@ -342,7 +350,6 @@ export default {
pathContent: './content',
port: siteConfig.port || 80,
public: (siteConfig.public === true),
selfRegister: (siteConfig.selfRegister === true),
telemetry: true,
title: siteConfig.title || 'Wiki',
upgrade: false,
Expand Down
12 changes: 12 additions & 0 deletions client/graph/editor/update.gql
@@ -0,0 +1,12 @@
mutation ($id: Int!, $content: String, $description: String, $editor: String, $isPrivate: Boolean, $isPublished: Boolean, $locale: String, $path: String, $publishEndDate: Date, $publishStartDate: Date, $tags: [String], $title: String) {
pages {
update(id: $id, content: $content, description: $description, editor: $editor, isPrivate: $isPrivate, isPublished: $isPublished, locale: $locale, path: $path, publishEndDate: $publishEndDate, publishStartDate: $publishStartDate, tags: $tags, title: $title) {
responseResult {
succeeded
errorCode
slug
message
}
}
}
}
1 change: 1 addition & 0 deletions client/store/editor.js
@@ -1,6 +1,7 @@
import { make } from 'vuex-pathify'

const state = {
id: 0,
content: '',
description: '',
isPublished: true,
Expand Down
26 changes: 26 additions & 0 deletions server/db/migrations/2.0.0.js
Expand Up @@ -68,6 +68,19 @@ exports.up = knex => {
table.string('createdAt').notNullable()
table.string('updatedAt').notNullable()
})
// PAGE HISTORY ------------------------
.createTable('pageHistory', table => {
table.increments('id').primary()
table.string('path').notNullable()
table.string('title').notNullable()
table.string('description')
table.boolean('isPrivate').notNullable().defaultTo(false)
table.boolean('isPublished').notNullable().defaultTo(false)
table.string('publishStartDate')
table.string('publishEndDate')
table.text('content')
table.string('createdAt').notNullable()
})
// PAGES -------------------------------
.createTable('pages', table => {
table.increments('id').primary()
Expand Down Expand Up @@ -126,6 +139,12 @@ exports.up = knex => {
// =====================================
// RELATION TABLES
// =====================================
// PAGE HISTORY TAGS ---------------------------
.createTable('pageHistoryTags', table => {
table.increments('id').primary()
table.integer('pageId').unsigned().references('id').inTable('pageHistory').onDelete('CASCADE')
table.integer('tagId').unsigned().references('id').inTable('tags').onDelete('CASCADE')
})
// PAGE TAGS ---------------------------
.createTable('pageTags', table => {
table.increments('id').primary()
Expand All @@ -149,10 +168,17 @@ exports.up = knex => {
table.integer('pageId').unsigned().references('id').inTable('pages')
table.integer('authorId').unsigned().references('id').inTable('users')
})
.table('pageHistory', table => {
table.integer('pageId').unsigned().references('id').inTable('pages')
table.string('editorKey').references('key').inTable('editors')
table.string('localeCode', 2).references('code').inTable('locales')
table.integer('authorId').unsigned().references('id').inTable('users')
})
.table('pages', table => {
table.string('editorKey').references('key').inTable('editors')
table.string('localeCode', 2).references('code').inTable('locales')
table.integer('authorId').unsigned().references('id').inTable('users')
table.integer('creatorId').unsigned().references('id').inTable('users')
})
.table('users', table => {
table.string('providerKey').references('key').inTable('authentication').notNullable().defaultTo('local')
Expand Down

0 comments on commit 803d86f

Please sign in to comment.