@devix-tecnologia/timeline-vue 1.0.2 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +148 -11
  2. package/dist/style.css +1 -1
  3. package/dist/timeline-vue.es.js +283 -256
  4. package/dist/types/components/timeline/atomos/AvatarTimeline.vue.d.ts +0 -1
  5. package/dist/types/components/timeline/atomos/BoxData.vue.d.ts +0 -1
  6. package/dist/types/components/timeline/atomos/Destaque.vue.d.ts +0 -1
  7. package/dist/types/components/timeline/atomos/Hora.vue.d.ts +0 -2
  8. package/dist/types/components/timeline/atomos/IconeCategoria.vue.d.ts +2 -3
  9. package/dist/types/components/timeline/atomos/IconeStatus.vue.d.ts +0 -1
  10. package/dist/types/components/timeline/atomos/SubtituloEvento.vue.d.ts +0 -1
  11. package/dist/types/components/timeline/atomos/TituloEvento.vue.d.ts +0 -1
  12. package/dist/types/components/timeline/moleculas/DescricaoEvento.vue.d.ts +0 -1
  13. package/dist/types/components/timeline/moleculas/EventoTimeline.vue.d.ts +84 -5
  14. package/dist/types/components/timeline/moleculas/HoraEvento.vue.d.ts +5 -3
  15. package/dist/types/components/timeline/moleculas/PerfilTimeline.vue.d.ts +0 -3
  16. package/dist/types/components/timeline/moleculas/SeparadorPeriodo.vue.d.ts +3 -7
  17. package/dist/types/components/timeline/moleculas/Topo.vue.d.ts +0 -1
  18. package/dist/types/components/timeline/organismos/Timeline.vue.d.ts +2 -5
  19. package/dist/types/components/timeline/type.d.ts +10 -7
  20. package/package.json +1 -1
  21. package/src/components/timeline/atomos/Destaque.vue +3 -3
  22. package/src/components/timeline/atomos/Hora.vue +7 -10
  23. package/src/components/timeline/atomos/IconeCategoria.vue +6 -6
  24. package/src/components/timeline/atomos/IconeStatus.vue +17 -16
  25. package/src/components/timeline/moleculas/DescricaoEvento.vue +5 -5
  26. package/src/components/timeline/moleculas/EventoTimeline.stories.ts +49 -49
  27. package/src/components/timeline/moleculas/EventoTimeline.vue +82 -26
  28. package/src/components/timeline/moleculas/HoraEvento.vue +5 -4
  29. package/src/components/timeline/moleculas/PerfilTimeline.vue +2 -29
  30. package/src/components/timeline/moleculas/SeparadorPeriodo.vue +26 -27
  31. package/src/components/timeline/organismos/Timeline.mock.ts +87 -57
  32. package/src/components/timeline/organismos/Timeline.stories.ts +22 -5
  33. package/src/components/timeline/organismos/Timeline.vue +102 -73
  34. package/src/components/timeline/type.ts +11 -7
@@ -1,30 +1,35 @@
1
1
  <template>
2
- <div>
3
- <div>
4
- <PerfilTimeline
5
- v-if="perfilTimeline !== null"
6
- :nomePerfil="perfilTimeline.nome"
7
- :imagemPerfil="perfilTimeline.imagem"
8
- :iconePerfil="perfilTimeline.icone"
9
- />
10
- </div>
11
-
12
- <div
13
- v-for="evento in eventosPorTipo"
14
- :key="evento.key"
15
- class="areaTimeline"
16
- >
2
+ <div class="areaTimeline">
3
+ <PerfilTimeline
4
+ v-if="perfilTimeline !== null"
5
+ :nomePerfil="perfilTimeline.nome"
6
+ :imagemPerfil="perfilTimeline.imagem"
7
+ :iconePerfil="perfilTimeline.icone"
8
+ />
9
+
10
+ <section class="timeline" :class="{ marginTop: perfilTimeline !== null }">
17
11
  <!-- SEPARADOR -->
18
- <div v-if="evento.tipo === 'dia'">
19
- <SeparadorPeriodo :dataSeparador="evento.valor.toDateString()" />
12
+ <div v-for="evento in eventosPorTipo" :key="evento.key">
13
+ <SeparadorPeriodo
14
+ v-if="evento.tipo === 'dia'"
15
+ :dataSeparador="evento.valor"
16
+ />
17
+ <!--loop-->
18
+ <EventoTimeline
19
+ v-if="evento.tipo === 'evento'"
20
+ :status="evento.valor.status"
21
+ :criticidade="evento.valor.criticidade"
22
+ :previsto="evento.valor.previsto"
23
+ :realizado="evento.valor.realizado"
24
+ :categoria="evento.valor.categoria"
25
+ :titulo="evento.valor.titulo"
26
+ :subtitulo="evento.valor.subtitulo"
27
+ :destaque="evento.valor.destaque"
28
+ :ehAtual="evento.valor.atual"
29
+ :aoCLicar="evento.valor.aoCLicar"
30
+ />
20
31
  </div>
