Skip to content

Instantly share code, notes, and snippets.

@iErik
Created April 16, 2019 17:01
Show Gist options
  • Select an option

  • Save iErik/568dfe3f916311cae1af21bac54badd3 to your computer and use it in GitHub Desktop.

Select an option

Save iErik/568dfe3f916311cae1af21bac54badd3 to your computer and use it in GitHub Desktop.
<template>
<div class="employee-info-timeline">
<div ref="shadowed" class="wrapper">
<info-timeline-item
v-for="(item, index) in timelineItems"
:key="index"
:fields="item.fields"
:item-info="item.itemInfo"
v-on="$listeners"
/>
</div>
</div>
</template>
<script>
import InfoTimelineItem from '@components/Employee/Details/Common/InfoTimelineItem'
import { Shadowed } from 'convenia-components'
export default {
components: { InfoTimelineItem },
mixins: [ Shadowed() ],
props: {
items: {
type: Array,
required: true
}
},
computed: {
timelineItems () {
return this.items.map((item, index) => {
const { subHighlight, highlight} = Object.keys(item || {})
.reduce((acc, fieldName) => {
const cardProps = item[fieldName].infoCardProps || {}
return {
...acc,
...(cardProps.highlight ? { highlight: { ...item[fieldName], fieldName } } : {}),
...(cardProps.subHighlight ? { subHighlight: { ...item[fieldName], fieldName } } : {}),
}
}, { })
return {
itemInfo: {
index,
id: item.id.value,
title: highlight || {},
subTitle: subHighlight || {},
icon: ((highlight || {}) || infoCardProps).icon
},
fields: {
...item,
[highlight.fieldName]: { hide: true },
[subHighlight.fieldName]: { hide: true },
}
}
})
}
}
}
</script>
<style lang="scss">
.employee-info-timeline {
display: flex;
flex-direction: column;
margin-top: 20px;
max-height: 625px;
overflow-y: hidden;
@include shadowed(150px);
& > .wrapper {
overflow-y: auto;
flex: 1;
}
}
</style>
<template>
<div :class="['employee-info-timeline-item', { '-shrunk': hideContents }]">
<div class="header">
<div class="lead">
<c-flag
:primary="!hideContents"
:grey="hideContents"
:icon="itemInfo.icon"
class="flag"
/>
<div class="info">
<span class="text -title">{{ getValue(itemInfo.title) }}</span>
<span class="text">{{ getValue(itemInfo.subTitle) }}</span>
</div>
</div>
<div class="actions">
<c-button
flat
size="30"
icon-size="15"
class="action"
icon="pencil"
@click="$emit('edit', `${title}.${itemInfo.index}`)"
/>
<c-button
flat
error
size="30"
icon-size="15"
class="action"
icon="cross"
@click="$emit('delete', itemInfo.id)"
/>
<c-button
flat
size="30"
icon-size="15"
class="action"
icon="chevron-up"
@click="hideContents = !hideContents"
/>
</div>
</div>
<div
ref="contentWrapper"
class="content"
:style="{ height: hideContents ? '0px' : `${contentHeight}px` }"
>
<info-chunk :fields="fields" />
</div>
</div>
</template>
<script>
import InfoChunk from '@common/InfoChunk'
import Collapsible from '@mixins/Collapsible'
// import MediaQuery from '@mixins/MediaQuery'
import { formatToBRL } from '@modules/formatters'
export default {
components: { InfoChunk },
mixins: [ Collapsible() ],
props: {
fields: {
type: Object,
required: true
},
itemInfo: {
type: Object,
required: true
}
},
data () {
return {
hideContents: !(this.itemInfo.index === 0)
}
},
methods: {
getValue (field) {
if (Array.isArray(field.value)) {
const values = (field.value || [])
.map(v => field.displayBy ? v[field.displayBy] : v)
return values.join(', ')
}
if (typeof field.value === 'object' && field.value.value === null) return '-'
if (typeof field.value === 'boolean') return field.value ? 'Sim' : 'Não'
if (field.displayBy) return (field.value || {})[field.displayBy]
if (field.isMoney) return formatToBRL(field.value)
return field.value
}
}
}
</script>
<style lang="scss">
.employee-info-timeline-item {
display: flex;
flex-direction: column;
border: $base-border;
border-radius: 5px;
padding-bottom: 30px;
margin: 0 0 20px 55px;
transition: padding-bottom .3s;
&.-shrunk { padding-bottom: 20px; }
& > .header {
display: flex;
justify-content: space-between;
padding: 20px;
padding-bottom: 0px;
& > .lead { display: flex; align-items: center; }
& > .lead > .flag {
flex-shrink: 0;
padding: 10px;
transition: background .3s;
}
& > .lead > .info {
display: flex;
flex-direction: column;
margin-left: 15px;
& > .text.-title {
font-family: $title-font-family;
font-weight: $title-font-weight;
font-size: 12px;
color: map-get($text-color, base-80);
margin-bottom: 2px;
}
& > .text {
font-size: 11px;
color: map-get($text-color, base-50);
}
}
& > .actions {
display: flex;
align-items: center;
& > .action:not(:last-child) { margin-right: 10px; }
}
}
& > .content { transition: height .3s; overflow: hidden; }
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment