Skip to content

Commit

Permalink
Merge pull request #605 from webitel/feature/global-variables
Browse files Browse the repository at this point in the history
Feature/global variables [WTEL-4195]
  • Loading branch information
dlohvinov authored Feb 27, 2024
2 parents 40d8073 + bf1c951 commit b041e59
Show file tree
Hide file tree
Showing 16 changed files with 562 additions and 15 deletions.
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@vuelidate/validators": "^2.0.0",
"@vueuse/core": "^10.3.0",
"@webitel/flow-ui-sdk": "^0.1.14",
"@webitel/ui-sdk": "^24.2.44",
"@webitel/ui-sdk": "^24.2.52",
"axios": "^1.6.5",
"clipboard-copy": "^4.0.1",
"cron-validator": "^1.3.1",
Expand Down
5 changes: 5 additions & 0 deletions src/app/locale/en/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,11 @@ export default {
configuration: 'Configuration | Configurations',
parameter: 'Parameter',
},
globalVariables: {
globalVariables: 'Global variable | Global variables',
encrypted: 'Encrypted',
valueInfo: 'Enter value only if you want to edit',
},
},

pagination: {
Expand Down
5 changes: 5 additions & 0 deletions src/app/locale/ru/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,11 @@ export default {
configuration: 'Конфигурация | Конфигурации',
parameter: 'Параметр',
},
globalVariables: {
globalVariables: 'Глобальная переменная | Глобальные переменные',
encrypted: 'Зашифровано',
valueInfo: 'Введите значение, если хотите перезаписать его',
},
},
pagination: {
rowsPerPage: 'Количество строк на странице',
Expand Down
5 changes: 5 additions & 0 deletions src/app/locale/ua/ua.js
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,11 @@ export default {
configuration: 'Конфігурація | Конфігурації',
parameter: 'Параметр',
},
globalVariables: {
globalVariables: 'Глобальна змінна | Глобальні змінні',
encrypted: 'Зашифровано',
valueInfo: 'Введіть значення, якщо хочете перезаписати його',
},
},
pagination: {
rowsPerPage: 'Кількість записів',
Expand Down
5 changes: 5 additions & 0 deletions src/app/router/_internals/NavigationPages.lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ const nav = Object.freeze([
locale: `WebitelApplications.${WebitelApplications.ADMIN}.sections.${AdminSections.CONFIGURATION}`,
route: 'configuration',
},
{
value: AdminSections.GLOBAL_VARIABLES,
locale: `WebitelApplications.${WebitelApplications.ADMIN}.sections.${AdminSections.GLOBAL_VARIABLES}`,
route: 'global-variables',
},
],
},
]);
Expand Down
1 change: 1 addition & 0 deletions src/app/router/_internals/RouteNames.enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default Object.freeze({
// SYSTEM
CHANGELOGS: 'changelogs',
CONFIGURATION: 'configuration',
GLOBAL_VARIABLES: 'global-variables',

SETTINGS_PAGE: 'settings',
PAGE_403: 'access-denied',
Expand Down
8 changes: 8 additions & 0 deletions src/app/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const OpenedTrigger = () => import('../../modules/integrations/modules/triggers/
const Changelogs = () => import('../../modules/system/modules/changelogs/components/the-changelogs.vue');
const OpenedChangelog = () => import('../../modules/system/modules/changelogs/components/opened-changelog.vue');
const Configuration = () => import('../../modules/system/modules/configuration/components/the-configuration.vue');
const GlobalVariables = () => import('../../modules/system/modules/global-variables/components/the-global-variables.vue');

const checkAppAccess = (to, from, next) => {
const hasReadAccess = store.getters['userinfo/CHECK_APP_ACCESS'](store.getters['userinfo/THIS_APP']);
Expand Down Expand Up @@ -714,6 +715,13 @@ const router = createRouter({
component: Configuration,
beforeEnter: checkRouteAccess,
},

{
path: '/system/global-variables',
name: RouteNames.GLOBAL_VARIABLES,
component: GlobalVariables,
beforeEnter: checkRouteAccess,
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class ObjectStoreModule extends BaseStoreModule {
actions = {
...BaseTableModule.getActions(),
...BaseOpenedInstanceModule.getActions(),

// https://webitel.atlassian.net/browse/WTEL-4195
ADD_ITEM: async (context) => {
if (!context.state.itemId) {
const { id } = await context.dispatch('POST_ITEM');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ConfigurationAPI from '../api/configuration';
import headers from './_internals/headers';

const actions = {
// https://webitel.atlassian.net/browse/WTEL-4195
ADD_ITEM: async (context) => {
if (!context.state.itemId) {
const { id } = await context.dispatch('POST_ITEM');
Expand Down
147 changes: 147 additions & 0 deletions src/modules/system/modules/global-variables/api/global-variables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import {
getDefaultGetListResponse,
getDefaultGetParams,
} from '@webitel/ui-sdk/src/api/defaults';
import applyTransform, {
camelToSnake,
merge,
notify,
sanitize,
snakeToCamel,
starToSearch,
} from '@webitel/ui-sdk/src/api/transformers';
import { SchemaVariablesServiceApiFactory } from 'webitel-sdk';
import instance from '../../../../../app/api/instance';
import configuration from '../../../../../app/api/openAPIConfig';

const service = new SchemaVariablesServiceApiFactory(configuration, '', instance);

const getList = async (params) => {
const {
page,
size,
search,
sort,
fields,
} = applyTransform(params, [
merge(getDefaultGetParams()),
starToSearch('search'),
]);

try {
const response = await service.searchSchemaVariable(
page,
size,
search,
sort,
fields,
);
const { items, next } = applyTransform(response.data, [
snakeToCamel(),
merge(getDefaultGetListResponse()),
]);
return {
items,
next,
};
} catch (err) {
throw applyTransform(err, [
notify,
]);
}
};

const get = async ({ itemId: id }) => {
try {
const response = await service.readSchemaVariable(id);
return applyTransform(response.data, [
snakeToCamel(),
]);
} catch (err) {
throw applyTransform(err, [
notify,
]);
}
};

const fieldsToSend = ['id', 'name', 'value', 'encrypt'];

const add = async ({itemInstance}) => {
const item = applyTransform(itemInstance, [
sanitize(fieldsToSend),
camelToSnake(),
]);
try {
const response = await service.createSchemaVariable(item);
return applyTransform(response.data, [
snakeToCamel(),
]);
} catch (err) {
throw applyTransform(err, [
notify,
]);
}
};

const update = async ({ itemInstance, itemId: id }) => {
const item = applyTransform(itemInstance, [
sanitize(fieldsToSend),
camelToSnake(),
]);
try {
const response = await service.updateSchemaVariable(id, item);
return applyTransform(response.data, [
snakeToCamel(),
]);
} catch (err) {
throw applyTransform(err, [
notify,
]);
}
};

const patch = async ({ id, changes }) => {
const body = applyTransform(changes, [
sanitize(fieldsToSend),
camelToSnake(),
]);
try {
const response = await service.patchSchemaVariable(id, body);
return applyTransform(response.data, [
snakeToCamel(),
]);
} catch (err) {
throw applyTransform(err, [
notify,
]);
}
};

const deleteItem = async ({ id }) => {
try {
const response = await service.deleteSchemaVariable(id);
return applyTransform(response.data, []);
} catch (err) {
throw applyTransform(err, [
notify,
]);
}
};

const getLookup = (params) => getList({
...params,
fields: params.fields || ['id', 'name'],
});


const GlobalVariablesAPI = {
getList,
get,
add,
update,
patch,
delete: deleteItem,
getLookup,
};

export default GlobalVariablesAPI;
Loading

0 comments on commit b041e59

Please sign in to comment.