21
- <div v-if="evento.tipo === 'evento'">
22
- <section class="timeline">
23
- <!--loop-->
24
- <EventoTimeline :dadosEvento="evento" />
25
- </section>
26
- </div>
27
- </div>
32
+ </section>
28
33
  </div>
29
34
  </template>
30
35
 
@@ -37,11 +42,9 @@ import { Evento } from "../type";
37
42
 
38
43
  type TipoEventoTimeline =
39
44
  | { tipo: "dia"; valor: Date; key: number }
40
- | { tipo: "evento"; valor: Evento; key: number; atual: boolean }
45
+ | { tipo: "evento"; valor: Evento; key: number }
41
46
  | { tipo: "eventos"; valor: Evento[]; key: number };
42
47
 
43
- // type Ordem = 'ascendente' | 'descendente';
44
-
45
48
  export default defineComponent({
46
49
  props: {
47
50
  perfilTimeline: {
@@ -52,10 +55,6 @@ export default defineComponent({
52
55
  required: true,
53
56
  type: Object,
54
57
  },
55
- // ordem: {
56
- // required: false,
57
- // type: Ordem,
58
- // },
59
58
  },
60
59
  components: {
61
60
  PerfilTimeline,
@@ -66,12 +65,29 @@ export default defineComponent({
66
65
  const dadosEventosTimeline: Evento[] = reactive(
67
66
  props.eventosTimeline as Array<Evento>
68
67
  );
68
+ let dadosEventosTimelineClone: Evento[] = reactive(dadosEventosTimeline);
69
+
70
+ function carregarListaEventos() {
71
+ dadosEventosTimelineClone = dadosEventosTimeline;
72
+ const resultado: Evento[] = filtraEventoAtual(dadosEventosTimelineClone);
73
+ dadosEventosTimelineClone.map((resp) => {
74
+ if (resultado[0].id === resp.id) {
75
+ resp.atual = true;
76
+ resp.scroll = true;
77
+ void scrollParaItemAtual();
78
+ } else {
79
+ resp.atual = false;
80
+ resp.scroll = false;
81
+ }
82
+ return {
83
+ evento: resp,
84
+ };
85
+ });
86
+ }
69
87
 
70
- const eventosOrdenados = dadosEventosTimeline.sort(
71
- (a: Evento, b: Evento) => {
72
- return a.data.getTime() - b.data.getTime();
73
- }
74
- );
88
+ const atualizarEventoAtual = () => {
89
+ setInterval(carregarListaEventos, 60000);
90
+ };
75
91
 
76
92
  const verifica_mesmo_dia = (a: Date, b: Date) => {
77
93
  const mesmo_dia = a.getDay() === b.getDay();
@@ -81,85 +97,94 @@ export default defineComponent({
81
97
  };
82
98
 
83
99
  //verifica qual evento está mais próximo da hora atual e coloca ele numa nova lista na primeira posição
84
- function filtraEventoAtual(eventos: Evento[]) {
100
+ const filtraEventoAtual = (eventos: Evento[]) => {
85
101
  if (eventos) {
86
102
  const agora = Date.now();
87
- let minDiff = null;
103
+ let minDiff: number | null = null;
88
104
  let listaEventos = [];
89
105
  for (const e of eventos) {
90
106
  const t = e.data.getTime();
91
- const diff = Math.abs(agora - t);
92
- if (minDiff === null || (diff < minDiff && t <= agora)) {
93
- minDiff = diff;
94
- listaEventos.length = 0;
95
- }
96
- //se o evento já estiver marcado como realizado, cancelado ou adiado, ele pula para o próximo da lista.
97
107
  if (e.status === "planejado" || e.status === "atrasado") {
108
+ const diff: number = Math.abs(agora - e.data.getTime());
109
+ if (minDiff === null || (diff < minDiff && t <= agora)) {
110
+ minDiff = diff;
111
+ listaEventos.length = 0;
112
+ } else if (diff > minDiff) {
113
+ continue;
114
+ }
98
115
  listaEventos.push(e);
99
116
  }
100
117
  }
101
118
  return listaEventos;
102
119
  } else {
103
- console.log("vazio.. ", []);
104
120
  return [];
105
121
  }
106
- }
107
- const eventosFiltrados: Evento[] = filtraEventoAtual(eventosOrdenados);
108
- const eventoAtual = eventosFiltrados[0]
109
- ? (eventosFiltrados[0] as Evento)
110
- : null;
111
-
112
- //lista de eventos
113
- const eventosPorTipo = computed(() => {
114
- if (dadosEventosTimeline) {
115
- let result: Array<TipoEventoTimeline> = [];
122
+ };
123
+
124
+ // lista de eventos por tipo
125
+ const eventosTimeline = computed(() => {
126
+ void atualizarEventoAtual();
127
+
128
+ const eventosOrdenados = dadosEventosTimelineClone.sort(
129
+ (a: Evento, b: Evento) => {
130
+ return a.data.getTime() - b.data.getTime();
131
+ }
132
+ );
133
+ if (eventosOrdenados) {
134
+ let resultado: Array<TipoEventoTimeline> = [];
116
135
  let dataAtual: Date | null = null;
117
136
  let idx = 0;
137
+ let statusEvento;
118
138
 
119
139
  for (const evento of eventosOrdenados) {
140
+ const agora = new Date();
120
141
  const dataEvento = evento.data;
121
-
142
+ statusEvento = evento.status;
143
+ const toleranciaEvento = evento.tolerancia * 60 * 1000;
144
+
145
+ //altera status para atrasado
146
+ if (
147
+ statusEvento === "planejado" &&
148
+ dataEvento.getTime() + toleranciaEvento < agora.getTime()
149
+ ) {
150
+ evento.status = "atrasado";
151
+ }
122
152
  if (!dataAtual || !verifica_mesmo_dia(dataAtual, dataEvento)) {
123
153
  dataAtual = dataEvento;
124
- result.push({
154
+ resultado.push({
125
155
  tipo: "dia",
126
156
  valor: evento.data,
127
157
  key: ++idx,
128
158
  });
129
159
  }
130
-
131
- result.push({
160
+ resultado.push({
132
161
  tipo: "evento",
133
162
  valor: evento,
134
163
  key: ++idx,
135
- atual:
136
- eventoAtual === null
137
- ? false
138
- : evento.id === eventoAtual.id
139
- ? true
140
- : false,
141
164
  });
142
165
  }
143
- return result;
166
+ return resultado;
144
167
  } else {
145
168
  return [];
146
169
  }
147
170
  });
148
171
 
149
- return {
150
- eventosPorTipo,
151
- };
152
- },
153
- methods: {
154
- scrollParaItemAtual() {
172
+ const scrollParaItemAtual = () => {
155
173
  const itemAtual = document.querySelector(".atual");
156
174
  itemAtual?.scrollIntoView({
157
175
  behavior: "smooth",
158
176
  block: "center",
159
177
  });
160
- },
178
+ };
179
+
180
+ carregarListaEventos();
181
+ return {
182
+ eventosPorTipo: eventosTimeline,
183
+ scrollParaItemAtual,
184
+ };
161
185
  },
162
186
  mounted() {
187
+ // Aguardando a renderização para fazer scroll
163
188
  this.scrollParaItemAtual();
164
189
  },
165
190
  });
@@ -185,4 +210,8 @@ export default defineComponent({
185
210
  width: 100%;
186
211
  position: relative;
187
212
  }
213
+
214
+ .marginTop {
215
+ margin-top: 8rem;
216
+ }
188
217
  </style>
@@ -4,20 +4,22 @@ export type Perfil = {
4
4
  icone: string | null;
5
5
  };
6
6
 
7
+ export type Categoria = {
8
+ nome: string;
9
+ icone: string;
10
+ };
11
+
7
12
  export type Evento = {
8
13
  id: string;
9
14
  data: Date;
10
15
  previsto: Date;
11
16
  duracao: number | null;
12
17
  realizado: Date | null;
13
- tolerancia: number | null;
18
+ tolerancia: number;
14
19
  titulo: string;
15
20
  subtitulo: string;
16
21
  destaque: string;
17
- categoria: {
18
- nome: string;
19
- icone: string;
20
- };
22
+ categoria: Categoria;
21
23
  status:
22
24
  | "atrasado"
23
25
  | "adiantado"
@@ -25,6 +27,8 @@ export type Evento = {
25
27
  | "realizado"
26
28
  | "planejado"
27
29
  | "cancelado";
28
- criticidade: string;
29
- acao: boolean;
30
+ criticidade: "baixa" | "media" | "alta";
31
+ aoCLicar?: VoidFunction;
32
+ atual: boolean;
33
+ scroll: boolean;
30
34
  };