-
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.
feature: add shift template page[WTEL-5079]
- Loading branch information
Showing
20 changed files
with
1,323 additions
and
16 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
107 changes: 107 additions & 0 deletions
107
src/modules/lookups/modules/shift-templates/api/shiftTemplates.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,107 @@ | ||
import { getDefaultGetListResponse, getDefaultGetParams } 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 { ShiftTemplateServiceApiFactory } from 'webitel-sdk'; | ||
|
||
import instance from '../../../../../app/api/instance'; | ||
import configuration from '../../../../../app/api/openAPIConfig'; | ||
|
||
const shiftTemplateService = new ShiftTemplateServiceApiFactory(configuration, '', instance); | ||
|
||
const getShiftTemplateList = async (params) => { | ||
const { search: q, page, size, sort, fields } = applyTransform(params, [ | ||
merge(getDefaultGetParams()), | ||
starToSearch(), | ||
]); | ||
|
||
try { | ||
const response = await shiftTemplateService.searchShiftTemplate(q, page, size, sort, fields); | ||
const { items, next } = applyTransform(response.data, [ | ||
snakeToCamel(), | ||
merge(getDefaultGetListResponse()), | ||
]); | ||
return { | ||
items, | ||
next, | ||
}; | ||
} catch (err) { | ||
throw applyTransform(err, [notify]); | ||
} | ||
}; | ||
|
||
const itemResponseHandler = (item) => { | ||
const copy = { | ||
...item.item, | ||
}; | ||
|
||
copy.times = copy.times.map((time) => ({ | ||
...time, | ||
duration: time.end - time.start, | ||
}), []); | ||
|
||
return copy; | ||
}; | ||
|
||
const getShiftTemplate = async ({ itemId: id }) => { | ||
|
||
try { | ||
const response = await shiftTemplateService.readShiftTemplate(id); | ||
return applyTransform(response.data, [snakeToCamel(), itemResponseHandler]); | ||
} catch (err) { | ||
throw applyTransform(err, [notify]); | ||
} | ||
}; | ||
|
||
const fieldsToSend = ['name', 'description', 'times']; | ||
|
||
const addShiftTemplate = async ({ itemInstance }) => { | ||
const item = applyTransform(itemInstance, [sanitize(fieldsToSend), camelToSnake()]); | ||
try { | ||
const response = await shiftTemplateService.createShiftTemplate({ item: { ...item } }); | ||
return applyTransform(response.data, [snakeToCamel()]); | ||
} catch (err) { | ||
throw applyTransform(err, [notify]); | ||
} | ||
}; | ||
|
||
const updateShiftTemplate = async ({ itemInstance, itemId: id }) => { | ||
const item = applyTransform(itemInstance, [sanitize(fieldsToSend), camelToSnake()]); | ||
try { | ||
const response = await shiftTemplateService.updateShiftTemplate(id, { item: { ...item }}); | ||
return applyTransform(response.data, [snakeToCamel()]); | ||
} catch (err) { | ||
throw applyTransform(err, [notify]); | ||
} | ||
}; | ||
|
||
const deleteShiftTemplate = async ({ id }) => { | ||
try { | ||
const response = await shiftTemplateService.deleteShiftTemplate(id); | ||
return applyTransform(response.data, []); | ||
} catch (err) { | ||
throw applyTransform(err, [notify]); | ||
} | ||
}; | ||
|
||
const getShiftTemplatesLookup = (params) => | ||
getShiftTemplateList({ | ||
...params, | ||
fields: params.fields || ['id', 'name'], | ||
}); | ||
|
||
const ShiftTemplatesAPI = { | ||
getList: getShiftTemplateList, | ||
get: getShiftTemplate, | ||
add: addShiftTemplate, | ||
update: updateShiftTemplate, | ||
delete: deleteShiftTemplate, | ||
getLookup: getShiftTemplatesLookup, | ||
} | ||
|
||
export default ShiftTemplatesAPI; |
38 changes: 38 additions & 0 deletions
38
src/modules/lookups/modules/shift-templates/components/opened-shift-template-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,38 @@ | ||
<template> | ||
<section> | ||
<header class="content-header"> | ||
<h3 class="content-title"> | ||
{{ $t('objects.generalInfo') }} | ||
</h3> | ||
</header> | ||
<div class="object-input-grid object-input-grid__1-col object-input-grid__w50"> | ||
<wt-input | ||
:disabled="disableUserInput" | ||
:label="$t('objects.name')" | ||
:v="v.itemInstance.name" | ||
:value="itemInstance.name" | ||
required | ||
@input="setItemProp({ prop: 'name', value: $event })" | ||
/> | ||
<wt-textarea | ||
:disabled="disableUserInput" | ||
:label="$t('objects.description')" | ||
:value="itemInstance.description" | ||
@input="setItemProp({ prop: 'description', value: $event })" | ||
/> | ||
</div> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
import openedTabComponentMixin from '../../../../../app/mixins/objectPagesMixins/openedObjectTabMixin/openedTabComponentMixin'; | ||
export default { | ||
name: 'OpenedShiftTemplateGeneral', | ||
mixins: [openedTabComponentMixin], | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
</style> |
123 changes: 123 additions & 0 deletions
123
src/modules/lookups/modules/shift-templates/components/opened-shift-template-template.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,123 @@ | ||
<template> | ||
<section class="opened-calendar-work-week"> | ||
<header class="content-header"> | ||
<h3 class="content-title"> | ||
{{ $tc('objects.routing.chatGateways.templates.templates', 1) }} | ||
</h3> | ||
|
||
<div class="content-header__actions-wrap"> | ||
<wt-icon-btn | ||
v-if="!disableUserInput" | ||
class="icon-action" | ||
icon="plus" | ||
@click="addTemplate" | ||
/> | ||
</div> | ||
</header> | ||
|
||
<div class="table-wrapper"> | ||
<div class="table-wrapper__visible-scroll-wrapper"> | ||
<wt-table | ||
:data="itemInstance.times" | ||
:grid-actions="!disableUserInput" | ||
:headers="headers" | ||
:selectable="false" | ||
> | ||
<template #start="{ item, index }"> | ||
<wt-timepicker | ||
:disabled="disableUserInput" | ||
:value="minToSec(item.start)" | ||
:v="v.itemInstance.times.$each.$response.$data[index].start" | ||
format="hh:mm" | ||
@input="setStartTime({ index, value: secToMin($event) })" | ||
/> | ||
</template> | ||
<template #end="{ item, index }"> | ||
<wt-timepicker | ||
:disabled="disableUserInput" | ||
:value="minToSec(item.end)" | ||
format="hh:mm" | ||
:v="v.itemInstance.times.$each.$response.$data[index].end" | ||
@input="setEndTime({ index, value: secToMin($event) })" | ||
/> | ||
</template> | ||
<template #duration="{ item, index }"> | ||
<wt-timepicker | ||
:value="minToSec(item.duration)" | ||
format="hh:mm" | ||
type="number" | ||
@input="setDuration({ index, value: secToMin($event) })" | ||
/> | ||
</template> | ||
<template #actions="{ item, index }"> | ||
<wt-icon-action | ||
action="delete" | ||
@click="deleteTemplate(index)" | ||
/> | ||
</template> | ||
</wt-table> | ||
</div> | ||
</div> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
import { mapActions, mapState } from 'vuex'; | ||
import openedTabComponentMixin from '../../../../../app/mixins/objectPagesMixins/openedObjectTabMixin/openedTabComponentMixin'; | ||
export default { | ||
name: 'OpenedShiftTemplateTemplate', | ||
mixins: [openedTabComponentMixin], | ||
computed: { | ||
headers() { | ||
return [ | ||
{ | ||
value: 'start', | ||
text: this.$t('objects.lookups.calendars.start'), | ||
}, | ||
{ | ||
value: 'end', | ||
text: this.$t('objects.lookups.calendars.end'), | ||
}, | ||
{ | ||
value: 'duration', | ||
text: this.$t('objects.ccenter.queues.logs.duration'), | ||
}, | ||
]; | ||
}, | ||
}, | ||
methods: { | ||
...mapActions('lookups/shiftTemplates', { | ||
addTemplate: 'ADD_TEMPLATE', | ||
setTemplate: 'SET_TEMPLATE', | ||
deleteTemplate: 'DELETE_TEMPLATE', | ||
}), | ||
minToSec(min) { | ||
return min * 60; | ||
}, | ||
secToMin(sec) { | ||
return sec / 60; | ||
}, | ||
setStartTime({ index, value }) { | ||
this.setTemplate({ prop: 'start', index, value }); | ||
this.setTemplate({ prop: 'duration', index, value: this.itemInstance.times[index].end - this.itemInstance.times[index].start }); | ||
}, | ||
setEndTime({ index, value }) { | ||
this.setTemplate({ prop: 'end', index, value }); | ||
this.setTemplate({ prop: 'duration', index, value: this.itemInstance.times[index].end - this.itemInstance.times[index].start }); | ||
}, | ||
setDuration({ index, value }) { | ||
this.setTemplate({ prop: 'duration', index, value }); | ||
this.setTemplate({ prop: 'end', index, value: this.itemInstance.times[index].start + this.itemInstance.times[index].duration }); | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.wt-timepicker :deep(.wt-label) { | ||
display: none; | ||
} | ||
</style> | ||
|
Oops, something went wrong.