Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

3.0 KB
Raw Blame
<template>
  <div class="container">
    <div class="progress-header">
      <span class="status">
        <strong>{{ t('common.labels.status') }}</strong>
        <span class="status-badge" :class="importJob.status"> {{ statusLabel }} </span>
      </span>
      <span v-if="importJob.status === 'in_progress'" class="progress-percent"> {{ progress }}% </span>
    </div>

    <div v-if="importJob.status === 'in_progress'" class="progress-bar-container">
      <div class="progress-bar" :style="{ width: progress + '%' }"></div>
    </div>

    <div class="footer">
      <!-- eslint-disable-next-line vue/no-v-html -->
      <small v-if="displayErr" v-html="`${importJob.error_message}`"></small>
      <small v-if="importJob.failures > 0">{{ importJob.failures }} {{ t('common.status.failed') }}</small>
      <small v-if="importJob.created.length > 0">{{ importJob.created.length }} {{ t('common.status.completed') }}</small>
    </div>
  </div>
</template>

<script setup lang="ts">
import type { ImportJob } from '~/helpers/backups/Importer';

const props = defineProps<{ importJob: ImportJob<object, object | null> }>();

const { t } = useI18nT();

const progress = computed(() =>
  Math.floor(
    ((props.importJob.created.length + props.importJob.updated.length + props.importJob.failures) * 100) /
      ((props.importJob.toCreate.length || 0) + (props.importJob.toUpdate.length || 0)),
  ),
);
const statusLabel = computed(() => {
  switch (props.importJob.status) {
    case 'pending':
      return t('common.status.pending');
    case 'in_progress':
      return t('common.status.processing');
    case 'completed':
      return t('common.status.completed');
    case 'failed':
      return t('common.status.failed');
    default:
      return t('common.status.unknown');
  }
});

const displayErr = computed(() => props.importJob.status === 'failed' || props.importJob.error_message);
</script>

<style scoped lang="scss">
.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-badge {
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;

  &.pending {
    color: var(--orange);
    background: var(--orange-bg);
  }

  &.in_progress {
    color: var(--primary);
    background: var(--primary-bg);
  }

  &.completed {
    color: var(--green);
    background: var(--green-bg);
  }

  &.failed {
    color: var(--red);
    background: var(--red-bg);
  }
}

.progress-percent {
  font-weight: 600;
  color: var(--primary);
}

.progress-bar-container {
  width: 100%;
  height: 8px;
  margin-bottom: 0.75rem;
  border-radius: var(--radius-xs);
  background: var(--border);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: var(--radius-xs);
  background: var(--primary);
  transition: width $transition-medium ease;
}

.footer {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

small {
  color: var(--text-primary);
}
</style>