Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #40 from wilcorrea-forks/master
Browse files Browse the repository at this point in the history
#4 Create more examples with more components, including examples with local components
  • Loading branch information
wilcorrea authored Mar 29, 2019
2 parents 08430d8 + f13c44c commit 03b73d0
Show file tree
Hide file tree
Showing 18 changed files with 263 additions and 125 deletions.
1 change: 1 addition & 0 deletions quasar.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ module.exports = function (context) {
'QCheckbox',
'QSelect',
'QRadio',
'QOptionGroup',
'QCard',
'QCardSection',
'QCardActions',
Expand Down
4 changes: 2 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/>
<router-view />
<a
class="github-fork-ribbon left-bottom fixed"
class="github-fork-ribbon left-top fixed"
href="https://github.com/xprototype/skeleton-quasar"
data-ribbon="Fork me on GitHub"
title="Fork me on GitHub"
Expand All @@ -25,6 +25,6 @@ export default {
lang="stylus"
scoped
>
.github-fork-ribbon.left-bottom:before
.github-fork-ribbon.left-top:before
background-color #333
</style>
32 changes: 32 additions & 0 deletions src/app/Prototype/Base.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-underscore-dangle */
import components from 'src/config/app/components'
import { apply } from 'src/app/Util'

/**
* @typedef {Base}
Expand Down Expand Up @@ -74,6 +75,11 @@ export default class Base {
*/
static mixins = []

/**
* @type {boolean}
*/
i18n = true

/**
* @param {Object} options
* @returns {this}
Expand All @@ -91,7 +97,10 @@ export default class Base {
this.__actions = {}
this.__sections = {}

this.__loaded = {}

this.init()
this.locale()

if (this.defaults && typeof this.defaults === 'function') {
this.defaults()
Expand All @@ -111,6 +120,29 @@ export default class Base {
this.constructor.mixins.forEach(mixin => this.mixin(mixin))
}

/**
*/
locale () {
if (!this.i18n) {
return
}
this.namespace = this.constructor.domain.replace(/\//, '.')
const map = (piece) => piece.charAt(0).toUpperCase() + piece.substring(1)
const domain = this.namespace.split('.').map(map).join('/')

const locale = window.app.i18n.locale
const path = `src/domains/${domain}/${locale}`
if (this.__loaded[path]) {
return
}
this.__loaded[path] = true

const messages = require(`src/domains/${domain}/${locale}`)
const translations = apply({}, `domains.${this.namespace}`, messages.default)

window.app.i18n.mergeLocaleMessage(locale, translations)
}

/**
* @param {Object} mixin
*/
Expand Down
5 changes: 1 addition & 4 deletions src/app/Prototype/Components/Form/PrototypeComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ export default {
const key = field.$key

const error = this.fieldHasError(key)
const style = {
display: field.$layout.formHidden ? 'none' : ''
}
const data = {
key: key,
class: this.fieldClass(field.$layout.formWidth, field.$layout.formHeight, error),
domProps: { style }
style: { display: field.$layout.formHidden ? 'none' : '' }
}

const children = [
Expand Down
13 changes: 13 additions & 0 deletions src/app/Prototype/Contracts/Basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ export default {
getFieldLayout () {
// will override by specialists
},
/**
* @param {string} property
* @param {*} value
*/
setRecord (property, value) {
// will override by specialists
},
/**
* @param {string} property
*/
getRecord (property) {
// will override by specialists
},
/**
* @param {Function} h
* @param {string} position
Expand Down
9 changes: 9 additions & 0 deletions src/app/Prototype/Contracts/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ export default {
return action
})
}

const label = this.$lang([
`domains.${this.domain}.actions.${button.$key}.label`,
`prototype.actions.${button.$key}.label`
])
if (label) {
button.attrs.label = label
}

buttons[button.$key] = button
return buttons
},
Expand Down
10 changes: 10 additions & 0 deletions src/app/Prototype/Contracts/Form/FormComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ export default {
field.attrs.after = this.parseFieldAfter(field)
}

if (field.attrs.label) {
field.attrs.label = this.$lang(
[
`domains.${this.domain}.fields.${field.$key}.${field.attrs.label}`,
`domains.${this.domain}.${field.attrs.label}`,
field.attrs.label
],
field.attrs.label
)
}
if (!field.parseInput) {
field.parseInput = (value) => value
}
Expand Down
14 changes: 14 additions & 0 deletions src/app/Prototype/Contracts/Form/FormField.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ const FormField = {
getFieldLayout (component, attr) {
return this.getFieldLayouts(component)[attr]
},
/**
* @param {string} property
* @param {*} value
*/
setRecord (property, value) {
this.record[property] = value
return this
},
/**
* @param {string} property
*/
getRecord (property) {
return this.record[property]
},
/**
* @param {string} component
* @param {Boolean} error
Expand Down
92 changes: 26 additions & 66 deletions src/app/Prototype/Prototype.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-underscore-dangle */
import Skeleton from './Skeleton'
import { lang } from 'src/app/Util/Lang'
import { apply } from 'src/app/Util'

import Field from 'src/app/Prototype/Prototype/Field'
import FieldForm from 'src/app/Prototype/Prototype/FieldForm'
Expand All @@ -18,28 +17,6 @@ export default class Prototype extends Skeleton {
*/
static mixins = [Field, FieldForm, FieldIs, FieldTable, Action]

/**
* @type {boolean}
*/
i18n = true

/**
* @param {Function} callback
*/
locale (callback = undefined) {
this.namespace = this.domain.replace(/\//, '.')
const map = (piece) => piece.charAt(0).toUpperCase() + piece.substring(1)
const domain = this.namespace.split('.').map(map).join('/')
const locale = this.$i18n.locale

import(/* webpackChunkName: "lang-[request]" */ `src/domains/${domain}/${locale}`)
.then((messages) => {
const translations = apply({}, `domains.${this.namespace}`, messages.default)
this.$i18n.mergeLocaleMessage(locale, translations)
})
.finally(callback)
}

/**
* @param {String|Array} key
* @param {string} [fallback]
Expand Down Expand Up @@ -81,7 +58,7 @@ export default class Prototype extends Skeleton {
*/
configureView () {
Object.keys(this.components).forEach(key => {
this.setFieldAttrs(key, { readonly: true })
this.setFieldAttrs(key, { readonly: true, disable: true })
})
this.fetchRecord(this.$route.params[this.primaryKey])
}
Expand Down Expand Up @@ -150,7 +127,7 @@ export default class Prototype extends Skeleton {
if (this.debuggers) {
window.alert(JSON.stringify(response))
}
this.$message.success(this.$lang(`prototype.operation.${scope}.success`))
this.$message.success(this.$lang(`prototype.operations.${scope}.success`))
if (scope === 'create') {
this.$browse(`${this.path}/${response[this.primaryKey]}/edit`, true)
}
Expand All @@ -167,66 +144,53 @@ export default class Prototype extends Skeleton {
const prototype = this

this.hook('created:default', function () {
/**
*/
const run = () => {
// Call component setup method
if (this.setup && typeof this.setup === 'function') {
this.setup()
}

// Call global prototype configure
prototype.configure.call(this)
// Call component setup method
if (this.setup && typeof this.setup === 'function') {
this.setup()
}

// Call configure of each field
this.configure()
// Call global prototype configure
prototype.configure.call(this)

if (this.scope === 'index') {
// Call configure to index scope
return prototype.configureIndex.call(this)
}
// Call configure of each field
this.configure()

if (this.scope === 'update') {
// Call configure to update scope
return prototype.configureEdit.call(this)
}
if (this.scope === 'index') {
// Call configure to index scope
return prototype.configureIndex.call(this)
}

if (this.scope === 'read') {
// Call configure to read scope
return prototype.configureView.call(this)
}
if (this.scope === 'update') {
// Call configure to update scope
return prototype.configureEdit.call(this)
}

if (this.scope === 'create') {
// Call configure to create scope
return prototype.configureAdd.call(this)
}
if (this.scope === 'read') {
// Call configure to read scope
return prototype.configureView.call(this)
}
// load i18n async
if (prototype.i18n) {
prototype.locale.call(this, run)
return

if (this.scope === 'create') {
// Call configure to create scope
return prototype.configureAdd.call(this)
}
run()
})

this.action('add')
.actionScopes(['index'])
.actionPositions(['table-top'])
.actionLabel(this.$lang('prototype.action.add.label'))
.actionIcon('add')
.actionColor('primary')

this.action('back')
.actionScopes(['index', 'create', 'read', 'update'])
.actionPositions(['form-footer'])
.actionLabel(this.$lang('prototype.action.back.label'))
.actionIcon('reply')

this.action('cancel')
.actionFloatRight()
.actionScopes(['index', 'create', 'read', 'update'])
.actionPositions(['form-footer'])
.actionLabel(this.$lang('prototype.action.cancel.label'))
.actionIcon('close')

this.action('refresh')
Expand All @@ -240,13 +204,12 @@ export default class Prototype extends Skeleton {
.actionScopes(['create', 'update'])
.actionPositions(['form-footer'])
.actionFloatRight()
.actionLabel(this.$lang('prototype.action.save.label'))
.actionIcon('save')
.actionColor('primary')
.actionOn('click', function () {
this.$v.$touch()
if (this.$v.$error || this.hasErrors) {
this.$message.error(this.$lang('prototype.action.save.validation'))
this.$message.error('prototype.actions.save.validation')
return
}
if (this.debuggers) {
Expand All @@ -258,20 +221,17 @@ export default class Prototype extends Skeleton {
this.action('view')
.actionScopes(['index'])
.actionPositions(['table-top', 'table-cell'])
.actionLabel(this.$lang('prototype.action.view.label'))
.actionIcon('visibility')

this.action('edit')
.actionScopes(['index'])
.actionPositions(['table-top', 'table-cell'])
.actionLabel(this.$lang('prototype.action.edit.label'))
.actionColor('primary')
.actionIcon('edit')

this.action('destroy')
.actionScopes(['index'])
.actionPositions(['table-top', 'table-cell'])
.actionLabel(this.$lang('prototype.action.destroy.label'))
.actionColor('negative')
.actionIcon('delete')
}
Expand Down
Loading

0 comments on commit 03b73d0

Please sign in to comment.