-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from webitel/feature/sources-page
feature/add-sources-page
- Loading branch information
Showing
14 changed files
with
709 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
src/modules/configuration/modules/lookups/modules/sources/api/sources.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import { | ||
getDefaultGetListResponse, | ||
getDefaultGetParams, | ||
getDefaultInstance, | ||
getDefaultOpenAPIConfig, | ||
} from '@webitel/ui-sdk/src/api/defaults/index.js'; | ||
import applyTransform, { | ||
camelToSnake, | ||
merge, | ||
notify, | ||
sanitize, | ||
snakeToCamel, | ||
starToSearch, | ||
} from '@webitel/ui-sdk/src/api/transformers/index.js'; | ||
import { SourcesApiFactory } from 'webitel-sdk'; | ||
|
||
const instance = getDefaultInstance(); | ||
const configuration = getDefaultOpenAPIConfig(); | ||
|
||
const sourceService = new SourcesApiFactory(configuration, '', instance); | ||
|
||
const fieldsToSend = ['name', 'description', 'type']; | ||
|
||
const getSourcesList = async (params) => { | ||
const fieldsToSend = ['page', 'size', 'q', 'sort', 'fields', 'id']; | ||
|
||
const listResponseHandler = (items) => { | ||
return items.map((item) => ({ | ||
...item, | ||
type: item.type.toLowerCase(), | ||
})); | ||
}; | ||
|
||
const { | ||
page, | ||
size, | ||
fields, | ||
sort, | ||
id, | ||
q, | ||
type, | ||
} = applyTransform(params, [ | ||
merge(getDefaultGetParams()), | ||
starToSearch('search'), | ||
(params) => ({ ...params, q: params.search }), | ||
sanitize(fieldsToSend), | ||
camelToSnake(), | ||
]); | ||
|
||
try { | ||
const response = await sourceService.listSources( | ||
page, | ||
size, | ||
fields, | ||
sort, | ||
id, | ||
q, | ||
type, | ||
) | ||
const { items, next } = applyTransform(response.data, [ | ||
merge(getDefaultGetListResponse()), | ||
]); | ||
return { | ||
items: applyTransform(items, [listResponseHandler]), | ||
next, | ||
}; | ||
} catch (err) { | ||
throw applyTransform(err, [notify]); | ||
} | ||
}; | ||
|
||
const getSource = async ({ itemId: id }) => { | ||
const itemResponseHandler = (item) => { | ||
if(item.source.type) { | ||
item.source.type = item.source.type.toLowerCase(); | ||
} | ||
return item.source; | ||
}; | ||
|
||
try { | ||
const response = await sourceService.locateSource(id); | ||
return applyTransform(response.data, [ | ||
snakeToCamel(), | ||
itemResponseHandler, | ||
]); | ||
} catch (err) { | ||
throw applyTransform(err, [notify]); | ||
} | ||
}; | ||
|
||
const preRequestHandler = (item) => { | ||
return { | ||
...item, | ||
type: item.type.toUpperCase(), | ||
} | ||
}; | ||
|
||
const addSource = async ({ itemInstance }) => { | ||
const item = applyTransform(itemInstance, [ | ||
preRequestHandler, | ||
sanitize(fieldsToSend), | ||
camelToSnake(), | ||
]); | ||
try { | ||
const response = await sourceService.createSource(item); | ||
return applyTransform(response.data, [ | ||
snakeToCamel() | ||
]); | ||
} catch (err) { | ||
throw applyTransform(err, [notify]); | ||
} | ||
}; | ||
|
||
const updateSource = async ({ itemInstance, itemId: id }) => { | ||
const item = applyTransform(itemInstance, [ | ||
preRequestHandler, | ||
camelToSnake(), | ||
sanitize(fieldsToSend)]); | ||
|
||
try { | ||
const response = await sourceService.updateSource(id, item); | ||
return applyTransform(response.data, [snakeToCamel()]); | ||
} catch (err) { | ||
throw applyTransform(err, [notify]); | ||
} | ||
}; | ||
|
||
const deleteSource = async ({ id }) => { | ||
try { | ||
const response = await sourceService.deleteSource(id); | ||
return applyTransform(response.data, []); | ||
} catch (err) { | ||
throw applyTransform(err, [notify]); | ||
} | ||
}; | ||
|
||
const SourcesAPI = { | ||
getList: getSourcesList, | ||
get: getSource, | ||
add: addSource, | ||
update: updateSource, | ||
delete: deleteSource, | ||
} | ||
|
||
export default SourcesAPI; |
63 changes: 63 additions & 0 deletions
63
...odules/configuration/modules/lookups/modules/sources/components/opened-source-general.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<template> | ||
<section> | ||
<header class="opened-card-header"> | ||
<h3 class="opened-card-header__title"> | ||
{{ t('reusable.generalInfo') }} | ||
</h3> | ||
</header> | ||
<div class="opened-card-input-grid"> | ||
<wt-input | ||
:label="t('reusable.name')" | ||
:value="itemInstance.name" | ||
required | ||
@input="setItemProp({ path: 'name', value: $event })" | ||
/> | ||
|
||
<wt-select | ||
:label="t('vocabulary.type')" | ||
:options="typesSourcesOptions" | ||
:value="currentTypeSource" | ||
required | ||
@input="setItemProp({ path: 'type', value: $event.id })" | ||
/> | ||
|
||
<wt-textarea | ||
:label="t('vocabulary.description')" | ||
:value="itemInstance.description" | ||
@input="setItemProp({ path: 'description', value: $event })" | ||
/> | ||
</div> | ||
</section> | ||
</template> | ||
|
||
<script setup> | ||
import { computed } from 'vue'; | ||
import { useCardStore } from '@webitel/ui-sdk/store'; | ||
import { useI18n } from 'vue-i18n'; | ||
import TypesSources from '../enums/TypesSources.enum.js'; | ||
const props = defineProps({ | ||
namespace: { | ||
type: String, | ||
required: true, | ||
}, | ||
}); | ||
const { t } = useI18n(); | ||
const { itemInstance, setItemProp } = useCardStore(props.namespace); | ||
const typesSourcesOptions = computed(() => Object.values(TypesSources).map((type) => { | ||
return { | ||
id: type, | ||
name: t(`lookups.sources.types.${type}`), | ||
}; | ||
})); | ||
const currentTypeSource = computed(() => { | ||
return typesSourcesOptions.value.find((type) => type.id === itemInstance.value?.type); | ||
}); | ||
</script> | ||
<style lang="scss" scoped> | ||
</style> |
Oops, something went wrong.