|
| 1 | +<template> |
| 2 | + <v-container> |
| 3 | + <component :is="currentComponent" @update:repos="repos = $event"></component> |
| 4 | + <router-view @update:repos="repos = $event"> </router-view> |
| 5 | + <div v-if="repos.length > 0"> |
| 6 | + <repository-table :repositories="repos" @update:selected="form.selected = $event"> |
| 7 | + </repository-table> |
| 8 | + <p class="text-subtitle-2 mt-6 mb-4">Schedule</p> |
| 9 | + <div class="mb-6"> |
| 10 | + <interval-selector v-model="form.interval"></interval-selector> |
| 11 | + </div> |
| 12 | + <v-alert |
| 13 | + v-model="alert.isOpen" |
| 14 | + :text="alert.text" |
| 15 | + :icon="alert.icon" |
| 16 | + :color="alert.color" |
| 17 | + density="compact" |
| 18 | + class="mb-6" |
| 19 | + /> |
| 20 | + <v-btn :loading="loading" color="primary" @click="createTasks"> Schedule selected </v-btn> |
| 21 | + </div> |
| 22 | + </v-container> |
| 23 | +</template> |
| 24 | +<script> |
| 25 | +import IntervalSelector from '@/components/IntervalSelector.vue' |
| 26 | +import RepositoryTable from '@/components/RepositoryTable.vue' |
| 27 | +import { defineAsyncComponent } from 'vue' |
| 28 | +import { API } from '@/services/api' |
| 29 | +import { getTaskArgs } from '@/utils/datasources' |
| 30 | +
|
| 31 | +export default { |
| 32 | + components: { |
| 33 | + GitHubView: defineAsyncComponent(() => import('./GitHub.vue')), |
| 34 | + SBoMView: defineAsyncComponent(() => import('./LoadSbom.vue')), |
| 35 | + IntervalSelector, |
| 36 | + RepositoryTable |
| 37 | + }, |
| 38 | + data() { |
| 39 | + return { |
| 40 | + errorMessage: null, |
| 41 | + loading: false, |
| 42 | + repos: [], |
| 43 | + form: { |
| 44 | + interval: '604800', |
| 45 | + selected: [] |
| 46 | + }, |
| 47 | + alert: { |
| 48 | + isOpen: false, |
| 49 | + text: '', |
| 50 | + color: 'error', |
| 51 | + icon: 'mdi-warning' |
| 52 | + } |
| 53 | + } |
| 54 | + }, |
| 55 | + computed: { |
| 56 | + project() { |
| 57 | + return this.$route.query?.project |
| 58 | + }, |
| 59 | + ecosystem() { |
| 60 | + return this.$route.query?.ecosystem |
| 61 | + }, |
| 62 | + currentComponent() { |
| 63 | + if (this.$route.query?.create === 'github') { |
| 64 | + return 'GitHubView' |
| 65 | + } else if (this.$route.query?.create === 'sbom') { |
| 66 | + return 'SBoMView' |
| 67 | + } |
| 68 | + return null |
| 69 | + } |
| 70 | + }, |
| 71 | + methods: { |
| 72 | + async createTasks() { |
| 73 | + if (this.form.selected.length === 0) { |
| 74 | + Object.assign(this.alert, { |
| 75 | + isOpen: true, |
| 76 | + color: 'error', |
| 77 | + text: 'Select at least one URL and one category (commits, issues and/or pull requests) to retrieve.', |
| 78 | + icon: 'mdi-alert-outline' |
| 79 | + }) |
| 80 | + return |
| 81 | + } |
| 82 | + this.loading = true |
| 83 | +
|
| 84 | + Promise.allSettled( |
| 85 | + this.form.selected.map((task) => { |
| 86 | + const { datasource_type, category, uri, backend_args } = getTaskArgs( |
| 87 | + task.datasource, |
| 88 | + task.category, |
| 89 | + task.url |
| 90 | + ) |
| 91 | + return API.repository.create(this.ecosystem, this.project, { |
| 92 | + datasource_type, |
| 93 | + category, |
| 94 | + uri, |
| 95 | + backend_args, |
| 96 | + scheduler: { |
| 97 | + job_interval: this.form.interval, |
| 98 | + job_max_retries: 3 |
| 99 | + } |
| 100 | + }) |
| 101 | + }) |
| 102 | + ) |
| 103 | + .then((responses) => { |
| 104 | + const errors = responses |
| 105 | + .filter((res) => res.status === 'rejected') |
| 106 | + .map((error) => { |
| 107 | + if (error.reason.response.data && typeof error.reason.response.data === 'object') { |
| 108 | + return Object.values(error.reason.response.data).toString() |
| 109 | + } else { |
| 110 | + return error.reason.message |
| 111 | + } |
| 112 | + }) |
| 113 | + if (errors.length > 0) { |
| 114 | + Object.assign(this.alert, { |
| 115 | + isOpen: true, |
| 116 | + color: 'error', |
| 117 | + text: errors, |
| 118 | + icon: 'mdi-alert-outline' |
| 119 | + }) |
| 120 | + } else { |
| 121 | + this.$router.push({ |
| 122 | + name: 'ecosystems', |
| 123 | + query: { ecosystem: this.ecosystem, project: this.project } |
| 124 | + }) |
| 125 | + } |
| 126 | + }) |
| 127 | + .finally(() => { |
| 128 | + this.loading = false |
| 129 | + }) |
| 130 | + } |
| 131 | + } |
| 132 | +} |
| 133 | +</script> |
| 134 | +<style lang="scss" scoped> |
| 135 | +:deep(.v-form) { |
| 136 | + max-width: 600px; |
| 137 | +} |
| 138 | +
|
| 139 | +:deep(.v-table) { |
| 140 | + background-color: transparent; |
| 141 | +
|
| 142 | + .v-table__wrapper { |
| 143 | + background-color: rgb(var(--v-theme-surface)); |
| 144 | + border: thin solid rgba(0, 0, 0, 0.08); |
| 145 | + border-radius: 4px; |
| 146 | + max-height: 55vh; |
| 147 | + } |
| 148 | +} |
| 149 | +</style> |
0 commit comments