Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add display settings[WTEL-3818] #527

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -169,6 +169,11 @@ const nav = Object.freeze([
locale: `WebitelApplications.${WebitelApplications.ADMIN}.sections.${AdminSections.CHANGELOGS}`,
route: 'changelogs',
},
{
value: AdminSections.SETTINGS,
locale: `WebitelApplications.${WebitelApplications.ADMIN}.sections.${AdminSections.SETTINGS}`,
route: 'settings',
},
],
},
]);
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 @@ -47,6 +47,7 @@ export default Object.freeze({

// SYSTEM
CHANGELOGS: 'changelogs',
SETTINGS: 'settings',

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

const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
Expand Down Expand Up @@ -577,6 +578,11 @@ const router = createRouter({
name: `${RouteNames.CHANGELOGS}-edit`,
component: OpenedChangelog,
},
{
path: '/system/settings',
name: RouteNames.SETTINGS,
component: OpenedSettings,
},
],
},
{
Expand Down
55 changes: 55 additions & 0 deletions src/modules/system/modules/settings/api/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
getDefaultGetListResponse,
getDefaultGetParams,
} from '@webitel/ui-sdk/src/api/defaults';
import applyTransform, {
merge, mergeEach, notify, snakeToCamel,
starToSearch,
} from '@webitel/ui-sdk/src/api/transformers';
import { SystemSettingServiceApiFactory } from 'webitel-sdk';
import instance from '../../../../../app/api/instance';
import configuration from '../../../../../app/api/openAPIConfig';

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

const getList = async (params = {}) => {
const {
page,
size,
search,
sort,
fields,
} = params;

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

const SettingsAPI = {
getList,
// get,
// add,
// update,
// delete: deleteItem,
};

export default SettingsAPI;
94 changes: 94 additions & 0 deletions src/modules/system/modules/settings/components/opened-settings.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<template>
<wt-page-wrapper
:actions-panel="false"
>
<template v-slot:header>
<wt-page-header
:primary-action="save"
:primary-text="saveText"
:hide-secondary="true"
>
<wt-headline-nav :path="path"></wt-headline-nav>
</wt-page-header>
</template>

<template v-slot:main>
<section>
<header class="content-header">
<h3 class="content-title">{{ $t('settings.settings') }}</h3>
<wt-icon-action
action="add"
@click="addSetting"
></wt-icon-action>
</header>
<div class="object-input-grid">
<div class="variables">
<div
class="value-pair"
v-for="(item, key) in itemInstance"
:key="key"
>
<wt-input
:value="item.name"
:placeholder="$t('objects.directory.users.varKey')"
@input="setSettingProp({index: key, prop: 'name', value: $event})"
></wt-input>
<wt-input
:value="item.value"
:placeholder="$t('objects.directory.users.varVal')"
@input="setSettingProp({index: key, prop: 'value', value: $event})"
></wt-input>
<wt-icon-action
action="delete"
class="value-pair__delete-button"
@click="deleteSetting(key)"
></wt-icon-action>
</div>
</div>
</div>
</section>
</template>

</wt-page-wrapper>
</template>

<script>
import getNamespacedState from '@webitel/ui-sdk/src/store/helpers/getNamespacedState';
import { mapActions, mapState } from 'vuex';

export default {
name: 'opened-settings',
data: () => ({
namespace: 'system/settings',
}),
computed: {
...mapState({
itemInstance(state) {
return getNamespacedState(state, this.namespace).itemInstance;
},
}),
path() {
return [
{ name: this.$t('objects.system.system') },
{ name: this.$t('settings.settings'), route: this.namespace },
];
},
},
methods: {
...mapActions({
loadSettings(dispatch, payload) {
return dispatch(`${this.namespace}/LOAD_SETTINGS`, payload);
},
setSettingProp(dispatch, payload) {
return dispatch(`${this.namespace}/SET_SETTING_PROPERTY`, payload);
},
addSetting(dispatch, payload) {
return dispatch(`${this.namespace}/ADD_SETTING`, payload);
},
}),
},
mounted() {
this.loadSettings();
},
};
</script>
45 changes: 45 additions & 0 deletions src/modules/system/modules/settings/store/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import SettingsAPI from '../api/settings';
import ObjectStoreModule from '../../../../../app/store/BaseStoreModules/StoreModules/ObjectStoreModule';

const resettableState = {
itemInstance: {
},
};

const actions = {
LOAD_SETTINGS: async (context, params) => {
const { items } = await SettingsAPI.getList(params);
context.commit('SET_SETTINGS', items);
},
SET_SETTING_PROPERTY: (context, { index, prop, value }) => {
context.commit('SET_SETTING_PROPERTY', { index, prop, value });
context.commit('SET_ITEM_PROPERTY', { prop: '_dirty', value: true });
},
ADD_SETTING: (context) => {
const pair = { name: '', value: '' };
context.commit('ADD_SETTING', pair);
context.commit('SET_ITEM_PROPERTY', { prop: '_dirty', value: true });
},
};

const mutations = {
SET_SETTINGS: (state, items) => {
state.itemInstance = items;
},
SET_SETTING_PROPERTY: (state, { index, prop, value }) => {
state.itemInstance[index][prop] = value;
},
SET_ITEM_PROPERTY: (state, { prop, value }) => {
state.itemInstance[prop] = value;
},
ADD_SETTING: (state, pair) => {
state.itemInstance.push(pair);
},
};

const settings = new ObjectStoreModule({ resettableState })
.attachAPIModule(SettingsAPI)
.generateAPIActions()
.getModule({ actions, mutations });

export default settings;
2 changes: 2 additions & 0 deletions src/modules/system/store/system.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import changelogs from '../modules/changelogs/store/changelogs';
import settings from '../modules/settings/store/settings';

export default {
namespaced: true,
modules: {
changelogs,
settings,
},
};