|
@@ -4,18 +4,20 @@ import { useRouter } from "vue-router";
|
|
|
import LayoutSistema from "../../layout/LayoutSistema.vue";
|
|
import LayoutSistema from "../../layout/LayoutSistema.vue";
|
|
|
import BotaoAlterarTema from "../../components/BotaoAlterarTema.vue";
|
|
import BotaoAlterarTema from "../../components/BotaoAlterarTema.vue";
|
|
|
import { useAuth } from "../../composables/useAuth.js";
|
|
import { useAuth } from "../../composables/useAuth.js";
|
|
|
-import { sincronizarAtendimentos } from "../../api/atendimentos.js";
|
|
|
|
|
|
|
+import { sincronizarAtendimentos, sincronizarTodosAtendimentos } from "../../api/atendimentos.js";
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
const router = useRouter();
|
|
|
const { user } = useAuth();
|
|
const { user } = useAuth();
|
|
|
const isAdmin = computed(() => String(user.value?.Nivel) === "3");
|
|
const isAdmin = computed(() => String(user.value?.Nivel) === "3");
|
|
|
|
|
|
|
|
const sincronizando = ref(false);
|
|
const sincronizando = ref(false);
|
|
|
|
|
+const importandoTudo = ref(false);
|
|
|
|
|
+const syncOcupado = computed(() => sincronizando.value || importandoTudo.value);
|
|
|
const syncResultado = ref(null);
|
|
const syncResultado = ref(null);
|
|
|
const syncErro = ref("");
|
|
const syncErro = ref("");
|
|
|
|
|
|
|
|
async function sincronizarAgora() {
|
|
async function sincronizarAgora() {
|
|
|
- if (sincronizando.value) return;
|
|
|
|
|
|
|
+ if (syncOcupado.value) return;
|
|
|
sincronizando.value = true;
|
|
sincronizando.value = true;
|
|
|
syncResultado.value = null;
|
|
syncResultado.value = null;
|
|
|
syncErro.value = "";
|
|
syncErro.value = "";
|
|
@@ -28,6 +30,20 @@ async function sincronizarAgora() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+async function importarTudo() {
|
|
|
|
|
+ if (syncOcupado.value) return;
|
|
|
|
|
+ importandoTudo.value = true;
|
|
|
|
|
+ syncResultado.value = null;
|
|
|
|
|
+ syncErro.value = "";
|
|
|
|
|
+ try {
|
|
|
|
|
+ syncResultado.value = await sincronizarTodosAtendimentos();
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ syncErro.value = err?.message ?? "Falha ao importar";
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ importandoTudo.value = false;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function irParaUsuarios() {
|
|
function irParaUsuarios() {
|
|
|
router.push({ name: "usuarios" });
|
|
router.push({ name: "usuarios" });
|
|
|
}
|
|
}
|
|
@@ -125,19 +141,32 @@ function irParaUsuarios() {
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
- <button
|
|
|
|
|
- type="button"
|
|
|
|
|
- class="shrink-0 rounded-lg bg-primary px-4 py-2 text-sm font-semibold text-white shadow-sm hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-60"
|
|
|
|
|
- :disabled="sincronizando"
|
|
|
|
|
- @click="sincronizarAgora"
|
|
|
|
|
- >
|
|
|
|
|
- {{ sincronizando ? "Sincronizando..." : "Sincronizar" }}
|
|
|
|
|
- </button>
|
|
|
|
|
|
|
+ <div class="flex shrink-0 items-center gap-2">
|
|
|
|
|
+ <button
|
|
|
|
|
+ type="button"
|
|
|
|
|
+ class="rounded-lg border border-gray-300 px-4 py-2 text-sm font-semibold text-gray-700 shadow-sm hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-60 dark:border-gray-600 dark:text-gray-200 dark:hover:bg-white/5"
|
|
|
|
|
+ :disabled="syncOcupado"
|
|
|
|
|
+ @click="importarTudo"
|
|
|
|
|
+ >
|
|
|
|
|
+ {{ importandoTudo ? "Importando..." : "Importar tudo" }}
|
|
|
|
|
+ </button>
|
|
|
|
|
+ <button
|
|
|
|
|
+ type="button"
|
|
|
|
|
+ class="rounded-lg bg-primary px-4 py-2 text-sm font-semibold text-white shadow-sm hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-60"
|
|
|
|
|
+ :disabled="syncOcupado"
|
|
|
|
|
+ @click="sincronizarAgora"
|
|
|
|
|
+ >
|
|
|
|
|
+ {{ sincronizando ? "Sincronizando..." : "Sincronizar" }}
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
+ <div v-if="importandoTudo" class="mt-4 rounded-lg bg-blue-50 px-4 py-3 text-xs text-blue-800 dark:bg-blue-900/30 dark:text-blue-300">
|
|
|
|
|
+ Importando todos os protocolos abertos — isso pode levar alguns minutos...
|
|
|
|
|
+ </div>
|
|
|
<div v-if="syncResultado" class="mt-4 rounded-lg bg-green-50 px-4 py-3 text-xs text-green-800 dark:bg-green-900/30 dark:text-green-300">
|
|
<div v-if="syncResultado" class="mt-4 rounded-lg bg-green-50 px-4 py-3 text-xs text-green-800 dark:bg-green-900/30 dark:text-green-300">
|
|
|
{{ syncResultado.importados }} de {{ syncResultado.processados }} protocolos importados
|
|
{{ syncResultado.importados }} de {{ syncResultado.processados }} protocolos importados
|
|
|
- ({{ syncResultado.mensagens }} mensagens).
|
|
|
|
|
|
|
+ ({{ syncResultado.mensagens }} mensagens<span v-if="syncResultado.paginas">, {{ syncResultado.paginas }} páginas</span>).
|
|
|
Total de protocolos abertos no chatbot: {{ syncResultado.total }}.
|
|
Total de protocolos abertos no chatbot: {{ syncResultado.total }}.
|
|
|
<span v-if="syncResultado.erros?.length"> {{ syncResultado.erros.length }} com erro.</span>
|
|
<span v-if="syncResultado.erros?.length"> {{ syncResultado.erros.length }} com erro.</span>
|
|
|
</div>
|
|
</div>
|