@tager/admin-blog 0.3.31 → 0.3.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/hooks/index.d.ts +0 -3
  2. package/dist/index.esm.js +120 -206
  3. package/dist/index.umd.js +119 -206
  4. package/dist/locales/en.d.ts +1 -0
  5. package/dist/services/requests.d.ts +2 -3
  6. package/dist/typings/model.d.ts +2 -16
  7. package/dist/utils/common.d.ts +0 -2
  8. package/dist/views/Categories/CategoryForm/CategoryForm.helpers.d.ts +3 -1
  9. package/dist/views/Categories/CategoryForm/CategoryForm.vue.d.ts +25 -20
  10. package/dist/views/Categories/CategoryList/CategoryList.helpers.d.ts +1 -1
  11. package/dist/views/Categories/CategoryList/CategoryList.vue.d.ts +0 -2
  12. package/dist/views/Posts/PostList/PostList.helpers.d.ts +1 -1
  13. package/dist/views/Posts/PostList/PostList.vue.d.ts +0 -2
  14. package/package.json +2 -4
  15. package/src/dev.ts +0 -4
  16. package/src/hooks/index.ts +0 -3
  17. package/src/locales/en.ts +1 -0
  18. package/src/locales/ru.ts +1 -0
  19. package/src/services/requests.ts +1 -6
  20. package/src/typings/model.ts +2 -21
  21. package/src/utils/common.ts +0 -10
  22. package/src/views/App.vue +1 -9
  23. package/src/views/Categories/CategoryForm/CategoryForm.helpers.ts +24 -4
  24. package/src/views/Categories/CategoryForm/CategoryForm.vue +39 -13
  25. package/src/views/Categories/CategoryList/CategoryList.helpers.ts +9 -12
  26. package/src/views/Categories/CategoryList/CategoryList.vue +8 -25
  27. package/src/views/Posts/PostForm/PostForm.vue +1 -1
  28. package/src/views/Posts/PostList/PostList.helpers.ts +8 -11
  29. package/src/views/Posts/PostList/PostList.vue +9 -30
  30. package/dist/constants/scopes.d.ts +0 -11
  31. package/dist/hooks/useStore.d.ts +0 -4
  32. package/dist/hooks/useUserPermission.d.ts +0 -3
  33. package/dist/hooks/useUserProfile.d.ts +0 -3
  34. package/dist/store/index.d.ts +0 -6
  35. package/dist/store/user.d.ts +0 -14
  36. package/src/constants/scopes.ts +0 -11
  37. package/src/hooks/useStore.ts +0 -8
  38. package/src/hooks/useUserPermission.ts +0 -16
  39. package/src/hooks/useUserProfile.ts +0 -13
  40. package/src/store/index.ts +0 -21
  41. package/src/store/user.ts +0 -110
@@ -1,16 +1,12 @@
1
1
  <template>
2
2
  <page
3
3
  :title="$t('blog:blogCategories')"
4
- :header-buttons="
5
- [
6
- canViewAdministrators
7
- ? {
8
- text: $t('blog:newCategory'),
9
- href: getBlogCategoryFormUrl({ categoryId: 'create' }),
10
- }
11
- : null,
12
- ].filter(Boolean)
13
- "
4
+ :header-buttons="[
5
+ {
6
+ text: $t('blog:newCategory'),
7
+ href: getBlogCategoryFormUrl({ categoryId: 'create' }),
8
+ },
9
+ ]"
14
10
  >
15
11
  <template v-slot:content>
16
12
  <data-table
@@ -102,7 +98,7 @@ import isEqual from 'lodash.isequal';
102
98
  import { useResourceDelete } from '@tager/admin-services';
103
99
  import { useDataTable } from '@tager/admin-ui';
104
100
 
105
- import { useFetchModuleConfig, useUserPermission } from '../../../hooks';
101
+ import { useFetchModuleConfig } from '../../../hooks';
106
102
  import { getBlogCategoryFormUrl } from '../../../constants/paths';
