Skip to content
This repository was archived by the owner on Mar 30, 2019. It is now read-only.

Commit f4a75fd

Browse files
authored
Merge pull request #7 from BlackMix/master
Novo recurso $comma() + Permission Store
2 parents e1f0cf4 + d94b620 commit f4a75fd

File tree

7 files changed

+73
-3
lines changed

7 files changed

+73
-3
lines changed

infra/store/schema/modules.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* Vuex modules
33
*/
44
import { store as auth } from 'genesis/modules/auth/index'
5+
import { store as permission } from 'genesis/modules/permission/index'
56
import { store as dashboard } from 'genesis/modules/dashboard/index'
67

78
export default {
8-
auth, dashboard
9+
auth, permission, dashboard
910
}

modules/permission/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as store } from 'genesis/modules/permission/store'

modules/permission/services/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import store from 'genesis/infra/store'
2+
import { promise } from 'genesis/support/utils'
3+
4+
/**
5+
* @param {Object} user
6+
* @param {Function} success
7+
* @returns {Promise}
8+
*/
9+
export const setPermissions = (permissions, success = () => ({})) => {
10+
return store.dispatch('setAuthPermission', permissions).then(success)
11+
}
12+
13+
/**
14+
* @param {Function} success
15+
* @returns {Promise}
16+
*/
17+
export const unPermissions = (success) => {
18+
return promise((resolve, reject) => {
19+
const solver = () => {
20+
success()
21+
resolve()
22+
}
23+
store
24+
.dispatch('setAuthPermission', undefined)
25+
.then(store.dispatch('setAppMenu', []).then(solver).catch(reject))
26+
.catch(reject)
27+
})
28+
}

modules/permission/store/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { APP_PERMISSIONS } from 'genesis/support/index'
2+
import { set } from 'genesis/infra/storage'
3+
4+
export const SET_PERMISSION = 'setAuthPermission'
5+
6+
const state = {
7+
permissions: undefined
8+
}
9+
10+
const getters = {
11+
getAuthPermission: (state) => state.permissions
12+
}
13+
14+
const actions = {
15+
setAuthPermission: (store, permissions) => {
16+
store.commit(SET_PERMISSION, permissions)
17+
set(APP_PERMISSIONS, permissions, false)
18+
}
19+
}
20+
21+
const mutations = {
22+
[SET_PERMISSION] (state, permissions) {
23+
state.permissions = permissions
24+
}
25+
}
26+
27+
export default {
28+
state,
29+
getters,
30+
actions,
31+
mutations
32+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "genesis",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "RAD dashboard tools using Quasar",
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
99
"author": "William Correa <wilcorrea@gmail.com>",
1010
"license": "MIT"
11-
}
11+
}

support/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export const APP_NAME = env.APP.NAME
99

1010
export const APP_USER = env.APP.USER
1111

12+
export const APP_PERMISSIONS = env.APP.PERMISSIONS
13+
1214
export const APP_TOKEN = env.APP.TOKEN
1315

1416
export const APP_REMEMBER = env.APP.REMEMBER

support/model/fields.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ export const standard = {
110110
}
111111
return this
112112
},
113+
$comma (key) {
114+
this.grid.format = (value) => {
115+
return value.map(c => c[key]).join(', ')
116+
}
117+
return this
118+
},
113119
$checkbox () {
114120
this.form.component = 'checkbox'
115121
this.grid.format = formatBoolean

0 commit comments

Comments
 (0)