107
103
  import {
108
104
  deleteCategory,
@@ -110,7 +106,6 @@ import {
110
106
  moveCategory,
111
107
  } from '../../../services/requests';
112
108
  import { Category, Language } from '../../../typings/model';
113
- import { Scope } from '../../../constants/scopes';
114
109
 
115
110
  import {
116
111
  convertCategoryList,
@@ -122,11 +117,6 @@ import { useAdvancedSearch } from './hooks';
122
117
  export default defineComponent({
123
118
  name: 'BlogCategoryList',
124
119
  setup(props, context) {
125
- const canViewAdministrators = useUserPermission(
126
- context,
127
- Scope.AdministratorsView
128
- );
129
-
130
120
  /** Fetch module config **/
131
121
 
132
122
  const {
@@ -232,11 +222,7 @@ export default defineComponent({
232
222
  );
233
223
 
234
224
  const columnDefs = computed(() =>
235
- getCategoryTableColumnDefs(
236
- moduleConfig.value,
237
- context.root.$t,
238
- canViewAdministrators.value
239
- )
225
+ getCategoryTableColumnDefs(moduleConfig.value, context.root.$t)
240
226
  );
241
227
 
242
228
  return {
@@ -262,9 +248,6 @@ export default defineComponent({
262
248
  languageOptionList,
263
249
  tags,
264
250
  tagRemovalHandler,
265
-
266
- // Permissions
267
- canViewAdministrators,
268
251
  };
269
252
  },
270
253
  });
@@ -530,7 +530,7 @@ export default defineComponent({
530
530
  const newSelectedOptions: OptionType<number>[] = [];
531
531
 
532
532
  selectedOptions.forEach((selectedOption) => {
533
- const findTreeSelectedCategory = (categoryId: number) => {
533
+ const findTreeSelectedCategory = (categoryId: Nullable<number>) => {
534
534
  const foundSelectedCategory = categoryList.value.find(
535
535
  ({ id }) => id === categoryId
536
536
  );
@@ -38,8 +38,7 @@ export function convertPostList(
38
38
 
39
39
  export function getPostTableColumnDefs(
40
40
  moduleConfig: Nullable<ModuleConfig>,
41
- t: TFunction,
42
- canViewAdministrators: boolean
41
+ t: TFunction
43
42
  ): ColumnDefinition<PostShort>[] {
44
43
  const isLangSpecific = moduleConfig
45
44
  ? moduleConfig.languages.length > 0
@@ -91,15 +90,13 @@ export function getPostTableColumnDefs(
91
90
  format: ({ row }) =>
92
91
  row.categories.map((category) => category.name).join(', '),
93
92
  },
94
- canViewAdministrators
95
- ? {
96
- id: 7,
97
- name: t('blog:actions'),
98
- field: 'actions',
99
- style: { whiteSpace: 'nowrap', width: '120px' },
100
- headStyle: { whiteSpace: 'nowrap', width: '120px' },
101
- }
102
- : null,
93
+ {
94
+ id: 7,
95
+ name: t('blog:actions'),
96
+ field: 'actions',
97
+ style: { whiteSpace: 'nowrap', width: '120px' },
98
+ headStyle: { whiteSpace: 'nowrap', width: '120px' },
99
+ },
103
100
  ];
104
101
 
105
102
  return COLUMN_DEFS.filter(notEmpty);
@@ -1,16 +1,12 @@
1
1
  <template>
2
2
  <page
3
3
  :title="pageTitle"
4
- :header-buttons="
5
- [
6
- canViewAdministrators
7
- ? {
8
- text: $t('blog:newPost'),
9
- href: getBlogPostFormUrl({ postId: 'create' }),
10
- }
11
- : null,
12
- ].filter(Boolean)
13
- "
4
+ :header-buttons="[
5
+ {
6
+ text: $t('blog:newPost'),
7
+ href: getBlogPostFormUrl({ postId: 'create' }),
8
+ },
9
+ ]"
14
10
  >
15
11
  <template v-slot:content>
16
12
  <data-table
@@ -126,12 +122,7 @@ import {
126
122
  useResourceDelete,
127
123
  } from '@tager/admin-services';
128
124
 
129
- import { Scope } from '../../../constants/scopes';
130
- import {
131
- useFetchModuleConfig,
132
- useFetchCategories,
133
- useUserPermission,
134
- } from '../../../hooks';
125
+ import { useFetchModuleConfig, useFetchCategories } from '../../../hooks';
135
126
  import {
136
127
  clonePost,
137
128
  deleteBlogPost,
@@ -153,11 +144,6 @@ export default defineComponent({
153
144
  setup(props, context) {
154
145
  const { t } = useTranslation(context);
155
146
 
156
- const canViewAdministrators = useUserPermission(
157
- context,
158
- Scope.AdministratorsView
159
- );
160
-
161
147
  const categoryId = computed<string>(() => {
162
148
  return Array.isArray(context.root.$route.query.category)
163
149
  ? context.root.$route.query.category[0] ?? ''
@@ -289,7 +275,7 @@ export default defineComponent({
289
275
  confirmMessage: t('blog:cloneConfirm'),
290
276
  successMessage: t('blog:cloneSuccess'),
291
277
  failureMessage: t('blog:cloneFailure'),
292
- onSuccessRedirectTo: (data: PostFull) => `/posts/${data.id}`,
278
+ onSuccessRedirectTo: (data: PostFull) => `/blog/posts/${data.id}`,
293
279
  context,
294
280
  });
295
281
 
@@ -298,11 +284,7 @@ export default defineComponent({
298
284
  }
299
285
 
300
286
  const columnDefs = computed<ColumnDefinition<PostShort>[]>(() =>
301
- getPostTableColumnDefs(
302
- moduleConfig.value,
303
- context.root.$t,
304
- canViewAdministrators.value
305
- )
287
+ getPostTableColumnDefs(moduleConfig.value, context.root.$t)
306
288
  );
307
289
 
308
290
  return {
@@ -332,9 +314,6 @@ export default defineComponent({
332
314
  tags,
333
315
  tagRemovalHandler,
334
316
 
335
- // Permissions
336
- canViewAdministrators,
337
-
338
317
  // Clone
339
318
  handleResourceClone,
340
319
  isBusy,
@@ -1,11 +0,0 @@
1
- export declare const Scope: {
2
- readonly All: "*";
3
- readonly OrdersCreate: "orders.create";
4
- readonly OrdersView: "orders.view";
5
- readonly OrdersDelete: "orders.delete";
6
- readonly RbacViewRoles: "rbac.view-roles";
7
- readonly RbacEditRoles: "rbac.edit-roles";
8
- readonly AdministratorsView: "administrators.view";
9
- readonly AdministratorsEdit: "administrators.edit";
10
- readonly AdministratorsDelete: "administrators.delete";
11
- };
@@ -1,4 +0,0 @@
1
- import { Store } from 'vuex';
2
- import { SetupContext } from '@vue/composition-api';
3
- import { RootState } from '../store';
4
- export declare function useStore(context: SetupContext): Store<RootState>;
@@ -1,3 +0,0 @@
1
- import { ComputedRef, SetupContext } from '@vue/composition-api';
2
- import { ScopeType } from '../typings/model';
3
- export declare function useUserPermission(context: SetupContext, scope: ScopeType): ComputedRef<boolean>;
@@ -1,3 +0,0 @@
1
- import { ComputedRef, SetupContext } from '@vue/composition-api';
2
- import { UserModel } from '../typings/model';
3
- export declare function useUserProfile(context: SetupContext): ComputedRef<UserModel>;
@@ -1,6 +0,0 @@
1
- import { UserModuleStateModel } from '../store/user';
2
- export interface RootState {
3
- user: UserModuleStateModel;
4
- }
5
- declare const store: import("vuex").Store<RootState>;
6
- export default store;
@@ -1,14 +0,0 @@
1
- import { Module } from 'vuex';
2
- import { FetchStatus } from '@tager/admin-services';
3
- import { UserModel } from '../typings/model';
4
- import { RootState } from './index';
5
- export interface UserModuleStateModel {
6
- profile: UserModel | null;
7
- status: FetchStatus;
8
- }
9
- export declare const USER_MODULE_NAMESPACE = "user";
10
- export declare const USER_ACTION_TYPES: {
11
- readonly FETCH_USER_PROFILE: "fetchUserProfile";
12
- };
13
- declare const userModule: Module<UserModuleStateModel, RootState>;
14
- export default userModule;
@@ -1,11 +0,0 @@
1
- export const Scope = {
2
- All: '*',
3
- OrdersCreate: 'orders.create',
4
- OrdersView: 'orders.view',
5
- OrdersDelete: 'orders.delete',
6
- RbacViewRoles: 'rbac.view-roles',
7
- RbacEditRoles: 'rbac.edit-roles',
8
- AdministratorsView: 'administrators.view',
9
- AdministratorsEdit: 'administrators.edit',
10
- AdministratorsDelete: 'administrators.delete',
11
- } as const;
@@ -1,8 +0,0 @@
1
- import { Store } from 'vuex';
2
- import { SetupContext } from '@vue/composition-api';
3
-
4
- import { RootState } from '../store';
5
-
6
- export function useStore(context: SetupContext): Store<RootState> {
7
- return context.root.$store;
8
- }
@@ -1,16 +0,0 @@
1
- import { computed, ComputedRef, SetupContext } from '@vue/composition-api';
2
-
3
- import { ScopeType } from '../typings/model';
4
- import { useStore } from '../hooks';
5
- import { userNamespace } from '../utils/common';
6
-
7
- export function useUserPermission(
8
- context: SetupContext,
9
- scope: ScopeType
10
- ): ComputedRef<boolean> {
11
- const store = useStore(context);
12
-
13
- return computed<boolean>(() => {
14
- return store.getters[userNamespace('userHasPermission')](scope);
15
- });
16
- }
@@ -1,13 +0,0 @@
1
- import { computed, ComputedRef, SetupContext } from '@vue/composition-api';
2
-
3
- import { UserModel } from '../typings/model';
4
- import { useStore } from '../hooks';
5
- import { userNamespace } from '../utils/common';
6
-
7
- export function useUserProfile(context: SetupContext): ComputedRef<UserModel> {
8
- const store = useStore(context);
9
-
10
- return computed<UserModel>(() => {
11
- return store.getters[userNamespace('userProfile')];
12
- });
13
- }
@@ -1,21 +0,0 @@
1
- import Vue from 'vue';
2
- import Vuex from 'vuex';
3
-
4
- import userModule, {
5
- USER_MODULE_NAMESPACE,
6
- UserModuleStateModel,
7
- } from '../store/user';
8
-
9
- Vue.use(Vuex);
10
-
11
- export interface RootState {
12
- user: UserModuleStateModel;
13
- }
14
-
15
- const store = new Vuex.Store({
16
- modules: {
17
- [USER_MODULE_NAMESPACE]: userModule,
18
- },
19
- });
20
-
21
- export default store;
package/src/store/user.ts DELETED
@@ -1,110 +0,0 @@
1
- import { GetterTree, Module } from 'vuex';
2
-
3
- import { FETCH_STATUSES, FetchStatus } from '@tager/admin-services';
4
-
5
- import { ScopeType, UserModel } from '../typings/model';
6
- import { getUserProfile } from '../services/requests';
7
- import { Scope } from '../constants/scopes';
8
-
9
- import { RootState } from './index';
10
-
11
- export interface UserModuleStateModel {
12
- profile: UserModel | null;
13
- status: FetchStatus;
14
- }
15
-
16
- export const USER_MODULE_NAMESPACE = 'user';
17
-
18
- const USER_MUTATION_TYPES = {
19
- PROFILE_REQUEST_STARTED: 'profileRequestStarted',
20
- PROFILE_REQUEST_FULFILLED: 'profileRequestFulfilled',
21
- PROFILE_REQUEST_REJECTED: 'profileRequestRejected',
22
- };
23
-
24
- export const USER_ACTION_TYPES = {
25
- FETCH_USER_PROFILE: 'fetchUserProfile',
26
- } as const;
27
-
28
- type ReturnValueMapType<
29
- T extends { [key: string]: (...args: any[]) => any }
30
- > = { [key in keyof T]: ReturnType<T[key]> };
31
-
32
- interface UserGettersType extends GetterTree<UserModuleStateModel, RootState> {
33
- userScopes: (state: UserModuleStateModel) => Array<ScopeType>;
34
- userHasPermission: (
35
- state: UserModuleStateModel,
36
- getters: ReturnValueMapType<UserGettersType>
37
- ) => (scope: ScopeType) => boolean;
38
- }
39
-
40
- const userGetters: UserGettersType = {
41
- userProfile(state) {
42
- return state.profile;
43
- },
44
- userScopes(state) {
45
- const roles = state.profile ? state.profile.roles : [];
46
- const scopes: Array<ScopeType> = [];
47
-
48
- roles.forEach((role) => {
49
- scopes.push(...role.scopes);
50
- });
51
-
52
- return scopes;
53
- },
54
- userHasPermission: (state, getters) => (scope: ScopeType) => {
55
- const scopes = getters.userScopes;
56
-
57
- if (scopes.includes(Scope.All)) return true;
58
-
59
- return scopes.includes(scope);
60
- },
61
- };
62
-
63
- const userModule: Module<UserModuleStateModel, RootState> = {
64
- namespaced: true,
65
- state: {
66
- profile: null,
67
- status: FETCH_STATUSES.IDLE,
68
- },
69
- mutations: {
70
- [USER_MUTATION_TYPES.PROFILE_REQUEST_STARTED](state) {
71
- if (state.status === FETCH_STATUSES.IDLE) {
72
- state.status = FETCH_STATUSES.LOADING;
73
- }
74
- },
75
- [USER_MUTATION_TYPES.PROFILE_REQUEST_FULFILLED](state, user: UserModel) {
76
- if (state.status === FETCH_STATUSES.LOADING) {
77
- state.status = FETCH_STATUSES.SUCCESS;
78
- state.profile = user;
79
- }
80
- },
81
- [USER_MUTATION_TYPES.PROFILE_REQUEST_REJECTED](state) {
82
- if (state.status === FETCH_STATUSES.LOADING) {
83
- state.status = FETCH_STATUSES.FAILURE;
84
- state.profile = null;
85
- }
86
- },
87
- },
88
- actions: {
89
- [USER_ACTION_TYPES.FETCH_USER_PROFILE](store) {
90
- if (store.state.status !== FETCH_STATUSES.IDLE) return;
91
-
92
- store.commit(USER_MUTATION_TYPES.PROFILE_REQUEST_STARTED);
93
-
94
- getUserProfile()
95
- .then((response) => {
96
- store.commit(
97
- USER_MUTATION_TYPES.PROFILE_REQUEST_FULFILLED,
98
- response.data
99
- );
100
- })
101
- .catch((error) => {
102
- console.error(error);
103
- store.commit(USER_MUTATION_TYPES.PROFILE_REQUEST_REJECTED);
104
- });
105
- },
106
- },
107
- getters: userGetters,
108
- };
109
-
110
- export default userModule;